rcuclassic.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Read-Copy Update mechanism for mutual exclusion (classic version)
  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 IBM Corporation, 2001
  19. *
  20. * Author: Dipankar Sarma <dipankar@in.ibm.com>
  21. *
  22. * Based on the original work by Paul McKenney <paulmck@us.ibm.com>
  23. * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
  24. * Papers:
  25. * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf
  26. * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001)
  27. *
  28. * For detailed explanation of Read-Copy Update mechanism see -
  29. * Documentation/RCU
  30. *
  31. */
  32. #ifndef __LINUX_RCUCLASSIC_H
  33. #define __LINUX_RCUCLASSIC_H
  34. #include <linux/cache.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/threads.h>
  37. #include <linux/percpu.h>
  38. #include <linux/cpumask.h>
  39. #include <linux/seqlock.h>
  40. #ifdef CONFIG_RCU_CPU_STALL_DETECTOR
  41. #define RCU_SECONDS_TILL_STALL_CHECK (10 * HZ) /* for rcp->jiffies_stall */
  42. #define RCU_SECONDS_TILL_STALL_RECHECK (30 * HZ) /* for rcp->jiffies_stall */
  43. #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
  44. /* Global control variables for rcupdate callback mechanism. */
  45. struct rcu_ctrlblk {
  46. long cur; /* Current batch number. */
  47. long completed; /* Number of the last completed batch */
  48. long pending; /* Number of the last pending batch */
  49. #ifdef CONFIG_RCU_CPU_STALL_DETECTOR
  50. unsigned long gp_start; /* Time at which GP started in jiffies. */
  51. unsigned long jiffies_stall;
  52. /* Time at which to check for CPU stalls. */
  53. #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
  54. int signaled;
  55. spinlock_t lock ____cacheline_internodealigned_in_smp;
  56. DECLARE_BITMAP(cpumask, NR_CPUS); /* CPUs that need to switch for */
  57. /* current batch to proceed. */
  58. } ____cacheline_internodealigned_in_smp;
  59. /* Is batch a before batch b ? */
  60. static inline int rcu_batch_before(long a, long b)
  61. {
  62. return (a - b) < 0;
  63. }
  64. /* Is batch a after batch b ? */
  65. static inline int rcu_batch_after(long a, long b)
  66. {
  67. return (a - b) > 0;
  68. }
  69. /* Per-CPU data for Read-Copy UPdate. */
  70. struct rcu_data {
  71. /* 1) quiescent state handling : */
  72. long quiescbatch; /* Batch # for grace period */
  73. int passed_quiesc; /* User-mode/idle loop etc. */
  74. int qs_pending; /* core waits for quiesc state */
  75. /* 2) batch handling */
  76. /*
  77. * if nxtlist is not NULL, then:
  78. * batch:
  79. * The batch # for the last entry of nxtlist
  80. * [*nxttail[1], NULL = *nxttail[2]):
  81. * Entries that batch # <= batch
  82. * [*nxttail[0], *nxttail[1]):
  83. * Entries that batch # <= batch - 1
  84. * [nxtlist, *nxttail[0]):
  85. * Entries that batch # <= batch - 2
  86. * The grace period for these entries has completed, and
  87. * the other grace-period-completed entries may be moved
  88. * here temporarily in rcu_process_callbacks().
  89. */
  90. long batch;
  91. struct rcu_head *nxtlist;
  92. struct rcu_head **nxttail[3];
  93. long qlen; /* # of queued callbacks */
  94. struct rcu_head *donelist;
  95. struct rcu_head **donetail;
  96. long blimit; /* Upper limit on a processed batch */
  97. int cpu;
  98. struct rcu_head barrier;
  99. };
  100. /*
  101. * Increment the quiescent state counter.
  102. * The counter is a bit degenerated: We do not need to know
  103. * how many quiescent states passed, just if there was at least
  104. * one since the start of the grace period. Thus just a flag.
  105. */
  106. extern void rcu_qsctr_inc(int cpu);
  107. extern void rcu_bh_qsctr_inc(int cpu);
  108. extern int rcu_pending(int cpu);
  109. extern int rcu_needs_cpu(int cpu);
  110. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  111. extern struct lockdep_map rcu_lock_map;
  112. # define rcu_read_acquire() \
  113. lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
  114. # define rcu_read_release() lock_release(&rcu_lock_map, 1, _THIS_IP_)
  115. #else
  116. # define rcu_read_acquire() do { } while (0)
  117. # define rcu_read_release() do { } while (0)
  118. #endif
  119. #define __rcu_read_lock() \
  120. do { \
  121. preempt_disable(); \
  122. __acquire(RCU); \
  123. rcu_read_acquire(); \
  124. } while (0)
  125. #define __rcu_read_unlock() \
  126. do { \
  127. rcu_read_release(); \
  128. __release(RCU); \
  129. preempt_enable(); \
  130. } while (0)
  131. #define __rcu_read_lock_bh() \
  132. do { \
  133. local_bh_disable(); \
  134. __acquire(RCU_BH); \
  135. rcu_read_acquire(); \
  136. } while (0)
  137. #define __rcu_read_unlock_bh() \
  138. do { \
  139. rcu_read_release(); \
  140. __release(RCU_BH); \
  141. local_bh_enable(); \
  142. } while (0)
  143. #define __synchronize_sched() synchronize_rcu()
  144. #define call_rcu_sched(head, func) call_rcu(head, func)
  145. extern void __rcu_init(void);
  146. #define rcu_init_sched() do { } while (0)
  147. extern void rcu_check_callbacks(int cpu, int user);
  148. extern void rcu_restart_cpu(int cpu);
  149. extern long rcu_batches_completed(void);
  150. extern long rcu_batches_completed_bh(void);
  151. #define rcu_enter_nohz() do { } while (0)
  152. #define rcu_exit_nohz() do { } while (0)
  153. /* A context switch is a grace period for rcuclassic. */
  154. static inline int rcu_blocking_is_gp(void)
  155. {
  156. return num_online_cpus() == 1;
  157. }
  158. #endif /* __LINUX_RCUCLASSIC_H */