blob: 04c728147be0a6b5b21a812cc23f462b899dd5c3 [file] [log] [blame]
Paul E. McKenney01c1c662008-01-25 21:08:24 +01001/*
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
Paul E. McKenney01c1c662008-01-25 21:08:24 +010036#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. */
45struct rcu_ctrlblk {
46 long cur; /* Current batch number. */
47 long completed; /* Number of the last completed batch */
Lai Jiangshan3cac97c2008-07-06 17:23:55 +080048 long pending; /* Number of the last pending batch */
Paul E. McKenney01c1c662008-01-25 21:08:24 +010049
50 int signaled;
51
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;
56
57/* Is batch a before batch b ? */
58static inline int rcu_batch_before(long a, long b)
59{
60 return (a - b) < 0;
61}
62
63/* Is batch a after batch b ? */
64static inline int rcu_batch_after(long a, long b)
65{
66 return (a - b) > 0;
67}
68
Lai Jiangshan5127bed2008-07-06 17:23:59 +080069/* Per-CPU data for Read-Copy UPdate. */
Paul E. McKenney01c1c662008-01-25 21:08:24 +010070struct 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
76 /* 2) batch handling */
Lai Jiangshan5127bed2008-07-06 17:23:59 +080077 /*
78 * if nxtlist is not NULL, then:
79 * batch:
80 * The batch # for the last entry of nxtlist
81 * [*nxttail[1], NULL = *nxttail[2]):
82 * Entries that batch # <= batch
83 * [*nxttail[0], *nxttail[1]):
84 * Entries that batch # <= batch - 1
85 * [nxtlist, *nxttail[0]):
86 * Entries that batch # <= batch - 2
87 * The grace period for these entries has completed, and
88 * the other grace-period-completed entries may be moved
89 * here temporarily in rcu_process_callbacks().
90 */
91 long batch;
Paul E. McKenney01c1c662008-01-25 21:08:24 +010092 struct rcu_head *nxtlist;
Lai Jiangshan5127bed2008-07-06 17:23:59 +080093 struct rcu_head **nxttail[3];
Paul E. McKenney01c1c662008-01-25 21:08:24 +010094 long qlen; /* # of queued callbacks */
Paul E. McKenney01c1c662008-01-25 21:08:24 +010095 struct rcu_head *donelist;
96 struct rcu_head **donetail;
97 long blimit; /* Upper limit on a processed batch */
98 int cpu;
99 struct rcu_head barrier;
100};
101
102DECLARE_PER_CPU(struct rcu_data, rcu_data);
103DECLARE_PER_CPU(struct rcu_data, rcu_bh_data);
104
105/*
106 * Increment the quiescent state counter.
107 * The counter is a bit degenerated: We do not need to know
108 * how many quiescent states passed, just if there was at least
109 * one since the start of the grace period. Thus just a flag.
110 */
111static inline void rcu_qsctr_inc(int cpu)
112{
113 struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
114 rdp->passed_quiesc = 1;
115}
116static inline void rcu_bh_qsctr_inc(int cpu)
117{
118 struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu);
119 rdp->passed_quiesc = 1;
120}
121
122extern int rcu_pending(int cpu);
123extern int rcu_needs_cpu(int cpu);
124
125#ifdef CONFIG_DEBUG_LOCK_ALLOC
126extern struct lockdep_map rcu_lock_map;
127# define rcu_read_acquire() \
128 lock_acquire(&rcu_lock_map, 0, 0, 2, 1, _THIS_IP_)
129# define rcu_read_release() lock_release(&rcu_lock_map, 1, _THIS_IP_)
130#else
131# define rcu_read_acquire() do { } while (0)
132# define rcu_read_release() do { } while (0)
133#endif
134
135#define __rcu_read_lock() \
136 do { \
137 preempt_disable(); \
138 __acquire(RCU); \
139 rcu_read_acquire(); \
140 } while (0)
141#define __rcu_read_unlock() \
142 do { \
143 rcu_read_release(); \
144 __release(RCU); \
145 preempt_enable(); \
146 } while (0)
147#define __rcu_read_lock_bh() \
148 do { \
149 local_bh_disable(); \
150 __acquire(RCU_BH); \
151 rcu_read_acquire(); \
152 } while (0)
153#define __rcu_read_unlock_bh() \
154 do { \
155 rcu_read_release(); \
156 __release(RCU_BH); \
157 local_bh_enable(); \
158 } while (0)
159
160#define __synchronize_sched() synchronize_rcu()
161
Paul E. McKenney4446a362008-05-12 21:21:05 +0200162#define call_rcu_sched(head, func) call_rcu(head, func)
163
Paul E. McKenney01c1c662008-01-25 21:08:24 +0100164extern void __rcu_init(void);
Paul E. McKenney4446a362008-05-12 21:21:05 +0200165#define rcu_init_sched() do { } while (0)
Paul E. McKenney01c1c662008-01-25 21:08:24 +0100166extern void rcu_check_callbacks(int cpu, int user);
167extern void rcu_restart_cpu(int cpu);
168
Paul E. McKenneye260be62008-01-25 21:08:24 +0100169extern long rcu_batches_completed(void);
170extern long rcu_batches_completed_bh(void);
171
Steven Rostedt2232c2d2008-02-29 18:46:50 +0100172#define rcu_enter_nohz() do { } while (0)
173#define rcu_exit_nohz() do { } while (0)
174
Paul E. McKenney01c1c662008-01-25 21:08:24 +0100175#endif /* __LINUX_RCUCLASSIC_H */