2 * Read-Copy Update mechanism for mutual exclusion (classic version)
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.
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.
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.
18 * Copyright IBM Corporation, 2001
20 * Author: Dipankar Sarma <dipankar@in.ibm.com>
22 * Based on the original work by Paul McKenney <paulmck@us.ibm.com>
23 * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
25 * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf
26 * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001)
28 * For detailed explanation of Read-Copy Update mechanism see -
33 #ifndef __LINUX_RCUCLASSIC_H
34 #define __LINUX_RCUCLASSIC_H
36 #include <linux/cache.h>
37 #include <linux/spinlock.h>
38 #include <linux/threads.h>
39 #include <linux/percpu.h>
40 #include <linux/cpumask.h>
41 #include <linux/seqlock.h>
44 /* Global control variables for rcupdate callback mechanism. */
46 long cur
; /* Current batch number. */
47 long completed
; /* Number of the last completed batch */
48 int next_pending
; /* Is the next batch already waiting? */
52 spinlock_t lock ____cacheline_internodealigned_in_smp
;
53 cpumask_t cpumask
; /* CPUs that need to switch in order */
54 /* for current batch to proceed. */
55 } ____cacheline_internodealigned_in_smp
;
57 /* Is batch a before batch b ? */
58 static inline int rcu_batch_before(long a
, long b
)
63 /* Is batch a after batch b ? */
64 static inline int rcu_batch_after(long a
, long b
)
70 * Per-CPU data for Read-Copy UPdate.
71 * nxtlist - new callbacks are added here
72 * curlist - current batch for which quiescent cycle started if any
75 /* 1) quiescent state handling : */
76 long quiescbatch
; /* Batch # for grace period */
77 int passed_quiesc
; /* User-mode/idle loop etc. */
78 int qs_pending
; /* core waits for quiesc state */
80 /* 2) batch handling */
81 long batch
; /* Batch # for current RCU batch */
82 struct rcu_head
*nxtlist
;
83 struct rcu_head
**nxttail
;
84 long qlen
; /* # of queued callbacks */
85 struct rcu_head
*curlist
;
86 struct rcu_head
**curtail
;
87 struct rcu_head
*donelist
;
88 struct rcu_head
**donetail
;
89 long blimit
; /* Upper limit on a processed batch */
91 struct rcu_head barrier
;
94 DECLARE_PER_CPU(struct rcu_data
, rcu_data
);
95 DECLARE_PER_CPU(struct rcu_data
, rcu_bh_data
);
98 * Increment the quiescent state counter.
99 * The counter is a bit degenerated: We do not need to know
100 * how many quiescent states passed, just if there was at least
101 * one since the start of the grace period. Thus just a flag.
103 static inline void rcu_qsctr_inc(int cpu
)
105 struct rcu_data
*rdp
= &per_cpu(rcu_data
, cpu
);
106 rdp
->passed_quiesc
= 1;
108 static inline void rcu_bh_qsctr_inc(int cpu
)
110 struct rcu_data
*rdp
= &per_cpu(rcu_bh_data
, cpu
);
111 rdp
->passed_quiesc
= 1;
114 extern int rcu_pending(int cpu
);
115 extern int rcu_needs_cpu(int cpu
);
117 #ifdef CONFIG_DEBUG_LOCK_ALLOC
118 extern struct lockdep_map rcu_lock_map
;
119 # define rcu_read_acquire() \
120 lock_acquire(&rcu_lock_map, 0, 0, 2, 1, _THIS_IP_)
121 # define rcu_read_release() lock_release(&rcu_lock_map, 1, _THIS_IP_)
123 # define rcu_read_acquire() do { } while (0)
124 # define rcu_read_release() do { } while (0)
127 #define __rcu_read_lock() \
131 rcu_read_acquire(); \
133 #define __rcu_read_unlock() \
135 rcu_read_release(); \
139 #define __rcu_read_lock_bh() \
141 local_bh_disable(); \
143 rcu_read_acquire(); \
145 #define __rcu_read_unlock_bh() \
147 rcu_read_release(); \
152 #define __synchronize_sched() synchronize_rcu()
154 extern void __rcu_init(void);
155 extern void rcu_check_callbacks(int cpu
, int user
);
156 extern void rcu_restart_cpu(int cpu
);
158 extern long rcu_batches_completed(void);
159 extern long rcu_batches_completed_bh(void);
161 #define rcu_enter_nohz() do { } while (0)
162 #define rcu_exit_nohz() do { } while (0)
164 #endif /* __LINUX_RCUCLASSIC_H */