rcutree.c 50 KB

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