rcutree.c 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184
  1. /*
  2. * Read-Copy Update mechanism for mutual exclusion
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * Copyright IBM Corporation, 2008
  19. *
  20. * Authors: Dipankar Sarma <dipankar@in.ibm.com>
  21. * Manfred Spraul <manfred@colorfullife.com>
  22. * Paul E. McKenney <paulmck@linux.vnet.ibm.com> Hierarchical version
  23. *
  24. * Based on the original work by Paul McKenney <paulmck@us.ibm.com>
  25. * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
  26. *
  27. * For detailed explanation of Read-Copy Update mechanism see -
  28. * Documentation/RCU
  29. */
  30. #include <linux/types.h>
  31. #include <linux/kernel.h>
  32. #include <linux/init.h>
  33. #include <linux/spinlock.h>
  34. #include <linux/smp.h>
  35. #include <linux/rcupdate.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/sched.h>
  38. #include <linux/nmi.h>
  39. #include <linux/atomic.h>
  40. #include <linux/bitops.h>
  41. #include <linux/export.h>
  42. #include <linux/completion.h>
  43. #include <linux/moduleparam.h>
  44. #include <linux/percpu.h>
  45. #include <linux/notifier.h>
  46. #include <linux/cpu.h>
  47. #include <linux/mutex.h>
  48. #include <linux/time.h>
  49. #include <linux/kernel_stat.h>
  50. #include <linux/wait.h>
  51. #include <linux/kthread.h>
  52. #include <linux/prefetch.h>
  53. #include <linux/delay.h>
  54. #include <linux/stop_machine.h>
  55. #include <linux/random.h>
  56. #include "rcutree.h"
  57. #include <trace/events/rcu.h>
  58. #include "rcu.h"
  59. /* Data structures. */
  60. static struct lock_class_key rcu_node_class[RCU_NUM_LVLS];
  61. static struct lock_class_key rcu_fqs_class[RCU_NUM_LVLS];
  62. #define RCU_STATE_INITIALIZER(sname, cr) { \
  63. .level = { &sname##_state.node[0] }, \
  64. .call = cr, \
  65. .fqs_state = RCU_GP_IDLE, \
  66. .gpnum = 0UL - 300UL, \
  67. .completed = 0UL - 300UL, \
  68. .orphan_lock = __RAW_SPIN_LOCK_UNLOCKED(&sname##_state.orphan_lock), \
  69. .orphan_nxttail = &sname##_state.orphan_nxtlist, \
  70. .orphan_donetail = &sname##_state.orphan_donelist, \
  71. .barrier_mutex = __MUTEX_INITIALIZER(sname##_state.barrier_mutex), \
  72. .onoff_mutex = __MUTEX_INITIALIZER(sname##_state.onoff_mutex), \
  73. .name = #sname, \
  74. }
  75. struct rcu_state rcu_sched_state =
  76. RCU_STATE_INITIALIZER(rcu_sched, call_rcu_sched);
  77. DEFINE_PER_CPU(struct rcu_data, rcu_sched_data);
  78. struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh, call_rcu_bh);
  79. DEFINE_PER_CPU(struct rcu_data, rcu_bh_data);
  80. static struct rcu_state *rcu_state;
  81. LIST_HEAD(rcu_struct_flavors);
  82. /* Increase (but not decrease) the CONFIG_RCU_FANOUT_LEAF at boot time. */
  83. static int rcu_fanout_leaf = CONFIG_RCU_FANOUT_LEAF;
  84. module_param(rcu_fanout_leaf, int, 0444);
  85. int rcu_num_lvls __read_mostly = RCU_NUM_LVLS;
  86. static int num_rcu_lvl[] = { /* Number of rcu_nodes at specified level. */
  87. NUM_RCU_LVL_0,
  88. NUM_RCU_LVL_1,
  89. NUM_RCU_LVL_2,
  90. NUM_RCU_LVL_3,
  91. NUM_RCU_LVL_4,
  92. };
  93. int rcu_num_nodes __read_mostly = NUM_RCU_NODES; /* Total # rcu_nodes in use. */
  94. /*
  95. * The rcu_scheduler_active variable transitions from zero to one just
  96. * before the first task is spawned. So when this variable is zero, RCU
  97. * can assume that there is but one task, allowing RCU to (for example)
  98. * optimize synchronize_sched() to a simple barrier(). When this variable
  99. * is one, RCU must actually do all the hard work required to detect real
  100. * grace periods. This variable is also used to suppress boot-time false
  101. * positives from lockdep-RCU error checking.
  102. */
  103. int rcu_scheduler_active __read_mostly;
  104. EXPORT_SYMBOL_GPL(rcu_scheduler_active);
  105. /*
  106. * The rcu_scheduler_fully_active variable transitions from zero to one
  107. * during the early_initcall() processing, which is after the scheduler
  108. * is capable of creating new tasks. So RCU processing (for example,
  109. * creating tasks for RCU priority boosting) must be delayed until after
  110. * rcu_scheduler_fully_active transitions from zero to one. We also
  111. * currently delay invocation of any RCU callbacks until after this point.
  112. *
  113. * It might later prove better for people registering RCU callbacks during
  114. * early boot to take responsibility for these callbacks, but one step at
  115. * a time.
  116. */
  117. static int rcu_scheduler_fully_active __read_mostly;
  118. #ifdef CONFIG_RCU_BOOST
  119. /*
  120. * Control variables for per-CPU and per-rcu_node kthreads. These
  121. * handle all flavors of RCU.
  122. */
  123. static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
  124. DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
  125. DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
  126. DEFINE_PER_CPU(char, rcu_cpu_has_work);
  127. #endif /* #ifdef CONFIG_RCU_BOOST */
  128. static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu);
  129. static void invoke_rcu_core(void);
  130. static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp);
  131. /*
  132. * Track the rcutorture test sequence number and the update version
  133. * number within a given test. The rcutorture_testseq is incremented
  134. * on every rcutorture module load and unload, so has an odd value
  135. * when a test is running. The rcutorture_vernum is set to zero
  136. * when rcutorture starts and is incremented on each rcutorture update.
  137. * These variables enable correlating rcutorture output with the
  138. * RCU tracing information.
  139. */
  140. unsigned long rcutorture_testseq;
  141. unsigned long rcutorture_vernum;
  142. /*
  143. * Return true if an RCU grace period is in progress. The ACCESS_ONCE()s
  144. * permit this function to be invoked without holding the root rcu_node
  145. * structure's ->lock, but of course results can be subject to change.
  146. */
  147. static int rcu_gp_in_progress(struct rcu_state *rsp)
  148. {
  149. return ACCESS_ONCE(rsp->completed) != ACCESS_ONCE(rsp->gpnum);
  150. }
  151. /*
  152. * Note a quiescent state. Because we do not need to know
  153. * how many quiescent states passed, just if there was at least
  154. * one since the start of the grace period, this just sets a flag.
  155. * The caller must have disabled preemption.
  156. */
  157. void rcu_sched_qs(int cpu)
  158. {
  159. struct rcu_data *rdp = &per_cpu(rcu_sched_data, cpu);
  160. if (rdp->passed_quiesce == 0)
  161. trace_rcu_grace_period("rcu_sched", rdp->gpnum, "cpuqs");
  162. rdp->passed_quiesce = 1;
  163. }
  164. void rcu_bh_qs(int cpu)
  165. {
  166. struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu);
  167. if (rdp->passed_quiesce == 0)
  168. trace_rcu_grace_period("rcu_bh", rdp->gpnum, "cpuqs");
  169. rdp->passed_quiesce = 1;
  170. }
  171. /*
  172. * Note a context switch. This is a quiescent state for RCU-sched,
  173. * and requires special handling for preemptible RCU.
  174. * The caller must have disabled preemption.
  175. */
  176. void rcu_note_context_switch(int cpu)
  177. {
  178. trace_rcu_utilization("Start context switch");
  179. rcu_sched_qs(cpu);
  180. rcu_preempt_note_context_switch(cpu);
  181. trace_rcu_utilization("End context switch");
  182. }
  183. EXPORT_SYMBOL_GPL(rcu_note_context_switch);
  184. DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = {
  185. .dynticks_nesting = DYNTICK_TASK_EXIT_IDLE,
  186. .dynticks = ATOMIC_INIT(1),
  187. };
  188. static long blimit = 10; /* Maximum callbacks per rcu_do_batch. */
  189. static long qhimark = 10000; /* If this many pending, ignore blimit. */
  190. static long qlowmark = 100; /* Once only this many pending, use blimit. */
  191. module_param(blimit, long, 0444);
  192. module_param(qhimark, long, 0444);
  193. module_param(qlowmark, long, 0444);
  194. static ulong jiffies_till_first_fqs = RCU_JIFFIES_TILL_FORCE_QS;
  195. static ulong jiffies_till_next_fqs = RCU_JIFFIES_TILL_FORCE_QS;
  196. module_param(jiffies_till_first_fqs, ulong, 0644);
  197. module_param(jiffies_till_next_fqs, ulong, 0644);
  198. static void force_qs_rnp(struct rcu_state *rsp, int (*f)(struct rcu_data *));
  199. static void force_quiescent_state(struct rcu_state *rsp);
  200. static int rcu_pending(int cpu);
  201. /*
  202. * Return the number of RCU-sched batches processed thus far for debug & stats.
  203. */
  204. long rcu_batches_completed_sched(void)
  205. {
  206. return rcu_sched_state.completed;
  207. }
  208. EXPORT_SYMBOL_GPL(rcu_batches_completed_sched);
  209. /*
  210. * Return the number of RCU BH batches processed thus far for debug & stats.
  211. */
  212. long rcu_batches_completed_bh(void)
  213. {
  214. return rcu_bh_state.completed;
  215. }
  216. EXPORT_SYMBOL_GPL(rcu_batches_completed_bh);
  217. /*
  218. * Force a quiescent state for RCU BH.
  219. */
  220. void rcu_bh_force_quiescent_state(void)
  221. {
  222. force_quiescent_state(&rcu_bh_state);
  223. }
  224. EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state);
  225. /*
  226. * Record the number of times rcutorture tests have been initiated and
  227. * terminated. This information allows the debugfs tracing stats to be
  228. * correlated to the rcutorture messages, even when the rcutorture module
  229. * is being repeatedly loaded and unloaded. In other words, we cannot
  230. * store this state in rcutorture itself.
  231. */
  232. void rcutorture_record_test_transition(void)
  233. {
  234. rcutorture_testseq++;
  235. rcutorture_vernum = 0;
  236. }
  237. EXPORT_SYMBOL_GPL(rcutorture_record_test_transition);
  238. /*
  239. * Record the number of writer passes through the current rcutorture test.
  240. * This is also used to correlate debugfs tracing stats with the rcutorture
  241. * messages.
  242. */
  243. void rcutorture_record_progress(unsigned long vernum)
  244. {
  245. rcutorture_vernum++;
  246. }
  247. EXPORT_SYMBOL_GPL(rcutorture_record_progress);
  248. /*
  249. * Force a quiescent state for RCU-sched.
  250. */
  251. void rcu_sched_force_quiescent_state(void)
  252. {
  253. force_quiescent_state(&rcu_sched_state);
  254. }
  255. EXPORT_SYMBOL_GPL(rcu_sched_force_quiescent_state);
  256. /*
  257. * Does the CPU have callbacks ready to be invoked?
  258. */
  259. static int
  260. cpu_has_callbacks_ready_to_invoke(struct rcu_data *rdp)
  261. {
  262. return &rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL] &&
  263. rdp->nxttail[RCU_DONE_TAIL] != NULL;
  264. }
  265. /*
  266. * Does the current CPU require a not-yet-started grace period?
  267. * The caller must have disabled interrupts to prevent races with
  268. * normal callback registry.
  269. */
  270. static int
  271. cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp)
  272. {
  273. int i;
  274. if (rcu_gp_in_progress(rsp))
  275. return 0; /* No, a grace period is already in progress. */
  276. if (rcu_nocb_needs_gp(rdp))
  277. return 1; /* Yes, a no-CBs CPU needs one. */
  278. if (!rdp->nxttail[RCU_NEXT_TAIL])
  279. return 0; /* No, this is a no-CBs (or offline) CPU. */
  280. if (*rdp->nxttail[RCU_NEXT_READY_TAIL])
  281. return 1; /* Yes, this CPU has newly registered callbacks. */
  282. for (i = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++)
  283. if (rdp->nxttail[i - 1] != rdp->nxttail[i] &&
  284. ULONG_CMP_LT(ACCESS_ONCE(rsp->completed),
  285. rdp->nxtcompleted[i]))
  286. return 1; /* Yes, CBs for future grace period. */
  287. return 0; /* No grace period needed. */
  288. }
  289. /*
  290. * Return the root node of the specified rcu_state structure.
  291. */
  292. static struct rcu_node *rcu_get_root(struct rcu_state *rsp)
  293. {
  294. return &rsp->node[0];
  295. }
  296. /*
  297. * rcu_eqs_enter_common - current CPU is moving towards extended quiescent state
  298. *
  299. * If the new value of the ->dynticks_nesting counter now is zero,
  300. * we really have entered idle, and must do the appropriate accounting.
  301. * The caller must have disabled interrupts.
  302. */
  303. static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
  304. bool user)
  305. {
  306. trace_rcu_dyntick("Start", oldval, rdtp->dynticks_nesting);
  307. if (!user && !is_idle_task(current)) {
  308. struct task_struct *idle = idle_task(smp_processor_id());
  309. trace_rcu_dyntick("Error on entry: not idle task", oldval, 0);
  310. ftrace_dump(DUMP_ORIG);
  311. WARN_ONCE(1, "Current pid: %d comm: %s / Idle pid: %d comm: %s",
  312. current->pid, current->comm,
  313. idle->pid, idle->comm); /* must be idle task! */
  314. }
  315. rcu_prepare_for_idle(smp_processor_id());
  316. /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
  317. smp_mb__before_atomic_inc(); /* See above. */
  318. atomic_inc(&rdtp->dynticks);
  319. smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
  320. WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
  321. /*
  322. * It is illegal to enter an extended quiescent state while
  323. * in an RCU read-side critical section.
  324. */
  325. rcu_lockdep_assert(!lock_is_held(&rcu_lock_map),
  326. "Illegal idle entry in RCU read-side critical section.");
  327. rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map),
  328. "Illegal idle entry in RCU-bh read-side critical section.");
  329. rcu_lockdep_assert(!lock_is_held(&rcu_sched_lock_map),
  330. "Illegal idle entry in RCU-sched read-side critical section.");
  331. }
  332. /*
  333. * Enter an RCU extended quiescent state, which can be either the
  334. * idle loop or adaptive-tickless usermode execution.
  335. */
  336. static void rcu_eqs_enter(bool user)
  337. {
  338. long long oldval;
  339. struct rcu_dynticks *rdtp;
  340. rdtp = &__get_cpu_var(rcu_dynticks);
  341. oldval = rdtp->dynticks_nesting;
  342. WARN_ON_ONCE((oldval & DYNTICK_TASK_NEST_MASK) == 0);
  343. if ((oldval & DYNTICK_TASK_NEST_MASK) == DYNTICK_TASK_NEST_VALUE)
  344. rdtp->dynticks_nesting = 0;
  345. else
  346. rdtp->dynticks_nesting -= DYNTICK_TASK_NEST_VALUE;
  347. rcu_eqs_enter_common(rdtp, oldval, user);
  348. }
  349. /**
  350. * rcu_idle_enter - inform RCU that current CPU is entering idle
  351. *
  352. * Enter idle mode, in other words, -leave- the mode in which RCU
  353. * read-side critical sections can occur. (Though RCU read-side
  354. * critical sections can occur in irq handlers in idle, a possibility
  355. * handled by irq_enter() and irq_exit().)
  356. *
  357. * We crowbar the ->dynticks_nesting field to zero to allow for
  358. * the possibility of usermode upcalls having messed up our count
  359. * of interrupt nesting level during the prior busy period.
  360. */
  361. void rcu_idle_enter(void)
  362. {
  363. unsigned long flags;
  364. local_irq_save(flags);
  365. rcu_eqs_enter(false);
  366. local_irq_restore(flags);
  367. }
  368. EXPORT_SYMBOL_GPL(rcu_idle_enter);
  369. #ifdef CONFIG_RCU_USER_QS
  370. /**
  371. * rcu_user_enter - inform RCU that we are resuming userspace.
  372. *
  373. * Enter RCU idle mode right before resuming userspace. No use of RCU
  374. * is permitted between this call and rcu_user_exit(). This way the
  375. * CPU doesn't need to maintain the tick for RCU maintenance purposes
  376. * when the CPU runs in userspace.
  377. */
  378. void rcu_user_enter(void)
  379. {
  380. rcu_eqs_enter(1);
  381. }
  382. /**
  383. * rcu_user_enter_after_irq - inform RCU that we are going to resume userspace
  384. * after the current irq returns.
  385. *
  386. * This is similar to rcu_user_enter() but in the context of a non-nesting
  387. * irq. After this call, RCU enters into idle mode when the interrupt
  388. * returns.
  389. */
  390. void rcu_user_enter_after_irq(void)
  391. {
  392. unsigned long flags;
  393. struct rcu_dynticks *rdtp;
  394. local_irq_save(flags);
  395. rdtp = &__get_cpu_var(rcu_dynticks);
  396. /* Ensure this irq is interrupting a non-idle RCU state. */
  397. WARN_ON_ONCE(!(rdtp->dynticks_nesting & DYNTICK_TASK_MASK));
  398. rdtp->dynticks_nesting = 1;
  399. local_irq_restore(flags);
  400. }
  401. #endif /* CONFIG_RCU_USER_QS */
  402. /**
  403. * rcu_irq_exit - inform RCU that current CPU is exiting irq towards idle
  404. *
  405. * Exit from an interrupt handler, which might possibly result in entering
  406. * idle mode, in other words, leaving the mode in which read-side critical
  407. * sections can occur.
  408. *
  409. * This code assumes that the idle loop never does anything that might
  410. * result in unbalanced calls to irq_enter() and irq_exit(). If your
  411. * architecture violates this assumption, RCU will give you what you
  412. * deserve, good and hard. But very infrequently and irreproducibly.
  413. *
  414. * Use things like work queues to work around this limitation.
  415. *
  416. * You have been warned.
  417. */
  418. void rcu_irq_exit(void)
  419. {
  420. unsigned long flags;
  421. long long oldval;
  422. struct rcu_dynticks *rdtp;
  423. local_irq_save(flags);
  424. rdtp = &__get_cpu_var(rcu_dynticks);
  425. oldval = rdtp->dynticks_nesting;
  426. rdtp->dynticks_nesting--;
  427. WARN_ON_ONCE(rdtp->dynticks_nesting < 0);
  428. if (rdtp->dynticks_nesting)
  429. trace_rcu_dyntick("--=", oldval, rdtp->dynticks_nesting);
  430. else
  431. rcu_eqs_enter_common(rdtp, oldval, true);
  432. local_irq_restore(flags);
  433. }
  434. /*
  435. * rcu_eqs_exit_common - current CPU moving away from extended quiescent state
  436. *
  437. * If the new value of the ->dynticks_nesting counter was previously zero,
  438. * we really have exited idle, and must do the appropriate accounting.
  439. * The caller must have disabled interrupts.
  440. */
  441. static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
  442. int user)
  443. {
  444. smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
  445. atomic_inc(&rdtp->dynticks);
  446. /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
  447. smp_mb__after_atomic_inc(); /* See above. */
  448. WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
  449. rcu_cleanup_after_idle(smp_processor_id());
  450. trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
  451. if (!user && !is_idle_task(current)) {
  452. struct task_struct *idle = idle_task(smp_processor_id());
  453. trace_rcu_dyntick("Error on exit: not idle task",
  454. oldval, rdtp->dynticks_nesting);
  455. ftrace_dump(DUMP_ORIG);
  456. WARN_ONCE(1, "Current pid: %d comm: %s / Idle pid: %d comm: %s",
  457. current->pid, current->comm,
  458. idle->pid, idle->comm); /* must be idle task! */
  459. }
  460. }
  461. /*
  462. * Exit an RCU extended quiescent state, which can be either the
  463. * idle loop or adaptive-tickless usermode execution.
  464. */
  465. static void rcu_eqs_exit(bool user)
  466. {
  467. struct rcu_dynticks *rdtp;
  468. long long oldval;
  469. rdtp = &__get_cpu_var(rcu_dynticks);
  470. oldval = rdtp->dynticks_nesting;
  471. WARN_ON_ONCE(oldval < 0);
  472. if (oldval & DYNTICK_TASK_NEST_MASK)
  473. rdtp->dynticks_nesting += DYNTICK_TASK_NEST_VALUE;
  474. else
  475. rdtp->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
  476. rcu_eqs_exit_common(rdtp, oldval, user);
  477. }
  478. /**
  479. * rcu_idle_exit - inform RCU that current CPU is leaving idle
  480. *
  481. * Exit idle mode, in other words, -enter- the mode in which RCU
  482. * read-side critical sections can occur.
  483. *
  484. * We crowbar the ->dynticks_nesting field to DYNTICK_TASK_NEST to
  485. * allow for the possibility of usermode upcalls messing up our count
  486. * of interrupt nesting level during the busy period that is just
  487. * now starting.
  488. */
  489. void rcu_idle_exit(void)
  490. {
  491. unsigned long flags;
  492. local_irq_save(flags);
  493. rcu_eqs_exit(false);
  494. local_irq_restore(flags);
  495. }
  496. EXPORT_SYMBOL_GPL(rcu_idle_exit);
  497. #ifdef CONFIG_RCU_USER_QS
  498. /**
  499. * rcu_user_exit - inform RCU that we are exiting userspace.
  500. *
  501. * Exit RCU idle mode while entering the kernel because it can
  502. * run a RCU read side critical section anytime.
  503. */
  504. void rcu_user_exit(void)
  505. {
  506. rcu_eqs_exit(1);
  507. }
  508. /**
  509. * rcu_user_exit_after_irq - inform RCU that we won't resume to userspace
  510. * idle mode after the current non-nesting irq returns.
  511. *
  512. * This is similar to rcu_user_exit() but in the context of an irq.
  513. * This is called when the irq has interrupted a userspace RCU idle mode
  514. * context. When the current non-nesting interrupt returns after this call,
  515. * the CPU won't restore the RCU idle mode.
  516. */
  517. void rcu_user_exit_after_irq(void)
  518. {
  519. unsigned long flags;
  520. struct rcu_dynticks *rdtp;
  521. local_irq_save(flags);
  522. rdtp = &__get_cpu_var(rcu_dynticks);
  523. /* Ensure we are interrupting an RCU idle mode. */
  524. WARN_ON_ONCE(rdtp->dynticks_nesting & DYNTICK_TASK_NEST_MASK);
  525. rdtp->dynticks_nesting += DYNTICK_TASK_EXIT_IDLE;
  526. local_irq_restore(flags);
  527. }
  528. #endif /* CONFIG_RCU_USER_QS */
  529. /**
  530. * rcu_irq_enter - inform RCU that current CPU is entering irq away from idle
  531. *
  532. * Enter an interrupt handler, which might possibly result in exiting
  533. * idle mode, in other words, entering the mode in which read-side critical
  534. * sections can occur.
  535. *
  536. * Note that the Linux kernel is fully capable of entering an interrupt
  537. * handler that it never exits, for example when doing upcalls to
  538. * user mode! This code assumes that the idle loop never does upcalls to
  539. * user mode. If your architecture does do upcalls from the idle loop (or
  540. * does anything else that results in unbalanced calls to the irq_enter()
  541. * and irq_exit() functions), RCU will give you what you deserve, good
  542. * and hard. But very infrequently and irreproducibly.
  543. *
  544. * Use things like work queues to work around this limitation.
  545. *
  546. * You have been warned.
  547. */
  548. void rcu_irq_enter(void)
  549. {
  550. unsigned long flags;
  551. struct rcu_dynticks *rdtp;
  552. long long oldval;
  553. local_irq_save(flags);
  554. rdtp = &__get_cpu_var(rcu_dynticks);
  555. oldval = rdtp->dynticks_nesting;
  556. rdtp->dynticks_nesting++;
  557. WARN_ON_ONCE(rdtp->dynticks_nesting == 0);
  558. if (oldval)
  559. trace_rcu_dyntick("++=", oldval, rdtp->dynticks_nesting);
  560. else
  561. rcu_eqs_exit_common(rdtp, oldval, true);
  562. local_irq_restore(flags);
  563. }
  564. /**
  565. * rcu_nmi_enter - inform RCU of entry to NMI context
  566. *
  567. * If the CPU was idle with dynamic ticks active, and there is no
  568. * irq handler running, this updates rdtp->dynticks_nmi to let the
  569. * RCU grace-period handling know that the CPU is active.
  570. */
  571. void rcu_nmi_enter(void)
  572. {
  573. struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
  574. if (rdtp->dynticks_nmi_nesting == 0 &&
  575. (atomic_read(&rdtp->dynticks) & 0x1))
  576. return;
  577. rdtp->dynticks_nmi_nesting++;
  578. smp_mb__before_atomic_inc(); /* Force delay from prior write. */
  579. atomic_inc(&rdtp->dynticks);
  580. /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
  581. smp_mb__after_atomic_inc(); /* See above. */
  582. WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
  583. }
  584. /**
  585. * rcu_nmi_exit - inform RCU of exit from NMI context
  586. *
  587. * If the CPU was idle with dynamic ticks active, and there is no
  588. * irq handler running, this updates rdtp->dynticks_nmi to let the
  589. * RCU grace-period handling know that the CPU is no longer active.
  590. */
  591. void rcu_nmi_exit(void)
  592. {
  593. struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
  594. if (rdtp->dynticks_nmi_nesting == 0 ||
  595. --rdtp->dynticks_nmi_nesting != 0)
  596. return;
  597. /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
  598. smp_mb__before_atomic_inc(); /* See above. */
  599. atomic_inc(&rdtp->dynticks);
  600. smp_mb__after_atomic_inc(); /* Force delay to next write. */
  601. WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
  602. }
  603. /**
  604. * rcu_is_cpu_idle - see if RCU thinks that the current CPU is idle
  605. *
  606. * If the current CPU is in its idle loop and is neither in an interrupt
  607. * or NMI handler, return true.
  608. */
  609. int rcu_is_cpu_idle(void)
  610. {
  611. int ret;
  612. preempt_disable();
  613. ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
  614. preempt_enable();
  615. return ret;
  616. }
  617. EXPORT_SYMBOL(rcu_is_cpu_idle);
  618. #if defined(CONFIG_PROVE_RCU) && defined(CONFIG_HOTPLUG_CPU)
  619. /*
  620. * Is the current CPU online? Disable preemption to avoid false positives
  621. * that could otherwise happen due to the current CPU number being sampled,
  622. * this task being preempted, its old CPU being taken offline, resuming
  623. * on some other CPU, then determining that its old CPU is now offline.
  624. * It is OK to use RCU on an offline processor during initial boot, hence
  625. * the check for rcu_scheduler_fully_active. Note also that it is OK
  626. * for a CPU coming online to use RCU for one jiffy prior to marking itself
  627. * online in the cpu_online_mask. Similarly, it is OK for a CPU going
  628. * offline to continue to use RCU for one jiffy after marking itself
  629. * offline in the cpu_online_mask. This leniency is necessary given the
  630. * non-atomic nature of the online and offline processing, for example,
  631. * the fact that a CPU enters the scheduler after completing the CPU_DYING
  632. * notifiers.
  633. *
  634. * This is also why RCU internally marks CPUs online during the
  635. * CPU_UP_PREPARE phase and offline during the CPU_DEAD phase.
  636. *
  637. * Disable checking if in an NMI handler because we cannot safely report
  638. * errors from NMI handlers anyway.
  639. */
  640. bool rcu_lockdep_current_cpu_online(void)
  641. {
  642. struct rcu_data *rdp;
  643. struct rcu_node *rnp;
  644. bool ret;
  645. if (in_nmi())
  646. return 1;
  647. preempt_disable();
  648. rdp = &__get_cpu_var(rcu_sched_data);
  649. rnp = rdp->mynode;
  650. ret = (rdp->grpmask & rnp->qsmaskinit) ||
  651. !rcu_scheduler_fully_active;
  652. preempt_enable();
  653. return ret;
  654. }
  655. EXPORT_SYMBOL_GPL(rcu_lockdep_current_cpu_online);
  656. #endif /* #if defined(CONFIG_PROVE_RCU) && defined(CONFIG_HOTPLUG_CPU) */
  657. /**
  658. * rcu_is_cpu_rrupt_from_idle - see if idle or immediately interrupted from idle
  659. *
  660. * If the current CPU is idle or running at a first-level (not nested)
  661. * interrupt from idle, return true. The caller must have at least
  662. * disabled preemption.
  663. */
  664. static int rcu_is_cpu_rrupt_from_idle(void)
  665. {
  666. return __get_cpu_var(rcu_dynticks).dynticks_nesting <= 1;
  667. }
  668. /*
  669. * Snapshot the specified CPU's dynticks counter so that we can later
  670. * credit them with an implicit quiescent state. Return 1 if this CPU
  671. * is in dynticks idle mode, which is an extended quiescent state.
  672. */
  673. static int dyntick_save_progress_counter(struct rcu_data *rdp)
  674. {
  675. rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
  676. return (rdp->dynticks_snap & 0x1) == 0;
  677. }
  678. /*
  679. * Return true if the specified CPU has passed through a quiescent
  680. * state by virtue of being in or having passed through an dynticks
  681. * idle state since the last call to dyntick_save_progress_counter()
  682. * for this same CPU, or by virtue of having been offline.
  683. */
  684. static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
  685. {
  686. unsigned int curr;
  687. unsigned int snap;
  688. curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
  689. snap = (unsigned int)rdp->dynticks_snap;
  690. /*
  691. * If the CPU passed through or entered a dynticks idle phase with
  692. * no active irq/NMI handlers, then we can safely pretend that the CPU
  693. * already acknowledged the request to pass through a quiescent
  694. * state. Either way, that CPU cannot possibly be in an RCU
  695. * read-side critical section that started before the beginning
  696. * of the current RCU grace period.
  697. */
  698. if ((curr & 0x1) == 0 || UINT_CMP_GE(curr, snap + 2)) {
  699. trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, "dti");
  700. rdp->dynticks_fqs++;
  701. return 1;
  702. }
  703. /*
  704. * Check for the CPU being offline, but only if the grace period
  705. * is old enough. We don't need to worry about the CPU changing
  706. * state: If we see it offline even once, it has been through a
  707. * quiescent state.
  708. *
  709. * The reason for insisting that the grace period be at least
  710. * one jiffy old is that CPUs that are not quite online and that
  711. * have just gone offline can still execute RCU read-side critical
  712. * sections.
  713. */
  714. if (ULONG_CMP_GE(rdp->rsp->gp_start + 2, jiffies))
  715. return 0; /* Grace period is not old enough. */
  716. barrier();
  717. if (cpu_is_offline(rdp->cpu)) {
  718. trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, "ofl");
  719. rdp->offline_fqs++;
  720. return 1;
  721. }
  722. return 0;
  723. }
  724. static void record_gp_stall_check_time(struct rcu_state *rsp)
  725. {
  726. rsp->gp_start = jiffies;
  727. rsp->jiffies_stall = jiffies + rcu_jiffies_till_stall_check();
  728. }
  729. /*
  730. * Dump stacks of all tasks running on stalled CPUs. This is a fallback
  731. * for architectures that do not implement trigger_all_cpu_backtrace().
  732. * The NMI-triggered stack traces are more accurate because they are
  733. * printed by the target CPU.
  734. */
  735. static void rcu_dump_cpu_stacks(struct rcu_state *rsp)
  736. {
  737. int cpu;
  738. unsigned long flags;
  739. struct rcu_node *rnp;
  740. rcu_for_each_leaf_node(rsp, rnp) {
  741. raw_spin_lock_irqsave(&rnp->lock, flags);
  742. if (rnp->qsmask != 0) {
  743. for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
  744. if (rnp->qsmask & (1UL << cpu))
  745. dump_cpu_task(rnp->grplo + cpu);
  746. }
  747. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  748. }
  749. }
  750. static void print_other_cpu_stall(struct rcu_state *rsp)
  751. {
  752. int cpu;
  753. long delta;
  754. unsigned long flags;
  755. int ndetected = 0;
  756. struct rcu_node *rnp = rcu_get_root(rsp);
  757. long totqlen = 0;
  758. /* Only let one CPU complain about others per time interval. */
  759. raw_spin_lock_irqsave(&rnp->lock, flags);
  760. delta = jiffies - rsp->jiffies_stall;
  761. if (delta < RCU_STALL_RAT_DELAY || !rcu_gp_in_progress(rsp)) {
  762. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  763. return;
  764. }
  765. rsp->jiffies_stall = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
  766. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  767. /*
  768. * OK, time to rat on our buddy...
  769. * See Documentation/RCU/stallwarn.txt for info on how to debug
  770. * RCU CPU stall warnings.
  771. */
  772. printk(KERN_ERR "INFO: %s detected stalls on CPUs/tasks:",
  773. rsp->name);
  774. print_cpu_stall_info_begin();
  775. rcu_for_each_leaf_node(rsp, rnp) {
  776. raw_spin_lock_irqsave(&rnp->lock, flags);
  777. ndetected += rcu_print_task_stall(rnp);
  778. if (rnp->qsmask != 0) {
  779. for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
  780. if (rnp->qsmask & (1UL << cpu)) {
  781. print_cpu_stall_info(rsp,
  782. rnp->grplo + cpu);
  783. ndetected++;
  784. }
  785. }
  786. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  787. }
  788. /*
  789. * Now rat on any tasks that got kicked up to the root rcu_node
  790. * due to CPU offlining.
  791. */
  792. rnp = rcu_get_root(rsp);
  793. raw_spin_lock_irqsave(&rnp->lock, flags);
  794. ndetected += rcu_print_task_stall(rnp);
  795. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  796. print_cpu_stall_info_end();
  797. for_each_possible_cpu(cpu)
  798. totqlen += per_cpu_ptr(rsp->rda, cpu)->qlen;
  799. pr_cont("(detected by %d, t=%ld jiffies, g=%lu, c=%lu, q=%lu)\n",
  800. smp_processor_id(), (long)(jiffies - rsp->gp_start),
  801. rsp->gpnum, rsp->completed, totqlen);
  802. if (ndetected == 0)
  803. printk(KERN_ERR "INFO: Stall ended before state dump start\n");
  804. else if (!trigger_all_cpu_backtrace())
  805. rcu_dump_cpu_stacks(rsp);
  806. /* Complain about tasks blocking the grace period. */
  807. rcu_print_detail_task_stall(rsp);
  808. force_quiescent_state(rsp); /* Kick them all. */
  809. }
  810. static void print_cpu_stall(struct rcu_state *rsp)
  811. {
  812. int cpu;
  813. unsigned long flags;
  814. struct rcu_node *rnp = rcu_get_root(rsp);
  815. long totqlen = 0;
  816. /*
  817. * OK, time to rat on ourselves...
  818. * See Documentation/RCU/stallwarn.txt for info on how to debug
  819. * RCU CPU stall warnings.
  820. */
  821. printk(KERN_ERR "INFO: %s self-detected stall on CPU", rsp->name);
  822. print_cpu_stall_info_begin();
  823. print_cpu_stall_info(rsp, smp_processor_id());
  824. print_cpu_stall_info_end();
  825. for_each_possible_cpu(cpu)
  826. totqlen += per_cpu_ptr(rsp->rda, cpu)->qlen;
  827. pr_cont(" (t=%lu jiffies g=%lu c=%lu q=%lu)\n",
  828. jiffies - rsp->gp_start, rsp->gpnum, rsp->completed, totqlen);
  829. if (!trigger_all_cpu_backtrace())
  830. dump_stack();
  831. raw_spin_lock_irqsave(&rnp->lock, flags);
  832. if (ULONG_CMP_GE(jiffies, rsp->jiffies_stall))
  833. rsp->jiffies_stall = jiffies +
  834. 3 * rcu_jiffies_till_stall_check() + 3;
  835. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  836. set_need_resched(); /* kick ourselves to get things going. */
  837. }
  838. static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
  839. {
  840. unsigned long j;
  841. unsigned long js;
  842. struct rcu_node *rnp;
  843. if (rcu_cpu_stall_suppress)
  844. return;
  845. j = ACCESS_ONCE(jiffies);
  846. js = ACCESS_ONCE(rsp->jiffies_stall);
  847. rnp = rdp->mynode;
  848. if (rcu_gp_in_progress(rsp) &&
  849. (ACCESS_ONCE(rnp->qsmask) & rdp->grpmask) && ULONG_CMP_GE(j, js)) {
  850. /* We haven't checked in, so go dump stack. */
  851. print_cpu_stall(rsp);
  852. } else if (rcu_gp_in_progress(rsp) &&
  853. ULONG_CMP_GE(j, js + RCU_STALL_RAT_DELAY)) {
  854. /* They had a few time units to dump stack, so complain. */
  855. print_other_cpu_stall(rsp);
  856. }
  857. }
  858. /**
  859. * rcu_cpu_stall_reset - prevent further stall warnings in current grace period
  860. *
  861. * Set the stall-warning timeout way off into the future, thus preventing
  862. * any RCU CPU stall-warning messages from appearing in the current set of
  863. * RCU grace periods.
  864. *
  865. * The caller must disable hard irqs.
  866. */
  867. void rcu_cpu_stall_reset(void)
  868. {
  869. struct rcu_state *rsp;
  870. for_each_rcu_flavor(rsp)
  871. rsp->jiffies_stall = jiffies + ULONG_MAX / 2;
  872. }
  873. /*
  874. * Update CPU-local rcu_data state to record the newly noticed grace period.
  875. * This is used both when we started the grace period and when we notice
  876. * that someone else started the grace period. The caller must hold the
  877. * ->lock of the leaf rcu_node structure corresponding to the current CPU,
  878. * and must have irqs disabled.
  879. */
  880. static void __note_new_gpnum(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_data *rdp)
  881. {
  882. if (rdp->gpnum != rnp->gpnum) {
  883. /*
  884. * If the current grace period is waiting for this CPU,
  885. * set up to detect a quiescent state, otherwise don't
  886. * go looking for one.
  887. */
  888. rdp->gpnum = rnp->gpnum;
  889. trace_rcu_grace_period(rsp->name, rdp->gpnum, "cpustart");
  890. rdp->passed_quiesce = 0;
  891. rdp->qs_pending = !!(rnp->qsmask & rdp->grpmask);
  892. zero_cpu_stall_ticks(rdp);
  893. }
  894. }
  895. static void note_new_gpnum(struct rcu_state *rsp, struct rcu_data *rdp)
  896. {
  897. unsigned long flags;
  898. struct rcu_node *rnp;
  899. local_irq_save(flags);
  900. rnp = rdp->mynode;
  901. if (rdp->gpnum == ACCESS_ONCE(rnp->gpnum) || /* outside lock. */
  902. !raw_spin_trylock(&rnp->lock)) { /* irqs already off, so later. */
  903. local_irq_restore(flags);
  904. return;
  905. }
  906. __note_new_gpnum(rsp, rnp, rdp);
  907. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  908. }
  909. /*
  910. * Did someone else start a new RCU grace period start since we last
  911. * checked? Update local state appropriately if so. Must be called
  912. * on the CPU corresponding to rdp.
  913. */
  914. static int
  915. check_for_new_grace_period(struct rcu_state *rsp, struct rcu_data *rdp)
  916. {
  917. unsigned long flags;
  918. int ret = 0;
  919. local_irq_save(flags);
  920. if (rdp->gpnum != rsp->gpnum) {
  921. note_new_gpnum(rsp, rdp);
  922. ret = 1;
  923. }
  924. local_irq_restore(flags);
  925. return ret;
  926. }
  927. /*
  928. * Initialize the specified rcu_data structure's callback list to empty.
  929. */
  930. static void init_callback_list(struct rcu_data *rdp)
  931. {
  932. int i;
  933. if (init_nocb_callback_list(rdp))
  934. return;
  935. rdp->nxtlist = NULL;
  936. for (i = 0; i < RCU_NEXT_SIZE; i++)
  937. rdp->nxttail[i] = &rdp->nxtlist;
  938. }
  939. /*
  940. * Determine the value that ->completed will have at the end of the
  941. * next subsequent grace period. This is used to tag callbacks so that
  942. * a CPU can invoke callbacks in a timely fashion even if that CPU has
  943. * been dyntick-idle for an extended period with callbacks under the
  944. * influence of RCU_FAST_NO_HZ.
  945. *
  946. * The caller must hold rnp->lock with interrupts disabled.
  947. */
  948. static unsigned long rcu_cbs_completed(struct rcu_state *rsp,
  949. struct rcu_node *rnp)
  950. {
  951. /*
  952. * If RCU is idle, we just wait for the next grace period.
  953. * But we can only be sure that RCU is idle if we are looking
  954. * at the root rcu_node structure -- otherwise, a new grace
  955. * period might have started, but just not yet gotten around
  956. * to initializing the current non-root rcu_node structure.
  957. */
  958. if (rcu_get_root(rsp) == rnp && rnp->gpnum == rnp->completed)
  959. return rnp->completed + 1;
  960. /*
  961. * Otherwise, wait for a possible partial grace period and
  962. * then the subsequent full grace period.
  963. */
  964. return rnp->completed + 2;
  965. }
  966. /*
  967. * If there is room, assign a ->completed number to any callbacks on
  968. * this CPU that have not already been assigned. Also accelerate any
  969. * callbacks that were previously assigned a ->completed number that has
  970. * since proven to be too conservative, which can happen if callbacks get
  971. * assigned a ->completed number while RCU is idle, but with reference to
  972. * a non-root rcu_node structure. This function is idempotent, so it does
  973. * not hurt to call it repeatedly.
  974. *
  975. * The caller must hold rnp->lock with interrupts disabled.
  976. */
  977. static void rcu_accelerate_cbs(struct rcu_state *rsp, struct rcu_node *rnp,
  978. struct rcu_data *rdp)
  979. {
  980. unsigned long c;
  981. int i;
  982. /* If the CPU has no callbacks, nothing to do. */
  983. if (!rdp->nxttail[RCU_NEXT_TAIL] || !*rdp->nxttail[RCU_DONE_TAIL])
  984. return;
  985. /*
  986. * Starting from the sublist containing the callbacks most
  987. * recently assigned a ->completed number and working down, find the
  988. * first sublist that is not assignable to an upcoming grace period.
  989. * Such a sublist has something in it (first two tests) and has
  990. * a ->completed number assigned that will complete sooner than
  991. * the ->completed number for newly arrived callbacks (last test).
  992. *
  993. * The key point is that any later sublist can be assigned the
  994. * same ->completed number as the newly arrived callbacks, which
  995. * means that the callbacks in any of these later sublist can be
  996. * grouped into a single sublist, whether or not they have already
  997. * been assigned a ->completed number.
  998. */
  999. c = rcu_cbs_completed(rsp, rnp);
  1000. for (i = RCU_NEXT_TAIL - 1; i > RCU_DONE_TAIL; i--)
  1001. if (rdp->nxttail[i] != rdp->nxttail[i - 1] &&
  1002. !ULONG_CMP_GE(rdp->nxtcompleted[i], c))
  1003. break;
  1004. /*
  1005. * If there are no sublist for unassigned callbacks, leave.
  1006. * At the same time, advance "i" one sublist, so that "i" will
  1007. * index into the sublist where all the remaining callbacks should
  1008. * be grouped into.
  1009. */
  1010. if (++i >= RCU_NEXT_TAIL)
  1011. return;
  1012. /*
  1013. * Assign all subsequent callbacks' ->completed number to the next
  1014. * full grace period and group them all in the sublist initially
  1015. * indexed by "i".
  1016. */
  1017. for (; i <= RCU_NEXT_TAIL; i++) {
  1018. rdp->nxttail[i] = rdp->nxttail[RCU_NEXT_TAIL];
  1019. rdp->nxtcompleted[i] = c;
  1020. }
  1021. /* Trace depending on how much we were able to accelerate. */
  1022. if (!*rdp->nxttail[RCU_WAIT_TAIL])
  1023. trace_rcu_grace_period(rsp->name, rdp->gpnum, "AccWaitCB");
  1024. else
  1025. trace_rcu_grace_period(rsp->name, rdp->gpnum, "AccReadyCB");
  1026. }
  1027. /*
  1028. * Move any callbacks whose grace period has completed to the
  1029. * RCU_DONE_TAIL sublist, then compact the remaining sublists and
  1030. * assign ->completed numbers to any callbacks in the RCU_NEXT_TAIL
  1031. * sublist. This function is idempotent, so it does not hurt to
  1032. * invoke it repeatedly. As long as it is not invoked -too- often...
  1033. *
  1034. * The caller must hold rnp->lock with interrupts disabled.
  1035. */
  1036. static void rcu_advance_cbs(struct rcu_state *rsp, struct rcu_node *rnp,
  1037. struct rcu_data *rdp)
  1038. {
  1039. int i, j;
  1040. /* If the CPU has no callbacks, nothing to do. */
  1041. if (!rdp->nxttail[RCU_NEXT_TAIL] || !*rdp->nxttail[RCU_DONE_TAIL])
  1042. return;
  1043. /*
  1044. * Find all callbacks whose ->completed numbers indicate that they
  1045. * are ready to invoke, and put them into the RCU_DONE_TAIL sublist.
  1046. */
  1047. for (i = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++) {
  1048. if (ULONG_CMP_LT(rnp->completed, rdp->nxtcompleted[i]))
  1049. break;
  1050. rdp->nxttail[RCU_DONE_TAIL] = rdp->nxttail[i];
  1051. }
  1052. /* Clean up any sublist tail pointers that were misordered above. */
  1053. for (j = RCU_WAIT_TAIL; j < i; j++)
  1054. rdp->nxttail[j] = rdp->nxttail[RCU_DONE_TAIL];
  1055. /* Copy down callbacks to fill in empty sublists. */
  1056. for (j = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++, j++) {
  1057. if (rdp->nxttail[j] == rdp->nxttail[RCU_NEXT_TAIL])
  1058. break;
  1059. rdp->nxttail[j] = rdp->nxttail[i];
  1060. rdp->nxtcompleted[j] = rdp->nxtcompleted[i];
  1061. }
  1062. /* Classify any remaining callbacks. */
  1063. rcu_accelerate_cbs(rsp, rnp, rdp);
  1064. }
  1065. /*
  1066. * Advance this CPU's callbacks, but only if the current grace period
  1067. * has ended. This may be called only from the CPU to whom the rdp
  1068. * belongs. In addition, the corresponding leaf rcu_node structure's
  1069. * ->lock must be held by the caller, with irqs disabled.
  1070. */
  1071. static void
  1072. __rcu_process_gp_end(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_data *rdp)
  1073. {
  1074. /* Did another grace period end? */
  1075. if (rdp->completed == rnp->completed) {
  1076. /* No, so just accelerate recent callbacks. */
  1077. rcu_accelerate_cbs(rsp, rnp, rdp);
  1078. } else {
  1079. /* Advance callbacks. */
  1080. rcu_advance_cbs(rsp, rnp, rdp);
  1081. /* Remember that we saw this grace-period completion. */
  1082. rdp->completed = rnp->completed;
  1083. trace_rcu_grace_period(rsp->name, rdp->gpnum, "cpuend");
  1084. /*
  1085. * If we were in an extended quiescent state, we may have
  1086. * missed some grace periods that others CPUs handled on
  1087. * our behalf. Catch up with this state to avoid noting
  1088. * spurious new grace periods. If another grace period
  1089. * has started, then rnp->gpnum will have advanced, so
  1090. * we will detect this later on. Of course, any quiescent
  1091. * states we found for the old GP are now invalid.
  1092. */
  1093. if (ULONG_CMP_LT(rdp->gpnum, rdp->completed)) {
  1094. rdp->gpnum = rdp->completed;
  1095. rdp->passed_quiesce = 0;
  1096. }
  1097. /*
  1098. * If RCU does not need a quiescent state from this CPU,
  1099. * then make sure that this CPU doesn't go looking for one.
  1100. */
  1101. if ((rnp->qsmask & rdp->grpmask) == 0)
  1102. rdp->qs_pending = 0;
  1103. }
  1104. }
  1105. /*
  1106. * Advance this CPU's callbacks, but only if the current grace period
  1107. * has ended. This may be called only from the CPU to whom the rdp
  1108. * belongs.
  1109. */
  1110. static void
  1111. rcu_process_gp_end(struct rcu_state *rsp, struct rcu_data *rdp)
  1112. {
  1113. unsigned long flags;
  1114. struct rcu_node *rnp;
  1115. local_irq_save(flags);
  1116. rnp = rdp->mynode;
  1117. if (rdp->completed == ACCESS_ONCE(rnp->completed) || /* outside lock. */
  1118. !raw_spin_trylock(&rnp->lock)) { /* irqs already off, so later. */
  1119. local_irq_restore(flags);
  1120. return;
  1121. }
  1122. __rcu_process_gp_end(rsp, rnp, rdp);
  1123. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1124. }
  1125. /*
  1126. * Do per-CPU grace-period initialization for running CPU. The caller
  1127. * must hold the lock of the leaf rcu_node structure corresponding to
  1128. * this CPU.
  1129. */
  1130. static void
  1131. rcu_start_gp_per_cpu(struct rcu_state *rsp, struct rcu_node *rnp, struct rcu_data *rdp)
  1132. {
  1133. /* Prior grace period ended, so advance callbacks for current CPU. */
  1134. __rcu_process_gp_end(rsp, rnp, rdp);
  1135. /* Set state so that this CPU will detect the next quiescent state. */
  1136. __note_new_gpnum(rsp, rnp, rdp);
  1137. }
  1138. /*
  1139. * Initialize a new grace period.
  1140. */
  1141. static int rcu_gp_init(struct rcu_state *rsp)
  1142. {
  1143. struct rcu_data *rdp;
  1144. struct rcu_node *rnp = rcu_get_root(rsp);
  1145. raw_spin_lock_irq(&rnp->lock);
  1146. rsp->gp_flags = 0; /* Clear all flags: New grace period. */
  1147. if (rcu_gp_in_progress(rsp)) {
  1148. /* Grace period already in progress, don't start another. */
  1149. raw_spin_unlock_irq(&rnp->lock);
  1150. return 0;
  1151. }
  1152. /* Advance to a new grace period and initialize state. */
  1153. rsp->gpnum++;
  1154. trace_rcu_grace_period(rsp->name, rsp->gpnum, "start");
  1155. record_gp_stall_check_time(rsp);
  1156. raw_spin_unlock_irq(&rnp->lock);
  1157. /* Exclude any concurrent CPU-hotplug operations. */
  1158. mutex_lock(&rsp->onoff_mutex);
  1159. /*
  1160. * Set the quiescent-state-needed bits in all the rcu_node
  1161. * structures for all currently online CPUs in breadth-first order,
  1162. * starting from the root rcu_node structure, relying on the layout
  1163. * of the tree within the rsp->node[] array. Note that other CPUs
  1164. * will access only the leaves of the hierarchy, thus seeing that no
  1165. * grace period is in progress, at least until the corresponding
  1166. * leaf node has been initialized. In addition, we have excluded
  1167. * CPU-hotplug operations.
  1168. *
  1169. * The grace period cannot complete until the initialization
  1170. * process finishes, because this kthread handles both.
  1171. */
  1172. rcu_for_each_node_breadth_first(rsp, rnp) {
  1173. raw_spin_lock_irq(&rnp->lock);
  1174. rdp = this_cpu_ptr(rsp->rda);
  1175. rcu_preempt_check_blocked_tasks(rnp);
  1176. rnp->qsmask = rnp->qsmaskinit;
  1177. rnp->gpnum = rsp->gpnum;
  1178. WARN_ON_ONCE(rnp->completed != rsp->completed);
  1179. rnp->completed = rsp->completed;
  1180. if (rnp == rdp->mynode)
  1181. rcu_start_gp_per_cpu(rsp, rnp, rdp);
  1182. rcu_preempt_boost_start_gp(rnp);
  1183. trace_rcu_grace_period_init(rsp->name, rnp->gpnum,
  1184. rnp->level, rnp->grplo,
  1185. rnp->grphi, rnp->qsmask);
  1186. raw_spin_unlock_irq(&rnp->lock);
  1187. #ifdef CONFIG_PROVE_RCU_DELAY
  1188. if ((random32() % (rcu_num_nodes * 8)) == 0)
  1189. schedule_timeout_uninterruptible(2);
  1190. #endif /* #ifdef CONFIG_PROVE_RCU_DELAY */
  1191. cond_resched();
  1192. }
  1193. mutex_unlock(&rsp->onoff_mutex);
  1194. return 1;
  1195. }
  1196. /*
  1197. * Do one round of quiescent-state forcing.
  1198. */
  1199. int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
  1200. {
  1201. int fqs_state = fqs_state_in;
  1202. struct rcu_node *rnp = rcu_get_root(rsp);
  1203. rsp->n_force_qs++;
  1204. if (fqs_state == RCU_SAVE_DYNTICK) {
  1205. /* Collect dyntick-idle snapshots. */
  1206. force_qs_rnp(rsp, dyntick_save_progress_counter);
  1207. fqs_state = RCU_FORCE_QS;
  1208. } else {
  1209. /* Handle dyntick-idle and offline CPUs. */
  1210. force_qs_rnp(rsp, rcu_implicit_dynticks_qs);
  1211. }
  1212. /* Clear flag to prevent immediate re-entry. */
  1213. if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
  1214. raw_spin_lock_irq(&rnp->lock);
  1215. rsp->gp_flags &= ~RCU_GP_FLAG_FQS;
  1216. raw_spin_unlock_irq(&rnp->lock);
  1217. }
  1218. return fqs_state;
  1219. }
  1220. /*
  1221. * Clean up after the old grace period.
  1222. */
  1223. static void rcu_gp_cleanup(struct rcu_state *rsp)
  1224. {
  1225. unsigned long gp_duration;
  1226. struct rcu_data *rdp;
  1227. struct rcu_node *rnp = rcu_get_root(rsp);
  1228. raw_spin_lock_irq(&rnp->lock);
  1229. gp_duration = jiffies - rsp->gp_start;
  1230. if (gp_duration > rsp->gp_max)
  1231. rsp->gp_max = gp_duration;
  1232. /*
  1233. * We know the grace period is complete, but to everyone else
  1234. * it appears to still be ongoing. But it is also the case
  1235. * that to everyone else it looks like there is nothing that
  1236. * they can do to advance the grace period. It is therefore
  1237. * safe for us to drop the lock in order to mark the grace
  1238. * period as completed in all of the rcu_node structures.
  1239. */
  1240. raw_spin_unlock_irq(&rnp->lock);
  1241. /*
  1242. * Propagate new ->completed value to rcu_node structures so
  1243. * that other CPUs don't have to wait until the start of the next
  1244. * grace period to process their callbacks. This also avoids
  1245. * some nasty RCU grace-period initialization races by forcing
  1246. * the end of the current grace period to be completely recorded in
  1247. * all of the rcu_node structures before the beginning of the next
  1248. * grace period is recorded in any of the rcu_node structures.
  1249. */
  1250. rcu_for_each_node_breadth_first(rsp, rnp) {
  1251. raw_spin_lock_irq(&rnp->lock);
  1252. rnp->completed = rsp->gpnum;
  1253. raw_spin_unlock_irq(&rnp->lock);
  1254. cond_resched();
  1255. }
  1256. rnp = rcu_get_root(rsp);
  1257. raw_spin_lock_irq(&rnp->lock);
  1258. rsp->completed = rsp->gpnum; /* Declare grace period done. */
  1259. trace_rcu_grace_period(rsp->name, rsp->completed, "end");
  1260. rsp->fqs_state = RCU_GP_IDLE;
  1261. rdp = this_cpu_ptr(rsp->rda);
  1262. if (cpu_needs_another_gp(rsp, rdp))
  1263. rsp->gp_flags = 1;
  1264. raw_spin_unlock_irq(&rnp->lock);
  1265. }
  1266. /*
  1267. * Body of kthread that handles grace periods.
  1268. */
  1269. static int __noreturn rcu_gp_kthread(void *arg)
  1270. {
  1271. int fqs_state;
  1272. unsigned long j;
  1273. int ret;
  1274. struct rcu_state *rsp = arg;
  1275. struct rcu_node *rnp = rcu_get_root(rsp);
  1276. for (;;) {
  1277. /* Handle grace-period start. */
  1278. for (;;) {
  1279. wait_event_interruptible(rsp->gp_wq,
  1280. rsp->gp_flags &
  1281. RCU_GP_FLAG_INIT);
  1282. if ((rsp->gp_flags & RCU_GP_FLAG_INIT) &&
  1283. rcu_gp_init(rsp))
  1284. break;
  1285. cond_resched();
  1286. flush_signals(current);
  1287. }
  1288. /* Handle quiescent-state forcing. */
  1289. fqs_state = RCU_SAVE_DYNTICK;
  1290. j = jiffies_till_first_fqs;
  1291. if (j > HZ) {
  1292. j = HZ;
  1293. jiffies_till_first_fqs = HZ;
  1294. }
  1295. for (;;) {
  1296. rsp->jiffies_force_qs = jiffies + j;
  1297. ret = wait_event_interruptible_timeout(rsp->gp_wq,
  1298. (rsp->gp_flags & RCU_GP_FLAG_FQS) ||
  1299. (!ACCESS_ONCE(rnp->qsmask) &&
  1300. !rcu_preempt_blocked_readers_cgp(rnp)),
  1301. j);
  1302. /* If grace period done, leave loop. */
  1303. if (!ACCESS_ONCE(rnp->qsmask) &&
  1304. !rcu_preempt_blocked_readers_cgp(rnp))
  1305. break;
  1306. /* If time for quiescent-state forcing, do it. */
  1307. if (ret == 0 || (rsp->gp_flags & RCU_GP_FLAG_FQS)) {
  1308. fqs_state = rcu_gp_fqs(rsp, fqs_state);
  1309. cond_resched();
  1310. } else {
  1311. /* Deal with stray signal. */
  1312. cond_resched();
  1313. flush_signals(current);
  1314. }
  1315. j = jiffies_till_next_fqs;
  1316. if (j > HZ) {
  1317. j = HZ;
  1318. jiffies_till_next_fqs = HZ;
  1319. } else if (j < 1) {
  1320. j = 1;
  1321. jiffies_till_next_fqs = 1;
  1322. }
  1323. }
  1324. /* Handle grace-period end. */
  1325. rcu_gp_cleanup(rsp);
  1326. }
  1327. }
  1328. /*
  1329. * Start a new RCU grace period if warranted, re-initializing the hierarchy
  1330. * in preparation for detecting the next grace period. The caller must hold
  1331. * the root node's ->lock, which is released before return. Hard irqs must
  1332. * be disabled.
  1333. *
  1334. * Note that it is legal for a dying CPU (which is marked as offline) to
  1335. * invoke this function. This can happen when the dying CPU reports its
  1336. * quiescent state.
  1337. */
  1338. static void
  1339. rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
  1340. __releases(rcu_get_root(rsp)->lock)
  1341. {
  1342. struct rcu_data *rdp = this_cpu_ptr(rsp->rda);
  1343. struct rcu_node *rnp = rcu_get_root(rsp);
  1344. if (!rsp->gp_kthread ||
  1345. !cpu_needs_another_gp(rsp, rdp)) {
  1346. /*
  1347. * Either we have not yet spawned the grace-period
  1348. * task, this CPU does not need another grace period,
  1349. * or a grace period is already in progress.
  1350. * Either way, don't start a new grace period.
  1351. */
  1352. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1353. return;
  1354. }
  1355. /*
  1356. * Because there is no grace period in progress right now,
  1357. * any callbacks we have up to this point will be satisfied
  1358. * by the next grace period. So this is a good place to
  1359. * assign a grace period number to recently posted callbacks.
  1360. */
  1361. rcu_accelerate_cbs(rsp, rnp, rdp);
  1362. rsp->gp_flags = RCU_GP_FLAG_INIT;
  1363. raw_spin_unlock(&rnp->lock); /* Interrupts remain disabled. */
  1364. /* Ensure that CPU is aware of completion of last grace period. */
  1365. rcu_process_gp_end(rsp, rdp);
  1366. local_irq_restore(flags);
  1367. /* Wake up rcu_gp_kthread() to start the grace period. */
  1368. wake_up(&rsp->gp_wq);
  1369. }
  1370. /*
  1371. * Report a full set of quiescent states to the specified rcu_state
  1372. * data structure. This involves cleaning up after the prior grace
  1373. * period and letting rcu_start_gp() start up the next grace period
  1374. * if one is needed. Note that the caller must hold rnp->lock, as
  1375. * required by rcu_start_gp(), which will release it.
  1376. */
  1377. static void rcu_report_qs_rsp(struct rcu_state *rsp, unsigned long flags)
  1378. __releases(rcu_get_root(rsp)->lock)
  1379. {
  1380. WARN_ON_ONCE(!rcu_gp_in_progress(rsp));
  1381. raw_spin_unlock_irqrestore(&rcu_get_root(rsp)->lock, flags);
  1382. wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
  1383. }
  1384. /*
  1385. * Similar to rcu_report_qs_rdp(), for which it is a helper function.
  1386. * Allows quiescent states for a group of CPUs to be reported at one go
  1387. * to the specified rcu_node structure, though all the CPUs in the group
  1388. * must be represented by the same rcu_node structure (which need not be
  1389. * a leaf rcu_node structure, though it often will be). That structure's
  1390. * lock must be held upon entry, and it is released before return.
  1391. */
  1392. static void
  1393. rcu_report_qs_rnp(unsigned long mask, struct rcu_state *rsp,
  1394. struct rcu_node *rnp, unsigned long flags)
  1395. __releases(rnp->lock)
  1396. {
  1397. struct rcu_node *rnp_c;
  1398. /* Walk up the rcu_node hierarchy. */
  1399. for (;;) {
  1400. if (!(rnp->qsmask & mask)) {
  1401. /* Our bit has already been cleared, so done. */
  1402. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1403. return;
  1404. }
  1405. rnp->qsmask &= ~mask;
  1406. trace_rcu_quiescent_state_report(rsp->name, rnp->gpnum,
  1407. mask, rnp->qsmask, rnp->level,
  1408. rnp->grplo, rnp->grphi,
  1409. !!rnp->gp_tasks);
  1410. if (rnp->qsmask != 0 || rcu_preempt_blocked_readers_cgp(rnp)) {
  1411. /* Other bits still set at this level, so done. */
  1412. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1413. return;
  1414. }
  1415. mask = rnp->grpmask;
  1416. if (rnp->parent == NULL) {
  1417. /* No more levels. Exit loop holding root lock. */
  1418. break;
  1419. }
  1420. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1421. rnp_c = rnp;
  1422. rnp = rnp->parent;
  1423. raw_spin_lock_irqsave(&rnp->lock, flags);
  1424. WARN_ON_ONCE(rnp_c->qsmask);
  1425. }
  1426. /*
  1427. * Get here if we are the last CPU to pass through a quiescent
  1428. * state for this grace period. Invoke rcu_report_qs_rsp()
  1429. * to clean up and start the next grace period if one is needed.
  1430. */
  1431. rcu_report_qs_rsp(rsp, flags); /* releases rnp->lock. */
  1432. }
  1433. /*
  1434. * Record a quiescent state for the specified CPU to that CPU's rcu_data
  1435. * structure. This must be either called from the specified CPU, or
  1436. * called when the specified CPU is known to be offline (and when it is
  1437. * also known that no other CPU is concurrently trying to help the offline
  1438. * CPU). The lastcomp argument is used to make sure we are still in the
  1439. * grace period of interest. We don't want to end the current grace period
  1440. * based on quiescent states detected in an earlier grace period!
  1441. */
  1442. static void
  1443. rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp)
  1444. {
  1445. unsigned long flags;
  1446. unsigned long mask;
  1447. struct rcu_node *rnp;
  1448. rnp = rdp->mynode;
  1449. raw_spin_lock_irqsave(&rnp->lock, flags);
  1450. if (rdp->passed_quiesce == 0 || rdp->gpnum != rnp->gpnum ||
  1451. rnp->completed == rnp->gpnum) {
  1452. /*
  1453. * The grace period in which this quiescent state was
  1454. * recorded has ended, so don't report it upwards.
  1455. * We will instead need a new quiescent state that lies
  1456. * within the current grace period.
  1457. */
  1458. rdp->passed_quiesce = 0; /* need qs for new gp. */
  1459. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1460. return;
  1461. }
  1462. mask = rdp->grpmask;
  1463. if ((rnp->qsmask & mask) == 0) {
  1464. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1465. } else {
  1466. rdp->qs_pending = 0;
  1467. /*
  1468. * This GP can't end until cpu checks in, so all of our
  1469. * callbacks can be processed during the next GP.
  1470. */
  1471. rcu_accelerate_cbs(rsp, rnp, rdp);
  1472. rcu_report_qs_rnp(mask, rsp, rnp, flags); /* rlses rnp->lock */
  1473. }
  1474. }
  1475. /*
  1476. * Check to see if there is a new grace period of which this CPU
  1477. * is not yet aware, and if so, set up local rcu_data state for it.
  1478. * Otherwise, see if this CPU has just passed through its first
  1479. * quiescent state for this grace period, and record that fact if so.
  1480. */
  1481. static void
  1482. rcu_check_quiescent_state(struct rcu_state *rsp, struct rcu_data *rdp)
  1483. {
  1484. /* If there is now a new grace period, record and return. */
  1485. if (check_for_new_grace_period(rsp, rdp))
  1486. return;
  1487. /*
  1488. * Does this CPU still need to do its part for current grace period?
  1489. * If no, return and let the other CPUs do their part as well.
  1490. */
  1491. if (!rdp->qs_pending)
  1492. return;
  1493. /*
  1494. * Was there a quiescent state since the beginning of the grace
  1495. * period? If no, then exit and wait for the next call.
  1496. */
  1497. if (!rdp->passed_quiesce)
  1498. return;
  1499. /*
  1500. * Tell RCU we are done (but rcu_report_qs_rdp() will be the
  1501. * judge of that).
  1502. */
  1503. rcu_report_qs_rdp(rdp->cpu, rsp, rdp);
  1504. }
  1505. #ifdef CONFIG_HOTPLUG_CPU
  1506. /*
  1507. * Send the specified CPU's RCU callbacks to the orphanage. The
  1508. * specified CPU must be offline, and the caller must hold the
  1509. * ->orphan_lock.
  1510. */
  1511. static void
  1512. rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
  1513. struct rcu_node *rnp, struct rcu_data *rdp)
  1514. {
  1515. /* No-CBs CPUs do not have orphanable callbacks. */
  1516. if (is_nocb_cpu(rdp->cpu))
  1517. return;
  1518. /*
  1519. * Orphan the callbacks. First adjust the counts. This is safe
  1520. * because _rcu_barrier() excludes CPU-hotplug operations, so it
  1521. * cannot be running now. Thus no memory barrier is required.
  1522. */
  1523. if (rdp->nxtlist != NULL) {
  1524. rsp->qlen_lazy += rdp->qlen_lazy;
  1525. rsp->qlen += rdp->qlen;
  1526. rdp->n_cbs_orphaned += rdp->qlen;
  1527. rdp->qlen_lazy = 0;
  1528. ACCESS_ONCE(rdp->qlen) = 0;
  1529. }
  1530. /*
  1531. * Next, move those callbacks still needing a grace period to
  1532. * the orphanage, where some other CPU will pick them up.
  1533. * Some of the callbacks might have gone partway through a grace
  1534. * period, but that is too bad. They get to start over because we
  1535. * cannot assume that grace periods are synchronized across CPUs.
  1536. * We don't bother updating the ->nxttail[] array yet, instead
  1537. * we just reset the whole thing later on.
  1538. */
  1539. if (*rdp->nxttail[RCU_DONE_TAIL] != NULL) {
  1540. *rsp->orphan_nxttail = *rdp->nxttail[RCU_DONE_TAIL];
  1541. rsp->orphan_nxttail = rdp->nxttail[RCU_NEXT_TAIL];
  1542. *rdp->nxttail[RCU_DONE_TAIL] = NULL;
  1543. }
  1544. /*
  1545. * Then move the ready-to-invoke callbacks to the orphanage,
  1546. * where some other CPU will pick them up. These will not be
  1547. * required to pass though another grace period: They are done.
  1548. */
  1549. if (rdp->nxtlist != NULL) {
  1550. *rsp->orphan_donetail = rdp->nxtlist;
  1551. rsp->orphan_donetail = rdp->nxttail[RCU_DONE_TAIL];
  1552. }
  1553. /* Finally, initialize the rcu_data structure's list to empty. */
  1554. init_callback_list(rdp);
  1555. }
  1556. /*
  1557. * Adopt the RCU callbacks from the specified rcu_state structure's
  1558. * orphanage. The caller must hold the ->orphan_lock.
  1559. */
  1560. static void rcu_adopt_orphan_cbs(struct rcu_state *rsp)
  1561. {
  1562. int i;
  1563. struct rcu_data *rdp = __this_cpu_ptr(rsp->rda);
  1564. /* No-CBs CPUs are handled specially. */
  1565. if (rcu_nocb_adopt_orphan_cbs(rsp, rdp))
  1566. return;
  1567. /* Do the accounting first. */
  1568. rdp->qlen_lazy += rsp->qlen_lazy;
  1569. rdp->qlen += rsp->qlen;
  1570. rdp->n_cbs_adopted += rsp->qlen;
  1571. if (rsp->qlen_lazy != rsp->qlen)
  1572. rcu_idle_count_callbacks_posted();
  1573. rsp->qlen_lazy = 0;
  1574. rsp->qlen = 0;
  1575. /*
  1576. * We do not need a memory barrier here because the only way we
  1577. * can get here if there is an rcu_barrier() in flight is if
  1578. * we are the task doing the rcu_barrier().
  1579. */
  1580. /* First adopt the ready-to-invoke callbacks. */
  1581. if (rsp->orphan_donelist != NULL) {
  1582. *rsp->orphan_donetail = *rdp->nxttail[RCU_DONE_TAIL];
  1583. *rdp->nxttail[RCU_DONE_TAIL] = rsp->orphan_donelist;
  1584. for (i = RCU_NEXT_SIZE - 1; i >= RCU_DONE_TAIL; i--)
  1585. if (rdp->nxttail[i] == rdp->nxttail[RCU_DONE_TAIL])
  1586. rdp->nxttail[i] = rsp->orphan_donetail;
  1587. rsp->orphan_donelist = NULL;
  1588. rsp->orphan_donetail = &rsp->orphan_donelist;
  1589. }
  1590. /* And then adopt the callbacks that still need a grace period. */
  1591. if (rsp->orphan_nxtlist != NULL) {
  1592. *rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_nxtlist;
  1593. rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_nxttail;
  1594. rsp->orphan_nxtlist = NULL;
  1595. rsp->orphan_nxttail = &rsp->orphan_nxtlist;
  1596. }
  1597. }
  1598. /*
  1599. * Trace the fact that this CPU is going offline.
  1600. */
  1601. static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
  1602. {
  1603. RCU_TRACE(unsigned long mask);
  1604. RCU_TRACE(struct rcu_data *rdp = this_cpu_ptr(rsp->rda));
  1605. RCU_TRACE(struct rcu_node *rnp = rdp->mynode);
  1606. RCU_TRACE(mask = rdp->grpmask);
  1607. trace_rcu_grace_period(rsp->name,
  1608. rnp->gpnum + 1 - !!(rnp->qsmask & mask),
  1609. "cpuofl");
  1610. }
  1611. /*
  1612. * The CPU has been completely removed, and some other CPU is reporting
  1613. * this fact from process context. Do the remainder of the cleanup,
  1614. * including orphaning the outgoing CPU's RCU callbacks, and also
  1615. * adopting them. There can only be one CPU hotplug operation at a time,
  1616. * so no other CPU can be attempting to update rcu_cpu_kthread_task.
  1617. */
  1618. static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
  1619. {
  1620. unsigned long flags;
  1621. unsigned long mask;
  1622. int need_report = 0;
  1623. struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
  1624. struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */
  1625. /* Adjust any no-longer-needed kthreads. */
  1626. rcu_boost_kthread_setaffinity(rnp, -1);
  1627. /* Remove the dead CPU from the bitmasks in the rcu_node hierarchy. */
  1628. /* Exclude any attempts to start a new grace period. */
  1629. mutex_lock(&rsp->onoff_mutex);
  1630. raw_spin_lock_irqsave(&rsp->orphan_lock, flags);
  1631. /* Orphan the dead CPU's callbacks, and adopt them if appropriate. */
  1632. rcu_send_cbs_to_orphanage(cpu, rsp, rnp, rdp);
  1633. rcu_adopt_orphan_cbs(rsp);
  1634. /* Remove the outgoing CPU from the masks in the rcu_node hierarchy. */
  1635. mask = rdp->grpmask; /* rnp->grplo is constant. */
  1636. do {
  1637. raw_spin_lock(&rnp->lock); /* irqs already disabled. */
  1638. rnp->qsmaskinit &= ~mask;
  1639. if (rnp->qsmaskinit != 0) {
  1640. if (rnp != rdp->mynode)
  1641. raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
  1642. break;
  1643. }
  1644. if (rnp == rdp->mynode)
  1645. need_report = rcu_preempt_offline_tasks(rsp, rnp, rdp);
  1646. else
  1647. raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
  1648. mask = rnp->grpmask;
  1649. rnp = rnp->parent;
  1650. } while (rnp != NULL);
  1651. /*
  1652. * We still hold the leaf rcu_node structure lock here, and
  1653. * irqs are still disabled. The reason for this subterfuge is
  1654. * because invoking rcu_report_unblock_qs_rnp() with ->orphan_lock
  1655. * held leads to deadlock.
  1656. */
  1657. raw_spin_unlock(&rsp->orphan_lock); /* irqs remain disabled. */
  1658. rnp = rdp->mynode;
  1659. if (need_report & RCU_OFL_TASKS_NORM_GP)
  1660. rcu_report_unblock_qs_rnp(rnp, flags);
  1661. else
  1662. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1663. if (need_report & RCU_OFL_TASKS_EXP_GP)
  1664. rcu_report_exp_rnp(rsp, rnp, true);
  1665. WARN_ONCE(rdp->qlen != 0 || rdp->nxtlist != NULL,
  1666. "rcu_cleanup_dead_cpu: Callbacks on offline CPU %d: qlen=%lu, nxtlist=%p\n",
  1667. cpu, rdp->qlen, rdp->nxtlist);
  1668. init_callback_list(rdp);
  1669. /* Disallow further callbacks on this CPU. */
  1670. rdp->nxttail[RCU_NEXT_TAIL] = NULL;
  1671. mutex_unlock(&rsp->onoff_mutex);
  1672. }
  1673. #else /* #ifdef CONFIG_HOTPLUG_CPU */
  1674. static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
  1675. {
  1676. }
  1677. static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
  1678. {
  1679. }
  1680. #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
  1681. /*
  1682. * Invoke any RCU callbacks that have made it to the end of their grace
  1683. * period. Thottle as specified by rdp->blimit.
  1684. */
  1685. static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
  1686. {
  1687. unsigned long flags;
  1688. struct rcu_head *next, *list, **tail;
  1689. long bl, count, count_lazy;
  1690. int i;
  1691. /* If no callbacks are ready, just return. */
  1692. if (!cpu_has_callbacks_ready_to_invoke(rdp)) {
  1693. trace_rcu_batch_start(rsp->name, rdp->qlen_lazy, rdp->qlen, 0);
  1694. trace_rcu_batch_end(rsp->name, 0, !!ACCESS_ONCE(rdp->nxtlist),
  1695. need_resched(), is_idle_task(current),
  1696. rcu_is_callbacks_kthread());
  1697. return;
  1698. }
  1699. /*
  1700. * Extract the list of ready callbacks, disabling to prevent
  1701. * races with call_rcu() from interrupt handlers.
  1702. */
  1703. local_irq_save(flags);
  1704. WARN_ON_ONCE(cpu_is_offline(smp_processor_id()));
  1705. bl = rdp->blimit;
  1706. trace_rcu_batch_start(rsp->name, rdp->qlen_lazy, rdp->qlen, bl);
  1707. list = rdp->nxtlist;
  1708. rdp->nxtlist = *rdp->nxttail[RCU_DONE_TAIL];
  1709. *rdp->nxttail[RCU_DONE_TAIL] = NULL;
  1710. tail = rdp->nxttail[RCU_DONE_TAIL];
  1711. for (i = RCU_NEXT_SIZE - 1; i >= 0; i--)
  1712. if (rdp->nxttail[i] == rdp->nxttail[RCU_DONE_TAIL])
  1713. rdp->nxttail[i] = &rdp->nxtlist;
  1714. local_irq_restore(flags);
  1715. /* Invoke callbacks. */
  1716. count = count_lazy = 0;
  1717. while (list) {
  1718. next = list->next;
  1719. prefetch(next);
  1720. debug_rcu_head_unqueue(list);
  1721. if (__rcu_reclaim(rsp->name, list))
  1722. count_lazy++;
  1723. list = next;
  1724. /* Stop only if limit reached and CPU has something to do. */
  1725. if (++count >= bl &&
  1726. (need_resched() ||
  1727. (!is_idle_task(current) && !rcu_is_callbacks_kthread())))
  1728. break;
  1729. }
  1730. local_irq_save(flags);
  1731. trace_rcu_batch_end(rsp->name, count, !!list, need_resched(),
  1732. is_idle_task(current),
  1733. rcu_is_callbacks_kthread());
  1734. /* Update count, and requeue any remaining callbacks. */
  1735. if (list != NULL) {
  1736. *tail = rdp->nxtlist;
  1737. rdp->nxtlist = list;
  1738. for (i = 0; i < RCU_NEXT_SIZE; i++)
  1739. if (&rdp->nxtlist == rdp->nxttail[i])
  1740. rdp->nxttail[i] = tail;
  1741. else
  1742. break;
  1743. }
  1744. smp_mb(); /* List handling before counting for rcu_barrier(). */
  1745. rdp->qlen_lazy -= count_lazy;
  1746. ACCESS_ONCE(rdp->qlen) -= count;
  1747. rdp->n_cbs_invoked += count;
  1748. /* Reinstate batch limit if we have worked down the excess. */
  1749. if (rdp->blimit == LONG_MAX && rdp->qlen <= qlowmark)
  1750. rdp->blimit = blimit;
  1751. /* Reset ->qlen_last_fqs_check trigger if enough CBs have drained. */
  1752. if (rdp->qlen == 0 && rdp->qlen_last_fqs_check != 0) {
  1753. rdp->qlen_last_fqs_check = 0;
  1754. rdp->n_force_qs_snap = rsp->n_force_qs;
  1755. } else if (rdp->qlen < rdp->qlen_last_fqs_check - qhimark)
  1756. rdp->qlen_last_fqs_check = rdp->qlen;
  1757. WARN_ON_ONCE((rdp->nxtlist == NULL) != (rdp->qlen == 0));
  1758. local_irq_restore(flags);
  1759. /* Re-invoke RCU core processing if there are callbacks remaining. */
  1760. if (cpu_has_callbacks_ready_to_invoke(rdp))
  1761. invoke_rcu_core();
  1762. }
  1763. /*
  1764. * Check to see if this CPU is in a non-context-switch quiescent state
  1765. * (user mode or idle loop for rcu, non-softirq execution for rcu_bh).
  1766. * Also schedule RCU core processing.
  1767. *
  1768. * This function must be called from hardirq context. It is normally
  1769. * invoked from the scheduling-clock interrupt. If rcu_pending returns
  1770. * false, there is no point in invoking rcu_check_callbacks().
  1771. */
  1772. void rcu_check_callbacks(int cpu, int user)
  1773. {
  1774. trace_rcu_utilization("Start scheduler-tick");
  1775. increment_cpu_stall_ticks();
  1776. if (user || rcu_is_cpu_rrupt_from_idle()) {
  1777. /*
  1778. * Get here if this CPU took its interrupt from user
  1779. * mode or from the idle loop, and if this is not a
  1780. * nested interrupt. In this case, the CPU is in
  1781. * a quiescent state, so note it.
  1782. *
  1783. * No memory barrier is required here because both
  1784. * rcu_sched_qs() and rcu_bh_qs() reference only CPU-local
  1785. * variables that other CPUs neither access nor modify,
  1786. * at least not while the corresponding CPU is online.
  1787. */
  1788. rcu_sched_qs(cpu);
  1789. rcu_bh_qs(cpu);
  1790. } else if (!in_softirq()) {
  1791. /*
  1792. * Get here if this CPU did not take its interrupt from
  1793. * softirq, in other words, if it is not interrupting
  1794. * a rcu_bh read-side critical section. This is an _bh
  1795. * critical section, so note it.
  1796. */
  1797. rcu_bh_qs(cpu);
  1798. }
  1799. rcu_preempt_check_callbacks(cpu);
  1800. if (rcu_pending(cpu))
  1801. invoke_rcu_core();
  1802. trace_rcu_utilization("End scheduler-tick");
  1803. }
  1804. /*
  1805. * Scan the leaf rcu_node structures, processing dyntick state for any that
  1806. * have not yet encountered a quiescent state, using the function specified.
  1807. * Also initiate boosting for any threads blocked on the root rcu_node.
  1808. *
  1809. * The caller must have suppressed start of new grace periods.
  1810. */
  1811. static void force_qs_rnp(struct rcu_state *rsp, int (*f)(struct rcu_data *))
  1812. {
  1813. unsigned long bit;
  1814. int cpu;
  1815. unsigned long flags;
  1816. unsigned long mask;
  1817. struct rcu_node *rnp;
  1818. rcu_for_each_leaf_node(rsp, rnp) {
  1819. cond_resched();
  1820. mask = 0;
  1821. raw_spin_lock_irqsave(&rnp->lock, flags);
  1822. if (!rcu_gp_in_progress(rsp)) {
  1823. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1824. return;
  1825. }
  1826. if (rnp->qsmask == 0) {
  1827. rcu_initiate_boost(rnp, flags); /* releases rnp->lock */
  1828. continue;
  1829. }
  1830. cpu = rnp->grplo;
  1831. bit = 1;
  1832. for (; cpu <= rnp->grphi; cpu++, bit <<= 1) {
  1833. if ((rnp->qsmask & bit) != 0 &&
  1834. f(per_cpu_ptr(rsp->rda, cpu)))
  1835. mask |= bit;
  1836. }
  1837. if (mask != 0) {
  1838. /* rcu_report_qs_rnp() releases rnp->lock. */
  1839. rcu_report_qs_rnp(mask, rsp, rnp, flags);
  1840. continue;
  1841. }
  1842. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1843. }
  1844. rnp = rcu_get_root(rsp);
  1845. if (rnp->qsmask == 0) {
  1846. raw_spin_lock_irqsave(&rnp->lock, flags);
  1847. rcu_initiate_boost(rnp, flags); /* releases rnp->lock. */
  1848. }
  1849. }
  1850. /*
  1851. * Force quiescent states on reluctant CPUs, and also detect which
  1852. * CPUs are in dyntick-idle mode.
  1853. */
  1854. static void force_quiescent_state(struct rcu_state *rsp)
  1855. {
  1856. unsigned long flags;
  1857. bool ret;
  1858. struct rcu_node *rnp;
  1859. struct rcu_node *rnp_old = NULL;
  1860. /* Funnel through hierarchy to reduce memory contention. */
  1861. rnp = per_cpu_ptr(rsp->rda, raw_smp_processor_id())->mynode;
  1862. for (; rnp != NULL; rnp = rnp->parent) {
  1863. ret = (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) ||
  1864. !raw_spin_trylock(&rnp->fqslock);
  1865. if (rnp_old != NULL)
  1866. raw_spin_unlock(&rnp_old->fqslock);
  1867. if (ret) {
  1868. rsp->n_force_qs_lh++;
  1869. return;
  1870. }
  1871. rnp_old = rnp;
  1872. }
  1873. /* rnp_old == rcu_get_root(rsp), rnp == NULL. */
  1874. /* Reached the root of the rcu_node tree, acquire lock. */
  1875. raw_spin_lock_irqsave(&rnp_old->lock, flags);
  1876. raw_spin_unlock(&rnp_old->fqslock);
  1877. if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
  1878. rsp->n_force_qs_lh++;
  1879. raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
  1880. return; /* Someone beat us to it. */
  1881. }
  1882. rsp->gp_flags |= RCU_GP_FLAG_FQS;
  1883. raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
  1884. wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
  1885. }
  1886. /*
  1887. * This does the RCU core processing work for the specified rcu_state
  1888. * and rcu_data structures. This may be called only from the CPU to
  1889. * whom the rdp belongs.
  1890. */
  1891. static void
  1892. __rcu_process_callbacks(struct rcu_state *rsp)
  1893. {
  1894. unsigned long flags;
  1895. struct rcu_data *rdp = __this_cpu_ptr(rsp->rda);
  1896. WARN_ON_ONCE(rdp->beenonline == 0);
  1897. /* Handle the end of a grace period that some other CPU ended. */
  1898. rcu_process_gp_end(rsp, rdp);
  1899. /* Update RCU state based on any recent quiescent states. */
  1900. rcu_check_quiescent_state(rsp, rdp);
  1901. /* Does this CPU require a not-yet-started grace period? */
  1902. local_irq_save(flags);
  1903. if (cpu_needs_another_gp(rsp, rdp)) {
  1904. raw_spin_lock(&rcu_get_root(rsp)->lock); /* irqs disabled. */
  1905. rcu_start_gp(rsp, flags); /* releases above lock */
  1906. } else {
  1907. local_irq_restore(flags);
  1908. }
  1909. /* If there are callbacks ready, invoke them. */
  1910. if (cpu_has_callbacks_ready_to_invoke(rdp))
  1911. invoke_rcu_callbacks(rsp, rdp);
  1912. }
  1913. /*
  1914. * Do RCU core processing for the current CPU.
  1915. */
  1916. static void rcu_process_callbacks(struct softirq_action *unused)
  1917. {
  1918. struct rcu_state *rsp;
  1919. if (cpu_is_offline(smp_processor_id()))
  1920. return;
  1921. trace_rcu_utilization("Start RCU core");
  1922. for_each_rcu_flavor(rsp)
  1923. __rcu_process_callbacks(rsp);
  1924. trace_rcu_utilization("End RCU core");
  1925. }
  1926. /*
  1927. * Schedule RCU callback invocation. If the specified type of RCU
  1928. * does not support RCU priority boosting, just do a direct call,
  1929. * otherwise wake up the per-CPU kernel kthread. Note that because we
  1930. * are running on the current CPU with interrupts disabled, the
  1931. * rcu_cpu_kthread_task cannot disappear out from under us.
  1932. */
  1933. static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
  1934. {
  1935. if (unlikely(!ACCESS_ONCE(rcu_scheduler_fully_active)))
  1936. return;
  1937. if (likely(!rsp->boost)) {
  1938. rcu_do_batch(rsp, rdp);
  1939. return;
  1940. }
  1941. invoke_rcu_callbacks_kthread();
  1942. }
  1943. static void invoke_rcu_core(void)
  1944. {
  1945. raise_softirq(RCU_SOFTIRQ);
  1946. }
  1947. /*
  1948. * Handle any core-RCU processing required by a call_rcu() invocation.
  1949. */
  1950. static void __call_rcu_core(struct rcu_state *rsp, struct rcu_data *rdp,
  1951. struct rcu_head *head, unsigned long flags)
  1952. {
  1953. /*
  1954. * If called from an extended quiescent state, invoke the RCU
  1955. * core in order to force a re-evaluation of RCU's idleness.
  1956. */
  1957. if (rcu_is_cpu_idle() && cpu_online(smp_processor_id()))
  1958. invoke_rcu_core();
  1959. /* If interrupts were disabled or CPU offline, don't invoke RCU core. */
  1960. if (irqs_disabled_flags(flags) || cpu_is_offline(smp_processor_id()))
  1961. return;
  1962. /*
  1963. * Force the grace period if too many callbacks or too long waiting.
  1964. * Enforce hysteresis, and don't invoke force_quiescent_state()
  1965. * if some other CPU has recently done so. Also, don't bother
  1966. * invoking force_quiescent_state() if the newly enqueued callback
  1967. * is the only one waiting for a grace period to complete.
  1968. */
  1969. if (unlikely(rdp->qlen > rdp->qlen_last_fqs_check + qhimark)) {
  1970. /* Are we ignoring a completed grace period? */
  1971. rcu_process_gp_end(rsp, rdp);
  1972. check_for_new_grace_period(rsp, rdp);
  1973. /* Start a new grace period if one not already started. */
  1974. if (!rcu_gp_in_progress(rsp)) {
  1975. unsigned long nestflag;
  1976. struct rcu_node *rnp_root = rcu_get_root(rsp);
  1977. raw_spin_lock_irqsave(&rnp_root->lock, nestflag);
  1978. rcu_start_gp(rsp, nestflag); /* rlses rnp_root->lock */
  1979. } else {
  1980. /* Give the grace period a kick. */
  1981. rdp->blimit = LONG_MAX;
  1982. if (rsp->n_force_qs == rdp->n_force_qs_snap &&
  1983. *rdp->nxttail[RCU_DONE_TAIL] != head)
  1984. force_quiescent_state(rsp);
  1985. rdp->n_force_qs_snap = rsp->n_force_qs;
  1986. rdp->qlen_last_fqs_check = rdp->qlen;
  1987. }
  1988. }
  1989. }
  1990. /*
  1991. * Helper function for call_rcu() and friends. The cpu argument will
  1992. * normally be -1, indicating "currently running CPU". It may specify
  1993. * a CPU only if that CPU is a no-CBs CPU. Currently, only _rcu_barrier()
  1994. * is expected to specify a CPU.
  1995. */
  1996. static void
  1997. __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
  1998. struct rcu_state *rsp, int cpu, bool lazy)
  1999. {
  2000. unsigned long flags;
  2001. struct rcu_data *rdp;
  2002. WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
  2003. debug_rcu_head_queue(head);
  2004. head->func = func;
  2005. head->next = NULL;
  2006. /*
  2007. * Opportunistically note grace-period endings and beginnings.
  2008. * Note that we might see a beginning right after we see an
  2009. * end, but never vice versa, since this CPU has to pass through
  2010. * a quiescent state betweentimes.
  2011. */
  2012. local_irq_save(flags);
  2013. rdp = this_cpu_ptr(rsp->rda);
  2014. /* Add the callback to our list. */
  2015. if (unlikely(rdp->nxttail[RCU_NEXT_TAIL] == NULL) || cpu != -1) {
  2016. int offline;
  2017. if (cpu != -1)
  2018. rdp = per_cpu_ptr(rsp->rda, cpu);
  2019. offline = !__call_rcu_nocb(rdp, head, lazy);
  2020. WARN_ON_ONCE(offline);
  2021. /* _call_rcu() is illegal on offline CPU; leak the callback. */
  2022. local_irq_restore(flags);
  2023. return;
  2024. }
  2025. ACCESS_ONCE(rdp->qlen)++;
  2026. if (lazy)
  2027. rdp->qlen_lazy++;
  2028. else
  2029. rcu_idle_count_callbacks_posted();
  2030. smp_mb(); /* Count before adding callback for rcu_barrier(). */
  2031. *rdp->nxttail[RCU_NEXT_TAIL] = head;
  2032. rdp->nxttail[RCU_NEXT_TAIL] = &head->next;
  2033. if (__is_kfree_rcu_offset((unsigned long)func))
  2034. trace_rcu_kfree_callback(rsp->name, head, (unsigned long)func,
  2035. rdp->qlen_lazy, rdp->qlen);
  2036. else
  2037. trace_rcu_callback(rsp->name, head, rdp->qlen_lazy, rdp->qlen);
  2038. /* Go handle any RCU core processing required. */
  2039. __call_rcu_core(rsp, rdp, head, flags);
  2040. local_irq_restore(flags);
  2041. }
  2042. /*
  2043. * Queue an RCU-sched callback for invocation after a grace period.
  2044. */
  2045. void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
  2046. {
  2047. __call_rcu(head, func, &rcu_sched_state, -1, 0);
  2048. }
  2049. EXPORT_SYMBOL_GPL(call_rcu_sched);
  2050. /*
  2051. * Queue an RCU callback for invocation after a quicker grace period.
  2052. */
  2053. void call_rcu_bh(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
  2054. {
  2055. __call_rcu(head, func, &rcu_bh_state, -1, 0);
  2056. }
  2057. EXPORT_SYMBOL_GPL(call_rcu_bh);
  2058. /*
  2059. * Because a context switch is a grace period for RCU-sched and RCU-bh,
  2060. * any blocking grace-period wait automatically implies a grace period
  2061. * if there is only one CPU online at any point time during execution
  2062. * of either synchronize_sched() or synchronize_rcu_bh(). It is OK to
  2063. * occasionally incorrectly indicate that there are multiple CPUs online
  2064. * when there was in fact only one the whole time, as this just adds
  2065. * some overhead: RCU still operates correctly.
  2066. */
  2067. static inline int rcu_blocking_is_gp(void)
  2068. {
  2069. int ret;
  2070. might_sleep(); /* Check for RCU read-side critical section. */
  2071. preempt_disable();
  2072. ret = num_online_cpus() <= 1;
  2073. preempt_enable();
  2074. return ret;
  2075. }
  2076. /**
  2077. * synchronize_sched - wait until an rcu-sched grace period has elapsed.
  2078. *
  2079. * Control will return to the caller some time after a full rcu-sched
  2080. * grace period has elapsed, in other words after all currently executing
  2081. * rcu-sched read-side critical sections have completed. These read-side
  2082. * critical sections are delimited by rcu_read_lock_sched() and
  2083. * rcu_read_unlock_sched(), and may be nested. Note that preempt_disable(),
  2084. * local_irq_disable(), and so on may be used in place of
  2085. * rcu_read_lock_sched().
  2086. *
  2087. * This means that all preempt_disable code sequences, including NMI and
  2088. * non-threaded hardware-interrupt handlers, in progress on entry will
  2089. * have completed before this primitive returns. However, this does not
  2090. * guarantee that softirq handlers will have completed, since in some
  2091. * kernels, these handlers can run in process context, and can block.
  2092. *
  2093. * Note that this guarantee implies further memory-ordering guarantees.
  2094. * On systems with more than one CPU, when synchronize_sched() returns,
  2095. * each CPU is guaranteed to have executed a full memory barrier since the
  2096. * end of its last RCU-sched read-side critical section whose beginning
  2097. * preceded the call to synchronize_sched(). In addition, each CPU having
  2098. * an RCU read-side critical section that extends beyond the return from
  2099. * synchronize_sched() is guaranteed to have executed a full memory barrier
  2100. * after the beginning of synchronize_sched() and before the beginning of
  2101. * that RCU read-side critical section. Note that these guarantees include
  2102. * CPUs that are offline, idle, or executing in user mode, as well as CPUs
  2103. * that are executing in the kernel.
  2104. *
  2105. * Furthermore, if CPU A invoked synchronize_sched(), which returned
  2106. * to its caller on CPU B, then both CPU A and CPU B are guaranteed
  2107. * to have executed a full memory barrier during the execution of
  2108. * synchronize_sched() -- even if CPU A and CPU B are the same CPU (but
  2109. * again only if the system has more than one CPU).
  2110. *
  2111. * This primitive provides the guarantees made by the (now removed)
  2112. * synchronize_kernel() API. In contrast, synchronize_rcu() only
  2113. * guarantees that rcu_read_lock() sections will have completed.
  2114. * In "classic RCU", these two guarantees happen to be one and
  2115. * the same, but can differ in realtime RCU implementations.
  2116. */
  2117. void synchronize_sched(void)
  2118. {
  2119. rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map) &&
  2120. !lock_is_held(&rcu_lock_map) &&
  2121. !lock_is_held(&rcu_sched_lock_map),
  2122. "Illegal synchronize_sched() in RCU-sched read-side critical section");
  2123. if (rcu_blocking_is_gp())
  2124. return;
  2125. if (rcu_expedited)
  2126. synchronize_sched_expedited();
  2127. else
  2128. wait_rcu_gp(call_rcu_sched);
  2129. }
  2130. EXPORT_SYMBOL_GPL(synchronize_sched);
  2131. /**
  2132. * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed.
  2133. *
  2134. * Control will return to the caller some time after a full rcu_bh grace
  2135. * period has elapsed, in other words after all currently executing rcu_bh
  2136. * read-side critical sections have completed. RCU read-side critical
  2137. * sections are delimited by rcu_read_lock_bh() and rcu_read_unlock_bh(),
  2138. * and may be nested.
  2139. *
  2140. * See the description of synchronize_sched() for more detailed information
  2141. * on memory ordering guarantees.
  2142. */
  2143. void synchronize_rcu_bh(void)
  2144. {
  2145. rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map) &&
  2146. !lock_is_held(&rcu_lock_map) &&
  2147. !lock_is_held(&rcu_sched_lock_map),
  2148. "Illegal synchronize_rcu_bh() in RCU-bh read-side critical section");
  2149. if (rcu_blocking_is_gp())
  2150. return;
  2151. if (rcu_expedited)
  2152. synchronize_rcu_bh_expedited();
  2153. else
  2154. wait_rcu_gp(call_rcu_bh);
  2155. }
  2156. EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
  2157. static int synchronize_sched_expedited_cpu_stop(void *data)
  2158. {
  2159. /*
  2160. * There must be a full memory barrier on each affected CPU
  2161. * between the time that try_stop_cpus() is called and the
  2162. * time that it returns.
  2163. *
  2164. * In the current initial implementation of cpu_stop, the
  2165. * above condition is already met when the control reaches
  2166. * this point and the following smp_mb() is not strictly
  2167. * necessary. Do smp_mb() anyway for documentation and
  2168. * robustness against future implementation changes.
  2169. */
  2170. smp_mb(); /* See above comment block. */
  2171. return 0;
  2172. }
  2173. /**
  2174. * synchronize_sched_expedited - Brute-force RCU-sched grace period
  2175. *
  2176. * Wait for an RCU-sched grace period to elapse, but use a "big hammer"
  2177. * approach to force the grace period to end quickly. This consumes
  2178. * significant time on all CPUs and is unfriendly to real-time workloads,
  2179. * so is thus not recommended for any sort of common-case code. In fact,
  2180. * if you are using synchronize_sched_expedited() in a loop, please
  2181. * restructure your code to batch your updates, and then use a single
  2182. * synchronize_sched() instead.
  2183. *
  2184. * Note that it is illegal to call this function while holding any lock
  2185. * that is acquired by a CPU-hotplug notifier. And yes, it is also illegal
  2186. * to call this function from a CPU-hotplug notifier. Failing to observe
  2187. * these restriction will result in deadlock.
  2188. *
  2189. * This implementation can be thought of as an application of ticket
  2190. * locking to RCU, with sync_sched_expedited_started and
  2191. * sync_sched_expedited_done taking on the roles of the halves
  2192. * of the ticket-lock word. Each task atomically increments
  2193. * sync_sched_expedited_started upon entry, snapshotting the old value,
  2194. * then attempts to stop all the CPUs. If this succeeds, then each
  2195. * CPU will have executed a context switch, resulting in an RCU-sched
  2196. * grace period. We are then done, so we use atomic_cmpxchg() to
  2197. * update sync_sched_expedited_done to match our snapshot -- but
  2198. * only if someone else has not already advanced past our snapshot.
  2199. *
  2200. * On the other hand, if try_stop_cpus() fails, we check the value
  2201. * of sync_sched_expedited_done. If it has advanced past our
  2202. * initial snapshot, then someone else must have forced a grace period
  2203. * some time after we took our snapshot. In this case, our work is
  2204. * done for us, and we can simply return. Otherwise, we try again,
  2205. * but keep our initial snapshot for purposes of checking for someone
  2206. * doing our work for us.
  2207. *
  2208. * If we fail too many times in a row, we fall back to synchronize_sched().
  2209. */
  2210. void synchronize_sched_expedited(void)
  2211. {
  2212. long firstsnap, s, snap;
  2213. int trycount = 0;
  2214. struct rcu_state *rsp = &rcu_sched_state;
  2215. /*
  2216. * If we are in danger of counter wrap, just do synchronize_sched().
  2217. * By allowing sync_sched_expedited_started to advance no more than
  2218. * ULONG_MAX/8 ahead of sync_sched_expedited_done, we are ensuring
  2219. * that more than 3.5 billion CPUs would be required to force a
  2220. * counter wrap on a 32-bit system. Quite a few more CPUs would of
  2221. * course be required on a 64-bit system.
  2222. */
  2223. if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
  2224. (ulong)atomic_long_read(&rsp->expedited_done) +
  2225. ULONG_MAX / 8)) {
  2226. synchronize_sched();
  2227. atomic_long_inc(&rsp->expedited_wrap);
  2228. return;
  2229. }
  2230. /*
  2231. * Take a ticket. Note that atomic_inc_return() implies a
  2232. * full memory barrier.
  2233. */
  2234. snap = atomic_long_inc_return(&rsp->expedited_start);
  2235. firstsnap = snap;
  2236. get_online_cpus();
  2237. WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
  2238. /*
  2239. * Each pass through the following loop attempts to force a
  2240. * context switch on each CPU.
  2241. */
  2242. while (try_stop_cpus(cpu_online_mask,
  2243. synchronize_sched_expedited_cpu_stop,
  2244. NULL) == -EAGAIN) {
  2245. put_online_cpus();
  2246. atomic_long_inc(&rsp->expedited_tryfail);
  2247. /* Check to see if someone else did our work for us. */
  2248. s = atomic_long_read(&rsp->expedited_done);
  2249. if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
  2250. /* ensure test happens before caller kfree */
  2251. smp_mb__before_atomic_inc(); /* ^^^ */
  2252. atomic_long_inc(&rsp->expedited_workdone1);
  2253. return;
  2254. }
  2255. /* No joy, try again later. Or just synchronize_sched(). */
  2256. if (trycount++ < 10) {
  2257. udelay(trycount * num_online_cpus());
  2258. } else {
  2259. wait_rcu_gp(call_rcu_sched);
  2260. atomic_long_inc(&rsp->expedited_normal);
  2261. return;
  2262. }
  2263. /* Recheck to see if someone else did our work for us. */
  2264. s = atomic_long_read(&rsp->expedited_done);
  2265. if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
  2266. /* ensure test happens before caller kfree */
  2267. smp_mb__before_atomic_inc(); /* ^^^ */
  2268. atomic_long_inc(&rsp->expedited_workdone2);
  2269. return;
  2270. }
  2271. /*
  2272. * Refetching sync_sched_expedited_started allows later
  2273. * callers to piggyback on our grace period. We retry
  2274. * after they started, so our grace period works for them,
  2275. * and they started after our first try, so their grace
  2276. * period works for us.
  2277. */
  2278. get_online_cpus();
  2279. snap = atomic_long_read(&rsp->expedited_start);
  2280. smp_mb(); /* ensure read is before try_stop_cpus(). */
  2281. }
  2282. atomic_long_inc(&rsp->expedited_stoppedcpus);
  2283. /*
  2284. * Everyone up to our most recent fetch is covered by our grace
  2285. * period. Update the counter, but only if our work is still
  2286. * relevant -- which it won't be if someone who started later
  2287. * than we did already did their update.
  2288. */
  2289. do {
  2290. atomic_long_inc(&rsp->expedited_done_tries);
  2291. s = atomic_long_read(&rsp->expedited_done);
  2292. if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
  2293. /* ensure test happens before caller kfree */
  2294. smp_mb__before_atomic_inc(); /* ^^^ */
  2295. atomic_long_inc(&rsp->expedited_done_lost);
  2296. break;
  2297. }
  2298. } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
  2299. atomic_long_inc(&rsp->expedited_done_exit);
  2300. put_online_cpus();
  2301. }
  2302. EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
  2303. /*
  2304. * Check to see if there is any immediate RCU-related work to be done
  2305. * by the current CPU, for the specified type of RCU, returning 1 if so.
  2306. * The checks are in order of increasing expense: checks that can be
  2307. * carried out against CPU-local state are performed first. However,
  2308. * we must check for CPU stalls first, else we might not get a chance.
  2309. */
  2310. static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp)
  2311. {
  2312. struct rcu_node *rnp = rdp->mynode;
  2313. rdp->n_rcu_pending++;
  2314. /* Check for CPU stalls, if enabled. */
  2315. check_cpu_stall(rsp, rdp);
  2316. /* Is the RCU core waiting for a quiescent state from this CPU? */
  2317. if (rcu_scheduler_fully_active &&
  2318. rdp->qs_pending && !rdp->passed_quiesce) {
  2319. rdp->n_rp_qs_pending++;
  2320. } else if (rdp->qs_pending && rdp->passed_quiesce) {
  2321. rdp->n_rp_report_qs++;
  2322. return 1;
  2323. }
  2324. /* Does this CPU have callbacks ready to invoke? */
  2325. if (cpu_has_callbacks_ready_to_invoke(rdp)) {
  2326. rdp->n_rp_cb_ready++;
  2327. return 1;
  2328. }
  2329. /* Has RCU gone idle with this CPU needing another grace period? */
  2330. if (cpu_needs_another_gp(rsp, rdp)) {
  2331. rdp->n_rp_cpu_needs_gp++;
  2332. return 1;
  2333. }
  2334. /* Has another RCU grace period completed? */
  2335. if (ACCESS_ONCE(rnp->completed) != rdp->completed) { /* outside lock */
  2336. rdp->n_rp_gp_completed++;
  2337. return 1;
  2338. }
  2339. /* Has a new RCU grace period started? */
  2340. if (ACCESS_ONCE(rnp->gpnum) != rdp->gpnum) { /* outside lock */
  2341. rdp->n_rp_gp_started++;
  2342. return 1;
  2343. }
  2344. /* nothing to do */
  2345. rdp->n_rp_need_nothing++;
  2346. return 0;
  2347. }
  2348. /*
  2349. * Check to see if there is any immediate RCU-related work to be done
  2350. * by the current CPU, returning 1 if so. This function is part of the
  2351. * RCU implementation; it is -not- an exported member of the RCU API.
  2352. */
  2353. static int rcu_pending(int cpu)
  2354. {
  2355. struct rcu_state *rsp;
  2356. for_each_rcu_flavor(rsp)
  2357. if (__rcu_pending(rsp, per_cpu_ptr(rsp->rda, cpu)))
  2358. return 1;
  2359. return 0;
  2360. }
  2361. /*
  2362. * Check to see if any future RCU-related work will need to be done
  2363. * by the current CPU, even if none need be done immediately, returning
  2364. * 1 if so.
  2365. */
  2366. static int rcu_cpu_has_callbacks(int cpu)
  2367. {
  2368. struct rcu_state *rsp;
  2369. /* RCU callbacks either ready or pending? */
  2370. for_each_rcu_flavor(rsp)
  2371. if (per_cpu_ptr(rsp->rda, cpu)->nxtlist)
  2372. return 1;
  2373. return 0;
  2374. }
  2375. /*
  2376. * Helper function for _rcu_barrier() tracing. If tracing is disabled,
  2377. * the compiler is expected to optimize this away.
  2378. */
  2379. static void _rcu_barrier_trace(struct rcu_state *rsp, char *s,
  2380. int cpu, unsigned long done)
  2381. {
  2382. trace_rcu_barrier(rsp->name, s, cpu,
  2383. atomic_read(&rsp->barrier_cpu_count), done);
  2384. }
  2385. /*
  2386. * RCU callback function for _rcu_barrier(). If we are last, wake
  2387. * up the task executing _rcu_barrier().
  2388. */
  2389. static void rcu_barrier_callback(struct rcu_head *rhp)
  2390. {
  2391. struct rcu_data *rdp = container_of(rhp, struct rcu_data, barrier_head);
  2392. struct rcu_state *rsp = rdp->rsp;
  2393. if (atomic_dec_and_test(&rsp->barrier_cpu_count)) {
  2394. _rcu_barrier_trace(rsp, "LastCB", -1, rsp->n_barrier_done);
  2395. complete(&rsp->barrier_completion);
  2396. } else {
  2397. _rcu_barrier_trace(rsp, "CB", -1, rsp->n_barrier_done);
  2398. }
  2399. }
  2400. /*
  2401. * Called with preemption disabled, and from cross-cpu IRQ context.
  2402. */
  2403. static void rcu_barrier_func(void *type)
  2404. {
  2405. struct rcu_state *rsp = type;
  2406. struct rcu_data *rdp = __this_cpu_ptr(rsp->rda);
  2407. _rcu_barrier_trace(rsp, "IRQ", -1, rsp->n_barrier_done);
  2408. atomic_inc(&rsp->barrier_cpu_count);
  2409. rsp->call(&rdp->barrier_head, rcu_barrier_callback);
  2410. }
  2411. /*
  2412. * Orchestrate the specified type of RCU barrier, waiting for all
  2413. * RCU callbacks of the specified type to complete.
  2414. */
  2415. static void _rcu_barrier(struct rcu_state *rsp)
  2416. {
  2417. int cpu;
  2418. struct rcu_data *rdp;
  2419. unsigned long snap = ACCESS_ONCE(rsp->n_barrier_done);
  2420. unsigned long snap_done;
  2421. _rcu_barrier_trace(rsp, "Begin", -1, snap);
  2422. /* Take mutex to serialize concurrent rcu_barrier() requests. */
  2423. mutex_lock(&rsp->barrier_mutex);
  2424. /*
  2425. * Ensure that all prior references, including to ->n_barrier_done,
  2426. * are ordered before the _rcu_barrier() machinery.
  2427. */
  2428. smp_mb(); /* See above block comment. */
  2429. /*
  2430. * Recheck ->n_barrier_done to see if others did our work for us.
  2431. * This means checking ->n_barrier_done for an even-to-odd-to-even
  2432. * transition. The "if" expression below therefore rounds the old
  2433. * value up to the next even number and adds two before comparing.
  2434. */
  2435. snap_done = ACCESS_ONCE(rsp->n_barrier_done);
  2436. _rcu_barrier_trace(rsp, "Check", -1, snap_done);
  2437. if (ULONG_CMP_GE(snap_done, ((snap + 1) & ~0x1) + 2)) {
  2438. _rcu_barrier_trace(rsp, "EarlyExit", -1, snap_done);
  2439. smp_mb(); /* caller's subsequent code after above check. */
  2440. mutex_unlock(&rsp->barrier_mutex);
  2441. return;
  2442. }
  2443. /*
  2444. * Increment ->n_barrier_done to avoid duplicate work. Use
  2445. * ACCESS_ONCE() to prevent the compiler from speculating
  2446. * the increment to precede the early-exit check.
  2447. */
  2448. ACCESS_ONCE(rsp->n_barrier_done)++;
  2449. WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
  2450. _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
  2451. smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
  2452. /*
  2453. * Initialize the count to one rather than to zero in order to
  2454. * avoid a too-soon return to zero in case of a short grace period
  2455. * (or preemption of this task). Exclude CPU-hotplug operations
  2456. * to ensure that no offline CPU has callbacks queued.
  2457. */
  2458. init_completion(&rsp->barrier_completion);
  2459. atomic_set(&rsp->barrier_cpu_count, 1);
  2460. get_online_cpus();
  2461. /*
  2462. * Force each CPU with callbacks to register a new callback.
  2463. * When that callback is invoked, we will know that all of the
  2464. * corresponding CPU's preceding callbacks have been invoked.
  2465. */
  2466. for_each_possible_cpu(cpu) {
  2467. if (!cpu_online(cpu) && !is_nocb_cpu(cpu))
  2468. continue;
  2469. rdp = per_cpu_ptr(rsp->rda, cpu);
  2470. if (is_nocb_cpu(cpu)) {
  2471. _rcu_barrier_trace(rsp, "OnlineNoCB", cpu,
  2472. rsp->n_barrier_done);
  2473. atomic_inc(&rsp->barrier_cpu_count);
  2474. __call_rcu(&rdp->barrier_head, rcu_barrier_callback,
  2475. rsp, cpu, 0);
  2476. } else if (ACCESS_ONCE(rdp->qlen)) {
  2477. _rcu_barrier_trace(rsp, "OnlineQ", cpu,
  2478. rsp->n_barrier_done);
  2479. smp_call_function_single(cpu, rcu_barrier_func, rsp, 1);
  2480. } else {
  2481. _rcu_barrier_trace(rsp, "OnlineNQ", cpu,
  2482. rsp->n_barrier_done);
  2483. }
  2484. }
  2485. put_online_cpus();
  2486. /*
  2487. * Now that we have an rcu_barrier_callback() callback on each
  2488. * CPU, and thus each counted, remove the initial count.
  2489. */
  2490. if (atomic_dec_and_test(&rsp->barrier_cpu_count))
  2491. complete(&rsp->barrier_completion);
  2492. /* Increment ->n_barrier_done to prevent duplicate work. */
  2493. smp_mb(); /* Keep increment after above mechanism. */
  2494. ACCESS_ONCE(rsp->n_barrier_done)++;
  2495. WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
  2496. _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
  2497. smp_mb(); /* Keep increment before caller's subsequent code. */
  2498. /* Wait for all rcu_barrier_callback() callbacks to be invoked. */
  2499. wait_for_completion(&rsp->barrier_completion);
  2500. /* Other rcu_barrier() invocations can now safely proceed. */
  2501. mutex_unlock(&rsp->barrier_mutex);
  2502. }
  2503. /**
  2504. * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete.
  2505. */
  2506. void rcu_barrier_bh(void)
  2507. {
  2508. _rcu_barrier(&rcu_bh_state);
  2509. }
  2510. EXPORT_SYMBOL_GPL(rcu_barrier_bh);
  2511. /**
  2512. * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks.
  2513. */
  2514. void rcu_barrier_sched(void)
  2515. {
  2516. _rcu_barrier(&rcu_sched_state);
  2517. }
  2518. EXPORT_SYMBOL_GPL(rcu_barrier_sched);
  2519. /*
  2520. * Do boot-time initialization of a CPU's per-CPU RCU data.
  2521. */
  2522. static void __init
  2523. rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
  2524. {
  2525. unsigned long flags;
  2526. struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
  2527. struct rcu_node *rnp = rcu_get_root(rsp);
  2528. /* Set up local state, ensuring consistent view of global state. */
  2529. raw_spin_lock_irqsave(&rnp->lock, flags);
  2530. rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
  2531. init_callback_list(rdp);
  2532. rdp->qlen_lazy = 0;
  2533. ACCESS_ONCE(rdp->qlen) = 0;
  2534. rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
  2535. WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
  2536. WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
  2537. rdp->cpu = cpu;
  2538. rdp->rsp = rsp;
  2539. rcu_boot_init_nocb_percpu_data(rdp);
  2540. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  2541. }
  2542. /*
  2543. * Initialize a CPU's per-CPU RCU data. Note that only one online or
  2544. * offline event can be happening at a given time. Note also that we
  2545. * can accept some slop in the rsp->completed access due to the fact
  2546. * that this CPU cannot possibly have any RCU callbacks in flight yet.
  2547. */
  2548. static void __cpuinit
  2549. rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
  2550. {
  2551. unsigned long flags;
  2552. unsigned long mask;
  2553. struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
  2554. struct rcu_node *rnp = rcu_get_root(rsp);
  2555. /* Exclude new grace periods. */
  2556. mutex_lock(&rsp->onoff_mutex);
  2557. /* Set up local state, ensuring consistent view of global state. */
  2558. raw_spin_lock_irqsave(&rnp->lock, flags);
  2559. rdp->beenonline = 1; /* We have now been online. */
  2560. rdp->preemptible = preemptible;
  2561. rdp->qlen_last_fqs_check = 0;
  2562. rdp->n_force_qs_snap = rsp->n_force_qs;
  2563. rdp->blimit = blimit;
  2564. init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
  2565. rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
  2566. atomic_set(&rdp->dynticks->dynticks,
  2567. (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
  2568. rcu_prepare_for_idle_init(cpu);
  2569. raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
  2570. /* Add CPU to rcu_node bitmasks. */
  2571. rnp = rdp->mynode;
  2572. mask = rdp->grpmask;
  2573. do {
  2574. /* Exclude any attempts to start a new GP on small systems. */
  2575. raw_spin_lock(&rnp->lock); /* irqs already disabled. */
  2576. rnp->qsmaskinit |= mask;
  2577. mask = rnp->grpmask;
  2578. if (rnp == rdp->mynode) {
  2579. /*
  2580. * If there is a grace period in progress, we will
  2581. * set up to wait for it next time we run the
  2582. * RCU core code.
  2583. */
  2584. rdp->gpnum = rnp->completed;
  2585. rdp->completed = rnp->completed;
  2586. rdp->passed_quiesce = 0;
  2587. rdp->qs_pending = 0;
  2588. trace_rcu_grace_period(rsp->name, rdp->gpnum, "cpuonl");
  2589. }
  2590. raw_spin_unlock(&rnp->lock); /* irqs already disabled. */
  2591. rnp = rnp->parent;
  2592. } while (rnp != NULL && !(rnp->qsmaskinit & mask));
  2593. local_irq_restore(flags);
  2594. mutex_unlock(&rsp->onoff_mutex);
  2595. }
  2596. static void __cpuinit rcu_prepare_cpu(int cpu)
  2597. {
  2598. struct rcu_state *rsp;
  2599. for_each_rcu_flavor(rsp)
  2600. rcu_init_percpu_data(cpu, rsp,
  2601. strcmp(rsp->name, "rcu_preempt") == 0);
  2602. }
  2603. /*
  2604. * Handle CPU online/offline notification events.
  2605. */
  2606. static int __cpuinit rcu_cpu_notify(struct notifier_block *self,
  2607. unsigned long action, void *hcpu)
  2608. {
  2609. long cpu = (long)hcpu;
  2610. struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, cpu);
  2611. struct rcu_node *rnp = rdp->mynode;
  2612. struct rcu_state *rsp;
  2613. trace_rcu_utilization("Start CPU hotplug");
  2614. switch (action) {
  2615. case CPU_UP_PREPARE:
  2616. case CPU_UP_PREPARE_FROZEN:
  2617. rcu_prepare_cpu(cpu);
  2618. rcu_prepare_kthreads(cpu);
  2619. break;
  2620. case CPU_ONLINE:
  2621. case CPU_DOWN_FAILED:
  2622. rcu_boost_kthread_setaffinity(rnp, -1);
  2623. break;
  2624. case CPU_DOWN_PREPARE:
  2625. rcu_boost_kthread_setaffinity(rnp, cpu);
  2626. break;
  2627. case CPU_DYING:
  2628. case CPU_DYING_FROZEN:
  2629. /*
  2630. * The whole machine is "stopped" except this CPU, so we can
  2631. * touch any data without introducing corruption. We send the
  2632. * dying CPU's callbacks to an arbitrarily chosen online CPU.
  2633. */
  2634. for_each_rcu_flavor(rsp)
  2635. rcu_cleanup_dying_cpu(rsp);
  2636. rcu_cleanup_after_idle(cpu);
  2637. break;
  2638. case CPU_DEAD:
  2639. case CPU_DEAD_FROZEN:
  2640. case CPU_UP_CANCELED:
  2641. case CPU_UP_CANCELED_FROZEN:
  2642. for_each_rcu_flavor(rsp)
  2643. rcu_cleanup_dead_cpu(cpu, rsp);
  2644. break;
  2645. default:
  2646. break;
  2647. }
  2648. trace_rcu_utilization("End CPU hotplug");
  2649. return NOTIFY_OK;
  2650. }
  2651. /*
  2652. * Spawn the kthread that handles this RCU flavor's grace periods.
  2653. */
  2654. static int __init rcu_spawn_gp_kthread(void)
  2655. {
  2656. unsigned long flags;
  2657. struct rcu_node *rnp;
  2658. struct rcu_state *rsp;
  2659. struct task_struct *t;
  2660. for_each_rcu_flavor(rsp) {
  2661. t = kthread_run(rcu_gp_kthread, rsp, rsp->name);
  2662. BUG_ON(IS_ERR(t));
  2663. rnp = rcu_get_root(rsp);
  2664. raw_spin_lock_irqsave(&rnp->lock, flags);
  2665. rsp->gp_kthread = t;
  2666. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  2667. rcu_spawn_nocb_kthreads(rsp);
  2668. }
  2669. return 0;
  2670. }
  2671. early_initcall(rcu_spawn_gp_kthread);
  2672. /*
  2673. * This function is invoked towards the end of the scheduler's initialization
  2674. * process. Before this is called, the idle task might contain
  2675. * RCU read-side critical sections (during which time, this idle
  2676. * task is booting the system). After this function is called, the
  2677. * idle tasks are prohibited from containing RCU read-side critical
  2678. * sections. This function also enables RCU lockdep checking.
  2679. */
  2680. void rcu_scheduler_starting(void)
  2681. {
  2682. WARN_ON(num_online_cpus() != 1);
  2683. WARN_ON(nr_context_switches() > 0);
  2684. rcu_scheduler_active = 1;
  2685. }
  2686. /*
  2687. * Compute the per-level fanout, either using the exact fanout specified
  2688. * or balancing the tree, depending on CONFIG_RCU_FANOUT_EXACT.
  2689. */
  2690. #ifdef CONFIG_RCU_FANOUT_EXACT
  2691. static void __init rcu_init_levelspread(struct rcu_state *rsp)
  2692. {
  2693. int i;
  2694. for (i = rcu_num_lvls - 1; i > 0; i--)
  2695. rsp->levelspread[i] = CONFIG_RCU_FANOUT;
  2696. rsp->levelspread[0] = rcu_fanout_leaf;
  2697. }
  2698. #else /* #ifdef CONFIG_RCU_FANOUT_EXACT */
  2699. static void __init rcu_init_levelspread(struct rcu_state *rsp)
  2700. {
  2701. int ccur;
  2702. int cprv;
  2703. int i;
  2704. cprv = nr_cpu_ids;
  2705. for (i = rcu_num_lvls - 1; i >= 0; i--) {
  2706. ccur = rsp->levelcnt[i];
  2707. rsp->levelspread[i] = (cprv + ccur - 1) / ccur;
  2708. cprv = ccur;
  2709. }
  2710. }
  2711. #endif /* #else #ifdef CONFIG_RCU_FANOUT_EXACT */
  2712. /*
  2713. * Helper function for rcu_init() that initializes one rcu_state structure.
  2714. */
  2715. static void __init rcu_init_one(struct rcu_state *rsp,
  2716. struct rcu_data __percpu *rda)
  2717. {
  2718. static char *buf[] = { "rcu_node_0",
  2719. "rcu_node_1",
  2720. "rcu_node_2",
  2721. "rcu_node_3" }; /* Match MAX_RCU_LVLS */
  2722. static char *fqs[] = { "rcu_node_fqs_0",
  2723. "rcu_node_fqs_1",
  2724. "rcu_node_fqs_2",
  2725. "rcu_node_fqs_3" }; /* Match MAX_RCU_LVLS */
  2726. int cpustride = 1;
  2727. int i;
  2728. int j;
  2729. struct rcu_node *rnp;
  2730. BUILD_BUG_ON(MAX_RCU_LVLS > ARRAY_SIZE(buf)); /* Fix buf[] init! */
  2731. /* Silence gcc 4.8 warning about array index out of range. */
  2732. if (rcu_num_lvls > RCU_NUM_LVLS)
  2733. panic("rcu_init_one: rcu_num_lvls overflow");
  2734. /* Initialize the level-tracking arrays. */
  2735. for (i = 0; i < rcu_num_lvls; i++)
  2736. rsp->levelcnt[i] = num_rcu_lvl[i];
  2737. for (i = 1; i < rcu_num_lvls; i++)
  2738. rsp->level[i] = rsp->level[i - 1] + rsp->levelcnt[i - 1];
  2739. rcu_init_levelspread(rsp);
  2740. /* Initialize the elements themselves, starting from the leaves. */
  2741. for (i = rcu_num_lvls - 1; i >= 0; i--) {
  2742. cpustride *= rsp->levelspread[i];
  2743. rnp = rsp->level[i];
  2744. for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) {
  2745. raw_spin_lock_init(&rnp->lock);
  2746. lockdep_set_class_and_name(&rnp->lock,
  2747. &rcu_node_class[i], buf[i]);
  2748. raw_spin_lock_init(&rnp->fqslock);
  2749. lockdep_set_class_and_name(&rnp->fqslock,
  2750. &rcu_fqs_class[i], fqs[i]);
  2751. rnp->gpnum = rsp->gpnum;
  2752. rnp->completed = rsp->completed;
  2753. rnp->qsmask = 0;
  2754. rnp->qsmaskinit = 0;
  2755. rnp->grplo = j * cpustride;
  2756. rnp->grphi = (j + 1) * cpustride - 1;
  2757. if (rnp->grphi >= NR_CPUS)
  2758. rnp->grphi = NR_CPUS - 1;
  2759. if (i == 0) {
  2760. rnp->grpnum = 0;
  2761. rnp->grpmask = 0;
  2762. rnp->parent = NULL;
  2763. } else {
  2764. rnp->grpnum = j % rsp->levelspread[i - 1];
  2765. rnp->grpmask = 1UL << rnp->grpnum;
  2766. rnp->parent = rsp->level[i - 1] +
  2767. j / rsp->levelspread[i - 1];
  2768. }
  2769. rnp->level = i;
  2770. INIT_LIST_HEAD(&rnp->blkd_tasks);
  2771. }
  2772. }
  2773. rsp->rda = rda;
  2774. init_waitqueue_head(&rsp->gp_wq);
  2775. rnp = rsp->level[rcu_num_lvls - 1];
  2776. for_each_possible_cpu(i) {
  2777. while (i > rnp->grphi)
  2778. rnp++;
  2779. per_cpu_ptr(rsp->rda, i)->mynode = rnp;
  2780. rcu_boot_init_percpu_data(i, rsp);
  2781. }
  2782. list_add(&rsp->flavors, &rcu_struct_flavors);
  2783. }
  2784. /*
  2785. * Compute the rcu_node tree geometry from kernel parameters. This cannot
  2786. * replace the definitions in rcutree.h because those are needed to size
  2787. * the ->node array in the rcu_state structure.
  2788. */
  2789. static void __init rcu_init_geometry(void)
  2790. {
  2791. int i;
  2792. int j;
  2793. int n = nr_cpu_ids;
  2794. int rcu_capacity[MAX_RCU_LVLS + 1];
  2795. /* If the compile-time values are accurate, just leave. */
  2796. if (rcu_fanout_leaf == CONFIG_RCU_FANOUT_LEAF &&
  2797. nr_cpu_ids == NR_CPUS)
  2798. return;
  2799. /*
  2800. * Compute number of nodes that can be handled an rcu_node tree
  2801. * with the given number of levels. Setting rcu_capacity[0] makes
  2802. * some of the arithmetic easier.
  2803. */
  2804. rcu_capacity[0] = 1;
  2805. rcu_capacity[1] = rcu_fanout_leaf;
  2806. for (i = 2; i <= MAX_RCU_LVLS; i++)
  2807. rcu_capacity[i] = rcu_capacity[i - 1] * CONFIG_RCU_FANOUT;
  2808. /*
  2809. * The boot-time rcu_fanout_leaf parameter is only permitted
  2810. * to increase the leaf-level fanout, not decrease it. Of course,
  2811. * the leaf-level fanout cannot exceed the number of bits in
  2812. * the rcu_node masks. Finally, the tree must be able to accommodate
  2813. * the configured number of CPUs. Complain and fall back to the
  2814. * compile-time values if these limits are exceeded.
  2815. */
  2816. if (rcu_fanout_leaf < CONFIG_RCU_FANOUT_LEAF ||
  2817. rcu_fanout_leaf > sizeof(unsigned long) * 8 ||
  2818. n > rcu_capacity[MAX_RCU_LVLS]) {
  2819. WARN_ON(1);
  2820. return;
  2821. }
  2822. /* Calculate the number of rcu_nodes at each level of the tree. */
  2823. for (i = 1; i <= MAX_RCU_LVLS; i++)
  2824. if (n <= rcu_capacity[i]) {
  2825. for (j = 0; j <= i; j++)
  2826. num_rcu_lvl[j] =
  2827. DIV_ROUND_UP(n, rcu_capacity[i - j]);
  2828. rcu_num_lvls = i;
  2829. for (j = i + 1; j <= MAX_RCU_LVLS; j++)
  2830. num_rcu_lvl[j] = 0;
  2831. break;
  2832. }
  2833. /* Calculate the total number of rcu_node structures. */
  2834. rcu_num_nodes = 0;
  2835. for (i = 0; i <= MAX_RCU_LVLS; i++)
  2836. rcu_num_nodes += num_rcu_lvl[i];
  2837. rcu_num_nodes -= n;
  2838. }
  2839. void __init rcu_init(void)
  2840. {
  2841. int cpu;
  2842. rcu_bootup_announce();
  2843. rcu_init_geometry();
  2844. rcu_init_one(&rcu_sched_state, &rcu_sched_data);
  2845. rcu_init_one(&rcu_bh_state, &rcu_bh_data);
  2846. __rcu_init_preempt();
  2847. open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
  2848. /*
  2849. * We don't need protection against CPU-hotplug here because
  2850. * this is called early in boot, before either interrupts
  2851. * or the scheduler are operational.
  2852. */
  2853. cpu_notifier(rcu_cpu_notify, 0);
  2854. for_each_online_cpu(cpu)
  2855. rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
  2856. }
  2857. #include "rcutree_plugin.h"