rcupdate.c 18 KB

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