tree_exp.h 34 KB

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