debuggers.hg

view xen/include/xen/rcupdate.h @ 22802:bb0d0141ebf7

rcupdate: Implement rcu_barrier() to synchronously flush RCU work.

Signed-off-by: Keir Fraser <keir@xen.org>
author Keir Fraser <keir@xen.org>
date Fri Jan 14 14:16:42 2011 +0000 (2011-01-14)
parents 0b88ccf6332d
children
line source
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 * Author: Dipankar Sarma <dipankar@in.ibm.com>
21 *
22 * Based on the original work by Paul McKenney <paul.mckenney@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 * http://lse.sourceforge.net/locking/rcupdate.html
30 */
32 #ifndef __XEN_RCUPDATE_H
33 #define __XEN_RCUPDATE_H
35 #include <xen/cache.h>
36 #include <xen/spinlock.h>
37 #include <xen/percpu.h>
38 #include <xen/cpumask.h>
39 #include <xen/preempt.h>
41 /**
42 * struct rcu_head - callback structure for use with RCU
43 * @next: next update requests in a list
44 * @func: actual update function to call after the grace period.
45 */
46 struct rcu_head {
47 struct rcu_head *next;
48 void (*func)(struct rcu_head *head);
49 };
51 #define RCU_HEAD_INIT { .next = NULL, .func = NULL }
52 #define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
53 #define INIT_RCU_HEAD(ptr) do { \
54 (ptr)->next = NULL; (ptr)->func = NULL; \
55 } while (0)
59 /* Global control variables for rcupdate callback mechanism. */
60 struct rcu_ctrlblk {
61 long cur; /* Current batch number. */
62 long completed; /* Number of the last completed batch */
63 int next_pending; /* Is the next batch already waiting? */
65 spinlock_t lock __cacheline_aligned;
66 cpumask_t cpumask; /* CPUs that need to switch in order */
67 /* for current batch to proceed. */
68 } __cacheline_aligned;
70 /* Is batch a before batch b ? */
71 static inline int rcu_batch_before(long a, long b)
72 {
73 return (a - b) < 0;
74 }
76 /* Is batch a after batch b ? */
77 static inline int rcu_batch_after(long a, long b)
78 {
79 return (a - b) > 0;
80 }
82 /*
83 * Per-CPU data for Read-Copy Update.
84 * nxtlist - new callbacks are added here
85 * curlist - current batch for which quiescent cycle started if any
86 */
87 struct rcu_data {
88 /* 1) quiescent state handling : */
89 long quiescbatch; /* Batch # for grace period */
90 int qs_pending; /* core waits for quiesc state */
92 /* 2) batch handling */
93 long batch; /* Batch # for current RCU batch */
94 struct rcu_head *nxtlist;
95 struct rcu_head **nxttail;
96 long qlen; /* # of queued callbacks */
97 struct rcu_head *curlist;
98 struct rcu_head **curtail;
99 struct rcu_head *donelist;
100 struct rcu_head **donetail;
101 long blimit; /* Upper limit on a processed batch */
102 int cpu;
103 struct rcu_head barrier;
104 #ifdef CONFIG_SMP
105 long last_rs_qlen; /* qlen during the last resched */
106 #endif
107 };
109 DECLARE_PER_CPU(struct rcu_data, rcu_data);
110 extern struct rcu_ctrlblk rcu_ctrlblk;
112 int rcu_pending(int cpu);
113 int rcu_needs_cpu(int cpu);
115 /*
116 * Dummy lock type for passing to rcu_read_{lock,unlock}. Currently exists
117 * only to document the reason for rcu_read_lock() critical sections.
118 */
119 struct _rcu_read_lock {};
120 typedef struct _rcu_read_lock rcu_read_lock_t;
121 #define DEFINE_RCU_READ_LOCK(x) rcu_read_lock_t x
123 /**
124 * rcu_read_lock - mark the beginning of an RCU read-side critical section.
125 *
126 * When call_rcu() is invoked
127 * on one CPU while other CPUs are within RCU read-side critical
128 * sections, invocation of the corresponding RCU callback is deferred
129 * until after the all the other CPUs exit their critical sections.
130 *
131 * Note, however, that RCU callbacks are permitted to run concurrently
132 * with RCU read-side critical sections. One way that this can happen
133 * is via the following sequence of events: (1) CPU 0 enters an RCU
134 * read-side critical section, (2) CPU 1 invokes call_rcu() to register
135 * an RCU callback, (3) CPU 0 exits the RCU read-side critical section,
136 * (4) CPU 2 enters a RCU read-side critical section, (5) the RCU
137 * callback is invoked. This is legal, because the RCU read-side critical
138 * section that was running concurrently with the call_rcu() (and which
139 * therefore might be referencing something that the corresponding RCU
140 * callback would free up) has completed before the corresponding
141 * RCU callback is invoked.
142 *
143 * RCU read-side critical sections may be nested. Any deferred actions
144 * will be deferred until the outermost RCU read-side critical section
145 * completes.
146 *
147 * It is illegal to block while in an RCU read-side critical section.
148 */
149 #define rcu_read_lock(x) ({ ((void)(x)); preempt_disable(); })
151 /**
152 * rcu_read_unlock - marks the end of an RCU read-side critical section.
153 *
154 * See rcu_read_lock() for more information.
155 */
156 #define rcu_read_unlock(x) ({ ((void)(x)); preempt_enable(); })
158 /*
159 * So where is rcu_write_lock()? It does not exist, as there is no
160 * way for writers to lock out RCU readers. This is a feature, not
161 * a bug -- this property is what provides RCU's performance benefits.
162 * Of course, writers must coordinate with each other. The normal
163 * spinlock primitives work well for this, but any other technique may be
164 * used as well. RCU does not care how the writers keep out of each
165 * others' way, as long as they do so.
166 */
168 /**
169 * rcu_dereference - fetch an RCU-protected pointer in an
170 * RCU read-side critical section. This pointer may later
171 * be safely dereferenced.
172 *
173 * Inserts memory barriers on architectures that require them
174 * (currently only the Alpha), and, more importantly, documents
175 * exactly which pointers are protected by RCU.
176 */
177 #define rcu_dereference(p) (p)
179 /**
180 * rcu_assign_pointer - assign (publicize) a pointer to a newly
181 * initialized structure that will be dereferenced by RCU read-side
182 * critical sections. Returns the value assigned.
183 *
184 * Inserts memory barriers on architectures that require them
185 * (pretty much all of them other than x86), and also prevents
186 * the compiler from reordering the code that initializes the
187 * structure after the pointer assignment. More importantly, this
188 * call documents which pointers will be dereferenced by RCU read-side
189 * code.
190 */
191 #define rcu_assign_pointer(p, v) ({ smp_wmb(); (p) = (v); })
193 void rcu_init(void);
194 void rcu_check_callbacks(int cpu);
196 /* Exported interfaces */
197 void fastcall call_rcu(struct rcu_head *head,
198 void (*func)(struct rcu_head *head));
200 int rcu_barrier(void);
202 #endif /* __XEN_RCUPDATE_H */