rcutree.c 50 KB

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