rcupdate.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. * Read-Copy Update mechanism for mutual exclusion
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * Copyright (C) IBM Corporation, 2001
  19. *
  20. * Authors: Dipankar Sarma <dipankar@in.ibm.com>
  21. * Manfred Spraul <manfred@colorfullife.com>
  22. *
  23. * Based on the original work by Paul McKenney <paulmck@us.ibm.com>
  24. * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
  25. * Papers:
  26. * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf
  27. * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001)
  28. *
  29. * For detailed explanation of Read-Copy Update mechanism see -
  30. * http://lse.sourceforge.net/locking/rcupdate.html
  31. *
  32. */
  33. #include <linux/types.h>
  34. #include <linux/kernel.h>
  35. #include <linux/init.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/smp.h>
  38. #include <linux/rcupdate.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/sched.h>
  41. #include <asm/atomic.h>
  42. #include <linux/bitops.h>
  43. #include <linux/module.h>
  44. #include <linux/completion.h>
  45. #include <linux/moduleparam.h>
  46. #include <linux/percpu.h>
  47. #include <linux/notifier.h>
  48. #include <linux/cpu.h>
  49. #include <linux/mutex.h>
  50. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  51. static struct lock_class_key rcu_lock_key;
  52. struct lockdep_map rcu_lock_map =
  53. STATIC_LOCKDEP_MAP_INIT("rcu_read_lock", &rcu_lock_key);
  54. EXPORT_SYMBOL_GPL(rcu_lock_map);
  55. #endif
  56. /* Definition for rcupdate control block. */
  57. static struct rcu_ctrlblk rcu_ctrlblk = {
  58. .cur = -300,
  59. .completed = -300,
  60. .lock = __SPIN_LOCK_UNLOCKED(&rcu_ctrlblk.lock),
  61. .cpumask = CPU_MASK_NONE,
  62. };
  63. static struct rcu_ctrlblk rcu_bh_ctrlblk = {
  64. .cur = -300,
  65. .completed = -300,
  66. .lock = __SPIN_LOCK_UNLOCKED(&rcu_bh_ctrlblk.lock),
  67. .cpumask = CPU_MASK_NONE,
  68. };
  69. DEFINE_PER_CPU(struct rcu_data, rcu_data) = { 0L };
  70. DEFINE_PER_CPU(struct rcu_data, rcu_bh_data) = { 0L };
  71. static int blimit = 10;
  72. static int qhimark = 10000;
  73. static int qlowmark = 100;
  74. static atomic_t rcu_barrier_cpu_count;
  75. static DEFINE_MUTEX(rcu_barrier_mutex);
  76. static struct completion rcu_barrier_completion;
  77. #ifdef CONFIG_SMP
  78. static void force_quiescent_state(struct rcu_data *rdp,
  79. struct rcu_ctrlblk *rcp)
  80. {
  81. int cpu;
  82. cpumask_t cpumask;
  83. set_need_resched();
  84. if (unlikely(!rcp->signaled)) {
  85. rcp->signaled = 1;
  86. /*
  87. * Don't send IPI to itself. With irqs disabled,
  88. * rdp->cpu is the current cpu.
  89. */
  90. cpumask = rcp->cpumask;
  91. cpu_clear(rdp->cpu, cpumask);
  92. for_each_cpu_mask(cpu, cpumask)
  93. smp_send_reschedule(cpu);
  94. }
  95. }
  96. #else
  97. static inline void force_quiescent_state(struct rcu_data *rdp,
  98. struct rcu_ctrlblk *rcp)
  99. {
  100. set_need_resched();
  101. }
  102. #endif
  103. /**
  104. * call_rcu - Queue an RCU callback for invocation after a grace period.
  105. * @head: structure to be used for queueing the RCU updates.
  106. * @func: actual update function to be invoked after the grace period
  107. *
  108. * The update function will be invoked some time after a full grace
  109. * period elapses, in other words after all currently executing RCU
  110. * read-side critical sections have completed. RCU read-side critical
  111. * sections are delimited by rcu_read_lock() and rcu_read_unlock(),
  112. * and may be nested.
  113. */
  114. void fastcall call_rcu(struct rcu_head *head,
  115. void (*func)(struct rcu_head *rcu))
  116. {
  117. unsigned long flags;
  118. struct rcu_data *rdp;
  119. head->func = func;
  120. head->next = NULL;
  121. local_irq_save(flags);
  122. rdp = &__get_cpu_var(rcu_data);
  123. *rdp->nxttail = head;
  124. rdp->nxttail = &head->next;
  125. if (unlikely(++rdp->qlen > qhimark)) {
  126. rdp->blimit = INT_MAX;
  127. force_quiescent_state(rdp, &rcu_ctrlblk);
  128. }
  129. local_irq_restore(flags);
  130. }
  131. /**
  132. * call_rcu_bh - Queue an RCU for invocation after a quicker grace period.
  133. * @head: structure to be used for queueing the RCU updates.
  134. * @func: actual update function to be invoked after the grace period
  135. *
  136. * The update function will be invoked some time after a full grace
  137. * period elapses, in other words after all currently executing RCU
  138. * read-side critical sections have completed. call_rcu_bh() assumes
  139. * that the read-side critical sections end on completion of a softirq
  140. * handler. This means that read-side critical sections in process
  141. * context must not be interrupted by softirqs. This interface is to be
  142. * used when most of the read-side critical sections are in softirq context.
  143. * RCU read-side critical sections are delimited by rcu_read_lock() and
  144. * rcu_read_unlock(), * if in interrupt context or rcu_read_lock_bh()
  145. * and rcu_read_unlock_bh(), if in process context. These may be nested.
  146. */
  147. void fastcall call_rcu_bh(struct rcu_head *head,
  148. void (*func)(struct rcu_head *rcu))
  149. {
  150. unsigned long flags;
  151. struct rcu_data *rdp;
  152. head->func = func;
  153. head->next = NULL;
  154. local_irq_save(flags);
  155. rdp = &__get_cpu_var(rcu_bh_data);
  156. *rdp->nxttail = head;
  157. rdp->nxttail = &head->next;
  158. if (unlikely(++rdp->qlen > qhimark)) {
  159. rdp->blimit = INT_MAX;
  160. force_quiescent_state(rdp, &rcu_bh_ctrlblk);
  161. }
  162. local_irq_restore(flags);
  163. }
  164. /*
  165. * Return the number of RCU batches processed thus far. Useful
  166. * for debug and statistics.
  167. */
  168. long rcu_batches_completed(void)
  169. {
  170. return rcu_ctrlblk.completed;
  171. }
  172. /*
  173. * Return the number of RCU batches processed thus far. Useful
  174. * for debug and statistics.
  175. */
  176. long rcu_batches_completed_bh(void)
  177. {
  178. return rcu_bh_ctrlblk.completed;
  179. }
  180. static void rcu_barrier_callback(struct rcu_head *notused)
  181. {
  182. if (atomic_dec_and_test(&rcu_barrier_cpu_count))
  183. complete(&rcu_barrier_completion);
  184. }
  185. /*
  186. * Called with preemption disabled, and from cross-cpu IRQ context.
  187. */
  188. static void rcu_barrier_func(void *notused)
  189. {
  190. int cpu = smp_processor_id();
  191. struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
  192. struct rcu_head *head;
  193. head = &rdp->barrier;
  194. atomic_inc(&rcu_barrier_cpu_count);
  195. call_rcu(head, rcu_barrier_callback);
  196. }
  197. /**
  198. * rcu_barrier - Wait until all the in-flight RCUs are complete.
  199. */
  200. void rcu_barrier(void)
  201. {
  202. BUG_ON(in_interrupt());
  203. /* Take cpucontrol mutex to protect against CPU hotplug */
  204. mutex_lock(&rcu_barrier_mutex);
  205. init_completion(&rcu_barrier_completion);
  206. atomic_set(&rcu_barrier_cpu_count, 0);
  207. on_each_cpu(rcu_barrier_func, NULL, 0, 1);
  208. wait_for_completion(&rcu_barrier_completion);
  209. mutex_unlock(&rcu_barrier_mutex);
  210. }
  211. EXPORT_SYMBOL_GPL(rcu_barrier);
  212. /* Raises the softirq for processing rcu_callbacks. */
  213. static inline void raise_rcu_softirq(void)
  214. {
  215. raise_softirq(RCU_SOFTIRQ);
  216. /*
  217. * The smp_mb() here is required to ensure that this cpu's
  218. * __rcu_process_callbacks() reads the most recently updated
  219. * value of rcu->cur.
  220. */
  221. smp_mb();
  222. }
  223. /*
  224. * Invoke the completed RCU callbacks. They are expected to be in
  225. * a per-cpu list.
  226. */
  227. static void rcu_do_batch(struct rcu_data *rdp)
  228. {
  229. struct rcu_head *next, *list;
  230. int count = 0;
  231. list = rdp->donelist;
  232. while (list) {
  233. next = list->next;
  234. prefetch(next);
  235. list->func(list);
  236. list = next;
  237. if (++count >= rdp->blimit)
  238. break;
  239. }
  240. rdp->donelist = list;
  241. local_irq_disable();
  242. rdp->qlen -= count;
  243. local_irq_enable();
  244. if (rdp->blimit == INT_MAX && rdp->qlen <= qlowmark)
  245. rdp->blimit = blimit;
  246. if (!rdp->donelist)
  247. rdp->donetail = &rdp->donelist;
  248. else
  249. raise_rcu_softirq();
  250. }
  251. /*
  252. * Grace period handling:
  253. * The grace period handling consists out of two steps:
  254. * - A new grace period is started.
  255. * This is done by rcu_start_batch. The start is not broadcasted to
  256. * all cpus, they must pick this up by comparing rcp->cur with
  257. * rdp->quiescbatch. All cpus are recorded in the
  258. * rcu_ctrlblk.cpumask bitmap.
  259. * - All cpus must go through a quiescent state.
  260. * Since the start of the grace period is not broadcasted, at least two
  261. * calls to rcu_check_quiescent_state are required:
  262. * The first call just notices that a new grace period is running. The
  263. * following calls check if there was a quiescent state since the beginning
  264. * of the grace period. If so, it updates rcu_ctrlblk.cpumask. If
  265. * the bitmap is empty, then the grace period is completed.
  266. * rcu_check_quiescent_state calls rcu_start_batch(0) to start the next grace
  267. * period (if necessary).
  268. */
  269. /*
  270. * Register a new batch of callbacks, and start it up if there is currently no
  271. * active batch and the batch to be registered has not already occurred.
  272. * Caller must hold rcu_ctrlblk.lock.
  273. */
  274. static void rcu_start_batch(struct rcu_ctrlblk *rcp)
  275. {
  276. if (rcp->next_pending &&
  277. rcp->completed == rcp->cur) {
  278. rcp->next_pending = 0;
  279. /*
  280. * next_pending == 0 must be visible in
  281. * __rcu_process_callbacks() before it can see new value of cur.
  282. */
  283. smp_wmb();
  284. rcp->cur++;
  285. /*
  286. * Accessing nohz_cpu_mask before incrementing rcp->cur needs a
  287. * Barrier Otherwise it can cause tickless idle CPUs to be
  288. * included in rcp->cpumask, which will extend graceperiods
  289. * unnecessarily.
  290. */
  291. smp_mb();
  292. cpus_andnot(rcp->cpumask, cpu_online_map, nohz_cpu_mask);
  293. rcp->signaled = 0;
  294. }
  295. }
  296. /*
  297. * cpu went through a quiescent state since the beginning of the grace period.
  298. * Clear it from the cpu mask and complete the grace period if it was the last
  299. * cpu. Start another grace period if someone has further entries pending
  300. */
  301. static void cpu_quiet(int cpu, struct rcu_ctrlblk *rcp)
  302. {
  303. cpu_clear(cpu, rcp->cpumask);
  304. if (cpus_empty(rcp->cpumask)) {
  305. /* batch completed ! */
  306. rcp->completed = rcp->cur;
  307. rcu_start_batch(rcp);
  308. }
  309. }
  310. /*
  311. * Check if the cpu has gone through a quiescent state (say context
  312. * switch). If so and if it already hasn't done so in this RCU
  313. * quiescent cycle, then indicate that it has done so.
  314. */
  315. static void rcu_check_quiescent_state(struct rcu_ctrlblk *rcp,
  316. struct rcu_data *rdp)
  317. {
  318. if (rdp->quiescbatch != rcp->cur) {
  319. /* start new grace period: */
  320. rdp->qs_pending = 1;
  321. rdp->passed_quiesc = 0;
  322. rdp->quiescbatch = rcp->cur;
  323. return;
  324. }
  325. /* Grace period already completed for this cpu?
  326. * qs_pending is checked instead of the actual bitmap to avoid
  327. * cacheline trashing.
  328. */
  329. if (!rdp->qs_pending)
  330. return;
  331. /*
  332. * Was there a quiescent state since the beginning of the grace
  333. * period? If no, then exit and wait for the next call.
  334. */
  335. if (!rdp->passed_quiesc)
  336. return;
  337. rdp->qs_pending = 0;
  338. spin_lock(&rcp->lock);
  339. /*
  340. * rdp->quiescbatch/rcp->cur and the cpu bitmap can come out of sync
  341. * during cpu startup. Ignore the quiescent state.
  342. */
  343. if (likely(rdp->quiescbatch == rcp->cur))
  344. cpu_quiet(rdp->cpu, rcp);
  345. spin_unlock(&rcp->lock);
  346. }
  347. #ifdef CONFIG_HOTPLUG_CPU
  348. /* warning! helper for rcu_offline_cpu. do not use elsewhere without reviewing
  349. * locking requirements, the list it's pulling from has to belong to a cpu
  350. * which is dead and hence not processing interrupts.
  351. */
  352. static void rcu_move_batch(struct rcu_data *this_rdp, struct rcu_head *list,
  353. struct rcu_head **tail)
  354. {
  355. local_irq_disable();
  356. *this_rdp->nxttail = list;
  357. if (list)
  358. this_rdp->nxttail = tail;
  359. local_irq_enable();
  360. }
  361. static void __rcu_offline_cpu(struct rcu_data *this_rdp,
  362. struct rcu_ctrlblk *rcp, struct rcu_data *rdp)
  363. {
  364. /* if the cpu going offline owns the grace period
  365. * we can block indefinitely waiting for it, so flush
  366. * it here
  367. */
  368. spin_lock_bh(&rcp->lock);
  369. if (rcp->cur != rcp->completed)
  370. cpu_quiet(rdp->cpu, rcp);
  371. spin_unlock_bh(&rcp->lock);
  372. rcu_move_batch(this_rdp, rdp->curlist, rdp->curtail);
  373. rcu_move_batch(this_rdp, rdp->nxtlist, rdp->nxttail);
  374. rcu_move_batch(this_rdp, rdp->donelist, rdp->donetail);
  375. }
  376. static void rcu_offline_cpu(int cpu)
  377. {
  378. struct rcu_data *this_rdp = &get_cpu_var(rcu_data);
  379. struct rcu_data *this_bh_rdp = &get_cpu_var(rcu_bh_data);
  380. __rcu_offline_cpu(this_rdp, &rcu_ctrlblk,
  381. &per_cpu(rcu_data, cpu));
  382. __rcu_offline_cpu(this_bh_rdp, &rcu_bh_ctrlblk,
  383. &per_cpu(rcu_bh_data, cpu));
  384. put_cpu_var(rcu_data);
  385. put_cpu_var(rcu_bh_data);
  386. }
  387. #else
  388. static void rcu_offline_cpu(int cpu)
  389. {
  390. }
  391. #endif
  392. /*
  393. * This does the RCU processing work from softirq context.
  394. */
  395. static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp,
  396. struct rcu_data *rdp)
  397. {
  398. if (rdp->curlist && !rcu_batch_before(rcp->completed, rdp->batch)) {
  399. *rdp->donetail = rdp->curlist;
  400. rdp->donetail = rdp->curtail;
  401. rdp->curlist = NULL;
  402. rdp->curtail = &rdp->curlist;
  403. }
  404. if (rdp->nxtlist && !rdp->curlist) {
  405. local_irq_disable();
  406. rdp->curlist = rdp->nxtlist;
  407. rdp->curtail = rdp->nxttail;
  408. rdp->nxtlist = NULL;
  409. rdp->nxttail = &rdp->nxtlist;
  410. local_irq_enable();
  411. /*
  412. * start the next batch of callbacks
  413. */
  414. /* determine batch number */
  415. rdp->batch = rcp->cur + 1;
  416. /* see the comment and corresponding wmb() in
  417. * the rcu_start_batch()
  418. */
  419. smp_rmb();
  420. if (!rcp->next_pending) {
  421. /* and start it/schedule start if it's a new batch */
  422. spin_lock(&rcp->lock);
  423. rcp->next_pending = 1;
  424. rcu_start_batch(rcp);
  425. spin_unlock(&rcp->lock);
  426. }
  427. }
  428. rcu_check_quiescent_state(rcp, rdp);
  429. if (rdp->donelist)
  430. rcu_do_batch(rdp);
  431. }
  432. static void rcu_process_callbacks(struct softirq_action *unused)
  433. {
  434. __rcu_process_callbacks(&rcu_ctrlblk, &__get_cpu_var(rcu_data));
  435. __rcu_process_callbacks(&rcu_bh_ctrlblk, &__get_cpu_var(rcu_bh_data));
  436. }
  437. static int __rcu_pending(struct rcu_ctrlblk *rcp, struct rcu_data *rdp)
  438. {
  439. /* This cpu has pending rcu entries and the grace period
  440. * for them has completed.
  441. */
  442. if (rdp->curlist && !rcu_batch_before(rcp->completed, rdp->batch))
  443. return 1;
  444. /* This cpu has no pending entries, but there are new entries */
  445. if (!rdp->curlist && rdp->nxtlist)
  446. return 1;
  447. /* This cpu has finished callbacks to invoke */
  448. if (rdp->donelist)
  449. return 1;
  450. /* The rcu core waits for a quiescent state from the cpu */
  451. if (rdp->quiescbatch != rcp->cur || rdp->qs_pending)
  452. return 1;
  453. /* nothing to do */
  454. return 0;
  455. }
  456. /*
  457. * Check to see if there is any immediate RCU-related work to be done
  458. * by the current CPU, returning 1 if so. This function is part of the
  459. * RCU implementation; it is -not- an exported member of the RCU API.
  460. */
  461. int rcu_pending(int cpu)
  462. {
  463. return __rcu_pending(&rcu_ctrlblk, &per_cpu(rcu_data, cpu)) ||
  464. __rcu_pending(&rcu_bh_ctrlblk, &per_cpu(rcu_bh_data, cpu));
  465. }
  466. /*
  467. * Check to see if any future RCU-related work will need to be done
  468. * by the current CPU, even if none need be done immediately, returning
  469. * 1 if so. This function is part of the RCU implementation; it is -not-
  470. * an exported member of the RCU API.
  471. */
  472. int rcu_needs_cpu(int cpu)
  473. {
  474. struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
  475. struct rcu_data *rdp_bh = &per_cpu(rcu_bh_data, cpu);
  476. return (!!rdp->curlist || !!rdp_bh->curlist || rcu_pending(cpu));
  477. }
  478. void rcu_check_callbacks(int cpu, int user)
  479. {
  480. if (user ||
  481. (idle_cpu(cpu) && !in_softirq() &&
  482. hardirq_count() <= (1 << HARDIRQ_SHIFT))) {
  483. rcu_qsctr_inc(cpu);
  484. rcu_bh_qsctr_inc(cpu);
  485. } else if (!in_softirq())
  486. rcu_bh_qsctr_inc(cpu);
  487. raise_rcu_softirq();
  488. }
  489. static void rcu_init_percpu_data(int cpu, struct rcu_ctrlblk *rcp,
  490. struct rcu_data *rdp)
  491. {
  492. memset(rdp, 0, sizeof(*rdp));
  493. rdp->curtail = &rdp->curlist;
  494. rdp->nxttail = &rdp->nxtlist;
  495. rdp->donetail = &rdp->donelist;
  496. rdp->quiescbatch = rcp->completed;
  497. rdp->qs_pending = 0;
  498. rdp->cpu = cpu;
  499. rdp->blimit = blimit;
  500. }
  501. static void __cpuinit rcu_online_cpu(int cpu)
  502. {
  503. struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
  504. struct rcu_data *bh_rdp = &per_cpu(rcu_bh_data, cpu);
  505. rcu_init_percpu_data(cpu, &rcu_ctrlblk, rdp);
  506. rcu_init_percpu_data(cpu, &rcu_bh_ctrlblk, bh_rdp);
  507. open_softirq(RCU_SOFTIRQ, rcu_process_callbacks, NULL);
  508. }
  509. static int __cpuinit rcu_cpu_notify(struct notifier_block *self,
  510. unsigned long action, void *hcpu)
  511. {
  512. long cpu = (long)hcpu;
  513. switch (action) {
  514. case CPU_UP_PREPARE:
  515. case CPU_UP_PREPARE_FROZEN:
  516. rcu_online_cpu(cpu);
  517. break;
  518. case CPU_DEAD:
  519. case CPU_DEAD_FROZEN:
  520. rcu_offline_cpu(cpu);
  521. break;
  522. default:
  523. break;
  524. }
  525. return NOTIFY_OK;
  526. }
  527. static struct notifier_block __cpuinitdata rcu_nb = {
  528. .notifier_call = rcu_cpu_notify,
  529. };
  530. /*
  531. * Initializes rcu mechanism. Assumed to be called early.
  532. * That is before local timer(SMP) or jiffie timer (uniproc) is setup.
  533. * Note that rcu_qsctr and friends are implicitly
  534. * initialized due to the choice of ``0'' for RCU_CTR_INVALID.
  535. */
  536. void __init rcu_init(void)
  537. {
  538. rcu_cpu_notify(&rcu_nb, CPU_UP_PREPARE,
  539. (void *)(long)smp_processor_id());
  540. /* Register notifier for non-boot CPUs */
  541. register_cpu_notifier(&rcu_nb);
  542. }
  543. struct rcu_synchronize {
  544. struct rcu_head head;
  545. struct completion completion;
  546. };
  547. /* Because of FASTCALL declaration of complete, we use this wrapper */
  548. static void wakeme_after_rcu(struct rcu_head *head)
  549. {
  550. struct rcu_synchronize *rcu;
  551. rcu = container_of(head, struct rcu_synchronize, head);
  552. complete(&rcu->completion);
  553. }
  554. /**
  555. * synchronize_rcu - wait until a grace period has elapsed.
  556. *
  557. * Control will return to the caller some time after a full grace
  558. * period has elapsed, in other words after all currently executing RCU
  559. * read-side critical sections have completed. RCU read-side critical
  560. * sections are delimited by rcu_read_lock() and rcu_read_unlock(),
  561. * and may be nested.
  562. *
  563. * If your read-side code is not protected by rcu_read_lock(), do -not-
  564. * use synchronize_rcu().
  565. */
  566. void synchronize_rcu(void)
  567. {
  568. struct rcu_synchronize rcu;
  569. init_completion(&rcu.completion);
  570. /* Will wake me after RCU finished */
  571. call_rcu(&rcu.head, wakeme_after_rcu);
  572. /* Wait for it */
  573. wait_for_completion(&rcu.completion);
  574. }
  575. module_param(blimit, int, 0);
  576. module_param(qhimark, int, 0);
  577. module_param(qlowmark, int, 0);
  578. EXPORT_SYMBOL_GPL(rcu_batches_completed);
  579. EXPORT_SYMBOL_GPL(rcu_batches_completed_bh);
  580. EXPORT_SYMBOL_GPL(call_rcu);
  581. EXPORT_SYMBOL_GPL(call_rcu_bh);
  582. EXPORT_SYMBOL_GPL(synchronize_rcu);