diff options
author | Nick Piggin <nickpiggin@yahoo.com.au> | 2006-01-08 04:02:19 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-08 23:13:48 -0500 |
commit | 095975da26dba21698582e91e96be10f7417333f (patch) | |
tree | ce1ffac556d394ef56a18faa97d38f79b07f31e2 /include | |
parent | a57004e1afb6ee03c509f1b1ec74a000682ab93b (diff) |
[PATCH] rcu file: use atomic primitives
Use atomic_inc_not_zero for rcu files instead of special case rcuref.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/fs.h | 3 | ||||
-rw-r--r-- | include/linux/radix-tree.h | 1 | ||||
-rw-r--r-- | include/linux/rcuref.h | 220 |
3 files changed, 2 insertions, 222 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h index 2c9c48d65630..ef29500b5df8 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -9,7 +9,6 @@ | |||
9 | #include <linux/config.h> | 9 | #include <linux/config.h> |
10 | #include <linux/limits.h> | 10 | #include <linux/limits.h> |
11 | #include <linux/ioctl.h> | 11 | #include <linux/ioctl.h> |
12 | #include <linux/rcuref.h> | ||
13 | 12 | ||
14 | /* | 13 | /* |
15 | * It's silly to have NR_OPEN bigger than NR_FILE, but you can change | 14 | * It's silly to have NR_OPEN bigger than NR_FILE, but you can change |
@@ -653,7 +652,7 @@ extern spinlock_t files_lock; | |||
653 | #define file_list_lock() spin_lock(&files_lock); | 652 | #define file_list_lock() spin_lock(&files_lock); |
654 | #define file_list_unlock() spin_unlock(&files_lock); | 653 | #define file_list_unlock() spin_unlock(&files_lock); |
655 | 654 | ||
656 | #define get_file(x) rcuref_inc(&(x)->f_count) | 655 | #define get_file(x) atomic_inc(&(x)->f_count) |
657 | #define file_count(x) atomic_read(&(x)->f_count) | 656 | #define file_count(x) atomic_read(&(x)->f_count) |
658 | 657 | ||
659 | #define MAX_NON_LFS ((1UL<<31) - 1) | 658 | #define MAX_NON_LFS ((1UL<<31) - 1) |
diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h index 36e5d269612f..c57ff2fcb30a 100644 --- a/include/linux/radix-tree.h +++ b/include/linux/radix-tree.h | |||
@@ -19,6 +19,7 @@ | |||
19 | #ifndef _LINUX_RADIX_TREE_H | 19 | #ifndef _LINUX_RADIX_TREE_H |
20 | #define _LINUX_RADIX_TREE_H | 20 | #define _LINUX_RADIX_TREE_H |
21 | 21 | ||
22 | #include <linux/sched.h> | ||
22 | #include <linux/preempt.h> | 23 | #include <linux/preempt.h> |
23 | #include <linux/types.h> | 24 | #include <linux/types.h> |
24 | 25 | ||
diff --git a/include/linux/rcuref.h b/include/linux/rcuref.h deleted file mode 100644 index e1adbba14b67..000000000000 --- a/include/linux/rcuref.h +++ /dev/null | |||
@@ -1,220 +0,0 @@ | |||
1 | /* | ||
2 | * rcuref.h | ||
3 | * | ||
4 | * Reference counting for elements of lists/arrays protected by | ||
5 | * RCU. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
20 | * | ||
21 | * Copyright (C) IBM Corporation, 2005 | ||
22 | * | ||
23 | * Author: Dipankar Sarma <dipankar@in.ibm.com> | ||
24 | * Ravikiran Thirumalai <kiran_th@gmail.com> | ||
25 | * | ||
26 | * See Documentation/RCU/rcuref.txt for detailed user guide. | ||
27 | * | ||
28 | */ | ||
29 | |||
30 | #ifndef _RCUREF_H_ | ||
31 | #define _RCUREF_H_ | ||
32 | |||
33 | #ifdef __KERNEL__ | ||
34 | |||
35 | #include <linux/types.h> | ||
36 | #include <linux/interrupt.h> | ||
37 | #include <linux/spinlock.h> | ||
38 | #include <asm/atomic.h> | ||
39 | |||
40 | /* | ||
41 | * These APIs work on traditional atomic_t counters used in the | ||
42 | * kernel for reference counting. Under special circumstances | ||
43 | * where a lock-free get() operation races with a put() operation | ||
44 | * these APIs can be used. See Documentation/RCU/rcuref.txt. | ||
45 | */ | ||
46 | |||
47 | #ifdef __HAVE_ARCH_CMPXCHG | ||
48 | |||
49 | /** | ||
50 | * rcuref_inc - increment refcount for object. | ||
51 | * @rcuref: reference counter in the object in question. | ||
52 | * | ||
53 | * This should be used only for objects where we use RCU and | ||
54 | * use the rcuref_inc_lf() api to acquire a reference | ||
55 | * in a lock-free reader-side critical section. | ||
56 | */ | ||
57 | static inline void rcuref_inc(atomic_t *rcuref) | ||
58 | { | ||
59 | atomic_inc(rcuref); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * rcuref_dec - decrement refcount for object. | ||
64 | * @rcuref: reference counter in the object in question. | ||
65 | * | ||
66 | * This should be used only for objects where we use RCU and | ||
67 | * use the rcuref_inc_lf() api to acquire a reference | ||
68 | * in a lock-free reader-side critical section. | ||
69 | */ | ||
70 | static inline void rcuref_dec(atomic_t *rcuref) | ||
71 | { | ||
72 | atomic_dec(rcuref); | ||
73 | } | ||
74 | |||
75 | /** | ||
76 | * rcuref_dec_and_test - decrement refcount for object and test | ||
77 | * @rcuref: reference counter in the object. | ||
78 | * @release: pointer to the function that will clean up the object | ||
79 | * when the last reference to the object is released. | ||
80 | * This pointer is required. | ||
81 | * | ||
82 | * Decrement the refcount, and if 0, return 1. Else return 0. | ||
83 | * | ||
84 | * This should be used only for objects where we use RCU and | ||
85 | * use the rcuref_inc_lf() api to acquire a reference | ||
86 | * in a lock-free reader-side critical section. | ||
87 | */ | ||
88 | static inline int rcuref_dec_and_test(atomic_t *rcuref) | ||
89 | { | ||
90 | return atomic_dec_and_test(rcuref); | ||
91 | } | ||
92 | |||
93 | /* | ||
94 | * cmpxchg is needed on UP too, if deletions to the list/array can happen | ||
95 | * in interrupt context. | ||
96 | */ | ||
97 | |||
98 | /** | ||
99 | * rcuref_inc_lf - Take reference to an object in a read-side | ||
100 | * critical section protected by RCU. | ||
101 | * @rcuref: reference counter in the object in question. | ||
102 | * | ||
103 | * Try and increment the refcount by 1. The increment might fail if | ||
104 | * the reference counter has been through a 1 to 0 transition and | ||
105 | * is no longer part of the lock-free list. | ||
106 | * Returns non-zero on successful increment and zero otherwise. | ||
107 | */ | ||
108 | static inline int rcuref_inc_lf(atomic_t *rcuref) | ||
109 | { | ||
110 | int c, old; | ||
111 | c = atomic_read(rcuref); | ||
112 | while (c && (old = cmpxchg(&rcuref->counter, c, c + 1)) != c) | ||
113 | c = old; | ||
114 | return c; | ||
115 | } | ||
116 | |||
117 | #else /* !__HAVE_ARCH_CMPXCHG */ | ||
118 | |||
119 | extern spinlock_t __rcuref_hash[]; | ||
120 | |||
121 | /* | ||
122 | * Use a hash table of locks to protect the reference count | ||
123 | * since cmpxchg is not available in this arch. | ||
124 | */ | ||
125 | #ifdef CONFIG_SMP | ||
126 | #define RCUREF_HASH_SIZE 4 | ||
127 | #define RCUREF_HASH(k) \ | ||
128 | (&__rcuref_hash[(((unsigned long)k)>>8) & (RCUREF_HASH_SIZE-1)]) | ||
129 | #else | ||
130 | #define RCUREF_HASH_SIZE 1 | ||
131 | #define RCUREF_HASH(k) &__rcuref_hash[0] | ||
132 | #endif /* CONFIG_SMP */ | ||
133 | |||
134 | /** | ||
135 | * rcuref_inc - increment refcount for object. | ||
136 | * @rcuref: reference counter in the object in question. | ||
137 | * | ||
138 | * This should be used only for objects where we use RCU and | ||
139 | * use the rcuref_inc_lf() api to acquire a reference in a lock-free | ||
140 | * reader-side critical section. | ||
141 | */ | ||
142 | static inline void rcuref_inc(atomic_t *rcuref) | ||
143 | { | ||
144 | unsigned long flags; | ||
145 | spin_lock_irqsave(RCUREF_HASH(rcuref), flags); | ||
146 | rcuref->counter += 1; | ||
147 | spin_unlock_irqrestore(RCUREF_HASH(rcuref), flags); | ||
148 | } | ||
149 | |||
150 | /** | ||
151 | * rcuref_dec - decrement refcount for object. | ||
152 | * @rcuref: reference counter in the object in question. | ||
153 | * | ||
154 | * This should be used only for objects where we use RCU and | ||
155 | * use the rcuref_inc_lf() api to acquire a reference in a lock-free | ||
156 | * reader-side critical section. | ||
157 | */ | ||
158 | static inline void rcuref_dec(atomic_t *rcuref) | ||
159 | { | ||
160 | unsigned long flags; | ||
161 | spin_lock_irqsave(RCUREF_HASH(rcuref), flags); | ||
162 | rcuref->counter -= 1; | ||
163 | spin_unlock_irqrestore(RCUREF_HASH(rcuref), flags); | ||
164 | } | ||
165 | |||
166 | /** | ||
167 | * rcuref_dec_and_test - decrement refcount for object and test | ||
168 | * @rcuref: reference counter in the object. | ||
169 | * @release: pointer to the function that will clean up the object | ||
170 | * when the last reference to the object is released. | ||
171 | * This pointer is required. | ||
172 | * | ||
173 | * Decrement the refcount, and if 0, return 1. Else return 0. | ||
174 | * | ||
175 | * This should be used only for objects where we use RCU and | ||
176 | * use the rcuref_inc_lf() api to acquire a reference in a lock-free | ||
177 | * reader-side critical section. | ||
178 | */ | ||
179 | static inline int rcuref_dec_and_test(atomic_t *rcuref) | ||
180 | { | ||
181 | unsigned long flags; | ||
182 | spin_lock_irqsave(RCUREF_HASH(rcuref), flags); | ||
183 | rcuref->counter--; | ||
184 | if (!rcuref->counter) { | ||
185 | spin_unlock_irqrestore(RCUREF_HASH(rcuref), flags); | ||
186 | return 1; | ||
187 | } else { | ||
188 | spin_unlock_irqrestore(RCUREF_HASH(rcuref), flags); | ||
189 | return 0; | ||
190 | } | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * rcuref_inc_lf - Take reference to an object of a lock-free collection | ||
195 | * by traversing a lock-free list/array. | ||
196 | * @rcuref: reference counter in the object in question. | ||
197 | * | ||
198 | * Try and increment the refcount by 1. The increment might fail if | ||
199 | * the reference counter has been through a 1 to 0 transition and | ||
200 | * object is no longer part of the lock-free list. | ||
201 | * Returns non-zero on successful increment and zero otherwise. | ||
202 | */ | ||
203 | static inline int rcuref_inc_lf(atomic_t *rcuref) | ||
204 | { | ||
205 | int ret; | ||
206 | unsigned long flags; | ||
207 | spin_lock_irqsave(RCUREF_HASH(rcuref), flags); | ||
208 | if (rcuref->counter) | ||
209 | ret = rcuref->counter++; | ||
210 | else | ||
211 | ret = 0; | ||
212 | spin_unlock_irqrestore(RCUREF_HASH(rcuref), flags); | ||
213 | return ret; | ||
214 | } | ||
215 | |||
216 | |||
217 | #endif /* !__HAVE_ARCH_CMPXCHG */ | ||
218 | |||
219 | #endif /* __KERNEL__ */ | ||
220 | #endif /* _RCUREF_H_ */ | ||