rcupdate.c 18 KB

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