rcutree_plugin.h 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288
  1. /*
  2. * Read-Copy Update mechanism for mutual exclusion (tree-based version)
  3. * Internal non-public definitions that provide either classic
  4. * or preemptible semantics.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. *
  20. * Copyright Red Hat, 2009
  21. * Copyright IBM Corporation, 2009
  22. *
  23. * Author: Ingo Molnar <mingo@elte.hu>
  24. * Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  25. */
  26. #include <linux/delay.h>
  27. #define RCU_KTHREAD_PRIO 1
  28. #ifdef CONFIG_RCU_BOOST
  29. #define RCU_BOOST_PRIO CONFIG_RCU_BOOST_PRIO
  30. #else
  31. #define RCU_BOOST_PRIO RCU_KTHREAD_PRIO
  32. #endif
  33. /*
  34. * Check the RCU kernel configuration parameters and print informative
  35. * messages about anything out of the ordinary. If you like #ifdef, you
  36. * will love this function.
  37. */
  38. static void __init rcu_bootup_announce_oddness(void)
  39. {
  40. #ifdef CONFIG_RCU_TRACE
  41. printk(KERN_INFO "\tRCU debugfs-based tracing is enabled.\n");
  42. #endif
  43. #if (defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 64) || (!defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 32)
  44. printk(KERN_INFO "\tCONFIG_RCU_FANOUT set to non-default value of %d\n",
  45. CONFIG_RCU_FANOUT);
  46. #endif
  47. #ifdef CONFIG_RCU_FANOUT_EXACT
  48. printk(KERN_INFO "\tHierarchical RCU autobalancing is disabled.\n");
  49. #endif
  50. #ifdef CONFIG_RCU_FAST_NO_HZ
  51. printk(KERN_INFO
  52. "\tRCU dyntick-idle grace-period acceleration is enabled.\n");
  53. #endif
  54. #ifdef CONFIG_PROVE_RCU
  55. printk(KERN_INFO "\tRCU lockdep checking is enabled.\n");
  56. #endif
  57. #ifdef CONFIG_RCU_TORTURE_TEST_RUNNABLE
  58. printk(KERN_INFO "\tRCU torture testing starts during boot.\n");
  59. #endif
  60. #if defined(CONFIG_TREE_PREEMPT_RCU) && !defined(CONFIG_RCU_CPU_STALL_VERBOSE)
  61. printk(KERN_INFO "\tDump stacks of tasks blocking RCU-preempt GP.\n");
  62. #endif
  63. #if defined(CONFIG_RCU_CPU_STALL_INFO)
  64. printk(KERN_INFO "\tAdditional per-CPU info printed with stalls.\n");
  65. #endif
  66. #if NUM_RCU_LVL_4 != 0
  67. printk(KERN_INFO "\tExperimental four-level hierarchy is enabled.\n");
  68. #endif
  69. }
  70. #ifdef CONFIG_TREE_PREEMPT_RCU
  71. struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt);
  72. DEFINE_PER_CPU(struct rcu_data, rcu_preempt_data);
  73. static struct rcu_state *rcu_state = &rcu_preempt_state;
  74. static void rcu_read_unlock_special(struct task_struct *t);
  75. static int rcu_preempted_readers_exp(struct rcu_node *rnp);
  76. /*
  77. * Tell them what RCU they are running.
  78. */
  79. static void __init rcu_bootup_announce(void)
  80. {
  81. printk(KERN_INFO "Preemptible hierarchical RCU implementation.\n");
  82. rcu_bootup_announce_oddness();
  83. }
  84. /*
  85. * Return the number of RCU-preempt batches processed thus far
  86. * for debug and statistics.
  87. */
  88. long rcu_batches_completed_preempt(void)
  89. {
  90. return rcu_preempt_state.completed;
  91. }
  92. EXPORT_SYMBOL_GPL(rcu_batches_completed_preempt);
  93. /*
  94. * Return the number of RCU batches processed thus far for debug & stats.
  95. */
  96. long rcu_batches_completed(void)
  97. {
  98. return rcu_batches_completed_preempt();
  99. }
  100. EXPORT_SYMBOL_GPL(rcu_batches_completed);
  101. /*
  102. * Force a quiescent state for preemptible RCU.
  103. */
  104. void rcu_force_quiescent_state(void)
  105. {
  106. force_quiescent_state(&rcu_preempt_state, 0);
  107. }
  108. EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
  109. /*
  110. * Record a preemptible-RCU quiescent state for the specified CPU. Note
  111. * that this just means that the task currently running on the CPU is
  112. * not in a quiescent state. There might be any number of tasks blocked
  113. * while in an RCU read-side critical section.
  114. *
  115. * Unlike the other rcu_*_qs() functions, callers to this function
  116. * must disable irqs in order to protect the assignment to
  117. * ->rcu_read_unlock_special.
  118. */
  119. static void rcu_preempt_qs(int cpu)
  120. {
  121. struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu);
  122. rdp->passed_quiesce_gpnum = rdp->gpnum;
  123. barrier();
  124. if (rdp->passed_quiesce == 0)
  125. trace_rcu_grace_period("rcu_preempt", rdp->gpnum, "cpuqs");
  126. rdp->passed_quiesce = 1;
  127. current->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
  128. }
  129. /*
  130. * We have entered the scheduler, and the current task might soon be
  131. * context-switched away from. If this task is in an RCU read-side
  132. * critical section, we will no longer be able to rely on the CPU to
  133. * record that fact, so we enqueue the task on the blkd_tasks list.
  134. * The task will dequeue itself when it exits the outermost enclosing
  135. * RCU read-side critical section. Therefore, the current grace period
  136. * cannot be permitted to complete until the blkd_tasks list entries
  137. * predating the current grace period drain, in other words, until
  138. * rnp->gp_tasks becomes NULL.
  139. *
  140. * Caller must disable preemption.
  141. */
  142. static void rcu_preempt_note_context_switch(int cpu)
  143. {
  144. struct task_struct *t = current;
  145. unsigned long flags;
  146. struct rcu_data *rdp;
  147. struct rcu_node *rnp;
  148. if (t->rcu_read_lock_nesting > 0 &&
  149. (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) {
  150. /* Possibly blocking in an RCU read-side critical section. */
  151. rdp = per_cpu_ptr(rcu_preempt_state.rda, cpu);
  152. rnp = rdp->mynode;
  153. raw_spin_lock_irqsave(&rnp->lock, flags);
  154. t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED;
  155. t->rcu_blocked_node = rnp;
  156. /*
  157. * If this CPU has already checked in, then this task
  158. * will hold up the next grace period rather than the
  159. * current grace period. Queue the task accordingly.
  160. * If the task is queued for the current grace period
  161. * (i.e., this CPU has not yet passed through a quiescent
  162. * state for the current grace period), then as long
  163. * as that task remains queued, the current grace period
  164. * cannot end. Note that there is some uncertainty as
  165. * to exactly when the current grace period started.
  166. * We take a conservative approach, which can result
  167. * in unnecessarily waiting on tasks that started very
  168. * slightly after the current grace period began. C'est
  169. * la vie!!!
  170. *
  171. * But first, note that the current CPU must still be
  172. * on line!
  173. */
  174. WARN_ON_ONCE((rdp->grpmask & rnp->qsmaskinit) == 0);
  175. WARN_ON_ONCE(!list_empty(&t->rcu_node_entry));
  176. if ((rnp->qsmask & rdp->grpmask) && rnp->gp_tasks != NULL) {
  177. list_add(&t->rcu_node_entry, rnp->gp_tasks->prev);
  178. rnp->gp_tasks = &t->rcu_node_entry;
  179. #ifdef CONFIG_RCU_BOOST
  180. if (rnp->boost_tasks != NULL)
  181. rnp->boost_tasks = rnp->gp_tasks;
  182. #endif /* #ifdef CONFIG_RCU_BOOST */
  183. } else {
  184. list_add(&t->rcu_node_entry, &rnp->blkd_tasks);
  185. if (rnp->qsmask & rdp->grpmask)
  186. rnp->gp_tasks = &t->rcu_node_entry;
  187. }
  188. trace_rcu_preempt_task(rdp->rsp->name,
  189. t->pid,
  190. (rnp->qsmask & rdp->grpmask)
  191. ? rnp->gpnum
  192. : rnp->gpnum + 1);
  193. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  194. } else if (t->rcu_read_lock_nesting < 0 &&
  195. t->rcu_read_unlock_special) {
  196. /*
  197. * Complete exit from RCU read-side critical section on
  198. * behalf of preempted instance of __rcu_read_unlock().
  199. */
  200. rcu_read_unlock_special(t);
  201. }
  202. /*
  203. * Either we were not in an RCU read-side critical section to
  204. * begin with, or we have now recorded that critical section
  205. * globally. Either way, we can now note a quiescent state
  206. * for this CPU. Again, if we were in an RCU read-side critical
  207. * section, and if that critical section was blocking the current
  208. * grace period, then the fact that the task has been enqueued
  209. * means that we continue to block the current grace period.
  210. */
  211. local_irq_save(flags);
  212. rcu_preempt_qs(cpu);
  213. local_irq_restore(flags);
  214. }
  215. /*
  216. * Tree-preemptible RCU implementation for rcu_read_lock().
  217. * Just increment ->rcu_read_lock_nesting, shared state will be updated
  218. * if we block.
  219. */
  220. void __rcu_read_lock(void)
  221. {
  222. current->rcu_read_lock_nesting++;
  223. barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
  224. }
  225. EXPORT_SYMBOL_GPL(__rcu_read_lock);
  226. /*
  227. * Check for preempted RCU readers blocking the current grace period
  228. * for the specified rcu_node structure. If the caller needs a reliable
  229. * answer, it must hold the rcu_node's ->lock.
  230. */
  231. static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)
  232. {
  233. return rnp->gp_tasks != NULL;
  234. }
  235. /*
  236. * Record a quiescent state for all tasks that were previously queued
  237. * on the specified rcu_node structure and that were blocking the current
  238. * RCU grace period. The caller must hold the specified rnp->lock with
  239. * irqs disabled, and this lock is released upon return, but irqs remain
  240. * disabled.
  241. */
  242. static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags)
  243. __releases(rnp->lock)
  244. {
  245. unsigned long mask;
  246. struct rcu_node *rnp_p;
  247. if (rnp->qsmask != 0 || rcu_preempt_blocked_readers_cgp(rnp)) {
  248. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  249. return; /* Still need more quiescent states! */
  250. }
  251. rnp_p = rnp->parent;
  252. if (rnp_p == NULL) {
  253. /*
  254. * Either there is only one rcu_node in the tree,
  255. * or tasks were kicked up to root rcu_node due to
  256. * CPUs going offline.
  257. */
  258. rcu_report_qs_rsp(&rcu_preempt_state, flags);
  259. return;
  260. }
  261. /* Report up the rest of the hierarchy. */
  262. mask = rnp->grpmask;
  263. raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
  264. raw_spin_lock(&rnp_p->lock); /* irqs already disabled. */
  265. rcu_report_qs_rnp(mask, &rcu_preempt_state, rnp_p, flags);
  266. }
  267. /*
  268. * Advance a ->blkd_tasks-list pointer to the next entry, instead
  269. * returning NULL if at the end of the list.
  270. */
  271. static struct list_head *rcu_next_node_entry(struct task_struct *t,
  272. struct rcu_node *rnp)
  273. {
  274. struct list_head *np;
  275. np = t->rcu_node_entry.next;
  276. if (np == &rnp->blkd_tasks)
  277. np = NULL;
  278. return np;
  279. }
  280. /*
  281. * Handle special cases during rcu_read_unlock(), such as needing to
  282. * notify RCU core processing or task having blocked during the RCU
  283. * read-side critical section.
  284. */
  285. static noinline void rcu_read_unlock_special(struct task_struct *t)
  286. {
  287. int empty;
  288. int empty_exp;
  289. int empty_exp_now;
  290. unsigned long flags;
  291. struct list_head *np;
  292. #ifdef CONFIG_RCU_BOOST
  293. struct rt_mutex *rbmp = NULL;
  294. #endif /* #ifdef CONFIG_RCU_BOOST */
  295. struct rcu_node *rnp;
  296. int special;
  297. /* NMI handlers cannot block and cannot safely manipulate state. */
  298. if (in_nmi())
  299. return;
  300. local_irq_save(flags);
  301. /*
  302. * If RCU core is waiting for this CPU to exit critical section,
  303. * let it know that we have done so.
  304. */
  305. special = t->rcu_read_unlock_special;
  306. if (special & RCU_READ_UNLOCK_NEED_QS) {
  307. rcu_preempt_qs(smp_processor_id());
  308. }
  309. /* Hardware IRQ handlers cannot block. */
  310. if (in_irq() || in_serving_softirq()) {
  311. local_irq_restore(flags);
  312. return;
  313. }
  314. /* Clean up if blocked during RCU read-side critical section. */
  315. if (special & RCU_READ_UNLOCK_BLOCKED) {
  316. t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_BLOCKED;
  317. /*
  318. * Remove this task from the list it blocked on. The
  319. * task can migrate while we acquire the lock, but at
  320. * most one time. So at most two passes through loop.
  321. */
  322. for (;;) {
  323. rnp = t->rcu_blocked_node;
  324. raw_spin_lock(&rnp->lock); /* irqs already disabled. */
  325. if (rnp == t->rcu_blocked_node)
  326. break;
  327. raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
  328. }
  329. empty = !rcu_preempt_blocked_readers_cgp(rnp);
  330. empty_exp = !rcu_preempted_readers_exp(rnp);
  331. smp_mb(); /* ensure expedited fastpath sees end of RCU c-s. */
  332. np = rcu_next_node_entry(t, rnp);
  333. list_del_init(&t->rcu_node_entry);
  334. t->rcu_blocked_node = NULL;
  335. trace_rcu_unlock_preempted_task("rcu_preempt",
  336. rnp->gpnum, t->pid);
  337. if (&t->rcu_node_entry == rnp->gp_tasks)
  338. rnp->gp_tasks = np;
  339. if (&t->rcu_node_entry == rnp->exp_tasks)
  340. rnp->exp_tasks = np;
  341. #ifdef CONFIG_RCU_BOOST
  342. if (&t->rcu_node_entry == rnp->boost_tasks)
  343. rnp->boost_tasks = np;
  344. /* Snapshot/clear ->rcu_boost_mutex with rcu_node lock held. */
  345. if (t->rcu_boost_mutex) {
  346. rbmp = t->rcu_boost_mutex;
  347. t->rcu_boost_mutex = NULL;
  348. }
  349. #endif /* #ifdef CONFIG_RCU_BOOST */
  350. /*
  351. * If this was the last task on the current list, and if
  352. * we aren't waiting on any CPUs, report the quiescent state.
  353. * Note that rcu_report_unblock_qs_rnp() releases rnp->lock,
  354. * so we must take a snapshot of the expedited state.
  355. */
  356. empty_exp_now = !rcu_preempted_readers_exp(rnp);
  357. if (!empty && !rcu_preempt_blocked_readers_cgp(rnp)) {
  358. trace_rcu_quiescent_state_report("preempt_rcu",
  359. rnp->gpnum,
  360. 0, rnp->qsmask,
  361. rnp->level,
  362. rnp->grplo,
  363. rnp->grphi,
  364. !!rnp->gp_tasks);
  365. rcu_report_unblock_qs_rnp(rnp, flags);
  366. } else
  367. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  368. #ifdef CONFIG_RCU_BOOST
  369. /* Unboost if we were boosted. */
  370. if (rbmp)
  371. rt_mutex_unlock(rbmp);
  372. #endif /* #ifdef CONFIG_RCU_BOOST */
  373. /*
  374. * If this was the last task on the expedited lists,
  375. * then we need to report up the rcu_node hierarchy.
  376. */
  377. if (!empty_exp && empty_exp_now)
  378. rcu_report_exp_rnp(&rcu_preempt_state, rnp, true);
  379. } else {
  380. local_irq_restore(flags);
  381. }
  382. }
  383. /*
  384. * Tree-preemptible RCU implementation for rcu_read_unlock().
  385. * Decrement ->rcu_read_lock_nesting. If the result is zero (outermost
  386. * rcu_read_unlock()) and ->rcu_read_unlock_special is non-zero, then
  387. * invoke rcu_read_unlock_special() to clean up after a context switch
  388. * in an RCU read-side critical section and other special cases.
  389. */
  390. void __rcu_read_unlock(void)
  391. {
  392. struct task_struct *t = current;
  393. if (t->rcu_read_lock_nesting != 1)
  394. --t->rcu_read_lock_nesting;
  395. else {
  396. barrier(); /* critical section before exit code. */
  397. t->rcu_read_lock_nesting = INT_MIN;
  398. barrier(); /* assign before ->rcu_read_unlock_special load */
  399. if (unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
  400. rcu_read_unlock_special(t);
  401. barrier(); /* ->rcu_read_unlock_special load before assign */
  402. t->rcu_read_lock_nesting = 0;
  403. }
  404. #ifdef CONFIG_PROVE_LOCKING
  405. {
  406. int rrln = ACCESS_ONCE(t->rcu_read_lock_nesting);
  407. WARN_ON_ONCE(rrln < 0 && rrln > INT_MIN / 2);
  408. }
  409. #endif /* #ifdef CONFIG_PROVE_LOCKING */
  410. }
  411. EXPORT_SYMBOL_GPL(__rcu_read_unlock);
  412. #ifdef CONFIG_RCU_CPU_STALL_VERBOSE
  413. /*
  414. * Dump detailed information for all tasks blocking the current RCU
  415. * grace period on the specified rcu_node structure.
  416. */
  417. static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
  418. {
  419. unsigned long flags;
  420. struct task_struct *t;
  421. if (!rcu_preempt_blocked_readers_cgp(rnp))
  422. return;
  423. raw_spin_lock_irqsave(&rnp->lock, flags);
  424. t = list_entry(rnp->gp_tasks,
  425. struct task_struct, rcu_node_entry);
  426. list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry)
  427. sched_show_task(t);
  428. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  429. }
  430. /*
  431. * Dump detailed information for all tasks blocking the current RCU
  432. * grace period.
  433. */
  434. static void rcu_print_detail_task_stall(struct rcu_state *rsp)
  435. {
  436. struct rcu_node *rnp = rcu_get_root(rsp);
  437. rcu_print_detail_task_stall_rnp(rnp);
  438. rcu_for_each_leaf_node(rsp, rnp)
  439. rcu_print_detail_task_stall_rnp(rnp);
  440. }
  441. #else /* #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */
  442. static void rcu_print_detail_task_stall(struct rcu_state *rsp)
  443. {
  444. }
  445. #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */
  446. #ifdef CONFIG_RCU_CPU_STALL_INFO
  447. static void rcu_print_task_stall_begin(struct rcu_node *rnp)
  448. {
  449. printk(KERN_ERR "\tTasks blocked on level-%d rcu_node (CPUs %d-%d):",
  450. rnp->level, rnp->grplo, rnp->grphi);
  451. }
  452. static void rcu_print_task_stall_end(void)
  453. {
  454. printk(KERN_CONT "\n");
  455. }
  456. #else /* #ifdef CONFIG_RCU_CPU_STALL_INFO */
  457. static void rcu_print_task_stall_begin(struct rcu_node *rnp)
  458. {
  459. }
  460. static void rcu_print_task_stall_end(void)
  461. {
  462. }
  463. #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_INFO */
  464. /*
  465. * Scan the current list of tasks blocked within RCU read-side critical
  466. * sections, printing out the tid of each.
  467. */
  468. static int rcu_print_task_stall(struct rcu_node *rnp)
  469. {
  470. struct task_struct *t;
  471. int ndetected = 0;
  472. if (!rcu_preempt_blocked_readers_cgp(rnp))
  473. return 0;
  474. rcu_print_task_stall_begin(rnp);
  475. t = list_entry(rnp->gp_tasks,
  476. struct task_struct, rcu_node_entry);
  477. list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
  478. printk(KERN_CONT " P%d", t->pid);
  479. ndetected++;
  480. }
  481. rcu_print_task_stall_end();
  482. return ndetected;
  483. }
  484. /*
  485. * Suppress preemptible RCU's CPU stall warnings by pushing the
  486. * time of the next stall-warning message comfortably far into the
  487. * future.
  488. */
  489. static void rcu_preempt_stall_reset(void)
  490. {
  491. rcu_preempt_state.jiffies_stall = jiffies + ULONG_MAX / 2;
  492. }
  493. /*
  494. * Check that the list of blocked tasks for the newly completed grace
  495. * period is in fact empty. It is a serious bug to complete a grace
  496. * period that still has RCU readers blocked! This function must be
  497. * invoked -before- updating this rnp's ->gpnum, and the rnp's ->lock
  498. * must be held by the caller.
  499. *
  500. * Also, if there are blocked tasks on the list, they automatically
  501. * block the newly created grace period, so set up ->gp_tasks accordingly.
  502. */
  503. static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
  504. {
  505. WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp));
  506. if (!list_empty(&rnp->blkd_tasks))
  507. rnp->gp_tasks = rnp->blkd_tasks.next;
  508. WARN_ON_ONCE(rnp->qsmask);
  509. }
  510. #ifdef CONFIG_HOTPLUG_CPU
  511. /*
  512. * Handle tasklist migration for case in which all CPUs covered by the
  513. * specified rcu_node have gone offline. Move them up to the root
  514. * rcu_node. The reason for not just moving them to the immediate
  515. * parent is to remove the need for rcu_read_unlock_special() to
  516. * make more than two attempts to acquire the target rcu_node's lock.
  517. * Returns true if there were tasks blocking the current RCU grace
  518. * period.
  519. *
  520. * Returns 1 if there was previously a task blocking the current grace
  521. * period on the specified rcu_node structure.
  522. *
  523. * The caller must hold rnp->lock with irqs disabled.
  524. */
  525. static int rcu_preempt_offline_tasks(struct rcu_state *rsp,
  526. struct rcu_node *rnp,
  527. struct rcu_data *rdp)
  528. {
  529. struct list_head *lp;
  530. struct list_head *lp_root;
  531. int retval = 0;
  532. struct rcu_node *rnp_root = rcu_get_root(rsp);
  533. struct task_struct *t;
  534. if (rnp == rnp_root) {
  535. WARN_ONCE(1, "Last CPU thought to be offlined?");
  536. return 0; /* Shouldn't happen: at least one CPU online. */
  537. }
  538. /* If we are on an internal node, complain bitterly. */
  539. WARN_ON_ONCE(rnp != rdp->mynode);
  540. /*
  541. * Move tasks up to root rcu_node. Don't try to get fancy for
  542. * this corner-case operation -- just put this node's tasks
  543. * at the head of the root node's list, and update the root node's
  544. * ->gp_tasks and ->exp_tasks pointers to those of this node's,
  545. * if non-NULL. This might result in waiting for more tasks than
  546. * absolutely necessary, but this is a good performance/complexity
  547. * tradeoff.
  548. */
  549. if (rcu_preempt_blocked_readers_cgp(rnp) && rnp->qsmask == 0)
  550. retval |= RCU_OFL_TASKS_NORM_GP;
  551. if (rcu_preempted_readers_exp(rnp))
  552. retval |= RCU_OFL_TASKS_EXP_GP;
  553. lp = &rnp->blkd_tasks;
  554. lp_root = &rnp_root->blkd_tasks;
  555. while (!list_empty(lp)) {
  556. t = list_entry(lp->next, typeof(*t), rcu_node_entry);
  557. raw_spin_lock(&rnp_root->lock); /* irqs already disabled */
  558. list_del(&t->rcu_node_entry);
  559. t->rcu_blocked_node = rnp_root;
  560. list_add(&t->rcu_node_entry, lp_root);
  561. if (&t->rcu_node_entry == rnp->gp_tasks)
  562. rnp_root->gp_tasks = rnp->gp_tasks;
  563. if (&t->rcu_node_entry == rnp->exp_tasks)
  564. rnp_root->exp_tasks = rnp->exp_tasks;
  565. #ifdef CONFIG_RCU_BOOST
  566. if (&t->rcu_node_entry == rnp->boost_tasks)
  567. rnp_root->boost_tasks = rnp->boost_tasks;
  568. #endif /* #ifdef CONFIG_RCU_BOOST */
  569. raw_spin_unlock(&rnp_root->lock); /* irqs still disabled */
  570. }
  571. #ifdef CONFIG_RCU_BOOST
  572. /* In case root is being boosted and leaf is not. */
  573. raw_spin_lock(&rnp_root->lock); /* irqs already disabled */
  574. if (rnp_root->boost_tasks != NULL &&
  575. rnp_root->boost_tasks != rnp_root->gp_tasks)
  576. rnp_root->boost_tasks = rnp_root->gp_tasks;
  577. raw_spin_unlock(&rnp_root->lock); /* irqs still disabled */
  578. #endif /* #ifdef CONFIG_RCU_BOOST */
  579. rnp->gp_tasks = NULL;
  580. rnp->exp_tasks = NULL;
  581. return retval;
  582. }
  583. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  584. /*
  585. * Do CPU-offline processing for preemptible RCU.
  586. */
  587. static void rcu_preempt_cleanup_dead_cpu(int cpu)
  588. {
  589. rcu_cleanup_dead_cpu(cpu, &rcu_preempt_state);
  590. }
  591. /*
  592. * Check for a quiescent state from the current CPU. When a task blocks,
  593. * the task is recorded in the corresponding CPU's rcu_node structure,
  594. * which is checked elsewhere.
  595. *
  596. * Caller must disable hard irqs.
  597. */
  598. static void rcu_preempt_check_callbacks(int cpu)
  599. {
  600. struct task_struct *t = current;
  601. if (t->rcu_read_lock_nesting == 0) {
  602. rcu_preempt_qs(cpu);
  603. return;
  604. }
  605. if (t->rcu_read_lock_nesting > 0 &&
  606. per_cpu(rcu_preempt_data, cpu).qs_pending)
  607. t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS;
  608. }
  609. /*
  610. * Process callbacks for preemptible RCU.
  611. */
  612. static void rcu_preempt_process_callbacks(void)
  613. {
  614. __rcu_process_callbacks(&rcu_preempt_state,
  615. &__get_cpu_var(rcu_preempt_data));
  616. }
  617. #ifdef CONFIG_RCU_BOOST
  618. static void rcu_preempt_do_callbacks(void)
  619. {
  620. rcu_do_batch(&rcu_preempt_state, &__get_cpu_var(rcu_preempt_data));
  621. }
  622. #endif /* #ifdef CONFIG_RCU_BOOST */
  623. /*
  624. * Queue a preemptible-RCU callback for invocation after a grace period.
  625. */
  626. void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
  627. {
  628. __call_rcu(head, func, &rcu_preempt_state, 0);
  629. }
  630. EXPORT_SYMBOL_GPL(call_rcu);
  631. /*
  632. * Queue an RCU callback for lazy invocation after a grace period.
  633. * This will likely be later named something like "call_rcu_lazy()",
  634. * but this change will require some way of tagging the lazy RCU
  635. * callbacks in the list of pending callbacks. Until then, this
  636. * function may only be called from __kfree_rcu().
  637. */
  638. void kfree_call_rcu(struct rcu_head *head,
  639. void (*func)(struct rcu_head *rcu))
  640. {
  641. __call_rcu(head, func, &rcu_preempt_state, 1);
  642. }
  643. EXPORT_SYMBOL_GPL(kfree_call_rcu);
  644. /**
  645. * synchronize_rcu - wait until a grace period has elapsed.
  646. *
  647. * Control will return to the caller some time after a full grace
  648. * period has elapsed, in other words after all currently executing RCU
  649. * read-side critical sections have completed. Note, however, that
  650. * upon return from synchronize_rcu(), the caller might well be executing
  651. * concurrently with new RCU read-side critical sections that began while
  652. * synchronize_rcu() was waiting. RCU read-side critical sections are
  653. * delimited by rcu_read_lock() and rcu_read_unlock(), and may be nested.
  654. */
  655. void synchronize_rcu(void)
  656. {
  657. rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map) &&
  658. !lock_is_held(&rcu_lock_map) &&
  659. !lock_is_held(&rcu_sched_lock_map),
  660. "Illegal synchronize_rcu() in RCU read-side critical section");
  661. if (!rcu_scheduler_active)
  662. return;
  663. wait_rcu_gp(call_rcu);
  664. }
  665. EXPORT_SYMBOL_GPL(synchronize_rcu);
  666. static DECLARE_WAIT_QUEUE_HEAD(sync_rcu_preempt_exp_wq);
  667. static long sync_rcu_preempt_exp_count;
  668. static DEFINE_MUTEX(sync_rcu_preempt_exp_mutex);
  669. /*
  670. * Return non-zero if there are any tasks in RCU read-side critical
  671. * sections blocking the current preemptible-RCU expedited grace period.
  672. * If there is no preemptible-RCU expedited grace period currently in
  673. * progress, returns zero unconditionally.
  674. */
  675. static int rcu_preempted_readers_exp(struct rcu_node *rnp)
  676. {
  677. return rnp->exp_tasks != NULL;
  678. }
  679. /*
  680. * return non-zero if there is no RCU expedited grace period in progress
  681. * for the specified rcu_node structure, in other words, if all CPUs and
  682. * tasks covered by the specified rcu_node structure have done their bit
  683. * for the current expedited grace period. Works only for preemptible
  684. * RCU -- other RCU implementation use other means.
  685. *
  686. * Caller must hold sync_rcu_preempt_exp_mutex.
  687. */
  688. static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
  689. {
  690. return !rcu_preempted_readers_exp(rnp) &&
  691. ACCESS_ONCE(rnp->expmask) == 0;
  692. }
  693. /*
  694. * Report the exit from RCU read-side critical section for the last task
  695. * that queued itself during or before the current expedited preemptible-RCU
  696. * grace period. This event is reported either to the rcu_node structure on
  697. * which the task was queued or to one of that rcu_node structure's ancestors,
  698. * recursively up the tree. (Calm down, calm down, we do the recursion
  699. * iteratively!)
  700. *
  701. * Most callers will set the "wake" flag, but the task initiating the
  702. * expedited grace period need not wake itself.
  703. *
  704. * Caller must hold sync_rcu_preempt_exp_mutex.
  705. */
  706. static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp,
  707. bool wake)
  708. {
  709. unsigned long flags;
  710. unsigned long mask;
  711. raw_spin_lock_irqsave(&rnp->lock, flags);
  712. for (;;) {
  713. if (!sync_rcu_preempt_exp_done(rnp)) {
  714. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  715. break;
  716. }
  717. if (rnp->parent == NULL) {
  718. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  719. if (wake)
  720. wake_up(&sync_rcu_preempt_exp_wq);
  721. break;
  722. }
  723. mask = rnp->grpmask;
  724. raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
  725. rnp = rnp->parent;
  726. raw_spin_lock(&rnp->lock); /* irqs already disabled */
  727. rnp->expmask &= ~mask;
  728. }
  729. }
  730. /*
  731. * Snapshot the tasks blocking the newly started preemptible-RCU expedited
  732. * grace period for the specified rcu_node structure. If there are no such
  733. * tasks, report it up the rcu_node hierarchy.
  734. *
  735. * Caller must hold sync_rcu_preempt_exp_mutex and rsp->onofflock.
  736. */
  737. static void
  738. sync_rcu_preempt_exp_init(struct rcu_state *rsp, struct rcu_node *rnp)
  739. {
  740. unsigned long flags;
  741. int must_wait = 0;
  742. raw_spin_lock_irqsave(&rnp->lock, flags);
  743. if (list_empty(&rnp->blkd_tasks))
  744. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  745. else {
  746. rnp->exp_tasks = rnp->blkd_tasks.next;
  747. rcu_initiate_boost(rnp, flags); /* releases rnp->lock */
  748. must_wait = 1;
  749. }
  750. if (!must_wait)
  751. rcu_report_exp_rnp(rsp, rnp, false); /* Don't wake self. */
  752. }
  753. /*
  754. * Wait for an rcu-preempt grace period, but expedite it. The basic idea
  755. * is to invoke synchronize_sched_expedited() to push all the tasks to
  756. * the ->blkd_tasks lists and wait for this list to drain.
  757. */
  758. void synchronize_rcu_expedited(void)
  759. {
  760. unsigned long flags;
  761. struct rcu_node *rnp;
  762. struct rcu_state *rsp = &rcu_preempt_state;
  763. long snap;
  764. int trycount = 0;
  765. smp_mb(); /* Caller's modifications seen first by other CPUs. */
  766. snap = ACCESS_ONCE(sync_rcu_preempt_exp_count) + 1;
  767. smp_mb(); /* Above access cannot bleed into critical section. */
  768. /*
  769. * Acquire lock, falling back to synchronize_rcu() if too many
  770. * lock-acquisition failures. Of course, if someone does the
  771. * expedited grace period for us, just leave.
  772. */
  773. while (!mutex_trylock(&sync_rcu_preempt_exp_mutex)) {
  774. if (trycount++ < 10)
  775. udelay(trycount * num_online_cpus());
  776. else {
  777. synchronize_rcu();
  778. return;
  779. }
  780. if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0)
  781. goto mb_ret; /* Others did our work for us. */
  782. }
  783. if ((ACCESS_ONCE(sync_rcu_preempt_exp_count) - snap) > 0)
  784. goto unlock_mb_ret; /* Others did our work for us. */
  785. /* force all RCU readers onto ->blkd_tasks lists. */
  786. synchronize_sched_expedited();
  787. raw_spin_lock_irqsave(&rsp->onofflock, flags);
  788. /* Initialize ->expmask for all non-leaf rcu_node structures. */
  789. rcu_for_each_nonleaf_node_breadth_first(rsp, rnp) {
  790. raw_spin_lock(&rnp->lock); /* irqs already disabled. */
  791. rnp->expmask = rnp->qsmaskinit;
  792. raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
  793. }
  794. /* Snapshot current state of ->blkd_tasks lists. */
  795. rcu_for_each_leaf_node(rsp, rnp)
  796. sync_rcu_preempt_exp_init(rsp, rnp);
  797. if (NUM_RCU_NODES > 1)
  798. sync_rcu_preempt_exp_init(rsp, rcu_get_root(rsp));
  799. raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
  800. /* Wait for snapshotted ->blkd_tasks lists to drain. */
  801. rnp = rcu_get_root(rsp);
  802. wait_event(sync_rcu_preempt_exp_wq,
  803. sync_rcu_preempt_exp_done(rnp));
  804. /* Clean up and exit. */
  805. smp_mb(); /* ensure expedited GP seen before counter increment. */
  806. ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
  807. unlock_mb_ret:
  808. mutex_unlock(&sync_rcu_preempt_exp_mutex);
  809. mb_ret:
  810. smp_mb(); /* ensure subsequent action seen after grace period. */
  811. }
  812. EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
  813. /*
  814. * Check to see if there is any immediate preemptible-RCU-related work
  815. * to be done.
  816. */
  817. static int rcu_preempt_pending(int cpu)
  818. {
  819. return __rcu_pending(&rcu_preempt_state,
  820. &per_cpu(rcu_preempt_data, cpu));
  821. }
  822. /*
  823. * Does preemptible RCU have callbacks on this CPU?
  824. */
  825. static int rcu_preempt_cpu_has_callbacks(int cpu)
  826. {
  827. return !!per_cpu(rcu_preempt_data, cpu).nxtlist;
  828. }
  829. /**
  830. * rcu_barrier - Wait until all in-flight call_rcu() callbacks complete.
  831. */
  832. void rcu_barrier(void)
  833. {
  834. _rcu_barrier(&rcu_preempt_state, call_rcu);
  835. }
  836. EXPORT_SYMBOL_GPL(rcu_barrier);
  837. /*
  838. * Initialize preemptible RCU's per-CPU data.
  839. */
  840. static void __cpuinit rcu_preempt_init_percpu_data(int cpu)
  841. {
  842. rcu_init_percpu_data(cpu, &rcu_preempt_state, 1);
  843. }
  844. /*
  845. * Move preemptible RCU's callbacks from dying CPU to other online CPU
  846. * and record a quiescent state.
  847. */
  848. static void rcu_preempt_cleanup_dying_cpu(void)
  849. {
  850. rcu_cleanup_dying_cpu(&rcu_preempt_state);
  851. }
  852. /*
  853. * Initialize preemptible RCU's state structures.
  854. */
  855. static void __init __rcu_init_preempt(void)
  856. {
  857. rcu_init_one(&rcu_preempt_state, &rcu_preempt_data);
  858. }
  859. /*
  860. * Check for a task exiting while in a preemptible-RCU read-side
  861. * critical section, clean up if so. No need to issue warnings,
  862. * as debug_check_no_locks_held() already does this if lockdep
  863. * is enabled.
  864. */
  865. void exit_rcu(void)
  866. {
  867. struct task_struct *t = current;
  868. if (t->rcu_read_lock_nesting == 0)
  869. return;
  870. t->rcu_read_lock_nesting = 1;
  871. __rcu_read_unlock();
  872. }
  873. #else /* #ifdef CONFIG_TREE_PREEMPT_RCU */
  874. static struct rcu_state *rcu_state = &rcu_sched_state;
  875. /*
  876. * Tell them what RCU they are running.
  877. */
  878. static void __init rcu_bootup_announce(void)
  879. {
  880. printk(KERN_INFO "Hierarchical RCU implementation.\n");
  881. rcu_bootup_announce_oddness();
  882. }
  883. /*
  884. * Return the number of RCU batches processed thus far for debug & stats.
  885. */
  886. long rcu_batches_completed(void)
  887. {
  888. return rcu_batches_completed_sched();
  889. }
  890. EXPORT_SYMBOL_GPL(rcu_batches_completed);
  891. /*
  892. * Force a quiescent state for RCU, which, because there is no preemptible
  893. * RCU, becomes the same as rcu-sched.
  894. */
  895. void rcu_force_quiescent_state(void)
  896. {
  897. rcu_sched_force_quiescent_state();
  898. }
  899. EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
  900. /*
  901. * Because preemptible RCU does not exist, we never have to check for
  902. * CPUs being in quiescent states.
  903. */
  904. static void rcu_preempt_note_context_switch(int cpu)
  905. {
  906. }
  907. /*
  908. * Because preemptible RCU does not exist, there are never any preempted
  909. * RCU readers.
  910. */
  911. static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)
  912. {
  913. return 0;
  914. }
  915. #ifdef CONFIG_HOTPLUG_CPU
  916. /* Because preemptible RCU does not exist, no quieting of tasks. */
  917. static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags)
  918. {
  919. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  920. }
  921. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  922. /*
  923. * Because preemptible RCU does not exist, we never have to check for
  924. * tasks blocked within RCU read-side critical sections.
  925. */
  926. static void rcu_print_detail_task_stall(struct rcu_state *rsp)
  927. {
  928. }
  929. /*
  930. * Because preemptible RCU does not exist, we never have to check for
  931. * tasks blocked within RCU read-side critical sections.
  932. */
  933. static int rcu_print_task_stall(struct rcu_node *rnp)
  934. {
  935. return 0;
  936. }
  937. /*
  938. * Because preemptible RCU does not exist, there is no need to suppress
  939. * its CPU stall warnings.
  940. */
  941. static void rcu_preempt_stall_reset(void)
  942. {
  943. }
  944. /*
  945. * Because there is no preemptible RCU, there can be no readers blocked,
  946. * so there is no need to check for blocked tasks. So check only for
  947. * bogus qsmask values.
  948. */
  949. static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
  950. {
  951. WARN_ON_ONCE(rnp->qsmask);
  952. }
  953. #ifdef CONFIG_HOTPLUG_CPU
  954. /*
  955. * Because preemptible RCU does not exist, it never needs to migrate
  956. * tasks that were blocked within RCU read-side critical sections, and
  957. * such non-existent tasks cannot possibly have been blocking the current
  958. * grace period.
  959. */
  960. static int rcu_preempt_offline_tasks(struct rcu_state *rsp,
  961. struct rcu_node *rnp,
  962. struct rcu_data *rdp)
  963. {
  964. return 0;
  965. }
  966. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  967. /*
  968. * Because preemptible RCU does not exist, it never needs CPU-offline
  969. * processing.
  970. */
  971. static void rcu_preempt_cleanup_dead_cpu(int cpu)
  972. {
  973. }
  974. /*
  975. * Because preemptible RCU does not exist, it never has any callbacks
  976. * to check.
  977. */
  978. static void rcu_preempt_check_callbacks(int cpu)
  979. {
  980. }
  981. /*
  982. * Because preemptible RCU does not exist, it never has any callbacks
  983. * to process.
  984. */
  985. static void rcu_preempt_process_callbacks(void)
  986. {
  987. }
  988. /*
  989. * Queue an RCU callback for lazy invocation after a grace period.
  990. * This will likely be later named something like "call_rcu_lazy()",
  991. * but this change will require some way of tagging the lazy RCU
  992. * callbacks in the list of pending callbacks. Until then, this
  993. * function may only be called from __kfree_rcu().
  994. *
  995. * Because there is no preemptible RCU, we use RCU-sched instead.
  996. */
  997. void kfree_call_rcu(struct rcu_head *head,
  998. void (*func)(struct rcu_head *rcu))
  999. {
  1000. __call_rcu(head, func, &rcu_sched_state, 1);
  1001. }
  1002. EXPORT_SYMBOL_GPL(kfree_call_rcu);
  1003. /*
  1004. * Wait for an rcu-preempt grace period, but make it happen quickly.
  1005. * But because preemptible RCU does not exist, map to rcu-sched.
  1006. */
  1007. void synchronize_rcu_expedited(void)
  1008. {
  1009. synchronize_sched_expedited();
  1010. }
  1011. EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
  1012. #ifdef CONFIG_HOTPLUG_CPU
  1013. /*
  1014. * Because preemptible RCU does not exist, there is never any need to
  1015. * report on tasks preempted in RCU read-side critical sections during
  1016. * expedited RCU grace periods.
  1017. */
  1018. static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp,
  1019. bool wake)
  1020. {
  1021. }
  1022. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  1023. /*
  1024. * Because preemptible RCU does not exist, it never has any work to do.
  1025. */
  1026. static int rcu_preempt_pending(int cpu)
  1027. {
  1028. return 0;
  1029. }
  1030. /*
  1031. * Because preemptible RCU does not exist, it never has callbacks
  1032. */
  1033. static int rcu_preempt_cpu_has_callbacks(int cpu)
  1034. {
  1035. return 0;
  1036. }
  1037. /*
  1038. * Because preemptible RCU does not exist, rcu_barrier() is just
  1039. * another name for rcu_barrier_sched().
  1040. */
  1041. void rcu_barrier(void)
  1042. {
  1043. rcu_barrier_sched();
  1044. }
  1045. EXPORT_SYMBOL_GPL(rcu_barrier);
  1046. /*
  1047. * Because preemptible RCU does not exist, there is no per-CPU
  1048. * data to initialize.
  1049. */
  1050. static void __cpuinit rcu_preempt_init_percpu_data(int cpu)
  1051. {
  1052. }
  1053. /*
  1054. * Because there is no preemptible RCU, there is no cleanup to do.
  1055. */
  1056. static void rcu_preempt_cleanup_dying_cpu(void)
  1057. {
  1058. }
  1059. /*
  1060. * Because preemptible RCU does not exist, it need not be initialized.
  1061. */
  1062. static void __init __rcu_init_preempt(void)
  1063. {
  1064. }
  1065. #endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */
  1066. #ifdef CONFIG_RCU_BOOST
  1067. #include "rtmutex_common.h"
  1068. #ifdef CONFIG_RCU_TRACE
  1069. static void rcu_initiate_boost_trace(struct rcu_node *rnp)
  1070. {
  1071. if (list_empty(&rnp->blkd_tasks))
  1072. rnp->n_balk_blkd_tasks++;
  1073. else if (rnp->exp_tasks == NULL && rnp->gp_tasks == NULL)
  1074. rnp->n_balk_exp_gp_tasks++;
  1075. else if (rnp->gp_tasks != NULL && rnp->boost_tasks != NULL)
  1076. rnp->n_balk_boost_tasks++;
  1077. else if (rnp->gp_tasks != NULL && rnp->qsmask != 0)
  1078. rnp->n_balk_notblocked++;
  1079. else if (rnp->gp_tasks != NULL &&
  1080. ULONG_CMP_LT(jiffies, rnp->boost_time))
  1081. rnp->n_balk_notyet++;
  1082. else
  1083. rnp->n_balk_nos++;
  1084. }
  1085. #else /* #ifdef CONFIG_RCU_TRACE */
  1086. static void rcu_initiate_boost_trace(struct rcu_node *rnp)
  1087. {
  1088. }
  1089. #endif /* #else #ifdef CONFIG_RCU_TRACE */
  1090. /*
  1091. * Carry out RCU priority boosting on the task indicated by ->exp_tasks
  1092. * or ->boost_tasks, advancing the pointer to the next task in the
  1093. * ->blkd_tasks list.
  1094. *
  1095. * Note that irqs must be enabled: boosting the task can block.
  1096. * Returns 1 if there are more tasks needing to be boosted.
  1097. */
  1098. static int rcu_boost(struct rcu_node *rnp)
  1099. {
  1100. unsigned long flags;
  1101. struct rt_mutex mtx;
  1102. struct task_struct *t;
  1103. struct list_head *tb;
  1104. if (rnp->exp_tasks == NULL && rnp->boost_tasks == NULL)
  1105. return 0; /* Nothing left to boost. */
  1106. raw_spin_lock_irqsave(&rnp->lock, flags);
  1107. /*
  1108. * Recheck under the lock: all tasks in need of boosting
  1109. * might exit their RCU read-side critical sections on their own.
  1110. */
  1111. if (rnp->exp_tasks == NULL && rnp->boost_tasks == NULL) {
  1112. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1113. return 0;
  1114. }
  1115. /*
  1116. * Preferentially boost tasks blocking expedited grace periods.
  1117. * This cannot starve the normal grace periods because a second
  1118. * expedited grace period must boost all blocked tasks, including
  1119. * those blocking the pre-existing normal grace period.
  1120. */
  1121. if (rnp->exp_tasks != NULL) {
  1122. tb = rnp->exp_tasks;
  1123. rnp->n_exp_boosts++;
  1124. } else {
  1125. tb = rnp->boost_tasks;
  1126. rnp->n_normal_boosts++;
  1127. }
  1128. rnp->n_tasks_boosted++;
  1129. /*
  1130. * We boost task t by manufacturing an rt_mutex that appears to
  1131. * be held by task t. We leave a pointer to that rt_mutex where
  1132. * task t can find it, and task t will release the mutex when it
  1133. * exits its outermost RCU read-side critical section. Then
  1134. * simply acquiring this artificial rt_mutex will boost task
  1135. * t's priority. (Thanks to tglx for suggesting this approach!)
  1136. *
  1137. * Note that task t must acquire rnp->lock to remove itself from
  1138. * the ->blkd_tasks list, which it will do from exit() if from
  1139. * nowhere else. We therefore are guaranteed that task t will
  1140. * stay around at least until we drop rnp->lock. Note that
  1141. * rnp->lock also resolves races between our priority boosting
  1142. * and task t's exiting its outermost RCU read-side critical
  1143. * section.
  1144. */
  1145. t = container_of(tb, struct task_struct, rcu_node_entry);
  1146. rt_mutex_init_proxy_locked(&mtx, t);
  1147. t->rcu_boost_mutex = &mtx;
  1148. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1149. rt_mutex_lock(&mtx); /* Side effect: boosts task t's priority. */
  1150. rt_mutex_unlock(&mtx); /* Keep lockdep happy. */
  1151. return ACCESS_ONCE(rnp->exp_tasks) != NULL ||
  1152. ACCESS_ONCE(rnp->boost_tasks) != NULL;
  1153. }
  1154. /*
  1155. * Timer handler to initiate waking up of boost kthreads that
  1156. * have yielded the CPU due to excessive numbers of tasks to
  1157. * boost. We wake up the per-rcu_node kthread, which in turn
  1158. * will wake up the booster kthread.
  1159. */
  1160. static void rcu_boost_kthread_timer(unsigned long arg)
  1161. {
  1162. invoke_rcu_node_kthread((struct rcu_node *)arg);
  1163. }
  1164. /*
  1165. * Priority-boosting kthread. One per leaf rcu_node and one for the
  1166. * root rcu_node.
  1167. */
  1168. static int rcu_boost_kthread(void *arg)
  1169. {
  1170. struct rcu_node *rnp = (struct rcu_node *)arg;
  1171. int spincnt = 0;
  1172. int more2boost;
  1173. trace_rcu_utilization("Start boost kthread@init");
  1174. for (;;) {
  1175. rnp->boost_kthread_status = RCU_KTHREAD_WAITING;
  1176. trace_rcu_utilization("End boost kthread@rcu_wait");
  1177. rcu_wait(rnp->boost_tasks || rnp->exp_tasks);
  1178. trace_rcu_utilization("Start boost kthread@rcu_wait");
  1179. rnp->boost_kthread_status = RCU_KTHREAD_RUNNING;
  1180. more2boost = rcu_boost(rnp);
  1181. if (more2boost)
  1182. spincnt++;
  1183. else
  1184. spincnt = 0;
  1185. if (spincnt > 10) {
  1186. trace_rcu_utilization("End boost kthread@rcu_yield");
  1187. rcu_yield(rcu_boost_kthread_timer, (unsigned long)rnp);
  1188. trace_rcu_utilization("Start boost kthread@rcu_yield");
  1189. spincnt = 0;
  1190. }
  1191. }
  1192. /* NOTREACHED */
  1193. trace_rcu_utilization("End boost kthread@notreached");
  1194. return 0;
  1195. }
  1196. /*
  1197. * Check to see if it is time to start boosting RCU readers that are
  1198. * blocking the current grace period, and, if so, tell the per-rcu_node
  1199. * kthread to start boosting them. If there is an expedited grace
  1200. * period in progress, it is always time to boost.
  1201. *
  1202. * The caller must hold rnp->lock, which this function releases,
  1203. * but irqs remain disabled. The ->boost_kthread_task is immortal,
  1204. * so we don't need to worry about it going away.
  1205. */
  1206. static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags)
  1207. {
  1208. struct task_struct *t;
  1209. if (!rcu_preempt_blocked_readers_cgp(rnp) && rnp->exp_tasks == NULL) {
  1210. rnp->n_balk_exp_gp_tasks++;
  1211. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1212. return;
  1213. }
  1214. if (rnp->exp_tasks != NULL ||
  1215. (rnp->gp_tasks != NULL &&
  1216. rnp->boost_tasks == NULL &&
  1217. rnp->qsmask == 0 &&
  1218. ULONG_CMP_GE(jiffies, rnp->boost_time))) {
  1219. if (rnp->exp_tasks == NULL)
  1220. rnp->boost_tasks = rnp->gp_tasks;
  1221. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1222. t = rnp->boost_kthread_task;
  1223. if (t != NULL)
  1224. wake_up_process(t);
  1225. } else {
  1226. rcu_initiate_boost_trace(rnp);
  1227. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1228. }
  1229. }
  1230. /*
  1231. * Wake up the per-CPU kthread to invoke RCU callbacks.
  1232. */
  1233. static void invoke_rcu_callbacks_kthread(void)
  1234. {
  1235. unsigned long flags;
  1236. local_irq_save(flags);
  1237. __this_cpu_write(rcu_cpu_has_work, 1);
  1238. if (__this_cpu_read(rcu_cpu_kthread_task) != NULL &&
  1239. current != __this_cpu_read(rcu_cpu_kthread_task))
  1240. wake_up_process(__this_cpu_read(rcu_cpu_kthread_task));
  1241. local_irq_restore(flags);
  1242. }
  1243. /*
  1244. * Is the current CPU running the RCU-callbacks kthread?
  1245. * Caller must have preemption disabled.
  1246. */
  1247. static bool rcu_is_callbacks_kthread(void)
  1248. {
  1249. return __get_cpu_var(rcu_cpu_kthread_task) == current;
  1250. }
  1251. /*
  1252. * Set the affinity of the boost kthread. The CPU-hotplug locks are
  1253. * held, so no one should be messing with the existence of the boost
  1254. * kthread.
  1255. */
  1256. static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp,
  1257. cpumask_var_t cm)
  1258. {
  1259. struct task_struct *t;
  1260. t = rnp->boost_kthread_task;
  1261. if (t != NULL)
  1262. set_cpus_allowed_ptr(rnp->boost_kthread_task, cm);
  1263. }
  1264. #define RCU_BOOST_DELAY_JIFFIES DIV_ROUND_UP(CONFIG_RCU_BOOST_DELAY * HZ, 1000)
  1265. /*
  1266. * Do priority-boost accounting for the start of a new grace period.
  1267. */
  1268. static void rcu_preempt_boost_start_gp(struct rcu_node *rnp)
  1269. {
  1270. rnp->boost_time = jiffies + RCU_BOOST_DELAY_JIFFIES;
  1271. }
  1272. /*
  1273. * Create an RCU-boost kthread for the specified node if one does not
  1274. * already exist. We only create this kthread for preemptible RCU.
  1275. * Returns zero if all is well, a negated errno otherwise.
  1276. */
  1277. static int __cpuinit rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
  1278. struct rcu_node *rnp,
  1279. int rnp_index)
  1280. {
  1281. unsigned long flags;
  1282. struct sched_param sp;
  1283. struct task_struct *t;
  1284. if (&rcu_preempt_state != rsp)
  1285. return 0;
  1286. rsp->boost = 1;
  1287. if (rnp->boost_kthread_task != NULL)
  1288. return 0;
  1289. t = kthread_create(rcu_boost_kthread, (void *)rnp,
  1290. "rcub/%d", rnp_index);
  1291. if (IS_ERR(t))
  1292. return PTR_ERR(t);
  1293. raw_spin_lock_irqsave(&rnp->lock, flags);
  1294. rnp->boost_kthread_task = t;
  1295. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1296. sp.sched_priority = RCU_BOOST_PRIO;
  1297. sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
  1298. wake_up_process(t); /* get to TASK_INTERRUPTIBLE quickly. */
  1299. return 0;
  1300. }
  1301. #ifdef CONFIG_HOTPLUG_CPU
  1302. /*
  1303. * Stop the RCU's per-CPU kthread when its CPU goes offline,.
  1304. */
  1305. static void rcu_stop_cpu_kthread(int cpu)
  1306. {
  1307. struct task_struct *t;
  1308. /* Stop the CPU's kthread. */
  1309. t = per_cpu(rcu_cpu_kthread_task, cpu);
  1310. if (t != NULL) {
  1311. per_cpu(rcu_cpu_kthread_task, cpu) = NULL;
  1312. kthread_stop(t);
  1313. }
  1314. }
  1315. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  1316. static void rcu_kthread_do_work(void)
  1317. {
  1318. rcu_do_batch(&rcu_sched_state, &__get_cpu_var(rcu_sched_data));
  1319. rcu_do_batch(&rcu_bh_state, &__get_cpu_var(rcu_bh_data));
  1320. rcu_preempt_do_callbacks();
  1321. }
  1322. /*
  1323. * Wake up the specified per-rcu_node-structure kthread.
  1324. * Because the per-rcu_node kthreads are immortal, we don't need
  1325. * to do anything to keep them alive.
  1326. */
  1327. static void invoke_rcu_node_kthread(struct rcu_node *rnp)
  1328. {
  1329. struct task_struct *t;
  1330. t = rnp->node_kthread_task;
  1331. if (t != NULL)
  1332. wake_up_process(t);
  1333. }
  1334. /*
  1335. * Set the specified CPU's kthread to run RT or not, as specified by
  1336. * the to_rt argument. The CPU-hotplug locks are held, so the task
  1337. * is not going away.
  1338. */
  1339. static void rcu_cpu_kthread_setrt(int cpu, int to_rt)
  1340. {
  1341. int policy;
  1342. struct sched_param sp;
  1343. struct task_struct *t;
  1344. t = per_cpu(rcu_cpu_kthread_task, cpu);
  1345. if (t == NULL)
  1346. return;
  1347. if (to_rt) {
  1348. policy = SCHED_FIFO;
  1349. sp.sched_priority = RCU_KTHREAD_PRIO;
  1350. } else {
  1351. policy = SCHED_NORMAL;
  1352. sp.sched_priority = 0;
  1353. }
  1354. sched_setscheduler_nocheck(t, policy, &sp);
  1355. }
  1356. /*
  1357. * Timer handler to initiate the waking up of per-CPU kthreads that
  1358. * have yielded the CPU due to excess numbers of RCU callbacks.
  1359. * We wake up the per-rcu_node kthread, which in turn will wake up
  1360. * the booster kthread.
  1361. */
  1362. static void rcu_cpu_kthread_timer(unsigned long arg)
  1363. {
  1364. struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, arg);
  1365. struct rcu_node *rnp = rdp->mynode;
  1366. atomic_or(rdp->grpmask, &rnp->wakemask);
  1367. invoke_rcu_node_kthread(rnp);
  1368. }
  1369. /*
  1370. * Drop to non-real-time priority and yield, but only after posting a
  1371. * timer that will cause us to regain our real-time priority if we
  1372. * remain preempted. Either way, we restore our real-time priority
  1373. * before returning.
  1374. */
  1375. static void rcu_yield(void (*f)(unsigned long), unsigned long arg)
  1376. {
  1377. struct sched_param sp;
  1378. struct timer_list yield_timer;
  1379. int prio = current->rt_priority;
  1380. setup_timer_on_stack(&yield_timer, f, arg);
  1381. mod_timer(&yield_timer, jiffies + 2);
  1382. sp.sched_priority = 0;
  1383. sched_setscheduler_nocheck(current, SCHED_NORMAL, &sp);
  1384. set_user_nice(current, 19);
  1385. schedule();
  1386. set_user_nice(current, 0);
  1387. sp.sched_priority = prio;
  1388. sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
  1389. del_timer(&yield_timer);
  1390. }
  1391. /*
  1392. * Handle cases where the rcu_cpu_kthread() ends up on the wrong CPU.
  1393. * This can happen while the corresponding CPU is either coming online
  1394. * or going offline. We cannot wait until the CPU is fully online
  1395. * before starting the kthread, because the various notifier functions
  1396. * can wait for RCU grace periods. So we park rcu_cpu_kthread() until
  1397. * the corresponding CPU is online.
  1398. *
  1399. * Return 1 if the kthread needs to stop, 0 otherwise.
  1400. *
  1401. * Caller must disable bh. This function can momentarily enable it.
  1402. */
  1403. static int rcu_cpu_kthread_should_stop(int cpu)
  1404. {
  1405. while (cpu_is_offline(cpu) ||
  1406. !cpumask_equal(&current->cpus_allowed, cpumask_of(cpu)) ||
  1407. smp_processor_id() != cpu) {
  1408. if (kthread_should_stop())
  1409. return 1;
  1410. per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
  1411. per_cpu(rcu_cpu_kthread_cpu, cpu) = raw_smp_processor_id();
  1412. local_bh_enable();
  1413. schedule_timeout_uninterruptible(1);
  1414. if (!cpumask_equal(&current->cpus_allowed, cpumask_of(cpu)))
  1415. set_cpus_allowed_ptr(current, cpumask_of(cpu));
  1416. local_bh_disable();
  1417. }
  1418. per_cpu(rcu_cpu_kthread_cpu, cpu) = cpu;
  1419. return 0;
  1420. }
  1421. /*
  1422. * Per-CPU kernel thread that invokes RCU callbacks. This replaces the
  1423. * RCU softirq used in flavors and configurations of RCU that do not
  1424. * support RCU priority boosting.
  1425. */
  1426. static int rcu_cpu_kthread(void *arg)
  1427. {
  1428. int cpu = (int)(long)arg;
  1429. unsigned long flags;
  1430. int spincnt = 0;
  1431. unsigned int *statusp = &per_cpu(rcu_cpu_kthread_status, cpu);
  1432. char work;
  1433. char *workp = &per_cpu(rcu_cpu_has_work, cpu);
  1434. trace_rcu_utilization("Start CPU kthread@init");
  1435. for (;;) {
  1436. *statusp = RCU_KTHREAD_WAITING;
  1437. trace_rcu_utilization("End CPU kthread@rcu_wait");
  1438. rcu_wait(*workp != 0 || kthread_should_stop());
  1439. trace_rcu_utilization("Start CPU kthread@rcu_wait");
  1440. local_bh_disable();
  1441. if (rcu_cpu_kthread_should_stop(cpu)) {
  1442. local_bh_enable();
  1443. break;
  1444. }
  1445. *statusp = RCU_KTHREAD_RUNNING;
  1446. per_cpu(rcu_cpu_kthread_loops, cpu)++;
  1447. local_irq_save(flags);
  1448. work = *workp;
  1449. *workp = 0;
  1450. local_irq_restore(flags);
  1451. if (work)
  1452. rcu_kthread_do_work();
  1453. local_bh_enable();
  1454. if (*workp != 0)
  1455. spincnt++;
  1456. else
  1457. spincnt = 0;
  1458. if (spincnt > 10) {
  1459. *statusp = RCU_KTHREAD_YIELDING;
  1460. trace_rcu_utilization("End CPU kthread@rcu_yield");
  1461. rcu_yield(rcu_cpu_kthread_timer, (unsigned long)cpu);
  1462. trace_rcu_utilization("Start CPU kthread@rcu_yield");
  1463. spincnt = 0;
  1464. }
  1465. }
  1466. *statusp = RCU_KTHREAD_STOPPED;
  1467. trace_rcu_utilization("End CPU kthread@term");
  1468. return 0;
  1469. }
  1470. /*
  1471. * Spawn a per-CPU kthread, setting up affinity and priority.
  1472. * Because the CPU hotplug lock is held, no other CPU will be attempting
  1473. * to manipulate rcu_cpu_kthread_task. There might be another CPU
  1474. * attempting to access it during boot, but the locking in kthread_bind()
  1475. * will enforce sufficient ordering.
  1476. *
  1477. * Please note that we cannot simply refuse to wake up the per-CPU
  1478. * kthread because kthreads are created in TASK_UNINTERRUPTIBLE state,
  1479. * which can result in softlockup complaints if the task ends up being
  1480. * idle for more than a couple of minutes.
  1481. *
  1482. * However, please note also that we cannot bind the per-CPU kthread to its
  1483. * CPU until that CPU is fully online. We also cannot wait until the
  1484. * CPU is fully online before we create its per-CPU kthread, as this would
  1485. * deadlock the system when CPU notifiers tried waiting for grace
  1486. * periods. So we bind the per-CPU kthread to its CPU only if the CPU
  1487. * is online. If its CPU is not yet fully online, then the code in
  1488. * rcu_cpu_kthread() will wait until it is fully online, and then do
  1489. * the binding.
  1490. */
  1491. static int __cpuinit rcu_spawn_one_cpu_kthread(int cpu)
  1492. {
  1493. struct sched_param sp;
  1494. struct task_struct *t;
  1495. if (!rcu_scheduler_fully_active ||
  1496. per_cpu(rcu_cpu_kthread_task, cpu) != NULL)
  1497. return 0;
  1498. t = kthread_create_on_node(rcu_cpu_kthread,
  1499. (void *)(long)cpu,
  1500. cpu_to_node(cpu),
  1501. "rcuc/%d", cpu);
  1502. if (IS_ERR(t))
  1503. return PTR_ERR(t);
  1504. if (cpu_online(cpu))
  1505. kthread_bind(t, cpu);
  1506. per_cpu(rcu_cpu_kthread_cpu, cpu) = cpu;
  1507. WARN_ON_ONCE(per_cpu(rcu_cpu_kthread_task, cpu) != NULL);
  1508. sp.sched_priority = RCU_KTHREAD_PRIO;
  1509. sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
  1510. per_cpu(rcu_cpu_kthread_task, cpu) = t;
  1511. wake_up_process(t); /* Get to TASK_INTERRUPTIBLE quickly. */
  1512. return 0;
  1513. }
  1514. /*
  1515. * Per-rcu_node kthread, which is in charge of waking up the per-CPU
  1516. * kthreads when needed. We ignore requests to wake up kthreads
  1517. * for offline CPUs, which is OK because force_quiescent_state()
  1518. * takes care of this case.
  1519. */
  1520. static int rcu_node_kthread(void *arg)
  1521. {
  1522. int cpu;
  1523. unsigned long flags;
  1524. unsigned long mask;
  1525. struct rcu_node *rnp = (struct rcu_node *)arg;
  1526. struct sched_param sp;
  1527. struct task_struct *t;
  1528. for (;;) {
  1529. rnp->node_kthread_status = RCU_KTHREAD_WAITING;
  1530. rcu_wait(atomic_read(&rnp->wakemask) != 0);
  1531. rnp->node_kthread_status = RCU_KTHREAD_RUNNING;
  1532. raw_spin_lock_irqsave(&rnp->lock, flags);
  1533. mask = atomic_xchg(&rnp->wakemask, 0);
  1534. rcu_initiate_boost(rnp, flags); /* releases rnp->lock. */
  1535. for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++, mask >>= 1) {
  1536. if ((mask & 0x1) == 0)
  1537. continue;
  1538. preempt_disable();
  1539. t = per_cpu(rcu_cpu_kthread_task, cpu);
  1540. if (!cpu_online(cpu) || t == NULL) {
  1541. preempt_enable();
  1542. continue;
  1543. }
  1544. per_cpu(rcu_cpu_has_work, cpu) = 1;
  1545. sp.sched_priority = RCU_KTHREAD_PRIO;
  1546. sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
  1547. preempt_enable();
  1548. }
  1549. }
  1550. /* NOTREACHED */
  1551. rnp->node_kthread_status = RCU_KTHREAD_STOPPED;
  1552. return 0;
  1553. }
  1554. /*
  1555. * Set the per-rcu_node kthread's affinity to cover all CPUs that are
  1556. * served by the rcu_node in question. The CPU hotplug lock is still
  1557. * held, so the value of rnp->qsmaskinit will be stable.
  1558. *
  1559. * We don't include outgoingcpu in the affinity set, use -1 if there is
  1560. * no outgoing CPU. If there are no CPUs left in the affinity set,
  1561. * this function allows the kthread to execute on any CPU.
  1562. */
  1563. static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
  1564. {
  1565. cpumask_var_t cm;
  1566. int cpu;
  1567. unsigned long mask = rnp->qsmaskinit;
  1568. if (rnp->node_kthread_task == NULL)
  1569. return;
  1570. if (!alloc_cpumask_var(&cm, GFP_KERNEL))
  1571. return;
  1572. cpumask_clear(cm);
  1573. for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++, mask >>= 1)
  1574. if ((mask & 0x1) && cpu != outgoingcpu)
  1575. cpumask_set_cpu(cpu, cm);
  1576. if (cpumask_weight(cm) == 0) {
  1577. cpumask_setall(cm);
  1578. for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++)
  1579. cpumask_clear_cpu(cpu, cm);
  1580. WARN_ON_ONCE(cpumask_weight(cm) == 0);
  1581. }
  1582. set_cpus_allowed_ptr(rnp->node_kthread_task, cm);
  1583. rcu_boost_kthread_setaffinity(rnp, cm);
  1584. free_cpumask_var(cm);
  1585. }
  1586. /*
  1587. * Spawn a per-rcu_node kthread, setting priority and affinity.
  1588. * Called during boot before online/offline can happen, or, if
  1589. * during runtime, with the main CPU-hotplug locks held. So only
  1590. * one of these can be executing at a time.
  1591. */
  1592. static int __cpuinit rcu_spawn_one_node_kthread(struct rcu_state *rsp,
  1593. struct rcu_node *rnp)
  1594. {
  1595. unsigned long flags;
  1596. int rnp_index = rnp - &rsp->node[0];
  1597. struct sched_param sp;
  1598. struct task_struct *t;
  1599. if (!rcu_scheduler_fully_active ||
  1600. rnp->qsmaskinit == 0)
  1601. return 0;
  1602. if (rnp->node_kthread_task == NULL) {
  1603. t = kthread_create(rcu_node_kthread, (void *)rnp,
  1604. "rcun/%d", rnp_index);
  1605. if (IS_ERR(t))
  1606. return PTR_ERR(t);
  1607. raw_spin_lock_irqsave(&rnp->lock, flags);
  1608. rnp->node_kthread_task = t;
  1609. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1610. sp.sched_priority = 99;
  1611. sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
  1612. wake_up_process(t); /* get to TASK_INTERRUPTIBLE quickly. */
  1613. }
  1614. return rcu_spawn_one_boost_kthread(rsp, rnp, rnp_index);
  1615. }
  1616. /*
  1617. * Spawn all kthreads -- called as soon as the scheduler is running.
  1618. */
  1619. static int __init rcu_spawn_kthreads(void)
  1620. {
  1621. int cpu;
  1622. struct rcu_node *rnp;
  1623. rcu_scheduler_fully_active = 1;
  1624. for_each_possible_cpu(cpu) {
  1625. per_cpu(rcu_cpu_has_work, cpu) = 0;
  1626. if (cpu_online(cpu))
  1627. (void)rcu_spawn_one_cpu_kthread(cpu);
  1628. }
  1629. rnp = rcu_get_root(rcu_state);
  1630. (void)rcu_spawn_one_node_kthread(rcu_state, rnp);
  1631. if (NUM_RCU_NODES > 1) {
  1632. rcu_for_each_leaf_node(rcu_state, rnp)
  1633. (void)rcu_spawn_one_node_kthread(rcu_state, rnp);
  1634. }
  1635. return 0;
  1636. }
  1637. early_initcall(rcu_spawn_kthreads);
  1638. static void __cpuinit rcu_prepare_kthreads(int cpu)
  1639. {
  1640. struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, cpu);
  1641. struct rcu_node *rnp = rdp->mynode;
  1642. /* Fire up the incoming CPU's kthread and leaf rcu_node kthread. */
  1643. if (rcu_scheduler_fully_active) {
  1644. (void)rcu_spawn_one_cpu_kthread(cpu);
  1645. if (rnp->node_kthread_task == NULL)
  1646. (void)rcu_spawn_one_node_kthread(rcu_state, rnp);
  1647. }
  1648. }
  1649. #else /* #ifdef CONFIG_RCU_BOOST */
  1650. static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags)
  1651. {
  1652. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  1653. }
  1654. static void invoke_rcu_callbacks_kthread(void)
  1655. {
  1656. WARN_ON_ONCE(1);
  1657. }
  1658. static bool rcu_is_callbacks_kthread(void)
  1659. {
  1660. return false;
  1661. }
  1662. static void rcu_preempt_boost_start_gp(struct rcu_node *rnp)
  1663. {
  1664. }
  1665. #ifdef CONFIG_HOTPLUG_CPU
  1666. static void rcu_stop_cpu_kthread(int cpu)
  1667. {
  1668. }
  1669. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  1670. static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
  1671. {
  1672. }
  1673. static void rcu_cpu_kthread_setrt(int cpu, int to_rt)
  1674. {
  1675. }
  1676. static int __init rcu_scheduler_really_started(void)
  1677. {
  1678. rcu_scheduler_fully_active = 1;
  1679. return 0;
  1680. }
  1681. early_initcall(rcu_scheduler_really_started);
  1682. static void __cpuinit rcu_prepare_kthreads(int cpu)
  1683. {
  1684. }
  1685. #endif /* #else #ifdef CONFIG_RCU_BOOST */
  1686. #if !defined(CONFIG_RCU_FAST_NO_HZ)
  1687. /*
  1688. * Check to see if any future RCU-related work will need to be done
  1689. * by the current CPU, even if none need be done immediately, returning
  1690. * 1 if so. This function is part of the RCU implementation; it is -not-
  1691. * an exported member of the RCU API.
  1692. *
  1693. * Because we not have RCU_FAST_NO_HZ, just check whether this CPU needs
  1694. * any flavor of RCU.
  1695. */
  1696. int rcu_needs_cpu(int cpu)
  1697. {
  1698. return rcu_cpu_has_callbacks(cpu);
  1699. }
  1700. /*
  1701. * Because we do not have RCU_FAST_NO_HZ, don't bother initializing for it.
  1702. */
  1703. static void rcu_prepare_for_idle_init(int cpu)
  1704. {
  1705. }
  1706. /*
  1707. * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up
  1708. * after it.
  1709. */
  1710. static void rcu_cleanup_after_idle(int cpu)
  1711. {
  1712. }
  1713. /*
  1714. * Do the idle-entry grace-period work, which, because CONFIG_RCU_FAST_NO_HZ=n,
  1715. * is nothing.
  1716. */
  1717. static void rcu_prepare_for_idle(int cpu)
  1718. {
  1719. }
  1720. #else /* #if !defined(CONFIG_RCU_FAST_NO_HZ) */
  1721. /*
  1722. * This code is invoked when a CPU goes idle, at which point we want
  1723. * to have the CPU do everything required for RCU so that it can enter
  1724. * the energy-efficient dyntick-idle mode. This is handled by a
  1725. * state machine implemented by rcu_prepare_for_idle() below.
  1726. *
  1727. * The following three proprocessor symbols control this state machine:
  1728. *
  1729. * RCU_IDLE_FLUSHES gives the maximum number of times that we will attempt
  1730. * to satisfy RCU. Beyond this point, it is better to incur a periodic
  1731. * scheduling-clock interrupt than to loop through the state machine
  1732. * at full power.
  1733. * RCU_IDLE_OPT_FLUSHES gives the number of RCU_IDLE_FLUSHES that are
  1734. * optional if RCU does not need anything immediately from this
  1735. * CPU, even if this CPU still has RCU callbacks queued. The first
  1736. * times through the state machine are mandatory: we need to give
  1737. * the state machine a chance to communicate a quiescent state
  1738. * to the RCU core.
  1739. * RCU_IDLE_GP_DELAY gives the number of jiffies that a CPU is permitted
  1740. * to sleep in dyntick-idle mode with RCU callbacks pending. This
  1741. * is sized to be roughly one RCU grace period. Those energy-efficiency
  1742. * benchmarkers who might otherwise be tempted to set this to a large
  1743. * number, be warned: Setting RCU_IDLE_GP_DELAY too high can hang your
  1744. * system. And if you are -that- concerned about energy efficiency,
  1745. * just power the system down and be done with it!
  1746. * RCU_IDLE_LAZY_GP_DELAY gives the number of jiffies that a CPU is
  1747. * permitted to sleep in dyntick-idle mode with only lazy RCU
  1748. * callbacks pending. Setting this too high can OOM your system.
  1749. *
  1750. * The values below work well in practice. If future workloads require
  1751. * adjustment, they can be converted into kernel config parameters, though
  1752. * making the state machine smarter might be a better option.
  1753. */
  1754. #define RCU_IDLE_FLUSHES 5 /* Number of dyntick-idle tries. */
  1755. #define RCU_IDLE_OPT_FLUSHES 3 /* Optional dyntick-idle tries. */
  1756. #define RCU_IDLE_GP_DELAY 6 /* Roughly one grace period. */
  1757. #define RCU_IDLE_LAZY_GP_DELAY (6 * HZ) /* Roughly six seconds. */
  1758. static DEFINE_PER_CPU(int, rcu_dyntick_drain);
  1759. static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff);
  1760. static DEFINE_PER_CPU(struct hrtimer, rcu_idle_gp_timer);
  1761. static ktime_t rcu_idle_gp_wait; /* If some non-lazy callbacks. */
  1762. static ktime_t rcu_idle_lazy_gp_wait; /* If only lazy callbacks. */
  1763. /*
  1764. * Allow the CPU to enter dyntick-idle mode if either: (1) There are no
  1765. * callbacks on this CPU, (2) this CPU has not yet attempted to enter
  1766. * dyntick-idle mode, or (3) this CPU is in the process of attempting to
  1767. * enter dyntick-idle mode. Otherwise, if we have recently tried and failed
  1768. * to enter dyntick-idle mode, we refuse to try to enter it. After all,
  1769. * it is better to incur scheduling-clock interrupts than to spin
  1770. * continuously for the same time duration!
  1771. */
  1772. int rcu_needs_cpu(int cpu)
  1773. {
  1774. /* If no callbacks, RCU doesn't need the CPU. */
  1775. if (!rcu_cpu_has_callbacks(cpu))
  1776. return 0;
  1777. /* Otherwise, RCU needs the CPU only if it recently tried and failed. */
  1778. return per_cpu(rcu_dyntick_holdoff, cpu) == jiffies;
  1779. }
  1780. /*
  1781. * Does the specified flavor of RCU have non-lazy callbacks pending on
  1782. * the specified CPU? Both RCU flavor and CPU are specified by the
  1783. * rcu_data structure.
  1784. */
  1785. static bool __rcu_cpu_has_nonlazy_callbacks(struct rcu_data *rdp)
  1786. {
  1787. return rdp->qlen != rdp->qlen_lazy;
  1788. }
  1789. #ifdef CONFIG_TREE_PREEMPT_RCU
  1790. /*
  1791. * Are there non-lazy RCU-preempt callbacks? (There cannot be if there
  1792. * is no RCU-preempt in the kernel.)
  1793. */
  1794. static bool rcu_preempt_cpu_has_nonlazy_callbacks(int cpu)
  1795. {
  1796. struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu);
  1797. return __rcu_cpu_has_nonlazy_callbacks(rdp);
  1798. }
  1799. #else /* #ifdef CONFIG_TREE_PREEMPT_RCU */
  1800. static bool rcu_preempt_cpu_has_nonlazy_callbacks(int cpu)
  1801. {
  1802. return 0;
  1803. }
  1804. #endif /* else #ifdef CONFIG_TREE_PREEMPT_RCU */
  1805. /*
  1806. * Does any flavor of RCU have non-lazy callbacks on the specified CPU?
  1807. */
  1808. static bool rcu_cpu_has_nonlazy_callbacks(int cpu)
  1809. {
  1810. return __rcu_cpu_has_nonlazy_callbacks(&per_cpu(rcu_sched_data, cpu)) ||
  1811. __rcu_cpu_has_nonlazy_callbacks(&per_cpu(rcu_bh_data, cpu)) ||
  1812. rcu_preempt_cpu_has_nonlazy_callbacks(cpu);
  1813. }
  1814. /*
  1815. * Timer handler used to force CPU to start pushing its remaining RCU
  1816. * callbacks in the case where it entered dyntick-idle mode with callbacks
  1817. * pending. The hander doesn't really need to do anything because the
  1818. * real work is done upon re-entry to idle, or by the next scheduling-clock
  1819. * interrupt should idle not be re-entered.
  1820. */
  1821. static enum hrtimer_restart rcu_idle_gp_timer_func(struct hrtimer *hrtp)
  1822. {
  1823. trace_rcu_prep_idle("Timer");
  1824. return HRTIMER_NORESTART;
  1825. }
  1826. /*
  1827. * Initialize the timer used to pull CPUs out of dyntick-idle mode.
  1828. */
  1829. static void rcu_prepare_for_idle_init(int cpu)
  1830. {
  1831. static int firsttime = 1;
  1832. struct hrtimer *hrtp = &per_cpu(rcu_idle_gp_timer, cpu);
  1833. hrtimer_init(hrtp, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  1834. hrtp->function = rcu_idle_gp_timer_func;
  1835. if (firsttime) {
  1836. unsigned int upj = jiffies_to_usecs(RCU_IDLE_GP_DELAY);
  1837. rcu_idle_gp_wait = ns_to_ktime(upj * (u64)1000);
  1838. upj = jiffies_to_usecs(RCU_IDLE_LAZY_GP_DELAY);
  1839. rcu_idle_lazy_gp_wait = ns_to_ktime(upj * (u64)1000);
  1840. firsttime = 0;
  1841. }
  1842. }
  1843. /*
  1844. * Clean up for exit from idle. Because we are exiting from idle, there
  1845. * is no longer any point to rcu_idle_gp_timer, so cancel it. This will
  1846. * do nothing if this timer is not active, so just cancel it unconditionally.
  1847. */
  1848. static void rcu_cleanup_after_idle(int cpu)
  1849. {
  1850. hrtimer_cancel(&per_cpu(rcu_idle_gp_timer, cpu));
  1851. }
  1852. /*
  1853. * Check to see if any RCU-related work can be done by the current CPU,
  1854. * and if so, schedule a softirq to get it done. This function is part
  1855. * of the RCU implementation; it is -not- an exported member of the RCU API.
  1856. *
  1857. * The idea is for the current CPU to clear out all work required by the
  1858. * RCU core for the current grace period, so that this CPU can be permitted
  1859. * to enter dyntick-idle mode. In some cases, it will need to be awakened
  1860. * at the end of the grace period by whatever CPU ends the grace period.
  1861. * This allows CPUs to go dyntick-idle more quickly, and to reduce the
  1862. * number of wakeups by a modest integer factor.
  1863. *
  1864. * Because it is not legal to invoke rcu_process_callbacks() with irqs
  1865. * disabled, we do one pass of force_quiescent_state(), then do a
  1866. * invoke_rcu_core() to cause rcu_process_callbacks() to be invoked
  1867. * later. The per-cpu rcu_dyntick_drain variable controls the sequencing.
  1868. *
  1869. * The caller must have disabled interrupts.
  1870. */
  1871. static void rcu_prepare_for_idle(int cpu)
  1872. {
  1873. /*
  1874. * If there are no callbacks on this CPU, enter dyntick-idle mode.
  1875. * Also reset state to avoid prejudicing later attempts.
  1876. */
  1877. if (!rcu_cpu_has_callbacks(cpu)) {
  1878. per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
  1879. per_cpu(rcu_dyntick_drain, cpu) = 0;
  1880. trace_rcu_prep_idle("No callbacks");
  1881. return;
  1882. }
  1883. /*
  1884. * If in holdoff mode, just return. We will presumably have
  1885. * refrained from disabling the scheduling-clock tick.
  1886. */
  1887. if (per_cpu(rcu_dyntick_holdoff, cpu) == jiffies) {
  1888. trace_rcu_prep_idle("In holdoff");
  1889. return;
  1890. }
  1891. /* Check and update the rcu_dyntick_drain sequencing. */
  1892. if (per_cpu(rcu_dyntick_drain, cpu) <= 0) {
  1893. /* First time through, initialize the counter. */
  1894. per_cpu(rcu_dyntick_drain, cpu) = RCU_IDLE_FLUSHES;
  1895. } else if (per_cpu(rcu_dyntick_drain, cpu) <= RCU_IDLE_OPT_FLUSHES &&
  1896. !rcu_pending(cpu)) {
  1897. /* Can we go dyntick-idle despite still having callbacks? */
  1898. trace_rcu_prep_idle("Dyntick with callbacks");
  1899. per_cpu(rcu_dyntick_drain, cpu) = 0;
  1900. per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
  1901. if (rcu_cpu_has_nonlazy_callbacks(cpu))
  1902. hrtimer_start(&per_cpu(rcu_idle_gp_timer, cpu),
  1903. rcu_idle_gp_wait, HRTIMER_MODE_REL);
  1904. else
  1905. hrtimer_start(&per_cpu(rcu_idle_gp_timer, cpu),
  1906. rcu_idle_lazy_gp_wait, HRTIMER_MODE_REL);
  1907. return; /* Nothing more to do immediately. */
  1908. } else if (--per_cpu(rcu_dyntick_drain, cpu) <= 0) {
  1909. /* We have hit the limit, so time to give up. */
  1910. per_cpu(rcu_dyntick_holdoff, cpu) = jiffies;
  1911. trace_rcu_prep_idle("Begin holdoff");
  1912. invoke_rcu_core(); /* Force the CPU out of dyntick-idle. */
  1913. return;
  1914. }
  1915. /*
  1916. * Do one step of pushing the remaining RCU callbacks through
  1917. * the RCU core state machine.
  1918. */
  1919. #ifdef CONFIG_TREE_PREEMPT_RCU
  1920. if (per_cpu(rcu_preempt_data, cpu).nxtlist) {
  1921. rcu_preempt_qs(cpu);
  1922. force_quiescent_state(&rcu_preempt_state, 0);
  1923. }
  1924. #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
  1925. if (per_cpu(rcu_sched_data, cpu).nxtlist) {
  1926. rcu_sched_qs(cpu);
  1927. force_quiescent_state(&rcu_sched_state, 0);
  1928. }
  1929. if (per_cpu(rcu_bh_data, cpu).nxtlist) {
  1930. rcu_bh_qs(cpu);
  1931. force_quiescent_state(&rcu_bh_state, 0);
  1932. }
  1933. /*
  1934. * If RCU callbacks are still pending, RCU still needs this CPU.
  1935. * So try forcing the callbacks through the grace period.
  1936. */
  1937. if (rcu_cpu_has_callbacks(cpu)) {
  1938. trace_rcu_prep_idle("More callbacks");
  1939. invoke_rcu_core();
  1940. } else
  1941. trace_rcu_prep_idle("Callbacks drained");
  1942. }
  1943. #endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */
  1944. #ifdef CONFIG_RCU_CPU_STALL_INFO
  1945. #ifdef CONFIG_RCU_FAST_NO_HZ
  1946. static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
  1947. {
  1948. struct hrtimer *hrtp = &per_cpu(rcu_idle_gp_timer, cpu);
  1949. sprintf(cp, "drain=%d %c timer=%lld",
  1950. per_cpu(rcu_dyntick_drain, cpu),
  1951. per_cpu(rcu_dyntick_holdoff, cpu) == jiffies ? 'H' : '.',
  1952. hrtimer_active(hrtp)
  1953. ? ktime_to_us(hrtimer_get_remaining(hrtp))
  1954. : -1);
  1955. }
  1956. #else /* #ifdef CONFIG_RCU_FAST_NO_HZ */
  1957. static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
  1958. {
  1959. }
  1960. #endif /* #else #ifdef CONFIG_RCU_FAST_NO_HZ */
  1961. /* Initiate the stall-info list. */
  1962. static void print_cpu_stall_info_begin(void)
  1963. {
  1964. printk(KERN_CONT "\n");
  1965. }
  1966. /*
  1967. * Print out diagnostic information for the specified stalled CPU.
  1968. *
  1969. * If the specified CPU is aware of the current RCU grace period
  1970. * (flavor specified by rsp), then print the number of scheduling
  1971. * clock interrupts the CPU has taken during the time that it has
  1972. * been aware. Otherwise, print the number of RCU grace periods
  1973. * that this CPU is ignorant of, for example, "1" if the CPU was
  1974. * aware of the previous grace period.
  1975. *
  1976. * Also print out idle and (if CONFIG_RCU_FAST_NO_HZ) idle-entry info.
  1977. */
  1978. static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
  1979. {
  1980. char fast_no_hz[72];
  1981. struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
  1982. struct rcu_dynticks *rdtp = rdp->dynticks;
  1983. char *ticks_title;
  1984. unsigned long ticks_value;
  1985. if (rsp->gpnum == rdp->gpnum) {
  1986. ticks_title = "ticks this GP";
  1987. ticks_value = rdp->ticks_this_gp;
  1988. } else {
  1989. ticks_title = "GPs behind";
  1990. ticks_value = rsp->gpnum - rdp->gpnum;
  1991. }
  1992. print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
  1993. printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
  1994. cpu, ticks_value, ticks_title,
  1995. atomic_read(&rdtp->dynticks) & 0xfff,
  1996. rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
  1997. fast_no_hz);
  1998. }
  1999. /* Terminate the stall-info list. */
  2000. static void print_cpu_stall_info_end(void)
  2001. {
  2002. printk(KERN_ERR "\t");
  2003. }
  2004. /* Zero ->ticks_this_gp for all flavors of RCU. */
  2005. static void zero_cpu_stall_ticks(struct rcu_data *rdp)
  2006. {
  2007. rdp->ticks_this_gp = 0;
  2008. }
  2009. /* Increment ->ticks_this_gp for all flavors of RCU. */
  2010. static void increment_cpu_stall_ticks(void)
  2011. {
  2012. __get_cpu_var(rcu_sched_data).ticks_this_gp++;
  2013. __get_cpu_var(rcu_bh_data).ticks_this_gp++;
  2014. #ifdef CONFIG_TREE_PREEMPT_RCU
  2015. __get_cpu_var(rcu_preempt_data).ticks_this_gp++;
  2016. #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
  2017. }
  2018. #else /* #ifdef CONFIG_RCU_CPU_STALL_INFO */
  2019. static void print_cpu_stall_info_begin(void)
  2020. {
  2021. printk(KERN_CONT " {");
  2022. }
  2023. static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
  2024. {
  2025. printk(KERN_CONT " %d", cpu);
  2026. }
  2027. static void print_cpu_stall_info_end(void)
  2028. {
  2029. printk(KERN_CONT "} ");
  2030. }
  2031. static void zero_cpu_stall_ticks(struct rcu_data *rdp)
  2032. {
  2033. }
  2034. static void increment_cpu_stall_ticks(void)
  2035. {
  2036. }
  2037. #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_INFO */