diff options
Diffstat (limited to 'include/linux/percpu.h')
-rw-r--r-- | include/linux/percpu.h | 96 |
1 files changed, 52 insertions, 44 deletions
diff --git a/include/linux/percpu.h b/include/linux/percpu.h index ee5615d65211..1581ff235c7e 100644 --- a/include/linux/percpu.h +++ b/include/linux/percpu.h | |||
@@ -9,50 +9,6 @@ | |||
9 | 9 | ||
10 | #include <asm/percpu.h> | 10 | #include <asm/percpu.h> |
11 | 11 | ||
12 | #ifndef PER_CPU_BASE_SECTION | ||
13 | #ifdef CONFIG_SMP | ||
14 | #define PER_CPU_BASE_SECTION ".data.percpu" | ||
15 | #else | ||
16 | #define PER_CPU_BASE_SECTION ".data" | ||
17 | #endif | ||
18 | #endif | ||
19 | |||
20 | #ifdef CONFIG_SMP | ||
21 | |||
22 | #ifdef MODULE | ||
23 | #define PER_CPU_SHARED_ALIGNED_SECTION "" | ||
24 | #else | ||
25 | #define PER_CPU_SHARED_ALIGNED_SECTION ".shared_aligned" | ||
26 | #endif | ||
27 | #define PER_CPU_FIRST_SECTION ".first" | ||
28 | |||
29 | #else | ||
30 | |||
31 | #define PER_CPU_SHARED_ALIGNED_SECTION "" | ||
32 | #define PER_CPU_FIRST_SECTION "" | ||
33 | |||
34 | #endif | ||
35 | |||
36 | #define DEFINE_PER_CPU_SECTION(type, name, section) \ | ||
37 | __attribute__((__section__(PER_CPU_BASE_SECTION section))) \ | ||
38 | PER_CPU_ATTRIBUTES __typeof__(type) per_cpu__##name | ||
39 | |||
40 | #define DEFINE_PER_CPU(type, name) \ | ||
41 | DEFINE_PER_CPU_SECTION(type, name, "") | ||
42 | |||
43 | #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name) \ | ||
44 | DEFINE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \ | ||
45 | ____cacheline_aligned_in_smp | ||
46 | |||
47 | #define DEFINE_PER_CPU_PAGE_ALIGNED(type, name) \ | ||
48 | DEFINE_PER_CPU_SECTION(type, name, ".page_aligned") | ||
49 | |||
50 | #define DEFINE_PER_CPU_FIRST(type, name) \ | ||
51 | DEFINE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION) | ||
52 | |||
53 | #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(per_cpu__##var) | ||
54 | #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(per_cpu__##var) | ||
55 | |||
56 | /* enough to cover all DEFINE_PER_CPUs in modules */ | 12 | /* enough to cover all DEFINE_PER_CPUs in modules */ |
57 | #ifdef CONFIG_MODULES | 13 | #ifdef CONFIG_MODULES |
58 | #define PERCPU_MODULE_RESERVE (8 << 10) | 14 | #define PERCPU_MODULE_RESERVE (8 << 10) |
@@ -168,4 +124,56 @@ static inline void free_percpu(void *p) | |||
168 | #define alloc_percpu(type) (type *)__alloc_percpu(sizeof(type), \ | 124 | #define alloc_percpu(type) (type *)__alloc_percpu(sizeof(type), \ |
169 | __alignof__(type)) | 125 | __alignof__(type)) |
170 | 126 | ||
127 | /* | ||
128 | * Optional methods for optimized non-lvalue per-cpu variable access. | ||
129 | * | ||
130 | * @var can be a percpu variable or a field of it and its size should | ||
131 | * equal char, int or long. percpu_read() evaluates to a lvalue and | ||
132 | * all others to void. | ||
133 | * | ||
134 | * These operations are guaranteed to be atomic w.r.t. preemption. | ||
135 | * The generic versions use plain get/put_cpu_var(). Archs are | ||
136 | * encouraged to implement single-instruction alternatives which don't | ||
137 | * require preemption protection. | ||
138 | */ | ||
139 | #ifndef percpu_read | ||
140 | # define percpu_read(var) \ | ||
141 | ({ \ | ||
142 | typeof(per_cpu_var(var)) __tmp_var__; \ | ||
143 | __tmp_var__ = get_cpu_var(var); \ | ||
144 | put_cpu_var(var); \ | ||
145 | __tmp_var__; \ | ||
146 | }) | ||
147 | #endif | ||
148 | |||
149 | #define __percpu_generic_to_op(var, val, op) \ | ||
150 | do { \ | ||
151 | get_cpu_var(var) op val; \ | ||
152 | put_cpu_var(var); \ | ||
153 | } while (0) | ||
154 | |||
155 | #ifndef percpu_write | ||
156 | # define percpu_write(var, val) __percpu_generic_to_op(var, (val), =) | ||
157 | #endif | ||
158 | |||
159 | #ifndef percpu_add | ||
160 | # define percpu_add(var, val) __percpu_generic_to_op(var, (val), +=) | ||
161 | #endif | ||
162 | |||
163 | #ifndef percpu_sub | ||
164 | # define percpu_sub(var, val) __percpu_generic_to_op(var, (val), -=) | ||
165 | #endif | ||
166 | |||
167 | #ifndef percpu_and | ||
168 | # define percpu_and(var, val) __percpu_generic_to_op(var, (val), &=) | ||
169 | #endif | ||
170 | |||
171 | #ifndef percpu_or | ||
172 | # define percpu_or(var, val) __percpu_generic_to_op(var, (val), |=) | ||
173 | #endif | ||
174 | |||
175 | #ifndef percpu_xor | ||
176 | # define percpu_xor(var, val) __percpu_generic_to_op(var, (val), ^=) | ||
177 | #endif | ||
178 | |||
171 | #endif /* __LINUX_PERCPU_H */ | 179 | #endif /* __LINUX_PERCPU_H */ |