debuggers.hg

view xen/include/xen/rcupdate.h @ 13686:32fd32bbf78d

Add RCU support to Xen.
Signed-off-by: Jose Renato Santos <jsantos@hpl.hp.com>
author kaf24@localhost.localdomain
date Fri Jan 26 18:34:36 2007 +0000 (2007-01-26)
parents
children 97826d77bd4d
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>
40 /**
41 * struct rcu_head - callback structure for use with RCU
42 * @next: next update requests in a list
43 * @func: actual update function to call after the grace period.
44 */
45 struct rcu_head {
46 struct rcu_head *next;
47 void (*func)(struct rcu_head *head);
48 };
50 #define RCU_HEAD_INIT { .next = NULL, .func = NULL }
51 #define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
52 #define INIT_RCU_HEAD(ptr) do { \
53 (ptr)->next = NULL; (ptr)->func = NULL; \
54 } while (0)
58 /* Global control variables for rcupdate callback mechanism. */
59 struct rcu_ctrlblk {
60 long cur; /* Current batch number. */
61 long completed; /* Number of the last completed batch */
62 int next_pending; /* Is the next batch already waiting? */
64 spinlock_t lock __cacheline_aligned;
65 cpumask_t cpumask; /* CPUs that need to switch in order */
66 /* for current batch to proceed. */
67 } __cacheline_aligned;
69 /* Is batch a before batch b ? */
70 static inline int rcu_batch_before(long a, long b)
71 {
72 return (a - b) < 0;
73 }
75 /* Is batch a after batch b ? */
76 static inline int rcu_batch_after(long a, long b)
77 {
78 return (a - b) > 0;
79 }
81 /*
82 * Per-CPU data for Read-Copy Update.
83 * nxtlist - new callbacks are added here
84 * curlist - current batch for which quiescent cycle started if any
85 */
86 struct rcu_data {
87 /* 1) quiescent state handling : */
88 long quiescbatch; /* Batch # for grace period */
89 int qs_pending; /* core waits for quiesc state */
91 /* 2) batch handling */
92 long batch; /* Batch # for current RCU batch */
93 struct rcu_head *nxtlist;
94 struct rcu_head **nxttail;
95 long qlen; /* # of queued callbacks */
96 struct rcu_head *curlist;
97 struct rcu_head **curtail;
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 #ifdef CONFIG_SMP
104 long last_rs_qlen; /* qlen during the last resched */
105 #endif
106 };
108 DECLARE_PER_CPU(struct rcu_data, rcu_data);
109 extern struct rcu_ctrlblk rcu_ctrlblk;
111 int rcu_pending(int cpu);
112 int rcu_needs_cpu(int cpu);
114 /**
115 * rcu_dereference - fetch an RCU-protected pointer in an
116 * RCU read-side critical section. This pointer may later
117 * be safely dereferenced.
118 *
119 * Inserts memory barriers on architectures that require them
120 * (currently only the Alpha), and, more importantly, documents
121 * exactly which pointers are protected by RCU.
122 */
123 #define rcu_dereference(p) (p)
125 /**
126 * rcu_assign_pointer - assign (publicize) a pointer to a newly
127 * initialized structure that will be dereferenced by RCU read-side
128 * critical sections. Returns the value assigned.
129 *
130 * Inserts memory barriers on architectures that require them
131 * (pretty much all of them other than x86), and also prevents
132 * the compiler from reordering the code that initializes the
133 * structure after the pointer assignment. More importantly, this
134 * call documents which pointers will be dereferenced by RCU read-side
135 * code.
136 */
137 #define rcu_assign_pointer(p, v) ({ smp_wmb(); (p) = (v); })
139 void rcu_init(void);
140 void __devinit rcu_online_cpu(int cpu);
141 void rcu_check_callbacks(int cpu);
143 /* Exported interfaces */
144 void fastcall call_rcu(struct rcu_head *head,
145 void (*func)(struct rcu_head *head));
147 #endif /* __XEN_RCUPDATE_H */