1 #ifndef __ARCH_I386_PERCPU__
2 #define __ARCH_I386_PERCPU__
7 * PER_CPU finds an address of a per-cpu variable.
11 * reg - 32bit register
13 * The resulting address is stored in the "reg" argument.
16 * PER_CPU(cpu_gdt_descr, %ebx)
19 #define PER_CPU(var, reg) \
20 movl %fs:per_cpu__##this_cpu_off, reg; \
21 lea per_cpu__##var(reg), reg
22 #define PER_CPU_VAR(var) %fs:per_cpu__##var
24 #define PER_CPU(var, reg) \
25 movl $per_cpu__##var, reg
26 #define PER_CPU_VAR(var) per_cpu__##var
29 #else /* ...!ASSEMBLY */
32 * PER_CPU finds an address of a per-cpu variable.
36 * cpu - 32bit register containing the current CPU number
38 * The resulting address is stored in the "cpu" argument.
41 * PER_CPU(cpu_gdt_descr, %ebx)
44 /* Same as generic implementation except for optimized local access. */
45 #define __GENERIC_PER_CPU
47 /* This is used for other cpus to find our section. */
48 extern unsigned long __per_cpu_offset[];
50 #define per_cpu_offset(x) (__per_cpu_offset[x])
52 /* Separate out the type, so (int[3], foo) works. */
53 #define DECLARE_PER_CPU(type, name) extern __typeof__(type) per_cpu__##name
54 #define DEFINE_PER_CPU(type, name) \
55 __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##name
57 /* We can use this directly for local CPU (faster). */
58 DECLARE_PER_CPU(unsigned long, this_cpu_off);
60 /* var is in discarded region: offset to particular copy we want */
61 #define per_cpu(var, cpu) (*({ \
62 extern int simple_indentifier_##var(void); \
63 RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu]); }))
65 #define __raw_get_cpu_var(var) (*({ \
66 extern int simple_indentifier_##var(void); \
67 RELOC_HIDE(&per_cpu__##var, x86_read_percpu(this_cpu_off)); \
70 #define __get_cpu_var(var) __raw_get_cpu_var(var)
72 /* A macro to avoid #include hell... */
73 #define percpu_modcopy(pcpudst, src, size) \
76 for_each_possible_cpu(__i) \
77 memcpy((pcpudst)+__per_cpu_offset[__i], \
81 #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(per_cpu__##var)
82 #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(per_cpu__##var)
84 /* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */
85 #define __percpu_seg "%%fs:"
87 #include <asm-generic/percpu.h>
88 #define __percpu_seg ""
91 /* For arch-specific code, we can use direct single-insn ops (they
92 * don't give an lvalue though). */
93 extern void __bad_percpu_size(void);
95 #define percpu_to_op(op,var,val) \
97 typedef typeof(var) T__; \
98 if (0) { T__ tmp__; tmp__ = (val); } \
99 switch (sizeof(var)) { \
101 asm(op "b %1,"__percpu_seg"%0" \
106 asm(op "w %1,"__percpu_seg"%0" \
111 asm(op "l %1,"__percpu_seg"%0" \
115 default: __bad_percpu_size(); \
119 #define percpu_from_op(op,var) \
122 switch (sizeof(var)) { \
124 asm(op "b "__percpu_seg"%1,%0" \
129 asm(op "w "__percpu_seg"%1,%0" \
134 asm(op "l "__percpu_seg"%1,%0" \
138 default: __bad_percpu_size(); \
142 #define x86_read_percpu(var) percpu_from_op("mov", per_cpu__##var)
143 #define x86_write_percpu(var,val) percpu_to_op("mov", per_cpu__##var, val)
144 #define x86_add_percpu(var,val) percpu_to_op("add", per_cpu__##var, val)
145 #define x86_sub_percpu(var,val) percpu_to_op("sub", per_cpu__##var, val)
146 #define x86_or_percpu(var,val) percpu_to_op("or", per_cpu__##var, val)
147 #endif /* !__ASSEMBLY__ */
149 #endif /* __ARCH_I386_PERCPU__ */