tree_exp.h 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * RCU expedited grace periods
  4. *
  5. * Copyright IBM Corporation, 2016
  6. *
  7. * Authors: Paul E. McKenney <paulmck@linux.ibm.com>
  8. */
  9. #include <linux/console.h>
  10. #include <linux/lockdep.h>
  11. static void rcu_exp_handler(void *unused);
  12. static int rcu_print_task_exp_stall(struct rcu_node *rnp);
  13. static void rcu_exp_print_detail_task_stall_rnp(struct rcu_node *rnp);
  14. /*
  15. * Record the start of an expedited grace period.
  16. */
  17. static void rcu_exp_gp_seq_start(void)
  18. {
  19. rcu_seq_start(&rcu_state.expedited_sequence);
  20. rcu_poll_gp_seq_start_unlocked(&rcu_state.gp_seq_polled_exp_snap);
  21. }
  22. /*
  23. * Return the value that the expedited-grace-period counter will have
  24. * at the end of the current grace period.
  25. */
  26. static __maybe_unused unsigned long rcu_exp_gp_seq_endval(void)
  27. {
  28. return rcu_seq_endval(&rcu_state.expedited_sequence);
  29. }
  30. /*
  31. * Record the end of an expedited grace period.
  32. */
  33. static void rcu_exp_gp_seq_end(void)
  34. {
  35. rcu_poll_gp_seq_end_unlocked(&rcu_state.gp_seq_polled_exp_snap);
  36. rcu_seq_end(&rcu_state.expedited_sequence);
  37. smp_mb(); /* Ensure that consecutive grace periods serialize. */
  38. }
  39. /*
  40. * Take a snapshot of the expedited-grace-period counter, which is the
  41. * earliest value that will indicate that a full grace period has
  42. * elapsed since the current time.
  43. */
  44. static unsigned long rcu_exp_gp_seq_snap(void)
  45. {
  46. unsigned long s;
  47. smp_mb(); /* Caller's modifications seen first by other CPUs. */
  48. s = rcu_seq_snap(&rcu_state.expedited_sequence);
  49. trace_rcu_exp_grace_period(rcu_state.name, s, TPS("snap"));
  50. return s;
  51. }
  52. /*
  53. * Given a counter snapshot from rcu_exp_gp_seq_snap(), return true
  54. * if a full expedited grace period has elapsed since that snapshot
  55. * was taken.
  56. */
  57. static bool rcu_exp_gp_seq_done(unsigned long s)
  58. {
  59. return rcu_seq_done(&rcu_state.expedited_sequence, s);
  60. }
  61. /*
  62. * Reset the ->expmaskinit values in the rcu_node tree to reflect any
  63. * recent CPU-online activity. Note that these masks are not cleared
  64. * when CPUs go offline, so they reflect the union of all CPUs that have
  65. * ever been online. This means that this function normally takes its
  66. * no-work-to-do fastpath.
  67. */
  68. static void sync_exp_reset_tree_hotplug(void)
  69. {
  70. bool done;
  71. unsigned long flags;
  72. unsigned long mask;
  73. unsigned long oldmask;
  74. int ncpus = smp_load_acquire(&rcu_state.ncpus); /* Order vs. locking. */
  75. struct rcu_node *rnp;
  76. struct rcu_node *rnp_up;
  77. /* If no new CPUs onlined since last time, nothing to do. */
  78. if (likely(ncpus == rcu_state.ncpus_snap))
  79. return;
  80. rcu_state.ncpus_snap = ncpus;
  81. /*
  82. * Each pass through the following loop propagates newly onlined
  83. * CPUs for the current rcu_node structure up the rcu_node tree.
  84. */
  85. rcu_for_each_leaf_node(rnp) {
  86. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  87. if (rnp->expmaskinit == rnp->expmaskinitnext) {
  88. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  89. continue; /* No new CPUs, nothing to do. */
  90. }
  91. /* Update this node's mask, track old value for propagation. */
  92. oldmask = rnp->expmaskinit;
  93. rnp->expmaskinit = rnp->expmaskinitnext;
  94. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  95. /* If was already nonzero, nothing to propagate. */
  96. if (oldmask)
  97. continue;
  98. /* Propagate the new CPU up the tree. */
  99. mask = rnp->grpmask;
  100. rnp_up = rnp->parent;
  101. done = false;
  102. while (rnp_up) {
  103. raw_spin_lock_irqsave_rcu_node(rnp_up, flags);
  104. if (rnp_up->expmaskinit)
  105. done = true;
  106. rnp_up->expmaskinit |= mask;
  107. raw_spin_unlock_irqrestore_rcu_node(rnp_up, flags);
  108. if (done)
  109. break;
  110. mask = rnp_up->grpmask;
  111. rnp_up = rnp_up->parent;
  112. }
  113. }
  114. }
  115. /*
  116. * Reset the ->expmask values in the rcu_node tree in preparation for
  117. * a new expedited grace period.
  118. */
  119. static void __maybe_unused sync_exp_reset_tree(void)
  120. {
  121. unsigned long flags;
  122. struct rcu_node *rnp;
  123. sync_exp_reset_tree_hotplug();
  124. rcu_for_each_node_breadth_first(rnp) {
  125. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  126. WARN_ON_ONCE(rnp->expmask);
  127. WRITE_ONCE(rnp->expmask, rnp->expmaskinit);
  128. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  129. }
  130. }
  131. /*
  132. * Return non-zero if there is no RCU expedited grace period in progress
  133. * for the specified rcu_node structure, in other words, if all CPUs and
  134. * tasks covered by the specified rcu_node structure have done their bit
  135. * for the current expedited grace period.
  136. */
  137. static bool sync_rcu_exp_done(struct rcu_node *rnp)
  138. {
  139. raw_lockdep_assert_held_rcu_node(rnp);
  140. return READ_ONCE(rnp->exp_tasks) == NULL &&
  141. READ_ONCE(rnp->expmask) == 0;
  142. }
  143. /*
  144. * Like sync_rcu_exp_done(), but where the caller does not hold the
  145. * rcu_node's ->lock.
  146. */
  147. static bool sync_rcu_exp_done_unlocked(struct rcu_node *rnp)
  148. {
  149. unsigned long flags;
  150. bool ret;
  151. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  152. ret = sync_rcu_exp_done(rnp);
  153. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  154. return ret;
  155. }
  156. /*
  157. * Report the exit from RCU read-side critical section for the last task
  158. * that queued itself during or before the current expedited preemptible-RCU
  159. * grace period. This event is reported either to the rcu_node structure on
  160. * which the task was queued or to one of that rcu_node structure's ancestors,
  161. * recursively up the tree. (Calm down, calm down, we do the recursion
  162. * iteratively!)
  163. */
  164. static void __rcu_report_exp_rnp(struct rcu_node *rnp,
  165. bool wake, unsigned long flags)
  166. __releases(rnp->lock)
  167. {
  168. unsigned long mask;
  169. raw_lockdep_assert_held_rcu_node(rnp);
  170. for (;;) {
  171. if (!sync_rcu_exp_done(rnp)) {
  172. if (!rnp->expmask)
  173. rcu_initiate_boost(rnp, flags);
  174. else
  175. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  176. break;
  177. }
  178. if (rnp->parent == NULL) {
  179. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  180. if (wake)
  181. swake_up_one_online(&rcu_state.expedited_wq);
  182. break;
  183. }
  184. mask = rnp->grpmask;
  185. raw_spin_unlock_rcu_node(rnp); /* irqs remain disabled */
  186. rnp = rnp->parent;
  187. raw_spin_lock_rcu_node(rnp); /* irqs already disabled */
  188. WARN_ON_ONCE(!(rnp->expmask & mask));
  189. WRITE_ONCE(rnp->expmask, rnp->expmask & ~mask);
  190. }
  191. }
  192. /*
  193. * Report expedited quiescent state for specified node. This is a
  194. * lock-acquisition wrapper function for __rcu_report_exp_rnp().
  195. */
  196. static void __maybe_unused rcu_report_exp_rnp(struct rcu_node *rnp, bool wake)
  197. {
  198. unsigned long flags;
  199. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  200. __rcu_report_exp_rnp(rnp, wake, flags);
  201. }
  202. /*
  203. * Report expedited quiescent state for multiple CPUs, all covered by the
  204. * specified leaf rcu_node structure.
  205. */
  206. static void rcu_report_exp_cpu_mult(struct rcu_node *rnp,
  207. unsigned long mask, bool wake)
  208. {
  209. int cpu;
  210. unsigned long flags;
  211. struct rcu_data *rdp;
  212. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  213. if (!(rnp->expmask & mask)) {
  214. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  215. return;
  216. }
  217. WRITE_ONCE(rnp->expmask, rnp->expmask & ~mask);
  218. for_each_leaf_node_cpu_mask(rnp, cpu, mask) {
  219. rdp = per_cpu_ptr(&rcu_data, cpu);
  220. if (!IS_ENABLED(CONFIG_NO_HZ_FULL) || !rdp->rcu_forced_tick_exp)
  221. continue;
  222. rdp->rcu_forced_tick_exp = false;
  223. tick_dep_clear_cpu(cpu, TICK_DEP_BIT_RCU_EXP);
  224. }
  225. __rcu_report_exp_rnp(rnp, wake, flags); /* Releases rnp->lock. */
  226. }
  227. /*
  228. * Report expedited quiescent state for specified rcu_data (CPU).
  229. */
  230. static void rcu_report_exp_rdp(struct rcu_data *rdp)
  231. {
  232. WRITE_ONCE(rdp->cpu_no_qs.b.exp, false);
  233. rcu_report_exp_cpu_mult(rdp->mynode, rdp->grpmask, true);
  234. }
  235. /* Common code for work-done checking. */
  236. static bool sync_exp_work_done(unsigned long s)
  237. {
  238. if (rcu_exp_gp_seq_done(s)) {
  239. trace_rcu_exp_grace_period(rcu_state.name, s, TPS("done"));
  240. /*
  241. * Order GP completion with preceding accesses. Order also GP
  242. * completion with post GP update side accesses. Pairs with
  243. * rcu_seq_end().
  244. */
  245. smp_mb();
  246. return true;
  247. }
  248. return false;
  249. }
  250. /*
  251. * Funnel-lock acquisition for expedited grace periods. Returns true
  252. * if some other task completed an expedited grace period that this task
  253. * can piggy-back on, and with no mutex held. Otherwise, returns false
  254. * with the mutex held, indicating that the caller must actually do the
  255. * expedited grace period.
  256. */
  257. static bool exp_funnel_lock(unsigned long s)
  258. {
  259. struct rcu_data *rdp = per_cpu_ptr(&rcu_data, raw_smp_processor_id());
  260. struct rcu_node *rnp = rdp->mynode;
  261. struct rcu_node *rnp_root = rcu_get_root();
  262. /* Low-contention fastpath. */
  263. if (ULONG_CMP_LT(READ_ONCE(rnp->exp_seq_rq), s) &&
  264. (rnp == rnp_root ||
  265. ULONG_CMP_LT(READ_ONCE(rnp_root->exp_seq_rq), s)) &&
  266. mutex_trylock(&rcu_state.exp_mutex))
  267. goto fastpath;
  268. /*
  269. * Each pass through the following loop works its way up
  270. * the rcu_node tree, returning if others have done the work or
  271. * otherwise falls through to acquire ->exp_mutex. The mapping
  272. * from CPU to rcu_node structure can be inexact, as it is just
  273. * promoting locality and is not strictly needed for correctness.
  274. */
  275. for (; rnp != NULL; rnp = rnp->parent) {
  276. if (sync_exp_work_done(s))
  277. return true;
  278. /* Work not done, either wait here or go up. */
  279. spin_lock(&rnp->exp_lock);
  280. if (ULONG_CMP_GE(rnp->exp_seq_rq, s)) {
  281. /* Someone else doing GP, so wait for them. */
  282. spin_unlock(&rnp->exp_lock);
  283. trace_rcu_exp_funnel_lock(rcu_state.name, rnp->level,
  284. rnp->grplo, rnp->grphi,
  285. TPS("wait"));
  286. wait_event(rnp->exp_wq[rcu_seq_ctr(s) & 0x3],
  287. sync_exp_work_done(s));
  288. return true;
  289. }
  290. WRITE_ONCE(rnp->exp_seq_rq, s); /* Followers can wait on us. */
  291. spin_unlock(&rnp->exp_lock);
  292. trace_rcu_exp_funnel_lock(rcu_state.name, rnp->level,
  293. rnp->grplo, rnp->grphi, TPS("nxtlvl"));
  294. }
  295. mutex_lock(&rcu_state.exp_mutex);
  296. fastpath:
  297. if (sync_exp_work_done(s)) {
  298. mutex_unlock(&rcu_state.exp_mutex);
  299. return true;
  300. }
  301. rcu_exp_gp_seq_start();
  302. trace_rcu_exp_grace_period(rcu_state.name, s, TPS("start"));
  303. return false;
  304. }
  305. /*
  306. * Select the CPUs within the specified rcu_node that the upcoming
  307. * expedited grace period needs to wait for.
  308. */
  309. static void __sync_rcu_exp_select_node_cpus(struct rcu_exp_work *rewp)
  310. {
  311. int cpu;
  312. unsigned long flags;
  313. unsigned long mask_ofl_test;
  314. unsigned long mask_ofl_ipi;
  315. int ret;
  316. struct rcu_node *rnp = container_of(rewp, struct rcu_node, rew);
  317. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  318. /* Each pass checks a CPU for identity, offline, and idle. */
  319. mask_ofl_test = 0;
  320. for_each_leaf_node_cpu_mask(rnp, cpu, rnp->expmask) {
  321. struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
  322. unsigned long mask = rdp->grpmask;
  323. int snap;
  324. if (raw_smp_processor_id() == cpu ||
  325. !(rnp->qsmaskinitnext & mask)) {
  326. mask_ofl_test |= mask;
  327. } else {
  328. /*
  329. * Full ordering between remote CPU's post idle accesses
  330. * and updater's accesses prior to current GP (and also
  331. * the started GP sequence number) is enforced by
  332. * rcu_seq_start() implicit barrier, relayed by kworkers
  333. * locking and even further by smp_mb__after_unlock_lock()
  334. * barriers chained all the way throughout the rnp locking
  335. * tree since sync_exp_reset_tree() and up to the current
  336. * leaf rnp locking.
  337. *
  338. * Ordering between remote CPU's pre idle accesses and
  339. * post grace period updater's accesses is enforced by the
  340. * below acquire semantic.
  341. */
  342. snap = ct_rcu_watching_cpu_acquire(cpu);
  343. if (rcu_watching_snap_in_eqs(snap))
  344. mask_ofl_test |= mask;
  345. else
  346. rdp->exp_watching_snap = snap;
  347. }
  348. }
  349. mask_ofl_ipi = rnp->expmask & ~mask_ofl_test;
  350. /*
  351. * Need to wait for any blocked tasks as well. Note that
  352. * additional blocking tasks will also block the expedited GP
  353. * until such time as the ->expmask bits are cleared.
  354. */
  355. if (rcu_preempt_has_tasks(rnp))
  356. WRITE_ONCE(rnp->exp_tasks, rnp->blkd_tasks.next);
  357. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  358. /* IPI the remaining CPUs for expedited quiescent state. */
  359. for_each_leaf_node_cpu_mask(rnp, cpu, mask_ofl_ipi) {
  360. struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
  361. unsigned long mask = rdp->grpmask;
  362. retry_ipi:
  363. if (rcu_watching_snap_stopped_since(rdp, rdp->exp_watching_snap)) {
  364. mask_ofl_test |= mask;
  365. continue;
  366. }
  367. if (get_cpu() == cpu) {
  368. mask_ofl_test |= mask;
  369. put_cpu();
  370. continue;
  371. }
  372. ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);
  373. put_cpu();
  374. /* The CPU will report the QS in response to the IPI. */
  375. if (!ret)
  376. continue;
  377. /* Failed, raced with CPU hotplug operation. */
  378. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  379. if ((rnp->qsmaskinitnext & mask) &&
  380. (rnp->expmask & mask)) {
  381. /* Online, so delay for a bit and try again. */
  382. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  383. trace_rcu_exp_grace_period(rcu_state.name, rcu_exp_gp_seq_endval(), TPS("selectofl"));
  384. schedule_timeout_idle(1);
  385. goto retry_ipi;
  386. }
  387. /* CPU really is offline, so we must report its QS. */
  388. if (rnp->expmask & mask)
  389. mask_ofl_test |= mask;
  390. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  391. }
  392. /* Report quiescent states for those that went offline. */
  393. if (mask_ofl_test)
  394. rcu_report_exp_cpu_mult(rnp, mask_ofl_test, false);
  395. }
  396. static void rcu_exp_sel_wait_wake(unsigned long s);
  397. static void sync_rcu_exp_select_node_cpus(struct kthread_work *wp)
  398. {
  399. struct rcu_exp_work *rewp =
  400. container_of(wp, struct rcu_exp_work, rew_work);
  401. __sync_rcu_exp_select_node_cpus(rewp);
  402. }
  403. static inline bool rcu_exp_worker_started(void)
  404. {
  405. return !!READ_ONCE(rcu_exp_gp_kworker);
  406. }
  407. static inline bool rcu_exp_par_worker_started(struct rcu_node *rnp)
  408. {
  409. return !!READ_ONCE(rnp->exp_kworker);
  410. }
  411. static inline void sync_rcu_exp_select_cpus_queue_work(struct rcu_node *rnp)
  412. {
  413. kthread_init_work(&rnp->rew.rew_work, sync_rcu_exp_select_node_cpus);
  414. /*
  415. * Use rcu_exp_par_gp_kworker, because flushing a work item from
  416. * another work item on the same kthread worker can result in
  417. * deadlock.
  418. */
  419. kthread_queue_work(READ_ONCE(rnp->exp_kworker), &rnp->rew.rew_work);
  420. }
  421. static inline void sync_rcu_exp_select_cpus_flush_work(struct rcu_node *rnp)
  422. {
  423. kthread_flush_work(&rnp->rew.rew_work);
  424. }
  425. /*
  426. * Work-queue handler to drive an expedited grace period forward.
  427. */
  428. static void wait_rcu_exp_gp(struct kthread_work *wp)
  429. {
  430. struct rcu_exp_work *rewp;
  431. rewp = container_of(wp, struct rcu_exp_work, rew_work);
  432. rcu_exp_sel_wait_wake(rewp->rew_s);
  433. }
  434. static inline void synchronize_rcu_expedited_queue_work(struct rcu_exp_work *rew)
  435. {
  436. kthread_init_work(&rew->rew_work, wait_rcu_exp_gp);
  437. kthread_queue_work(rcu_exp_gp_kworker, &rew->rew_work);
  438. }
  439. /*
  440. * Select the nodes that the upcoming expedited grace period needs
  441. * to wait for.
  442. */
  443. static void sync_rcu_exp_select_cpus(void)
  444. {
  445. struct rcu_node *rnp;
  446. trace_rcu_exp_grace_period(rcu_state.name, rcu_exp_gp_seq_endval(), TPS("reset"));
  447. sync_exp_reset_tree();
  448. trace_rcu_exp_grace_period(rcu_state.name, rcu_exp_gp_seq_endval(), TPS("select"));
  449. /* Schedule work for each leaf rcu_node structure. */
  450. rcu_for_each_leaf_node(rnp) {
  451. rnp->exp_need_flush = false;
  452. if (!READ_ONCE(rnp->expmask))
  453. continue; /* Avoid early boot non-existent wq. */
  454. if (!rcu_exp_par_worker_started(rnp) ||
  455. rcu_scheduler_active != RCU_SCHEDULER_RUNNING ||
  456. rcu_is_last_leaf_node(rnp)) {
  457. /* No worker started yet or last leaf, do direct call. */
  458. sync_rcu_exp_select_node_cpus(&rnp->rew.rew_work);
  459. continue;
  460. }
  461. sync_rcu_exp_select_cpus_queue_work(rnp);
  462. rnp->exp_need_flush = true;
  463. }
  464. /* Wait for jobs (if any) to complete. */
  465. rcu_for_each_leaf_node(rnp)
  466. if (rnp->exp_need_flush)
  467. sync_rcu_exp_select_cpus_flush_work(rnp);
  468. }
  469. /*
  470. * Wait for the expedited grace period to elapse, within time limit.
  471. * If the time limit is exceeded without the grace period elapsing,
  472. * return false, otherwise return true.
  473. */
  474. static bool synchronize_rcu_expedited_wait_once(long tlimit)
  475. {
  476. int t;
  477. struct rcu_node *rnp_root = rcu_get_root();
  478. t = swait_event_timeout_exclusive(rcu_state.expedited_wq,
  479. sync_rcu_exp_done_unlocked(rnp_root),
  480. tlimit);
  481. // Workqueues should not be signaled.
  482. if (t > 0 || sync_rcu_exp_done_unlocked(rnp_root))
  483. return true;
  484. WARN_ON(t < 0); /* workqueues should not be signaled. */
  485. return false;
  486. }
  487. /*
  488. * Print out an expedited RCU CPU stall warning message.
  489. */
  490. static void synchronize_rcu_expedited_stall(unsigned long jiffies_start, unsigned long j)
  491. {
  492. int cpu;
  493. unsigned long mask;
  494. int ndetected;
  495. struct rcu_node *rnp;
  496. struct rcu_node *rnp_root = rcu_get_root();
  497. if (READ_ONCE(csd_lock_suppress_rcu_stall) && csd_lock_is_stuck()) {
  498. pr_err("INFO: %s detected expedited stalls, but suppressed full report due to a stuck CSD-lock.\n", rcu_state.name);
  499. return;
  500. }
  501. pr_err("INFO: %s detected expedited stalls on CPUs/tasks: {", rcu_state.name);
  502. ndetected = 0;
  503. rcu_for_each_leaf_node(rnp) {
  504. ndetected += rcu_print_task_exp_stall(rnp);
  505. for_each_leaf_node_possible_cpu(rnp, cpu) {
  506. struct rcu_data *rdp;
  507. mask = leaf_node_cpu_bit(rnp, cpu);
  508. if (!(READ_ONCE(rnp->expmask) & mask))
  509. continue;
  510. ndetected++;
  511. rdp = per_cpu_ptr(&rcu_data, cpu);
  512. pr_cont(" %d-%c%c%c%c", cpu,
  513. "O."[!!cpu_online(cpu)],
  514. "o."[!!(rdp->grpmask & rnp->expmaskinit)],
  515. "N."[!!(rdp->grpmask & rnp->expmaskinitnext)],
  516. "D."[!!data_race(rdp->cpu_no_qs.b.exp)]);
  517. }
  518. }
  519. pr_cont(" } %lu jiffies s: %lu root: %#lx/%c\n",
  520. j - jiffies_start, rcu_state.expedited_sequence, data_race(rnp_root->expmask),
  521. ".T"[!!data_race(rnp_root->exp_tasks)]);
  522. if (ndetected) {
  523. pr_err("blocking rcu_node structures (internal RCU debug):");
  524. rcu_for_each_node_breadth_first(rnp) {
  525. if (rnp == rnp_root)
  526. continue; /* printed unconditionally */
  527. if (sync_rcu_exp_done_unlocked(rnp))
  528. continue;
  529. pr_cont(" l=%u:%d-%d:%#lx/%c",
  530. rnp->level, rnp->grplo, rnp->grphi, data_race(rnp->expmask),
  531. ".T"[!!data_race(rnp->exp_tasks)]);
  532. }
  533. pr_cont("\n");
  534. }
  535. rcu_for_each_leaf_node(rnp) {
  536. for_each_leaf_node_possible_cpu(rnp, cpu) {
  537. mask = leaf_node_cpu_bit(rnp, cpu);
  538. if (!(READ_ONCE(rnp->expmask) & mask))
  539. continue;
  540. dump_cpu_task(cpu);
  541. }
  542. rcu_exp_print_detail_task_stall_rnp(rnp);
  543. }
  544. }
  545. /*
  546. * Wait for the expedited grace period to elapse, issuing any needed
  547. * RCU CPU stall warnings along the way.
  548. */
  549. static void synchronize_rcu_expedited_wait(void)
  550. {
  551. int cpu;
  552. unsigned long j;
  553. unsigned long jiffies_stall;
  554. unsigned long jiffies_start;
  555. unsigned long mask;
  556. struct rcu_data *rdp;
  557. struct rcu_node *rnp;
  558. unsigned long flags;
  559. trace_rcu_exp_grace_period(rcu_state.name, rcu_exp_gp_seq_endval(), TPS("startwait"));
  560. jiffies_stall = rcu_exp_jiffies_till_stall_check();
  561. jiffies_start = jiffies;
  562. if (tick_nohz_full_enabled() && rcu_inkernel_boot_has_ended()) {
  563. if (synchronize_rcu_expedited_wait_once(1))
  564. return;
  565. rcu_for_each_leaf_node(rnp) {
  566. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  567. mask = READ_ONCE(rnp->expmask);
  568. for_each_leaf_node_cpu_mask(rnp, cpu, mask) {
  569. rdp = per_cpu_ptr(&rcu_data, cpu);
  570. if (rdp->rcu_forced_tick_exp)
  571. continue;
  572. rdp->rcu_forced_tick_exp = true;
  573. if (cpu_online(cpu))
  574. tick_dep_set_cpu(cpu, TICK_DEP_BIT_RCU_EXP);
  575. }
  576. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  577. }
  578. j = READ_ONCE(jiffies_till_first_fqs);
  579. if (synchronize_rcu_expedited_wait_once(j + HZ))
  580. return;
  581. }
  582. for (;;) {
  583. unsigned long j;
  584. if (synchronize_rcu_expedited_wait_once(jiffies_stall))
  585. return;
  586. if (rcu_stall_is_suppressed())
  587. continue;
  588. nbcon_cpu_emergency_enter();
  589. j = jiffies;
  590. rcu_stall_notifier_call_chain(RCU_STALL_NOTIFY_EXP, (void *)(j - jiffies_start));
  591. trace_rcu_stall_warning(rcu_state.name, TPS("ExpeditedStall"));
  592. synchronize_rcu_expedited_stall(jiffies_start, j);
  593. jiffies_stall = 3 * rcu_exp_jiffies_till_stall_check() + 3;
  594. nbcon_cpu_emergency_exit();
  595. panic_on_rcu_stall();
  596. }
  597. }
  598. /*
  599. * Wait for the current expedited grace period to complete, and then
  600. * wake up everyone who piggybacked on the just-completed expedited
  601. * grace period. Also update all the ->exp_seq_rq counters as needed
  602. * in order to avoid counter-wrap problems.
  603. */
  604. static void rcu_exp_wait_wake(unsigned long s)
  605. {
  606. struct rcu_node *rnp;
  607. synchronize_rcu_expedited_wait();
  608. // Switch over to wakeup mode, allowing the next GP to proceed.
  609. // End the previous grace period only after acquiring the mutex
  610. // to ensure that only one GP runs concurrently with wakeups.
  611. mutex_lock(&rcu_state.exp_wake_mutex);
  612. rcu_exp_gp_seq_end();
  613. trace_rcu_exp_grace_period(rcu_state.name, s, TPS("end"));
  614. rcu_for_each_node_breadth_first(rnp) {
  615. if (ULONG_CMP_LT(READ_ONCE(rnp->exp_seq_rq), s)) {
  616. spin_lock(&rnp->exp_lock);
  617. /* Recheck, avoid hang in case someone just arrived. */
  618. if (ULONG_CMP_LT(rnp->exp_seq_rq, s))
  619. WRITE_ONCE(rnp->exp_seq_rq, s);
  620. spin_unlock(&rnp->exp_lock);
  621. }
  622. smp_mb(); /* All above changes before wakeup. */
  623. wake_up_all(&rnp->exp_wq[rcu_seq_ctr(s) & 0x3]);
  624. }
  625. trace_rcu_exp_grace_period(rcu_state.name, s, TPS("endwake"));
  626. mutex_unlock(&rcu_state.exp_wake_mutex);
  627. }
  628. /*
  629. * Common code to drive an expedited grace period forward, used by
  630. * workqueues and mid-boot-time tasks.
  631. */
  632. static void rcu_exp_sel_wait_wake(unsigned long s)
  633. {
  634. /* Initialize the rcu_node tree in preparation for the wait. */
  635. sync_rcu_exp_select_cpus();
  636. /* Wait and clean up, including waking everyone. */
  637. rcu_exp_wait_wake(s);
  638. }
  639. #ifdef CONFIG_PREEMPT_RCU
  640. /*
  641. * Remote handler for smp_call_function_single(). If there is an
  642. * RCU read-side critical section in effect, request that the
  643. * next rcu_read_unlock() record the quiescent state up the
  644. * ->expmask fields in the rcu_node tree. Otherwise, immediately
  645. * report the quiescent state.
  646. */
  647. static void rcu_exp_handler(void *unused)
  648. {
  649. int depth = rcu_preempt_depth();
  650. unsigned long flags;
  651. struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
  652. struct rcu_node *rnp = rdp->mynode;
  653. struct task_struct *t = current;
  654. /*
  655. * First, the common case of not being in an RCU read-side
  656. * critical section. If also enabled or idle, immediately
  657. * report the quiescent state, otherwise defer.
  658. */
  659. if (!depth) {
  660. if (!(preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK)) ||
  661. rcu_is_cpu_rrupt_from_idle()) {
  662. rcu_report_exp_rdp(rdp);
  663. } else {
  664. WRITE_ONCE(rdp->cpu_no_qs.b.exp, true);
  665. set_tsk_need_resched(t);
  666. set_preempt_need_resched();
  667. }
  668. return;
  669. }
  670. /*
  671. * Second, the less-common case of being in an RCU read-side
  672. * critical section. In this case we can count on a future
  673. * rcu_read_unlock(). However, this rcu_read_unlock() might
  674. * execute on some other CPU, but in that case there will be
  675. * a future context switch. Either way, if the expedited
  676. * grace period is still waiting on this CPU, set ->deferred_qs
  677. * so that the eventual quiescent state will be reported.
  678. * Note that there is a large group of race conditions that
  679. * can have caused this quiescent state to already have been
  680. * reported, so we really do need to check ->expmask.
  681. */
  682. if (depth > 0) {
  683. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  684. if (rnp->expmask & rdp->grpmask) {
  685. WRITE_ONCE(rdp->cpu_no_qs.b.exp, true);
  686. t->rcu_read_unlock_special.b.exp_hint = true;
  687. }
  688. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  689. return;
  690. }
  691. // Finally, negative nesting depth should not happen.
  692. WARN_ON_ONCE(1);
  693. }
  694. /* PREEMPTION=y, so no PREEMPTION=n expedited grace period to clean up after. */
  695. static void sync_sched_exp_online_cleanup(int cpu)
  696. {
  697. }
  698. /*
  699. * Scan the current list of tasks blocked within RCU read-side critical
  700. * sections, printing out the tid of each that is blocking the current
  701. * expedited grace period.
  702. */
  703. static int rcu_print_task_exp_stall(struct rcu_node *rnp)
  704. {
  705. unsigned long flags;
  706. int ndetected = 0;
  707. struct task_struct *t;
  708. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  709. if (!rnp->exp_tasks) {
  710. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  711. return 0;
  712. }
  713. t = list_entry(rnp->exp_tasks->prev,
  714. struct task_struct, rcu_node_entry);
  715. list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
  716. pr_cont(" P%d", t->pid);
  717. ndetected++;
  718. }
  719. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  720. return ndetected;
  721. }
  722. /*
  723. * Scan the current list of tasks blocked within RCU read-side critical
  724. * sections, dumping the stack of each that is blocking the current
  725. * expedited grace period.
  726. */
  727. static void rcu_exp_print_detail_task_stall_rnp(struct rcu_node *rnp)
  728. {
  729. unsigned long flags;
  730. struct task_struct *t;
  731. if (!rcu_exp_stall_task_details)
  732. return;
  733. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  734. if (!READ_ONCE(rnp->exp_tasks)) {
  735. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  736. return;
  737. }
  738. t = list_entry(rnp->exp_tasks->prev,
  739. struct task_struct, rcu_node_entry);
  740. list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
  741. /*
  742. * We could be printing a lot while holding a spinlock.
  743. * Avoid triggering hard lockup.
  744. */
  745. touch_nmi_watchdog();
  746. sched_show_task(t);
  747. }
  748. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  749. }
  750. #else /* #ifdef CONFIG_PREEMPT_RCU */
  751. /* Request an expedited quiescent state. */
  752. static void rcu_exp_need_qs(void)
  753. {
  754. __this_cpu_write(rcu_data.cpu_no_qs.b.exp, true);
  755. /* Store .exp before .rcu_urgent_qs. */
  756. smp_store_release(this_cpu_ptr(&rcu_data.rcu_urgent_qs), true);
  757. set_tsk_need_resched(current);
  758. set_preempt_need_resched();
  759. }
  760. /* Invoked on each online non-idle CPU for expedited quiescent state. */
  761. static void rcu_exp_handler(void *unused)
  762. {
  763. struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
  764. struct rcu_node *rnp = rdp->mynode;
  765. bool preempt_bh_enabled = !(preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK));
  766. if (!(READ_ONCE(rnp->expmask) & rdp->grpmask) ||
  767. __this_cpu_read(rcu_data.cpu_no_qs.b.exp))
  768. return;
  769. if (rcu_is_cpu_rrupt_from_idle() ||
  770. (IS_ENABLED(CONFIG_PREEMPT_COUNT) && preempt_bh_enabled)) {
  771. rcu_report_exp_rdp(this_cpu_ptr(&rcu_data));
  772. return;
  773. }
  774. rcu_exp_need_qs();
  775. }
  776. /* Send IPI for expedited cleanup if needed at end of CPU-hotplug operation. */
  777. static void sync_sched_exp_online_cleanup(int cpu)
  778. {
  779. unsigned long flags;
  780. int my_cpu;
  781. struct rcu_data *rdp;
  782. int ret;
  783. struct rcu_node *rnp;
  784. rdp = per_cpu_ptr(&rcu_data, cpu);
  785. rnp = rdp->mynode;
  786. my_cpu = get_cpu();
  787. /* Quiescent state either not needed or already requested, leave. */
  788. if (!(READ_ONCE(rnp->expmask) & rdp->grpmask) ||
  789. READ_ONCE(rdp->cpu_no_qs.b.exp)) {
  790. put_cpu();
  791. return;
  792. }
  793. /* Quiescent state needed on current CPU, so set it up locally. */
  794. if (my_cpu == cpu) {
  795. local_irq_save(flags);
  796. rcu_exp_need_qs();
  797. local_irq_restore(flags);
  798. put_cpu();
  799. return;
  800. }
  801. /* Quiescent state needed on some other CPU, send IPI. */
  802. ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);
  803. put_cpu();
  804. WARN_ON_ONCE(ret);
  805. }
  806. /*
  807. * Because preemptible RCU does not exist, we never have to check for
  808. * tasks blocked within RCU read-side critical sections that are
  809. * blocking the current expedited grace period.
  810. */
  811. static int rcu_print_task_exp_stall(struct rcu_node *rnp)
  812. {
  813. return 0;
  814. }
  815. /*
  816. * Because preemptible RCU does not exist, we never have to print out
  817. * tasks blocked within RCU read-side critical sections that are blocking
  818. * the current expedited grace period.
  819. */
  820. static void rcu_exp_print_detail_task_stall_rnp(struct rcu_node *rnp)
  821. {
  822. }
  823. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  824. /**
  825. * synchronize_rcu_expedited - Brute-force RCU grace period
  826. *
  827. * Wait for an RCU grace period, but expedite it. The basic idea is to
  828. * IPI all non-idle non-nohz online CPUs. The IPI handler checks whether
  829. * the CPU is in an RCU critical section, and if so, it sets a flag that
  830. * causes the outermost rcu_read_unlock() to report the quiescent state
  831. * for RCU-preempt or asks the scheduler for help for RCU-sched. On the
  832. * other hand, if the CPU is not in an RCU read-side critical section,
  833. * the IPI handler reports the quiescent state immediately.
  834. *
  835. * Although this is a great improvement over previous expedited
  836. * implementations, it is still unfriendly to real-time workloads, so is
  837. * thus not recommended for any sort of common-case code. In fact, if
  838. * you are using synchronize_rcu_expedited() in a loop, please restructure
  839. * your code to batch your updates, and then use a single synchronize_rcu()
  840. * instead.
  841. *
  842. * This has the same semantics as (but is more brutal than) synchronize_rcu().
  843. */
  844. void synchronize_rcu_expedited(void)
  845. {
  846. unsigned long flags;
  847. struct rcu_exp_work rew;
  848. struct rcu_node *rnp;
  849. unsigned long s;
  850. RCU_LOCKDEP_WARN(lock_is_held(&rcu_bh_lock_map) ||
  851. lock_is_held(&rcu_lock_map) ||
  852. lock_is_held(&rcu_sched_lock_map),
  853. "Illegal synchronize_rcu_expedited() in RCU read-side critical section");
  854. /* Is the state is such that the call is a grace period? */
  855. if (rcu_blocking_is_gp()) {
  856. // Note well that this code runs with !PREEMPT && !SMP.
  857. // In addition, all code that advances grace periods runs
  858. // at process level. Therefore, this expedited GP overlaps
  859. // with other expedited GPs only by being fully nested within
  860. // them, which allows reuse of ->gp_seq_polled_exp_snap.
  861. rcu_poll_gp_seq_start_unlocked(&rcu_state.gp_seq_polled_exp_snap);
  862. rcu_poll_gp_seq_end_unlocked(&rcu_state.gp_seq_polled_exp_snap);
  863. local_irq_save(flags);
  864. WARN_ON_ONCE(num_online_cpus() > 1);
  865. rcu_state.expedited_sequence += (1 << RCU_SEQ_CTR_SHIFT);
  866. local_irq_restore(flags);
  867. return; // Context allows vacuous grace periods.
  868. }
  869. /* If expedited grace periods are prohibited, fall back to normal. */
  870. if (rcu_gp_is_normal()) {
  871. synchronize_rcu_normal();
  872. return;
  873. }
  874. /* Take a snapshot of the sequence number. */
  875. s = rcu_exp_gp_seq_snap();
  876. if (exp_funnel_lock(s))
  877. return; /* Someone else did our work for us. */
  878. /* Ensure that load happens before action based on it. */
  879. if (unlikely((rcu_scheduler_active == RCU_SCHEDULER_INIT) || !rcu_exp_worker_started())) {
  880. /* Direct call during scheduler init and early_initcalls(). */
  881. rcu_exp_sel_wait_wake(s);
  882. } else {
  883. /* Marshall arguments & schedule the expedited grace period. */
  884. rew.rew_s = s;
  885. synchronize_rcu_expedited_queue_work(&rew);
  886. }
  887. /* Wait for expedited grace period to complete. */
  888. rnp = rcu_get_root();
  889. wait_event(rnp->exp_wq[rcu_seq_ctr(s) & 0x3],
  890. sync_exp_work_done(s));
  891. /* Let the next expedited grace period start. */
  892. mutex_unlock(&rcu_state.exp_mutex);
  893. }
  894. EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
  895. /*
  896. * Ensure that start_poll_synchronize_rcu_expedited() has the expedited
  897. * RCU grace periods that it needs.
  898. */
  899. static void sync_rcu_do_polled_gp(struct work_struct *wp)
  900. {
  901. unsigned long flags;
  902. int i = 0;
  903. struct rcu_node *rnp = container_of(wp, struct rcu_node, exp_poll_wq);
  904. unsigned long s;
  905. raw_spin_lock_irqsave(&rnp->exp_poll_lock, flags);
  906. s = rnp->exp_seq_poll_rq;
  907. rnp->exp_seq_poll_rq = RCU_GET_STATE_COMPLETED;
  908. raw_spin_unlock_irqrestore(&rnp->exp_poll_lock, flags);
  909. if (s == RCU_GET_STATE_COMPLETED)
  910. return;
  911. while (!poll_state_synchronize_rcu(s)) {
  912. synchronize_rcu_expedited();
  913. if (i == 10 || i == 20)
  914. pr_info("%s: i = %d s = %lx gp_seq_polled = %lx\n", __func__, i, s, READ_ONCE(rcu_state.gp_seq_polled));
  915. i++;
  916. }
  917. raw_spin_lock_irqsave(&rnp->exp_poll_lock, flags);
  918. s = rnp->exp_seq_poll_rq;
  919. if (poll_state_synchronize_rcu(s))
  920. rnp->exp_seq_poll_rq = RCU_GET_STATE_COMPLETED;
  921. raw_spin_unlock_irqrestore(&rnp->exp_poll_lock, flags);
  922. }
  923. /**
  924. * start_poll_synchronize_rcu_expedited - Snapshot current RCU state and start expedited grace period
  925. *
  926. * Returns a cookie to pass to a call to cond_synchronize_rcu(),
  927. * cond_synchronize_rcu_expedited(), or poll_state_synchronize_rcu(),
  928. * allowing them to determine whether or not any sort of grace period has
  929. * elapsed in the meantime. If the needed expedited grace period is not
  930. * already slated to start, initiates that grace period.
  931. */
  932. unsigned long start_poll_synchronize_rcu_expedited(void)
  933. {
  934. unsigned long flags;
  935. struct rcu_data *rdp;
  936. struct rcu_node *rnp;
  937. unsigned long s;
  938. s = get_state_synchronize_rcu();
  939. rdp = per_cpu_ptr(&rcu_data, raw_smp_processor_id());
  940. rnp = rdp->mynode;
  941. if (rcu_init_invoked())
  942. raw_spin_lock_irqsave(&rnp->exp_poll_lock, flags);
  943. if (!poll_state_synchronize_rcu(s)) {
  944. if (rcu_init_invoked()) {
  945. rnp->exp_seq_poll_rq = s;
  946. queue_work(rcu_gp_wq, &rnp->exp_poll_wq);
  947. }
  948. }
  949. if (rcu_init_invoked())
  950. raw_spin_unlock_irqrestore(&rnp->exp_poll_lock, flags);
  951. return s;
  952. }
  953. EXPORT_SYMBOL_GPL(start_poll_synchronize_rcu_expedited);
  954. /**
  955. * start_poll_synchronize_rcu_expedited_full - Take a full snapshot and start expedited grace period
  956. * @rgosp: Place to put snapshot of grace-period state
  957. *
  958. * Places the normal and expedited grace-period states in rgosp. This
  959. * state value can be passed to a later call to cond_synchronize_rcu_full()
  960. * or poll_state_synchronize_rcu_full() to determine whether or not a
  961. * grace period (whether normal or expedited) has elapsed in the meantime.
  962. * If the needed expedited grace period is not already slated to start,
  963. * initiates that grace period.
  964. */
  965. void start_poll_synchronize_rcu_expedited_full(struct rcu_gp_oldstate *rgosp)
  966. {
  967. get_state_synchronize_rcu_full(rgosp);
  968. (void)start_poll_synchronize_rcu_expedited();
  969. }
  970. EXPORT_SYMBOL_GPL(start_poll_synchronize_rcu_expedited_full);
  971. /**
  972. * cond_synchronize_rcu_expedited - Conditionally wait for an expedited RCU grace period
  973. *
  974. * @oldstate: value from get_state_synchronize_rcu(), start_poll_synchronize_rcu(), or start_poll_synchronize_rcu_expedited()
  975. *
  976. * If any type of full RCU grace period has elapsed since the earlier
  977. * call to get_state_synchronize_rcu(), start_poll_synchronize_rcu(),
  978. * or start_poll_synchronize_rcu_expedited(), just return. Otherwise,
  979. * invoke synchronize_rcu_expedited() to wait for a full grace period.
  980. *
  981. * Yes, this function does not take counter wrap into account.
  982. * But counter wrap is harmless. If the counter wraps, we have waited for
  983. * more than 2 billion grace periods (and way more on a 64-bit system!),
  984. * so waiting for a couple of additional grace periods should be just fine.
  985. *
  986. * This function provides the same memory-ordering guarantees that
  987. * would be provided by a synchronize_rcu() that was invoked at the call
  988. * to the function that provided @oldstate and that returned at the end
  989. * of this function.
  990. */
  991. void cond_synchronize_rcu_expedited(unsigned long oldstate)
  992. {
  993. if (!poll_state_synchronize_rcu(oldstate))
  994. synchronize_rcu_expedited();
  995. }
  996. EXPORT_SYMBOL_GPL(cond_synchronize_rcu_expedited);
  997. /**
  998. * cond_synchronize_rcu_expedited_full - Conditionally wait for an expedited RCU grace period
  999. * @rgosp: value from get_state_synchronize_rcu_full(), start_poll_synchronize_rcu_full(), or start_poll_synchronize_rcu_expedited_full()
  1000. *
  1001. * If a full RCU grace period has elapsed since the call to
  1002. * get_state_synchronize_rcu_full(), start_poll_synchronize_rcu_full(),
  1003. * or start_poll_synchronize_rcu_expedited_full() from which @rgosp was
  1004. * obtained, just return. Otherwise, invoke synchronize_rcu_expedited()
  1005. * to wait for a full grace period.
  1006. *
  1007. * Yes, this function does not take counter wrap into account.
  1008. * But counter wrap is harmless. If the counter wraps, we have waited for
  1009. * more than 2 billion grace periods (and way more on a 64-bit system!),
  1010. * so waiting for a couple of additional grace periods should be just fine.
  1011. *
  1012. * This function provides the same memory-ordering guarantees that
  1013. * would be provided by a synchronize_rcu() that was invoked at the call
  1014. * to the function that provided @rgosp and that returned at the end of
  1015. * this function.
  1016. */
  1017. void cond_synchronize_rcu_expedited_full(struct rcu_gp_oldstate *rgosp)
  1018. {
  1019. if (!poll_state_synchronize_rcu_full(rgosp))
  1020. synchronize_rcu_expedited();
  1021. }
  1022. EXPORT_SYMBOL_GPL(cond_synchronize_rcu_expedited_full);