diff options
Diffstat (limited to 'include/asm-generic/percpu.h')
| -rw-r--r-- | include/asm-generic/percpu.h | 71 |
1 files changed, 18 insertions, 53 deletions
diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h index 00f45ff081a6..d7d50d7ee51e 100644 --- a/include/asm-generic/percpu.h +++ b/include/asm-generic/percpu.h | |||
| @@ -1,13 +1,9 @@ | |||
| 1 | #ifndef _ASM_GENERIC_PERCPU_H_ | 1 | #ifndef _ASM_GENERIC_PERCPU_H_ |
| 2 | #define _ASM_GENERIC_PERCPU_H_ | 2 | #define _ASM_GENERIC_PERCPU_H_ |
| 3 | |||
| 3 | #include <linux/compiler.h> | 4 | #include <linux/compiler.h> |
| 4 | #include <linux/threads.h> | 5 | #include <linux/threads.h> |
| 5 | 6 | #include <linux/percpu-defs.h> | |
| 6 | /* | ||
| 7 | * Determine the real variable name from the name visible in the | ||
| 8 | * kernel sources. | ||
| 9 | */ | ||
| 10 | #define per_cpu_var(var) per_cpu__##var | ||
| 11 | 7 | ||
| 12 | #ifdef CONFIG_SMP | 8 | #ifdef CONFIG_SMP |
| 13 | 9 | ||
| @@ -73,63 +69,32 @@ extern void setup_per_cpu_areas(void); | |||
| 73 | 69 | ||
| 74 | #endif /* SMP */ | 70 | #endif /* SMP */ |
| 75 | 71 | ||
| 76 | #ifndef PER_CPU_ATTRIBUTES | 72 | #ifndef PER_CPU_BASE_SECTION |
| 77 | #define PER_CPU_ATTRIBUTES | 73 | #ifdef CONFIG_SMP |
| 74 | #define PER_CPU_BASE_SECTION ".data.percpu" | ||
| 75 | #else | ||
| 76 | #define PER_CPU_BASE_SECTION ".data" | ||
| 78 | #endif | 77 | #endif |
| 79 | |||
| 80 | #define DECLARE_PER_CPU(type, name) extern PER_CPU_ATTRIBUTES \ | ||
| 81 | __typeof__(type) per_cpu_var(name) | ||
| 82 | |||
| 83 | /* | ||
| 84 | * Optional methods for optimized non-lvalue per-cpu variable access. | ||
| 85 | * | ||
| 86 | * @var can be a percpu variable or a field of it and its size should | ||
| 87 | * equal char, int or long. percpu_read() evaluates to a lvalue and | ||
| 88 | * all others to void. | ||
| 89 | * | ||
| 90 | * These operations are guaranteed to be atomic w.r.t. preemption. | ||
| 91 | * The generic versions use plain get/put_cpu_var(). Archs are | ||
| 92 | * encouraged to implement single-instruction alternatives which don't | ||
| 93 | * require preemption protection. | ||
| 94 | */ | ||
| 95 | #ifndef percpu_read | ||
| 96 | # define percpu_read(var) \ | ||
| 97 | ({ \ | ||
| 98 | typeof(per_cpu_var(var)) __tmp_var__; \ | ||
| 99 | __tmp_var__ = get_cpu_var(var); \ | ||
| 100 | put_cpu_var(var); \ | ||
| 101 | __tmp_var__; \ | ||
| 102 | }) | ||
| 103 | #endif | 78 | #endif |
| 104 | 79 | ||
| 105 | #define __percpu_generic_to_op(var, val, op) \ | 80 | #ifdef CONFIG_SMP |
| 106 | do { \ | ||
| 107 | get_cpu_var(var) op val; \ | ||
| 108 | put_cpu_var(var); \ | ||
| 109 | } while (0) | ||
| 110 | |||
| 111 | #ifndef percpu_write | ||
| 112 | # define percpu_write(var, val) __percpu_generic_to_op(var, (val), =) | ||
| 113 | #endif | ||
| 114 | 81 | ||
| 115 | #ifndef percpu_add | 82 | #ifdef MODULE |
| 116 | # define percpu_add(var, val) __percpu_generic_to_op(var, (val), +=) | 83 | #define PER_CPU_SHARED_ALIGNED_SECTION "" |
| 84 | #else | ||
| 85 | #define PER_CPU_SHARED_ALIGNED_SECTION ".shared_aligned" | ||
| 117 | #endif | 86 | #endif |
| 87 | #define PER_CPU_FIRST_SECTION ".first" | ||
| 118 | 88 | ||
| 119 | #ifndef percpu_sub | 89 | #else |
| 120 | # define percpu_sub(var, val) __percpu_generic_to_op(var, (val), -=) | ||
| 121 | #endif | ||
| 122 | 90 | ||
| 123 | #ifndef percpu_and | 91 | #define PER_CPU_SHARED_ALIGNED_SECTION "" |
| 124 | # define percpu_and(var, val) __percpu_generic_to_op(var, (val), &=) | 92 | #define PER_CPU_FIRST_SECTION "" |
| 125 | #endif | ||
| 126 | 93 | ||
| 127 | #ifndef percpu_or | ||
| 128 | # define percpu_or(var, val) __percpu_generic_to_op(var, (val), |=) | ||
| 129 | #endif | 94 | #endif |
| 130 | 95 | ||
| 131 | #ifndef percpu_xor | 96 | #ifndef PER_CPU_ATTRIBUTES |
| 132 | # define percpu_xor(var, val) __percpu_generic_to_op(var, (val), ^=) | 97 | #define PER_CPU_ATTRIBUTES |
| 133 | #endif | 98 | #endif |
| 134 | 99 | ||
| 135 | #endif /* _ASM_GENERIC_PERCPU_H_ */ | 100 | #endif /* _ASM_GENERIC_PERCPU_H_ */ |
