]> bbs.cooldavid.org Git - net-next-2.6.git/blob - include/linux/rcuclassic.h
Merge commit 'v2.6.27-rc6' into core/rcu
[net-next-2.6.git] / include / linux / rcuclassic.h
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
33 #ifndef __LINUX_RCUCLASSIC_H
34 #define __LINUX_RCUCLASSIC_H
35
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>
42
43
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_DEBUG_RCU_STALL
50         unsigned long gp_check; /* Time grace period should end, in seconds.  */
51 #endif /* #ifdef CONFIG_DEBUG_RCU_STALL */
52
53         int     signaled;
54
55         spinlock_t      lock    ____cacheline_internodealigned_in_smp;
56         cpumask_t       cpumask; /* CPUs that need to switch in order    */
57                                  /* for current batch to proceed.        */
58 } ____cacheline_internodealigned_in_smp;
59
60 /* Is batch a before batch b ? */
61 static inline int rcu_batch_before(long a, long b)
62 {
63         return (a - b) < 0;
64 }
65
66 /* Is batch a after batch b ? */
67 static inline int rcu_batch_after(long a, long b)
68 {
69         return (a - b) > 0;
70 }
71
72 /* Per-CPU data for Read-Copy UPdate. */
73 struct rcu_data {
74         /* 1) quiescent state handling : */
75         long            quiescbatch;     /* Batch # for grace period */
76         int             passed_quiesc;   /* User-mode/idle loop etc. */
77         int             qs_pending;      /* core waits for quiesc state */
78
79         /* 2) batch handling */
80         /*
81          * if nxtlist is not NULL, then:
82          * batch:
83          *      The batch # for the last entry of nxtlist
84          * [*nxttail[1], NULL = *nxttail[2]):
85          *      Entries that batch # <= batch
86          * [*nxttail[0], *nxttail[1]):
87          *      Entries that batch # <= batch - 1
88          * [nxtlist, *nxttail[0]):
89          *      Entries that batch # <= batch - 2
90          *      The grace period for these entries has completed, and
91          *      the other grace-period-completed entries may be moved
92          *      here temporarily in rcu_process_callbacks().
93          */
94         long            batch;
95         struct rcu_head *nxtlist;
96         struct rcu_head **nxttail[3];
97         long            qlen;            /* # of queued callbacks */
98         struct rcu_head *donelist;
99         struct rcu_head **donetail;
100         long            blimit;          /* Upper limit on a processed batch */
101         int cpu;
102         struct rcu_head barrier;
103 };
104
105 DECLARE_PER_CPU(struct rcu_data, rcu_data);
106 DECLARE_PER_CPU(struct rcu_data, rcu_bh_data);
107
108 /*
109  * Increment the quiescent state counter.
110  * The counter is a bit degenerated: We do not need to know
111  * how many quiescent states passed, just if there was at least
112  * one since the start of the grace period. Thus just a flag.
113  */
114 static inline void rcu_qsctr_inc(int cpu)
115 {
116         struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
117         rdp->passed_quiesc = 1;
118 }
119 static inline void rcu_bh_qsctr_inc(int cpu)
120 {
121         struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu);
122         rdp->passed_quiesc = 1;
123 }
124
125 extern int rcu_pending(int cpu);
126 extern int rcu_needs_cpu(int cpu);
127
128 #ifdef CONFIG_DEBUG_LOCK_ALLOC
129 extern struct lockdep_map rcu_lock_map;
130 # define rcu_read_acquire()     \
131                         lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
132 # define rcu_read_release()     lock_release(&rcu_lock_map, 1, _THIS_IP_)
133 #else
134 # define rcu_read_acquire()     do { } while (0)
135 # define rcu_read_release()     do { } while (0)
136 #endif
137
138 #define __rcu_read_lock() \
139         do { \
140                 preempt_disable(); \
141                 __acquire(RCU); \
142                 rcu_read_acquire(); \
143         } while (0)
144 #define __rcu_read_unlock() \
145         do { \
146                 rcu_read_release(); \
147                 __release(RCU); \
148                 preempt_enable(); \
149         } while (0)
150 #define __rcu_read_lock_bh() \
151         do { \
152                 local_bh_disable(); \
153                 __acquire(RCU_BH); \
154                 rcu_read_acquire(); \
155         } while (0)
156 #define __rcu_read_unlock_bh() \
157         do { \
158                 rcu_read_release(); \
159                 __release(RCU_BH); \
160                 local_bh_enable(); \
161         } while (0)
162
163 #define __synchronize_sched() synchronize_rcu()
164
165 #define call_rcu_sched(head, func) call_rcu(head, func)
166
167 extern void __rcu_init(void);
168 #define rcu_init_sched()        do { } while (0)
169 extern void rcu_check_callbacks(int cpu, int user);
170 extern void rcu_restart_cpu(int cpu);
171
172 extern long rcu_batches_completed(void);
173 extern long rcu_batches_completed_bh(void);
174
175 #define rcu_enter_nohz()        do { } while (0)
176 #define rcu_exit_nohz()         do { } while (0)
177
178 #endif /* __LINUX_RCUCLASSIC_H */