rcutree.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  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 <asm/atomic.h>
  40. #include <linux/bitops.h>
  41. #include <linux/module.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 "rcutree.h"
  50. /* Data structures. */
  51. static struct lock_class_key rcu_root_class;
  52. #define RCU_STATE_INITIALIZER(name) { \
  53. .level = { &name.node[0] }, \
  54. .levelcnt = { \
  55. NUM_RCU_LVL_0, /* root of hierarchy. */ \
  56. NUM_RCU_LVL_1, \
  57. NUM_RCU_LVL_2, \
  58. NUM_RCU_LVL_3, /* == MAX_RCU_LVLS */ \
  59. }, \
  60. .signaled = RCU_GP_IDLE, \
  61. .gpnum = -300, \
  62. .completed = -300, \
  63. .onofflock = __SPIN_LOCK_UNLOCKED(&name.onofflock), \
  64. .orphan_cbs_list = NULL, \
  65. .orphan_cbs_tail = &name.orphan_cbs_list, \
  66. .orphan_qlen = 0, \
  67. .fqslock = __SPIN_LOCK_UNLOCKED(&name.fqslock), \
  68. .n_force_qs = 0, \
  69. .n_force_qs_ngp = 0, \
  70. }
  71. struct rcu_state rcu_sched_state = RCU_STATE_INITIALIZER(rcu_sched_state);
  72. DEFINE_PER_CPU(struct rcu_data, rcu_sched_data);
  73. struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state);
  74. DEFINE_PER_CPU(struct rcu_data, rcu_bh_data);
  75. /*
  76. * Return true if an RCU grace period is in progress. The ACCESS_ONCE()s
  77. * permit this function to be invoked without holding the root rcu_node
  78. * structure's ->lock, but of course results can be subject to change.
  79. */
  80. static int rcu_gp_in_progress(struct rcu_state *rsp)
  81. {
  82. return ACCESS_ONCE(rsp->completed) != ACCESS_ONCE(rsp->gpnum);
  83. }
  84. /*
  85. * Note a quiescent state. Because we do not need to know
  86. * how many quiescent states passed, just if there was at least
  87. * one since the start of the grace period, this just sets a flag.
  88. */
  89. void rcu_sched_qs(int cpu)
  90. {
  91. struct rcu_data *rdp;
  92. rdp = &per_cpu(rcu_sched_data, cpu);
  93. rdp->passed_quiesc_completed = rdp->completed;
  94. barrier();
  95. rdp->passed_quiesc = 1;
  96. rcu_preempt_note_context_switch(cpu);
  97. }
  98. void rcu_bh_qs(int cpu)
  99. {
  100. struct rcu_data *rdp;
  101. rdp = &per_cpu(rcu_bh_data, cpu);
  102. rdp->passed_quiesc_completed = rdp->completed;
  103. barrier();
  104. rdp->passed_quiesc = 1;
  105. }
  106. #ifdef CONFIG_NO_HZ
  107. DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = {
  108. .dynticks_nesting = 1,
  109. .dynticks = 1,
  110. };
  111. #endif /* #ifdef CONFIG_NO_HZ */
  112. static int blimit = 10; /* Maximum callbacks per softirq. */
  113. static int qhimark = 10000; /* If this many pending, ignore blimit. */
  114. static int qlowmark = 100; /* Once only this many pending, use blimit. */
  115. module_param(blimit, int, 0);
  116. module_param(qhimark, int, 0);
  117. module_param(qlowmark, int, 0);
  118. static void force_quiescent_state(struct rcu_state *rsp, int relaxed);
  119. static int rcu_pending(int cpu);
  120. /*
  121. * Return the number of RCU-sched batches processed thus far for debug & stats.
  122. */
  123. long rcu_batches_completed_sched(void)
  124. {
  125. return rcu_sched_state.completed;
  126. }
  127. EXPORT_SYMBOL_GPL(rcu_batches_completed_sched);
  128. /*
  129. * Return the number of RCU BH batches processed thus far for debug & stats.
  130. */
  131. long rcu_batches_completed_bh(void)
  132. {
  133. return rcu_bh_state.completed;
  134. }
  135. EXPORT_SYMBOL_GPL(rcu_batches_completed_bh);
  136. /*
  137. * Does the CPU have callbacks ready to be invoked?
  138. */
  139. static int
  140. cpu_has_callbacks_ready_to_invoke(struct rcu_data *rdp)
  141. {
  142. return &rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL];
  143. }
  144. /*
  145. * Does the current CPU require a yet-as-unscheduled grace period?
  146. */
  147. static int
  148. cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp)
  149. {
  150. return *rdp->nxttail[RCU_DONE_TAIL] && !rcu_gp_in_progress(rsp);
  151. }
  152. /*
  153. * Return the root node of the specified rcu_state structure.
  154. */
  155. static struct rcu_node *rcu_get_root(struct rcu_state *rsp)
  156. {
  157. return &rsp->node[0];
  158. }
  159. /*
  160. * Record the specified "completed" value, which is later used to validate
  161. * dynticks counter manipulations and CPU-offline checks. Specify
  162. * "rsp->completed - 1" to unconditionally invalidate any future dynticks
  163. * manipulations and CPU-offline checks. Such invalidation is useful at
  164. * the beginning of a grace period.
  165. */
  166. static void dyntick_record_completed(struct rcu_state *rsp, long comp)
  167. {
  168. rsp->dynticks_completed = comp;
  169. }
  170. #ifdef CONFIG_SMP
  171. /*
  172. * Recall the previously recorded value of the completion for dynticks.
  173. */
  174. static long dyntick_recall_completed(struct rcu_state *rsp)
  175. {
  176. return rsp->dynticks_completed;
  177. }
  178. /*
  179. * If the specified CPU is offline, tell the caller that it is in
  180. * a quiescent state. Otherwise, whack it with a reschedule IPI.
  181. * Grace periods can end up waiting on an offline CPU when that
  182. * CPU is in the process of coming online -- it will be added to the
  183. * rcu_node bitmasks before it actually makes it online. The same thing
  184. * can happen while a CPU is in the process of coming online. Because this
  185. * race is quite rare, we check for it after detecting that the grace
  186. * period has been delayed rather than checking each and every CPU
  187. * each and every time we start a new grace period.
  188. */
  189. static int rcu_implicit_offline_qs(struct rcu_data *rdp)
  190. {
  191. /*
  192. * If the CPU is offline, it is in a quiescent state. We can
  193. * trust its state not to change because interrupts are disabled.
  194. */
  195. if (cpu_is_offline(rdp->cpu)) {
  196. rdp->offline_fqs++;
  197. return 1;
  198. }
  199. /* If preemptable RCU, no point in sending reschedule IPI. */
  200. if (rdp->preemptable)
  201. return 0;
  202. /* The CPU is online, so send it a reschedule IPI. */
  203. if (rdp->cpu != smp_processor_id())
  204. smp_send_reschedule(rdp->cpu);
  205. else
  206. set_need_resched();
  207. rdp->resched_ipi++;
  208. return 0;
  209. }
  210. #endif /* #ifdef CONFIG_SMP */
  211. #ifdef CONFIG_NO_HZ
  212. /**
  213. * rcu_enter_nohz - inform RCU that current CPU is entering nohz
  214. *
  215. * Enter nohz mode, in other words, -leave- the mode in which RCU
  216. * read-side critical sections can occur. (Though RCU read-side
  217. * critical sections can occur in irq handlers in nohz mode, a possibility
  218. * handled by rcu_irq_enter() and rcu_irq_exit()).
  219. */
  220. void rcu_enter_nohz(void)
  221. {
  222. unsigned long flags;
  223. struct rcu_dynticks *rdtp;
  224. smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */
  225. local_irq_save(flags);
  226. rdtp = &__get_cpu_var(rcu_dynticks);
  227. rdtp->dynticks++;
  228. rdtp->dynticks_nesting--;
  229. WARN_ON_ONCE(rdtp->dynticks & 0x1);
  230. local_irq_restore(flags);
  231. }
  232. /*
  233. * rcu_exit_nohz - inform RCU that current CPU is leaving nohz
  234. *
  235. * Exit nohz mode, in other words, -enter- the mode in which RCU
  236. * read-side critical sections normally occur.
  237. */
  238. void rcu_exit_nohz(void)
  239. {
  240. unsigned long flags;
  241. struct rcu_dynticks *rdtp;
  242. local_irq_save(flags);
  243. rdtp = &__get_cpu_var(rcu_dynticks);
  244. rdtp->dynticks++;
  245. rdtp->dynticks_nesting++;
  246. WARN_ON_ONCE(!(rdtp->dynticks & 0x1));
  247. local_irq_restore(flags);
  248. smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */
  249. }
  250. /**
  251. * rcu_nmi_enter - inform RCU of entry to NMI context
  252. *
  253. * If the CPU was idle with dynamic ticks active, and there is no
  254. * irq handler running, this updates rdtp->dynticks_nmi to let the
  255. * RCU grace-period handling know that the CPU is active.
  256. */
  257. void rcu_nmi_enter(void)
  258. {
  259. struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
  260. if (rdtp->dynticks & 0x1)
  261. return;
  262. rdtp->dynticks_nmi++;
  263. WARN_ON_ONCE(!(rdtp->dynticks_nmi & 0x1));
  264. smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */
  265. }
  266. /**
  267. * rcu_nmi_exit - inform RCU of exit from NMI context
  268. *
  269. * If the CPU was idle with dynamic ticks active, and there is no
  270. * irq handler running, this updates rdtp->dynticks_nmi to let the
  271. * RCU grace-period handling know that the CPU is no longer active.
  272. */
  273. void rcu_nmi_exit(void)
  274. {
  275. struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
  276. if (rdtp->dynticks & 0x1)
  277. return;
  278. smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */
  279. rdtp->dynticks_nmi++;
  280. WARN_ON_ONCE(rdtp->dynticks_nmi & 0x1);
  281. }
  282. /**
  283. * rcu_irq_enter - inform RCU of entry to hard irq context
  284. *
  285. * If the CPU was idle with dynamic ticks active, this updates the
  286. * rdtp->dynticks to let the RCU handling know that the CPU is active.
  287. */
  288. void rcu_irq_enter(void)
  289. {
  290. struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
  291. if (rdtp->dynticks_nesting++)
  292. return;
  293. rdtp->dynticks++;
  294. WARN_ON_ONCE(!(rdtp->dynticks & 0x1));
  295. smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */
  296. }
  297. /**
  298. * rcu_irq_exit - inform RCU of exit from hard irq context
  299. *
  300. * If the CPU was idle with dynamic ticks active, update the rdp->dynticks
  301. * to put let the RCU handling be aware that the CPU is going back to idle
  302. * with no ticks.
  303. */
  304. void rcu_irq_exit(void)
  305. {
  306. struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
  307. if (--rdtp->dynticks_nesting)
  308. return;
  309. smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */
  310. rdtp->dynticks++;
  311. WARN_ON_ONCE(rdtp->dynticks & 0x1);
  312. /* If the interrupt queued a callback, get out of dyntick mode. */
  313. if (__get_cpu_var(rcu_sched_data).nxtlist ||
  314. __get_cpu_var(rcu_bh_data).nxtlist)
  315. set_need_resched();
  316. }
  317. #ifdef CONFIG_SMP
  318. /*
  319. * Snapshot the specified CPU's dynticks counter so that we can later
  320. * credit them with an implicit quiescent state. Return 1 if this CPU
  321. * is in dynticks idle mode, which is an extended quiescent state.
  322. */
  323. static int dyntick_save_progress_counter(struct rcu_data *rdp)
  324. {
  325. int ret;
  326. int snap;
  327. int snap_nmi;
  328. snap = rdp->dynticks->dynticks;
  329. snap_nmi = rdp->dynticks->dynticks_nmi;
  330. smp_mb(); /* Order sampling of snap with end of grace period. */
  331. rdp->dynticks_snap = snap;
  332. rdp->dynticks_nmi_snap = snap_nmi;
  333. ret = ((snap & 0x1) == 0) && ((snap_nmi & 0x1) == 0);
  334. if (ret)
  335. rdp->dynticks_fqs++;
  336. return ret;
  337. }
  338. /*
  339. * Return true if the specified CPU has passed through a quiescent
  340. * state by virtue of being in or having passed through an dynticks
  341. * idle state since the last call to dyntick_save_progress_counter()
  342. * for this same CPU.
  343. */
  344. static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
  345. {
  346. long curr;
  347. long curr_nmi;
  348. long snap;
  349. long snap_nmi;
  350. curr = rdp->dynticks->dynticks;
  351. snap = rdp->dynticks_snap;
  352. curr_nmi = rdp->dynticks->dynticks_nmi;
  353. snap_nmi = rdp->dynticks_nmi_snap;
  354. smp_mb(); /* force ordering with cpu entering/leaving dynticks. */
  355. /*
  356. * If the CPU passed through or entered a dynticks idle phase with
  357. * no active irq/NMI handlers, then we can safely pretend that the CPU
  358. * already acknowledged the request to pass through a quiescent
  359. * state. Either way, that CPU cannot possibly be in an RCU
  360. * read-side critical section that started before the beginning
  361. * of the current RCU grace period.
  362. */
  363. if ((curr != snap || (curr & 0x1) == 0) &&
  364. (curr_nmi != snap_nmi || (curr_nmi & 0x1) == 0)) {
  365. rdp->dynticks_fqs++;
  366. return 1;
  367. }
  368. /* Go check for the CPU being offline. */
  369. return rcu_implicit_offline_qs(rdp);
  370. }
  371. #endif /* #ifdef CONFIG_SMP */
  372. #else /* #ifdef CONFIG_NO_HZ */
  373. #ifdef CONFIG_SMP
  374. static int dyntick_save_progress_counter(struct rcu_data *rdp)
  375. {
  376. return 0;
  377. }
  378. static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
  379. {
  380. return rcu_implicit_offline_qs(rdp);
  381. }
  382. #endif /* #ifdef CONFIG_SMP */
  383. #endif /* #else #ifdef CONFIG_NO_HZ */
  384. #ifdef CONFIG_RCU_CPU_STALL_DETECTOR
  385. static void record_gp_stall_check_time(struct rcu_state *rsp)
  386. {
  387. rsp->gp_start = jiffies;
  388. rsp->jiffies_stall = jiffies + RCU_SECONDS_TILL_STALL_CHECK;
  389. }
  390. static void print_other_cpu_stall(struct rcu_state *rsp)
  391. {
  392. int cpu;
  393. long delta;
  394. unsigned long flags;
  395. struct rcu_node *rnp = rcu_get_root(rsp);
  396. /* Only let one CPU complain about others per time interval. */
  397. spin_lock_irqsave(&rnp->lock, flags);
  398. delta = jiffies - rsp->jiffies_stall;
  399. if (delta < RCU_STALL_RAT_DELAY || !rcu_gp_in_progress(rsp)) {
  400. spin_unlock_irqrestore(&rnp->lock, flags);
  401. return;
  402. }
  403. rsp->jiffies_stall = jiffies + RCU_SECONDS_TILL_STALL_RECHECK;
  404. /*
  405. * Now rat on any tasks that got kicked up to the root rcu_node
  406. * due to CPU offlining.
  407. */
  408. rcu_print_task_stall(rnp);
  409. spin_unlock_irqrestore(&rnp->lock, flags);
  410. /* OK, time to rat on our buddy... */
  411. printk(KERN_ERR "INFO: RCU detected CPU stalls:");
  412. rcu_for_each_leaf_node(rsp, rnp) {
  413. rcu_print_task_stall(rnp);
  414. if (rnp->qsmask == 0)
  415. continue;
  416. for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
  417. if (rnp->qsmask & (1UL << cpu))
  418. printk(" %d", rnp->grplo + cpu);
  419. }
  420. printk(" (detected by %d, t=%ld jiffies)\n",
  421. smp_processor_id(), (long)(jiffies - rsp->gp_start));
  422. trigger_all_cpu_backtrace();
  423. force_quiescent_state(rsp, 0); /* Kick them all. */
  424. }
  425. static void print_cpu_stall(struct rcu_state *rsp)
  426. {
  427. unsigned long flags;
  428. struct rcu_node *rnp = rcu_get_root(rsp);
  429. printk(KERN_ERR "INFO: RCU detected CPU %d stall (t=%lu jiffies)\n",
  430. smp_processor_id(), jiffies - rsp->gp_start);
  431. trigger_all_cpu_backtrace();
  432. spin_lock_irqsave(&rnp->lock, flags);
  433. if ((long)(jiffies - rsp->jiffies_stall) >= 0)
  434. rsp->jiffies_stall =
  435. jiffies + RCU_SECONDS_TILL_STALL_RECHECK;
  436. spin_unlock_irqrestore(&rnp->lock, flags);
  437. set_need_resched(); /* kick ourselves to get things going. */
  438. }
  439. static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
  440. {
  441. long delta;
  442. struct rcu_node *rnp;
  443. delta = jiffies - rsp->jiffies_stall;
  444. rnp = rdp->mynode;
  445. if ((rnp->qsmask & rdp->grpmask) && delta >= 0) {
  446. /* We haven't checked in, so go dump stack. */
  447. print_cpu_stall(rsp);
  448. } else if (rcu_gp_in_progress(rsp) && delta >= RCU_STALL_RAT_DELAY) {
  449. /* They had two time units to dump stack, so complain. */
  450. print_other_cpu_stall(rsp);
  451. }
  452. }
  453. #else /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
  454. static void record_gp_stall_check_time(struct rcu_state *rsp)
  455. {
  456. }
  457. static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
  458. {
  459. }
  460. #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
  461. /*
  462. * Update CPU-local rcu_data state to record the newly noticed grace period.
  463. * This is used both when we started the grace period and when we notice
  464. * that someone else started the grace period.
  465. */
  466. static void note_new_gpnum(struct rcu_state *rsp, struct rcu_data *rdp)
  467. {
  468. rdp->qs_pending = 1;
  469. rdp->passed_quiesc = 0;
  470. rdp->gpnum = rsp->gpnum;
  471. }
  472. /*
  473. * Did someone else start a new RCU grace period start since we last
  474. * checked? Update local state appropriately if so. Must be called
  475. * on the CPU corresponding to rdp.
  476. */
  477. static int
  478. check_for_new_grace_period(struct rcu_state *rsp, struct rcu_data *rdp)
  479. {
  480. unsigned long flags;
  481. int ret = 0;
  482. local_irq_save(flags);
  483. if (rdp->gpnum != rsp->gpnum) {
  484. note_new_gpnum(rsp, rdp);
  485. ret = 1;
  486. }
  487. local_irq_restore(flags);
  488. return ret;
  489. }
  490. /*
  491. * Start a new RCU grace period if warranted, re-initializing the hierarchy
  492. * in preparation for detecting the next grace period. The caller must hold
  493. * the root node's ->lock, which is released before return. Hard irqs must
  494. * be disabled.
  495. */
  496. static void
  497. rcu_start_gp(struct rcu_state *rsp, unsigned long flags)
  498. __releases(rcu_get_root(rsp)->lock)
  499. {
  500. struct rcu_data *rdp = rsp->rda[smp_processor_id()];
  501. struct rcu_node *rnp = rcu_get_root(rsp);
  502. if (!cpu_needs_another_gp(rsp, rdp)) {
  503. spin_unlock_irqrestore(&rnp->lock, flags);
  504. return;
  505. }
  506. /* Advance to a new grace period and initialize state. */
  507. rsp->gpnum++;
  508. WARN_ON_ONCE(rsp->signaled == RCU_GP_INIT);
  509. rsp->signaled = RCU_GP_INIT; /* Hold off force_quiescent_state. */
  510. rsp->jiffies_force_qs = jiffies + RCU_JIFFIES_TILL_FORCE_QS;
  511. record_gp_stall_check_time(rsp);
  512. dyntick_record_completed(rsp, rsp->completed - 1);
  513. note_new_gpnum(rsp, rdp);
  514. /*
  515. * Because this CPU just now started the new grace period, we know
  516. * that all of its callbacks will be covered by this upcoming grace
  517. * period, even the ones that were registered arbitrarily recently.
  518. * Therefore, advance all outstanding callbacks to RCU_WAIT_TAIL.
  519. *
  520. * Other CPUs cannot be sure exactly when the grace period started.
  521. * Therefore, their recently registered callbacks must pass through
  522. * an additional RCU_NEXT_READY stage, so that they will be handled
  523. * by the next RCU grace period.
  524. */
  525. rdp->nxttail[RCU_NEXT_READY_TAIL] = rdp->nxttail[RCU_NEXT_TAIL];
  526. rdp->nxttail[RCU_WAIT_TAIL] = rdp->nxttail[RCU_NEXT_TAIL];
  527. /* Special-case the common single-level case. */
  528. if (NUM_RCU_NODES == 1) {
  529. rcu_preempt_check_blocked_tasks(rnp);
  530. rnp->qsmask = rnp->qsmaskinit;
  531. rnp->gpnum = rsp->gpnum;
  532. rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state OK. */
  533. spin_unlock_irqrestore(&rnp->lock, flags);
  534. return;
  535. }
  536. spin_unlock(&rnp->lock); /* leave irqs disabled. */
  537. /* Exclude any concurrent CPU-hotplug operations. */
  538. spin_lock(&rsp->onofflock); /* irqs already disabled. */
  539. /*
  540. * Set the quiescent-state-needed bits in all the rcu_node
  541. * structures for all currently online CPUs in breadth-first
  542. * order, starting from the root rcu_node structure. This
  543. * operation relies on the layout of the hierarchy within the
  544. * rsp->node[] array. Note that other CPUs will access only
  545. * the leaves of the hierarchy, which still indicate that no
  546. * grace period is in progress, at least until the corresponding
  547. * leaf node has been initialized. In addition, we have excluded
  548. * CPU-hotplug operations.
  549. *
  550. * Note that the grace period cannot complete until we finish
  551. * the initialization process, as there will be at least one
  552. * qsmask bit set in the root node until that time, namely the
  553. * one corresponding to this CPU, due to the fact that we have
  554. * irqs disabled.
  555. */
  556. rcu_for_each_node_breadth_first(rsp, rnp) {
  557. spin_lock(&rnp->lock); /* irqs already disabled. */
  558. rcu_preempt_check_blocked_tasks(rnp);
  559. rnp->qsmask = rnp->qsmaskinit;
  560. rnp->gpnum = rsp->gpnum;
  561. spin_unlock(&rnp->lock); /* irqs remain disabled. */
  562. }
  563. rnp = rcu_get_root(rsp);
  564. spin_lock(&rnp->lock); /* irqs already disabled. */
  565. rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state now OK. */
  566. spin_unlock(&rnp->lock); /* irqs remain disabled. */
  567. spin_unlock_irqrestore(&rsp->onofflock, flags);
  568. }
  569. /*
  570. * Advance this CPU's callbacks, but only if the current grace period
  571. * has ended. This may be called only from the CPU to whom the rdp
  572. * belongs.
  573. */
  574. static void
  575. rcu_process_gp_end(struct rcu_state *rsp, struct rcu_data *rdp)
  576. {
  577. long completed_snap;
  578. unsigned long flags;
  579. local_irq_save(flags);
  580. completed_snap = ACCESS_ONCE(rsp->completed); /* outside of lock. */
  581. /* Did another grace period end? */
  582. if (rdp->completed != completed_snap) {
  583. /* Advance callbacks. No harm if list empty. */
  584. rdp->nxttail[RCU_DONE_TAIL] = rdp->nxttail[RCU_WAIT_TAIL];
  585. rdp->nxttail[RCU_WAIT_TAIL] = rdp->nxttail[RCU_NEXT_READY_TAIL];
  586. rdp->nxttail[RCU_NEXT_READY_TAIL] = rdp->nxttail[RCU_NEXT_TAIL];
  587. /* Remember that we saw this grace-period completion. */
  588. rdp->completed = completed_snap;
  589. }
  590. local_irq_restore(flags);
  591. }
  592. /*
  593. * Clean up after the prior grace period and let rcu_start_gp() start up
  594. * the next grace period if one is needed. Note that the caller must
  595. * hold rnp->lock, as required by rcu_start_gp(), which will release it.
  596. */
  597. static void cpu_quiet_msk_finish(struct rcu_state *rsp, unsigned long flags)
  598. __releases(rcu_get_root(rsp)->lock)
  599. {
  600. WARN_ON_ONCE(!rcu_gp_in_progress(rsp));
  601. rsp->completed = rsp->gpnum;
  602. rsp->signaled = RCU_GP_IDLE;
  603. rcu_process_gp_end(rsp, rsp->rda[smp_processor_id()]);
  604. rcu_start_gp(rsp, flags); /* releases root node's rnp->lock. */
  605. }
  606. /*
  607. * Similar to cpu_quiet(), for which it is a helper function. Allows
  608. * a group of CPUs to be quieted at one go, though all the CPUs in the
  609. * group must be represented by the same leaf rcu_node structure.
  610. * That structure's lock must be held upon entry, and it is released
  611. * before return.
  612. */
  613. static void
  614. cpu_quiet_msk(unsigned long mask, struct rcu_state *rsp, struct rcu_node *rnp,
  615. unsigned long flags)
  616. __releases(rnp->lock)
  617. {
  618. struct rcu_node *rnp_c;
  619. /* Walk up the rcu_node hierarchy. */
  620. for (;;) {
  621. if (!(rnp->qsmask & mask)) {
  622. /* Our bit has already been cleared, so done. */
  623. spin_unlock_irqrestore(&rnp->lock, flags);
  624. return;
  625. }
  626. rnp->qsmask &= ~mask;
  627. if (rnp->qsmask != 0 || rcu_preempted_readers(rnp)) {
  628. /* Other bits still set at this level, so done. */
  629. spin_unlock_irqrestore(&rnp->lock, flags);
  630. return;
  631. }
  632. mask = rnp->grpmask;
  633. if (rnp->parent == NULL) {
  634. /* No more levels. Exit loop holding root lock. */
  635. break;
  636. }
  637. spin_unlock_irqrestore(&rnp->lock, flags);
  638. rnp_c = rnp;
  639. rnp = rnp->parent;
  640. spin_lock_irqsave(&rnp->lock, flags);
  641. WARN_ON_ONCE(rnp_c->qsmask);
  642. }
  643. /*
  644. * Get here if we are the last CPU to pass through a quiescent
  645. * state for this grace period. Invoke cpu_quiet_msk_finish()
  646. * to clean up and start the next grace period if one is needed.
  647. */
  648. cpu_quiet_msk_finish(rsp, flags); /* releases rnp->lock. */
  649. }
  650. /*
  651. * Record a quiescent state for the specified CPU, which must either be
  652. * the current CPU. The lastcomp argument is used to make sure we are
  653. * still in the grace period of interest. We don't want to end the current
  654. * grace period based on quiescent states detected in an earlier grace
  655. * period!
  656. */
  657. static void
  658. cpu_quiet(int cpu, struct rcu_state *rsp, struct rcu_data *rdp, long lastcomp)
  659. {
  660. unsigned long flags;
  661. unsigned long mask;
  662. struct rcu_node *rnp;
  663. rnp = rdp->mynode;
  664. spin_lock_irqsave(&rnp->lock, flags);
  665. if (lastcomp != ACCESS_ONCE(rsp->completed)) {
  666. /*
  667. * Someone beat us to it for this grace period, so leave.
  668. * The race with GP start is resolved by the fact that we
  669. * hold the leaf rcu_node lock, so that the per-CPU bits
  670. * cannot yet be initialized -- so we would simply find our
  671. * CPU's bit already cleared in cpu_quiet_msk() if this race
  672. * occurred.
  673. */
  674. rdp->passed_quiesc = 0; /* try again later! */
  675. spin_unlock_irqrestore(&rnp->lock, flags);
  676. return;
  677. }
  678. mask = rdp->grpmask;
  679. if ((rnp->qsmask & mask) == 0) {
  680. spin_unlock_irqrestore(&rnp->lock, flags);
  681. } else {
  682. rdp->qs_pending = 0;
  683. /*
  684. * This GP can't end until cpu checks in, so all of our
  685. * callbacks can be processed during the next GP.
  686. */
  687. rdp->nxttail[RCU_NEXT_READY_TAIL] = rdp->nxttail[RCU_NEXT_TAIL];
  688. cpu_quiet_msk(mask, rsp, rnp, flags); /* releases rnp->lock */
  689. }
  690. }
  691. /*
  692. * Check to see if there is a new grace period of which this CPU
  693. * is not yet aware, and if so, set up local rcu_data state for it.
  694. * Otherwise, see if this CPU has just passed through its first
  695. * quiescent state for this grace period, and record that fact if so.
  696. */
  697. static void
  698. rcu_check_quiescent_state(struct rcu_state *rsp, struct rcu_data *rdp)
  699. {
  700. /* If there is now a new grace period, record and return. */
  701. if (check_for_new_grace_period(rsp, rdp))
  702. return;
  703. /*
  704. * Does this CPU still need to do its part for current grace period?
  705. * If no, return and let the other CPUs do their part as well.
  706. */
  707. if (!rdp->qs_pending)
  708. return;
  709. /*
  710. * Was there a quiescent state since the beginning of the grace
  711. * period? If no, then exit and wait for the next call.
  712. */
  713. if (!rdp->passed_quiesc)
  714. return;
  715. /* Tell RCU we are done (but cpu_quiet() will be the judge of that). */
  716. cpu_quiet(rdp->cpu, rsp, rdp, rdp->passed_quiesc_completed);
  717. }
  718. #ifdef CONFIG_HOTPLUG_CPU
  719. /*
  720. * Move a dying CPU's RCU callbacks to the ->orphan_cbs_list for the
  721. * specified flavor of RCU. The callbacks will be adopted by the next
  722. * _rcu_barrier() invocation or by the CPU_DEAD notifier, whichever
  723. * comes first. Because this is invoked from the CPU_DYING notifier,
  724. * irqs are already disabled.
  725. */
  726. static void rcu_send_cbs_to_orphanage(struct rcu_state *rsp)
  727. {
  728. int i;
  729. struct rcu_data *rdp = rsp->rda[smp_processor_id()];
  730. if (rdp->nxtlist == NULL)
  731. return; /* irqs disabled, so comparison is stable. */
  732. spin_lock(&rsp->onofflock); /* irqs already disabled. */
  733. *rsp->orphan_cbs_tail = rdp->nxtlist;
  734. rsp->orphan_cbs_tail = rdp->nxttail[RCU_NEXT_TAIL];
  735. rdp->nxtlist = NULL;
  736. for (i = 0; i < RCU_NEXT_SIZE; i++)
  737. rdp->nxttail[i] = &rdp->nxtlist;
  738. rsp->orphan_qlen += rdp->qlen;
  739. rdp->qlen = 0;
  740. spin_unlock(&rsp->onofflock); /* irqs remain disabled. */
  741. }
  742. /*
  743. * Adopt previously orphaned RCU callbacks.
  744. */
  745. static void rcu_adopt_orphan_cbs(struct rcu_state *rsp)
  746. {
  747. unsigned long flags;
  748. struct rcu_data *rdp;
  749. spin_lock_irqsave(&rsp->onofflock, flags);
  750. rdp = rsp->rda[smp_processor_id()];
  751. if (rsp->orphan_cbs_list == NULL) {
  752. spin_unlock_irqrestore(&rsp->onofflock, flags);
  753. return;
  754. }
  755. *rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_cbs_list;
  756. rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_cbs_tail;
  757. rdp->qlen += rsp->orphan_qlen;
  758. rsp->orphan_cbs_list = NULL;
  759. rsp->orphan_cbs_tail = &rsp->orphan_cbs_list;
  760. rsp->orphan_qlen = 0;
  761. spin_unlock_irqrestore(&rsp->onofflock, flags);
  762. }
  763. /*
  764. * Remove the outgoing CPU from the bitmasks in the rcu_node hierarchy
  765. * and move all callbacks from the outgoing CPU to the current one.
  766. */
  767. static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp)
  768. {
  769. unsigned long flags;
  770. long lastcomp;
  771. unsigned long mask;
  772. struct rcu_data *rdp = rsp->rda[cpu];
  773. struct rcu_node *rnp;
  774. /* Exclude any attempts to start a new grace period. */
  775. spin_lock_irqsave(&rsp->onofflock, flags);
  776. /* Remove the outgoing CPU from the masks in the rcu_node hierarchy. */
  777. rnp = rdp->mynode; /* this is the outgoing CPU's rnp. */
  778. mask = rdp->grpmask; /* rnp->grplo is constant. */
  779. do {
  780. spin_lock(&rnp->lock); /* irqs already disabled. */
  781. rnp->qsmaskinit &= ~mask;
  782. if (rnp->qsmaskinit != 0) {
  783. spin_unlock(&rnp->lock); /* irqs remain disabled. */
  784. break;
  785. }
  786. /*
  787. * If there was a task blocking the current grace period,
  788. * and if all CPUs have checked in, we need to propagate
  789. * the quiescent state up the rcu_node hierarchy. But that
  790. * is inconvenient at the moment due to deadlock issues if
  791. * this should end the current grace period. So set the
  792. * offlined CPU's bit in ->qsmask in order to force the
  793. * next force_quiescent_state() invocation to clean up this
  794. * mess in a deadlock-free manner.
  795. */
  796. if (rcu_preempt_offline_tasks(rsp, rnp, rdp) && !rnp->qsmask)
  797. rnp->qsmask |= mask;
  798. mask = rnp->grpmask;
  799. spin_unlock(&rnp->lock); /* irqs remain disabled. */
  800. rnp = rnp->parent;
  801. } while (rnp != NULL);
  802. lastcomp = rsp->completed;
  803. spin_unlock_irqrestore(&rsp->onofflock, flags);
  804. rcu_adopt_orphan_cbs(rsp);
  805. }
  806. /*
  807. * Remove the specified CPU from the RCU hierarchy and move any pending
  808. * callbacks that it might have to the current CPU. This code assumes
  809. * that at least one CPU in the system will remain running at all times.
  810. * Any attempt to offline -all- CPUs is likely to strand RCU callbacks.
  811. */
  812. static void rcu_offline_cpu(int cpu)
  813. {
  814. __rcu_offline_cpu(cpu, &rcu_sched_state);
  815. __rcu_offline_cpu(cpu, &rcu_bh_state);
  816. rcu_preempt_offline_cpu(cpu);
  817. }
  818. #else /* #ifdef CONFIG_HOTPLUG_CPU */
  819. static void rcu_send_cbs_to_orphanage(struct rcu_state *rsp)
  820. {
  821. }
  822. static void rcu_adopt_orphan_cbs(struct rcu_state *rsp)
  823. {
  824. }
  825. static void rcu_offline_cpu(int cpu)
  826. {
  827. }
  828. #endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
  829. /*
  830. * Invoke any RCU callbacks that have made it to the end of their grace
  831. * period. Thottle as specified by rdp->blimit.
  832. */
  833. static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
  834. {
  835. unsigned long flags;
  836. struct rcu_head *next, *list, **tail;
  837. int count;
  838. /* If no callbacks are ready, just return.*/
  839. if (!cpu_has_callbacks_ready_to_invoke(rdp))
  840. return;
  841. /*
  842. * Extract the list of ready callbacks, disabling to prevent
  843. * races with call_rcu() from interrupt handlers.
  844. */
  845. local_irq_save(flags);
  846. list = rdp->nxtlist;
  847. rdp->nxtlist = *rdp->nxttail[RCU_DONE_TAIL];
  848. *rdp->nxttail[RCU_DONE_TAIL] = NULL;
  849. tail = rdp->nxttail[RCU_DONE_TAIL];
  850. for (count = RCU_NEXT_SIZE - 1; count >= 0; count--)
  851. if (rdp->nxttail[count] == rdp->nxttail[RCU_DONE_TAIL])
  852. rdp->nxttail[count] = &rdp->nxtlist;
  853. local_irq_restore(flags);
  854. /* Invoke callbacks. */
  855. count = 0;
  856. while (list) {
  857. next = list->next;
  858. prefetch(next);
  859. list->func(list);
  860. list = next;
  861. if (++count >= rdp->blimit)
  862. break;
  863. }
  864. local_irq_save(flags);
  865. /* Update count, and requeue any remaining callbacks. */
  866. rdp->qlen -= count;
  867. if (list != NULL) {
  868. *tail = rdp->nxtlist;
  869. rdp->nxtlist = list;
  870. for (count = 0; count < RCU_NEXT_SIZE; count++)
  871. if (&rdp->nxtlist == rdp->nxttail[count])
  872. rdp->nxttail[count] = tail;
  873. else
  874. break;
  875. }
  876. /* Reinstate batch limit if we have worked down the excess. */
  877. if (rdp->blimit == LONG_MAX && rdp->qlen <= qlowmark)
  878. rdp->blimit = blimit;
  879. /* Reset ->qlen_last_fqs_check trigger if enough CBs have drained. */
  880. if (rdp->qlen == 0 && rdp->qlen_last_fqs_check != 0) {
  881. rdp->qlen_last_fqs_check = 0;
  882. rdp->n_force_qs_snap = rsp->n_force_qs;
  883. } else if (rdp->qlen < rdp->qlen_last_fqs_check - qhimark)
  884. rdp->qlen_last_fqs_check = rdp->qlen;
  885. local_irq_restore(flags);
  886. /* Re-raise the RCU softirq if there are callbacks remaining. */
  887. if (cpu_has_callbacks_ready_to_invoke(rdp))
  888. raise_softirq(RCU_SOFTIRQ);
  889. }
  890. /*
  891. * Check to see if this CPU is in a non-context-switch quiescent state
  892. * (user mode or idle loop for rcu, non-softirq execution for rcu_bh).
  893. * Also schedule the RCU softirq handler.
  894. *
  895. * This function must be called with hardirqs disabled. It is normally
  896. * invoked from the scheduling-clock interrupt. If rcu_pending returns
  897. * false, there is no point in invoking rcu_check_callbacks().
  898. */
  899. void rcu_check_callbacks(int cpu, int user)
  900. {
  901. if (!rcu_pending(cpu))
  902. return; /* if nothing for RCU to do. */
  903. if (user ||
  904. (idle_cpu(cpu) && rcu_scheduler_active &&
  905. !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) {
  906. /*
  907. * Get here if this CPU took its interrupt from user
  908. * mode or from the idle loop, and if this is not a
  909. * nested interrupt. In this case, the CPU is in
  910. * a quiescent state, so note it.
  911. *
  912. * No memory barrier is required here because both
  913. * rcu_sched_qs() and rcu_bh_qs() reference only CPU-local
  914. * variables that other CPUs neither access nor modify,
  915. * at least not while the corresponding CPU is online.
  916. */
  917. rcu_sched_qs(cpu);
  918. rcu_bh_qs(cpu);
  919. } else if (!in_softirq()) {
  920. /*
  921. * Get here if this CPU did not take its interrupt from
  922. * softirq, in other words, if it is not interrupting
  923. * a rcu_bh read-side critical section. This is an _bh
  924. * critical section, so note it.
  925. */
  926. rcu_bh_qs(cpu);
  927. }
  928. rcu_preempt_check_callbacks(cpu);
  929. raise_softirq(RCU_SOFTIRQ);
  930. }
  931. #ifdef CONFIG_SMP
  932. /*
  933. * Scan the leaf rcu_node structures, processing dyntick state for any that
  934. * have not yet encountered a quiescent state, using the function specified.
  935. * Returns 1 if the current grace period ends while scanning (possibly
  936. * because we made it end).
  937. */
  938. static int rcu_process_dyntick(struct rcu_state *rsp, long lastcomp,
  939. int (*f)(struct rcu_data *))
  940. {
  941. unsigned long bit;
  942. int cpu;
  943. unsigned long flags;
  944. unsigned long mask;
  945. struct rcu_node *rnp;
  946. rcu_for_each_leaf_node(rsp, rnp) {
  947. mask = 0;
  948. spin_lock_irqsave(&rnp->lock, flags);
  949. if (rsp->completed != lastcomp) {
  950. spin_unlock_irqrestore(&rnp->lock, flags);
  951. return 1;
  952. }
  953. if (rnp->qsmask == 0) {
  954. spin_unlock_irqrestore(&rnp->lock, flags);
  955. continue;
  956. }
  957. cpu = rnp->grplo;
  958. bit = 1;
  959. for (; cpu <= rnp->grphi; cpu++, bit <<= 1) {
  960. if ((rnp->qsmask & bit) != 0 && f(rsp->rda[cpu]))
  961. mask |= bit;
  962. }
  963. if (mask != 0 && rsp->completed == lastcomp) {
  964. /* cpu_quiet_msk() releases rnp->lock. */
  965. cpu_quiet_msk(mask, rsp, rnp, flags);
  966. continue;
  967. }
  968. spin_unlock_irqrestore(&rnp->lock, flags);
  969. }
  970. return 0;
  971. }
  972. /*
  973. * Force quiescent states on reluctant CPUs, and also detect which
  974. * CPUs are in dyntick-idle mode.
  975. */
  976. static void force_quiescent_state(struct rcu_state *rsp, int relaxed)
  977. {
  978. unsigned long flags;
  979. long lastcomp;
  980. struct rcu_node *rnp = rcu_get_root(rsp);
  981. u8 signaled;
  982. u8 forcenow;
  983. if (!rcu_gp_in_progress(rsp))
  984. return; /* No grace period in progress, nothing to force. */
  985. if (!spin_trylock_irqsave(&rsp->fqslock, flags)) {
  986. rsp->n_force_qs_lh++; /* Inexact, can lose counts. Tough! */
  987. return; /* Someone else is already on the job. */
  988. }
  989. if (relaxed &&
  990. (long)(rsp->jiffies_force_qs - jiffies) >= 0)
  991. goto unlock_ret; /* no emergency and done recently. */
  992. rsp->n_force_qs++;
  993. spin_lock(&rnp->lock);
  994. lastcomp = rsp->completed;
  995. signaled = rsp->signaled;
  996. rsp->jiffies_force_qs = jiffies + RCU_JIFFIES_TILL_FORCE_QS;
  997. if (lastcomp == rsp->gpnum) {
  998. rsp->n_force_qs_ngp++;
  999. spin_unlock(&rnp->lock);
  1000. goto unlock_ret; /* no GP in progress, time updated. */
  1001. }
  1002. spin_unlock(&rnp->lock);
  1003. switch (signaled) {
  1004. case RCU_GP_IDLE:
  1005. case RCU_GP_INIT:
  1006. break; /* grace period idle or initializing, ignore. */
  1007. case RCU_SAVE_DYNTICK:
  1008. if (RCU_SIGNAL_INIT != RCU_SAVE_DYNTICK)
  1009. break; /* So gcc recognizes the dead code. */
  1010. /* Record dyntick-idle state. */
  1011. if (rcu_process_dyntick(rsp, lastcomp,
  1012. dyntick_save_progress_counter))
  1013. goto unlock_ret;
  1014. /* fall into next case. */
  1015. case RCU_SAVE_COMPLETED:
  1016. /* Update state, record completion counter. */
  1017. forcenow = 0;
  1018. spin_lock(&rnp->lock);
  1019. if (lastcomp == rsp->completed &&
  1020. rsp->signaled == signaled) {
  1021. rsp->signaled = RCU_FORCE_QS;
  1022. dyntick_record_completed(rsp, lastcomp);
  1023. forcenow = signaled == RCU_SAVE_COMPLETED;
  1024. }
  1025. spin_unlock(&rnp->lock);
  1026. if (!forcenow)
  1027. break;
  1028. /* fall into next case. */
  1029. case RCU_FORCE_QS:
  1030. /* Check dyntick-idle state, send IPI to laggarts. */
  1031. if (rcu_process_dyntick(rsp, dyntick_recall_completed(rsp),
  1032. rcu_implicit_dynticks_qs))
  1033. goto unlock_ret;
  1034. /* Leave state in case more forcing is required. */
  1035. break;
  1036. }
  1037. unlock_ret:
  1038. spin_unlock_irqrestore(&rsp->fqslock, flags);
  1039. }
  1040. #else /* #ifdef CONFIG_SMP */
  1041. static void force_quiescent_state(struct rcu_state *rsp, int relaxed)
  1042. {
  1043. set_need_resched();
  1044. }
  1045. #endif /* #else #ifdef CONFIG_SMP */
  1046. /*
  1047. * This does the RCU processing work from softirq context for the
  1048. * specified rcu_state and rcu_data structures. This may be called
  1049. * only from the CPU to whom the rdp belongs.
  1050. */
  1051. static void
  1052. __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
  1053. {
  1054. unsigned long flags;
  1055. WARN_ON_ONCE(rdp->beenonline == 0);
  1056. /*
  1057. * If an RCU GP has gone long enough, go check for dyntick
  1058. * idle CPUs and, if needed, send resched IPIs.
  1059. */
  1060. if ((long)(ACCESS_ONCE(rsp->jiffies_force_qs) - jiffies) < 0)
  1061. force_quiescent_state(rsp, 1);
  1062. /*
  1063. * Advance callbacks in response to end of earlier grace
  1064. * period that some other CPU ended.
  1065. */
  1066. rcu_process_gp_end(rsp, rdp);
  1067. /* Update RCU state based on any recent quiescent states. */
  1068. rcu_check_quiescent_state(rsp, rdp);
  1069. /* Does this CPU require a not-yet-started grace period? */
  1070. if (cpu_needs_another_gp(rsp, rdp)) {
  1071. spin_lock_irqsave(&rcu_get_root(rsp)->lock, flags);
  1072. rcu_start_gp(rsp, flags); /* releases above lock */
  1073. }
  1074. /* If there are callbacks ready, invoke them. */
  1075. rcu_do_batch(rsp, rdp);
  1076. }
  1077. /*
  1078. * Do softirq processing for the current CPU.
  1079. */
  1080. static void rcu_process_callbacks(struct softirq_action *unused)
  1081. {
  1082. /*
  1083. * Memory references from any prior RCU read-side critical sections
  1084. * executed by the interrupted code must be seen before any RCU
  1085. * grace-period manipulations below.
  1086. */
  1087. smp_mb(); /* See above block comment. */
  1088. __rcu_process_callbacks(&rcu_sched_state,
  1089. &__get_cpu_var(rcu_sched_data));
  1090. __rcu_process_callbacks(&rcu_bh_state, &__get_cpu_var(rcu_bh_data));
  1091. rcu_preempt_process_callbacks();
  1092. /*
  1093. * Memory references from any later RCU read-side critical sections
  1094. * executed by the interrupted code must be seen after any RCU
  1095. * grace-period manipulations above.
  1096. */
  1097. smp_mb(); /* See above block comment. */
  1098. }
  1099. static void
  1100. __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
  1101. struct rcu_state *rsp)
  1102. {
  1103. unsigned long flags;
  1104. struct rcu_data *rdp;
  1105. head->func = func;
  1106. head->next = NULL;
  1107. smp_mb(); /* Ensure RCU update seen before callback registry. */
  1108. /*
  1109. * Opportunistically note grace-period endings and beginnings.
  1110. * Note that we might see a beginning right after we see an
  1111. * end, but never vice versa, since this CPU has to pass through
  1112. * a quiescent state betweentimes.
  1113. */
  1114. local_irq_save(flags);
  1115. rdp = rsp->rda[smp_processor_id()];
  1116. rcu_process_gp_end(rsp, rdp);
  1117. check_for_new_grace_period(rsp, rdp);
  1118. /* Add the callback to our list. */
  1119. *rdp->nxttail[RCU_NEXT_TAIL] = head;
  1120. rdp->nxttail[RCU_NEXT_TAIL] = &head->next;
  1121. /* Start a new grace period if one not already started. */
  1122. if (!rcu_gp_in_progress(rsp)) {
  1123. unsigned long nestflag;
  1124. struct rcu_node *rnp_root = rcu_get_root(rsp);
  1125. spin_lock_irqsave(&rnp_root->lock, nestflag);
  1126. rcu_start_gp(rsp, nestflag); /* releases rnp_root->lock. */
  1127. }
  1128. /*
  1129. * Force the grace period if too many callbacks or too long waiting.
  1130. * Enforce hysteresis, and don't invoke force_quiescent_state()
  1131. * if some other CPU has recently done so. Also, don't bother
  1132. * invoking force_quiescent_state() if the newly enqueued callback
  1133. * is the only one waiting for a grace period to complete.
  1134. */
  1135. if (unlikely(++rdp->qlen > rdp->qlen_last_fqs_check + qhimark)) {
  1136. rdp->blimit = LONG_MAX;
  1137. if (rsp->n_force_qs == rdp->n_force_qs_snap &&
  1138. *rdp->nxttail[RCU_DONE_TAIL] != head)
  1139. force_quiescent_state(rsp, 0);
  1140. rdp->n_force_qs_snap = rsp->n_force_qs;
  1141. rdp->qlen_last_fqs_check = rdp->qlen;
  1142. } else if ((long)(ACCESS_ONCE(rsp->jiffies_force_qs) - jiffies) < 0)
  1143. force_quiescent_state(rsp, 1);
  1144. local_irq_restore(flags);
  1145. }
  1146. /*
  1147. * Queue an RCU-sched callback for invocation after a grace period.
  1148. */
  1149. void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
  1150. {
  1151. __call_rcu(head, func, &rcu_sched_state);
  1152. }
  1153. EXPORT_SYMBOL_GPL(call_rcu_sched);
  1154. /*
  1155. * Queue an RCU for invocation after a quicker grace period.
  1156. */
  1157. void call_rcu_bh(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
  1158. {
  1159. __call_rcu(head, func, &rcu_bh_state);
  1160. }
  1161. EXPORT_SYMBOL_GPL(call_rcu_bh);
  1162. /*
  1163. * Check to see if there is any immediate RCU-related work to be done
  1164. * by the current CPU, for the specified type of RCU, returning 1 if so.
  1165. * The checks are in order of increasing expense: checks that can be
  1166. * carried out against CPU-local state are performed first. However,
  1167. * we must check for CPU stalls first, else we might not get a chance.
  1168. */
  1169. static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp)
  1170. {
  1171. rdp->n_rcu_pending++;
  1172. /* Check for CPU stalls, if enabled. */
  1173. check_cpu_stall(rsp, rdp);
  1174. /* Is the RCU core waiting for a quiescent state from this CPU? */
  1175. if (rdp->qs_pending) {
  1176. rdp->n_rp_qs_pending++;
  1177. return 1;
  1178. }
  1179. /* Does this CPU have callbacks ready to invoke? */
  1180. if (cpu_has_callbacks_ready_to_invoke(rdp)) {
  1181. rdp->n_rp_cb_ready++;
  1182. return 1;
  1183. }
  1184. /* Has RCU gone idle with this CPU needing another grace period? */
  1185. if (cpu_needs_another_gp(rsp, rdp)) {
  1186. rdp->n_rp_cpu_needs_gp++;
  1187. return 1;
  1188. }
  1189. /* Has another RCU grace period completed? */
  1190. if (ACCESS_ONCE(rsp->completed) != rdp->completed) { /* outside lock */
  1191. rdp->n_rp_gp_completed++;
  1192. return 1;
  1193. }
  1194. /* Has a new RCU grace period started? */
  1195. if (ACCESS_ONCE(rsp->gpnum) != rdp->gpnum) { /* outside lock */
  1196. rdp->n_rp_gp_started++;
  1197. return 1;
  1198. }
  1199. /* Has an RCU GP gone long enough to send resched IPIs &c? */
  1200. if (rcu_gp_in_progress(rsp) &&
  1201. ((long)(ACCESS_ONCE(rsp->jiffies_force_qs) - jiffies) < 0)) {
  1202. rdp->n_rp_need_fqs++;
  1203. return 1;
  1204. }
  1205. /* nothing to do */
  1206. rdp->n_rp_need_nothing++;
  1207. return 0;
  1208. }
  1209. /*
  1210. * Check to see if there is any immediate RCU-related work to be done
  1211. * by the current CPU, returning 1 if so. This function is part of the
  1212. * RCU implementation; it is -not- an exported member of the RCU API.
  1213. */
  1214. static int rcu_pending(int cpu)
  1215. {
  1216. return __rcu_pending(&rcu_sched_state, &per_cpu(rcu_sched_data, cpu)) ||
  1217. __rcu_pending(&rcu_bh_state, &per_cpu(rcu_bh_data, cpu)) ||
  1218. rcu_preempt_pending(cpu);
  1219. }
  1220. /*
  1221. * Check to see if any future RCU-related work will need to be done
  1222. * by the current CPU, even if none need be done immediately, returning
  1223. * 1 if so. This function is part of the RCU implementation; it is -not-
  1224. * an exported member of the RCU API.
  1225. */
  1226. int rcu_needs_cpu(int cpu)
  1227. {
  1228. /* RCU callbacks either ready or pending? */
  1229. return per_cpu(rcu_sched_data, cpu).nxtlist ||
  1230. per_cpu(rcu_bh_data, cpu).nxtlist ||
  1231. rcu_preempt_needs_cpu(cpu);
  1232. }
  1233. static DEFINE_PER_CPU(struct rcu_head, rcu_barrier_head) = {NULL};
  1234. static atomic_t rcu_barrier_cpu_count;
  1235. static DEFINE_MUTEX(rcu_barrier_mutex);
  1236. static struct completion rcu_barrier_completion;
  1237. static void rcu_barrier_callback(struct rcu_head *notused)
  1238. {
  1239. if (atomic_dec_and_test(&rcu_barrier_cpu_count))
  1240. complete(&rcu_barrier_completion);
  1241. }
  1242. /*
  1243. * Called with preemption disabled, and from cross-cpu IRQ context.
  1244. */
  1245. static void rcu_barrier_func(void *type)
  1246. {
  1247. int cpu = smp_processor_id();
  1248. struct rcu_head *head = &per_cpu(rcu_barrier_head, cpu);
  1249. void (*call_rcu_func)(struct rcu_head *head,
  1250. void (*func)(struct rcu_head *head));
  1251. atomic_inc(&rcu_barrier_cpu_count);
  1252. call_rcu_func = type;
  1253. call_rcu_func(head, rcu_barrier_callback);
  1254. }
  1255. /*
  1256. * Orchestrate the specified type of RCU barrier, waiting for all
  1257. * RCU callbacks of the specified type to complete.
  1258. */
  1259. static void _rcu_barrier(struct rcu_state *rsp,
  1260. void (*call_rcu_func)(struct rcu_head *head,
  1261. void (*func)(struct rcu_head *head)))
  1262. {
  1263. BUG_ON(in_interrupt());
  1264. /* Take mutex to serialize concurrent rcu_barrier() requests. */
  1265. mutex_lock(&rcu_barrier_mutex);
  1266. init_completion(&rcu_barrier_completion);
  1267. /*
  1268. * Initialize rcu_barrier_cpu_count to 1, then invoke
  1269. * rcu_barrier_func() on each CPU, so that each CPU also has
  1270. * incremented rcu_barrier_cpu_count. Only then is it safe to
  1271. * decrement rcu_barrier_cpu_count -- otherwise the first CPU
  1272. * might complete its grace period before all of the other CPUs
  1273. * did their increment, causing this function to return too
  1274. * early.
  1275. */
  1276. atomic_set(&rcu_barrier_cpu_count, 1);
  1277. preempt_disable(); /* stop CPU_DYING from filling orphan_cbs_list */
  1278. rcu_adopt_orphan_cbs(rsp);
  1279. on_each_cpu(rcu_barrier_func, (void *)call_rcu_func, 1);
  1280. preempt_enable(); /* CPU_DYING can again fill orphan_cbs_list */
  1281. if (atomic_dec_and_test(&rcu_barrier_cpu_count))
  1282. complete(&rcu_barrier_completion);
  1283. wait_for_completion(&rcu_barrier_completion);
  1284. mutex_unlock(&rcu_barrier_mutex);
  1285. }
  1286. /**
  1287. * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete.
  1288. */
  1289. void rcu_barrier_bh(void)
  1290. {
  1291. _rcu_barrier(&rcu_bh_state, call_rcu_bh);
  1292. }
  1293. EXPORT_SYMBOL_GPL(rcu_barrier_bh);
  1294. /**
  1295. * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks.
  1296. */
  1297. void rcu_barrier_sched(void)
  1298. {
  1299. _rcu_barrier(&rcu_sched_state, call_rcu_sched);
  1300. }
  1301. EXPORT_SYMBOL_GPL(rcu_barrier_sched);
  1302. /*
  1303. * Do boot-time initialization of a CPU's per-CPU RCU data.
  1304. */
  1305. static void __init
  1306. rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
  1307. {
  1308. unsigned long flags;
  1309. int i;
  1310. struct rcu_data *rdp = rsp->rda[cpu];
  1311. struct rcu_node *rnp = rcu_get_root(rsp);
  1312. /* Set up local state, ensuring consistent view of global state. */
  1313. spin_lock_irqsave(&rnp->lock, flags);
  1314. rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
  1315. rdp->nxtlist = NULL;
  1316. for (i = 0; i < RCU_NEXT_SIZE; i++)
  1317. rdp->nxttail[i] = &rdp->nxtlist;
  1318. rdp->qlen = 0;
  1319. #ifdef CONFIG_NO_HZ
  1320. rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
  1321. #endif /* #ifdef CONFIG_NO_HZ */
  1322. rdp->cpu = cpu;
  1323. spin_unlock_irqrestore(&rnp->lock, flags);
  1324. }
  1325. /*
  1326. * Initialize a CPU's per-CPU RCU data. Note that only one online or
  1327. * offline event can be happening at a given time. Note also that we
  1328. * can accept some slop in the rsp->completed access due to the fact
  1329. * that this CPU cannot possibly have any RCU callbacks in flight yet.
  1330. */
  1331. static void __cpuinit
  1332. rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptable)
  1333. {
  1334. unsigned long flags;
  1335. long lastcomp;
  1336. unsigned long mask;
  1337. struct rcu_data *rdp = rsp->rda[cpu];
  1338. struct rcu_node *rnp = rcu_get_root(rsp);
  1339. /* Set up local state, ensuring consistent view of global state. */
  1340. spin_lock_irqsave(&rnp->lock, flags);
  1341. lastcomp = rsp->completed;
  1342. rdp->completed = lastcomp;
  1343. rdp->gpnum = lastcomp;
  1344. rdp->passed_quiesc = 0; /* We could be racing with new GP, */
  1345. rdp->qs_pending = 1; /* so set up to respond to current GP. */
  1346. rdp->beenonline = 1; /* We have now been online. */
  1347. rdp->preemptable = preemptable;
  1348. rdp->passed_quiesc_completed = lastcomp - 1;
  1349. rdp->qlen_last_fqs_check = 0;
  1350. rdp->n_force_qs_snap = rsp->n_force_qs;
  1351. rdp->blimit = blimit;
  1352. spin_unlock(&rnp->lock); /* irqs remain disabled. */
  1353. /*
  1354. * A new grace period might start here. If so, we won't be part
  1355. * of it, but that is OK, as we are currently in a quiescent state.
  1356. */
  1357. /* Exclude any attempts to start a new GP on large systems. */
  1358. spin_lock(&rsp->onofflock); /* irqs already disabled. */
  1359. /* Add CPU to rcu_node bitmasks. */
  1360. rnp = rdp->mynode;
  1361. mask = rdp->grpmask;
  1362. do {
  1363. /* Exclude any attempts to start a new GP on small systems. */
  1364. spin_lock(&rnp->lock); /* irqs already disabled. */
  1365. rnp->qsmaskinit |= mask;
  1366. mask = rnp->grpmask;
  1367. spin_unlock(&rnp->lock); /* irqs already disabled. */
  1368. rnp = rnp->parent;
  1369. } while (rnp != NULL && !(rnp->qsmaskinit & mask));
  1370. spin_unlock_irqrestore(&rsp->onofflock, flags);
  1371. }
  1372. static void __cpuinit rcu_online_cpu(int cpu)
  1373. {
  1374. rcu_init_percpu_data(cpu, &rcu_sched_state, 0);
  1375. rcu_init_percpu_data(cpu, &rcu_bh_state, 0);
  1376. rcu_preempt_init_percpu_data(cpu);
  1377. }
  1378. /*
  1379. * Handle CPU online/offline notification events.
  1380. */
  1381. int __cpuinit rcu_cpu_notify(struct notifier_block *self,
  1382. unsigned long action, void *hcpu)
  1383. {
  1384. long cpu = (long)hcpu;
  1385. switch (action) {
  1386. case CPU_UP_PREPARE:
  1387. case CPU_UP_PREPARE_FROZEN:
  1388. rcu_online_cpu(cpu);
  1389. break;
  1390. case CPU_DYING:
  1391. case CPU_DYING_FROZEN:
  1392. /*
  1393. * preempt_disable() in _rcu_barrier() prevents stop_machine(),
  1394. * so when "on_each_cpu(rcu_barrier_func, (void *)type, 1);"
  1395. * returns, all online cpus have queued rcu_barrier_func().
  1396. * The dying CPU clears its cpu_online_mask bit and
  1397. * moves all of its RCU callbacks to ->orphan_cbs_list
  1398. * in the context of stop_machine(), so subsequent calls
  1399. * to _rcu_barrier() will adopt these callbacks and only
  1400. * then queue rcu_barrier_func() on all remaining CPUs.
  1401. */
  1402. rcu_send_cbs_to_orphanage(&rcu_bh_state);
  1403. rcu_send_cbs_to_orphanage(&rcu_sched_state);
  1404. rcu_preempt_send_cbs_to_orphanage();
  1405. break;
  1406. case CPU_DEAD:
  1407. case CPU_DEAD_FROZEN:
  1408. case CPU_UP_CANCELED:
  1409. case CPU_UP_CANCELED_FROZEN:
  1410. rcu_offline_cpu(cpu);
  1411. break;
  1412. default:
  1413. break;
  1414. }
  1415. return NOTIFY_OK;
  1416. }
  1417. /*
  1418. * Compute the per-level fanout, either using the exact fanout specified
  1419. * or balancing the tree, depending on CONFIG_RCU_FANOUT_EXACT.
  1420. */
  1421. #ifdef CONFIG_RCU_FANOUT_EXACT
  1422. static void __init rcu_init_levelspread(struct rcu_state *rsp)
  1423. {
  1424. int i;
  1425. for (i = NUM_RCU_LVLS - 1; i >= 0; i--)
  1426. rsp->levelspread[i] = CONFIG_RCU_FANOUT;
  1427. }
  1428. #else /* #ifdef CONFIG_RCU_FANOUT_EXACT */
  1429. static void __init rcu_init_levelspread(struct rcu_state *rsp)
  1430. {
  1431. int ccur;
  1432. int cprv;
  1433. int i;
  1434. cprv = NR_CPUS;
  1435. for (i = NUM_RCU_LVLS - 1; i >= 0; i--) {
  1436. ccur = rsp->levelcnt[i];
  1437. rsp->levelspread[i] = (cprv + ccur - 1) / ccur;
  1438. cprv = ccur;
  1439. }
  1440. }
  1441. #endif /* #else #ifdef CONFIG_RCU_FANOUT_EXACT */
  1442. /*
  1443. * Helper function for rcu_init() that initializes one rcu_state structure.
  1444. */
  1445. static void __init rcu_init_one(struct rcu_state *rsp)
  1446. {
  1447. int cpustride = 1;
  1448. int i;
  1449. int j;
  1450. struct rcu_node *rnp;
  1451. /* Initialize the level-tracking arrays. */
  1452. for (i = 1; i < NUM_RCU_LVLS; i++)
  1453. rsp->level[i] = rsp->level[i - 1] + rsp->levelcnt[i - 1];
  1454. rcu_init_levelspread(rsp);
  1455. /* Initialize the elements themselves, starting from the leaves. */
  1456. for (i = NUM_RCU_LVLS - 1; i >= 0; i--) {
  1457. cpustride *= rsp->levelspread[i];
  1458. rnp = rsp->level[i];
  1459. for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) {
  1460. spin_lock_init(&rnp->lock);
  1461. rnp->gpnum = 0;
  1462. rnp->qsmask = 0;
  1463. rnp->qsmaskinit = 0;
  1464. rnp->grplo = j * cpustride;
  1465. rnp->grphi = (j + 1) * cpustride - 1;
  1466. if (rnp->grphi >= NR_CPUS)
  1467. rnp->grphi = NR_CPUS - 1;
  1468. if (i == 0) {
  1469. rnp->grpnum = 0;
  1470. rnp->grpmask = 0;
  1471. rnp->parent = NULL;
  1472. } else {
  1473. rnp->grpnum = j % rsp->levelspread[i - 1];
  1474. rnp->grpmask = 1UL << rnp->grpnum;
  1475. rnp->parent = rsp->level[i - 1] +
  1476. j / rsp->levelspread[i - 1];
  1477. }
  1478. rnp->level = i;
  1479. INIT_LIST_HEAD(&rnp->blocked_tasks[0]);
  1480. INIT_LIST_HEAD(&rnp->blocked_tasks[1]);
  1481. }
  1482. }
  1483. lockdep_set_class(&rcu_get_root(rsp)->lock, &rcu_root_class);
  1484. }
  1485. /*
  1486. * Helper macro for __rcu_init() and __rcu_init_preempt(). To be used
  1487. * nowhere else! Assigns leaf node pointers into each CPU's rcu_data
  1488. * structure.
  1489. */
  1490. #define RCU_INIT_FLAVOR(rsp, rcu_data) \
  1491. do { \
  1492. int i; \
  1493. int j; \
  1494. struct rcu_node *rnp; \
  1495. \
  1496. rcu_init_one(rsp); \
  1497. rnp = (rsp)->level[NUM_RCU_LVLS - 1]; \
  1498. j = 0; \
  1499. for_each_possible_cpu(i) { \
  1500. if (i > rnp[j].grphi) \
  1501. j++; \
  1502. per_cpu(rcu_data, i).mynode = &rnp[j]; \
  1503. (rsp)->rda[i] = &per_cpu(rcu_data, i); \
  1504. rcu_boot_init_percpu_data(i, rsp); \
  1505. } \
  1506. } while (0)
  1507. void __init __rcu_init(void)
  1508. {
  1509. rcu_bootup_announce();
  1510. #ifdef CONFIG_RCU_CPU_STALL_DETECTOR
  1511. printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n");
  1512. #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
  1513. RCU_INIT_FLAVOR(&rcu_sched_state, rcu_sched_data);
  1514. RCU_INIT_FLAVOR(&rcu_bh_state, rcu_bh_data);
  1515. __rcu_init_preempt();
  1516. open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
  1517. }
  1518. #include "rcutree_plugin.h"