x86: arch/x86/mm/init_32.c cleanup
[wrt350n-kernel.git] / include / linux / percpu.h
blob00412bb494c40b100bc1e996983b72ba877ccf69
1 #ifndef __LINUX_PERCPU_H
2 #define __LINUX_PERCPU_H
4 #include <linux/preempt.h>
5 #include <linux/slab.h> /* For kmalloc() */
6 #include <linux/smp.h>
7 #include <linux/string.h> /* For memset() */
8 #include <linux/cpumask.h>
10 #include <asm/percpu.h>
12 #ifndef PER_CPU_ATTRIBUTES
13 #define PER_CPU_ATTRIBUTES
14 #endif
16 #ifdef CONFIG_SMP
17 #define DEFINE_PER_CPU(type, name) \
18 __attribute__((__section__(".data.percpu"))) \
19 PER_CPU_ATTRIBUTES __typeof__(type) per_cpu__##name
21 #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name) \
22 __attribute__((__section__(".data.percpu.shared_aligned"))) \
23 PER_CPU_ATTRIBUTES __typeof__(type) per_cpu__##name \
24 ____cacheline_aligned_in_smp
25 #else
26 #define DEFINE_PER_CPU(type, name) \
27 PER_CPU_ATTRIBUTES __typeof__(type) per_cpu__##name
29 #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name) \
30 DEFINE_PER_CPU(type, name)
31 #endif
33 #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(per_cpu__##var)
34 #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(per_cpu__##var)
36 /* Enough to cover all DEFINE_PER_CPUs in kernel, including modules. */
37 #ifndef PERCPU_ENOUGH_ROOM
38 #ifdef CONFIG_MODULES
39 #define PERCPU_MODULE_RESERVE 8192
40 #else
41 #define PERCPU_MODULE_RESERVE 0
42 #endif
44 #define PERCPU_ENOUGH_ROOM \
45 (__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE)
46 #endif /* PERCPU_ENOUGH_ROOM */
49 * Must be an lvalue. Since @var must be a simple identifier,
50 * we force a syntax error here if it isn't.
52 #define get_cpu_var(var) (*({ \
53 extern int simple_identifier_##var(void); \
54 preempt_disable(); \
55 &__get_cpu_var(var); }))
56 #define put_cpu_var(var) preempt_enable()
58 #ifdef CONFIG_SMP
60 struct percpu_data {
61 void *ptrs[NR_CPUS];
64 #define __percpu_disguise(pdata) (struct percpu_data *)~(unsigned long)(pdata)
65 /*
66 * Use this to get to a cpu's version of the per-cpu object dynamically
67 * allocated. Non-atomic access to the current CPU's version should
68 * probably be combined with get_cpu()/put_cpu().
69 */
70 #define percpu_ptr(ptr, cpu) \
71 ({ \
72 struct percpu_data *__p = __percpu_disguise(ptr); \
73 (__typeof__(ptr))__p->ptrs[(cpu)]; \
76 extern void *percpu_populate(void *__pdata, size_t size, gfp_t gfp, int cpu);
77 extern void percpu_depopulate(void *__pdata, int cpu);
78 extern int __percpu_populate_mask(void *__pdata, size_t size, gfp_t gfp,
79 cpumask_t *mask);
80 extern void __percpu_depopulate_mask(void *__pdata, cpumask_t *mask);
81 extern void *__percpu_alloc_mask(size_t size, gfp_t gfp, cpumask_t *mask);
82 extern void percpu_free(void *__pdata);
84 #else /* CONFIG_SMP */
86 #define percpu_ptr(ptr, cpu) ({ (void)(cpu); (ptr); })
88 static inline void percpu_depopulate(void *__pdata, int cpu)
92 static inline void __percpu_depopulate_mask(void *__pdata, cpumask_t *mask)
96 static inline void *percpu_populate(void *__pdata, size_t size, gfp_t gfp,
97 int cpu)
99 return percpu_ptr(__pdata, cpu);
102 static inline int __percpu_populate_mask(void *__pdata, size_t size, gfp_t gfp,
103 cpumask_t *mask)
105 return 0;
108 static __always_inline void *__percpu_alloc_mask(size_t size, gfp_t gfp, cpumask_t *mask)
110 return kzalloc(size, gfp);
113 static inline void percpu_free(void *__pdata)
115 kfree(__pdata);
118 #endif /* CONFIG_SMP */
120 #define percpu_populate_mask(__pdata, size, gfp, mask) \
121 __percpu_populate_mask((__pdata), (size), (gfp), &(mask))
122 #define percpu_depopulate_mask(__pdata, mask) \
123 __percpu_depopulate_mask((__pdata), &(mask))
124 #define percpu_alloc_mask(size, gfp, mask) \
125 __percpu_alloc_mask((size), (gfp), &(mask))
127 #define percpu_alloc(size, gfp) percpu_alloc_mask((size), (gfp), cpu_online_map)
129 /* (legacy) interface for use without CPU hotplug handling */
131 #define __alloc_percpu(size) percpu_alloc_mask((size), GFP_KERNEL, \
132 cpu_possible_map)
133 #define alloc_percpu(type) (type *)__alloc_percpu(sizeof(type))
134 #define free_percpu(ptr) percpu_free((ptr))
135 #define per_cpu_ptr(ptr, cpu) percpu_ptr((ptr), (cpu))
137 #endif /* __LINUX_PERCPU_H */