Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
percpu.h
Go to the documentation of this file.
1 #ifndef __ARCH_S390_PERCPU__
2 #define __ARCH_S390_PERCPU__
3 
4 #include <linux/preempt.h>
5 #include <asm/cmpxchg.h>
6 
7 /*
8  * s390 uses its own implementation for per cpu data, the offset of
9  * the cpu local data area is cached in the cpu's lowcore memory.
10  */
11 #define __my_cpu_offset S390_lowcore.percpu_offset
12 
13 /*
14  * For 64 bit module code, the module may be more than 4G above the
15  * per cpu area, use weak definitions to force the compiler to
16  * generate external references.
17  */
18 #if defined(CONFIG_SMP) && defined(CONFIG_64BIT) && defined(MODULE)
19 #define ARCH_NEEDS_WEAK_PER_CPU
20 #endif
21 
22 #define arch_this_cpu_to_op(pcp, val, op) \
23 ({ \
24  typedef typeof(pcp) pcp_op_T__; \
25  pcp_op_T__ old__, new__, prev__; \
26  pcp_op_T__ *ptr__; \
27  preempt_disable(); \
28  ptr__ = __this_cpu_ptr(&(pcp)); \
29  prev__ = *ptr__; \
30  do { \
31  old__ = prev__; \
32  new__ = old__ op (val); \
33  switch (sizeof(*ptr__)) { \
34  case 8: \
35  prev__ = cmpxchg64(ptr__, old__, new__); \
36  break; \
37  default: \
38  prev__ = cmpxchg(ptr__, old__, new__); \
39  } \
40  } while (prev__ != old__); \
41  preempt_enable(); \
42  new__; \
43 })
44 
45 #define this_cpu_add_1(pcp, val) arch_this_cpu_to_op(pcp, val, +)
46 #define this_cpu_add_2(pcp, val) arch_this_cpu_to_op(pcp, val, +)
47 #define this_cpu_add_4(pcp, val) arch_this_cpu_to_op(pcp, val, +)
48 #define this_cpu_add_8(pcp, val) arch_this_cpu_to_op(pcp, val, +)
49 
50 #define this_cpu_add_return_1(pcp, val) arch_this_cpu_to_op(pcp, val, +)
51 #define this_cpu_add_return_2(pcp, val) arch_this_cpu_to_op(pcp, val, +)
52 #define this_cpu_add_return_4(pcp, val) arch_this_cpu_to_op(pcp, val, +)
53 #define this_cpu_add_return_8(pcp, val) arch_this_cpu_to_op(pcp, val, +)
54 
55 #define this_cpu_and_1(pcp, val) arch_this_cpu_to_op(pcp, val, &)
56 #define this_cpu_and_2(pcp, val) arch_this_cpu_to_op(pcp, val, &)
57 #define this_cpu_and_4(pcp, val) arch_this_cpu_to_op(pcp, val, &)
58 #define this_cpu_and_8(pcp, val) arch_this_cpu_to_op(pcp, val, &)
59 
60 #define this_cpu_or_1(pcp, val) arch_this_cpu_to_op(pcp, val, |)
61 #define this_cpu_or_2(pcp, val) arch_this_cpu_to_op(pcp, val, |)
62 #define this_cpu_or_4(pcp, val) arch_this_cpu_to_op(pcp, val, |)
63 #define this_cpu_or_8(pcp, val) arch_this_cpu_to_op(pcp, val, |)
64 
65 #define this_cpu_xor_1(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
66 #define this_cpu_xor_2(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
67 #define this_cpu_xor_4(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
68 #define this_cpu_xor_8(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
69 
70 #define arch_this_cpu_cmpxchg(pcp, oval, nval) \
71 ({ \
72  typedef typeof(pcp) pcp_op_T__; \
73  pcp_op_T__ ret__; \
74  pcp_op_T__ *ptr__; \
75  preempt_disable(); \
76  ptr__ = __this_cpu_ptr(&(pcp)); \
77  switch (sizeof(*ptr__)) { \
78  case 8: \
79  ret__ = cmpxchg64(ptr__, oval, nval); \
80  break; \
81  default: \
82  ret__ = cmpxchg(ptr__, oval, nval); \
83  } \
84  preempt_enable(); \
85  ret__; \
86 })
87 
88 #define this_cpu_cmpxchg_1(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
89 #define this_cpu_cmpxchg_2(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
90 #define this_cpu_cmpxchg_4(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
91 #define this_cpu_cmpxchg_8(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
92 
93 #define arch_this_cpu_xchg(pcp, nval) \
94 ({ \
95  typeof(pcp) *ptr__; \
96  typeof(pcp) ret__; \
97  preempt_disable(); \
98  ptr__ = __this_cpu_ptr(&(pcp)); \
99  ret__ = xchg(ptr__, nval); \
100  preempt_enable(); \
101  ret__; \
102 })
103 
104 #define this_cpu_xchg_1(pcp, nval) arch_this_cpu_xchg(pcp, nval)
105 #define this_cpu_xchg_2(pcp, nval) arch_this_cpu_xchg(pcp, nval)
106 #define this_cpu_xchg_4(pcp, nval) arch_this_cpu_xchg(pcp, nval)
107 #ifdef CONFIG_64BIT
108 #define this_cpu_xchg_8(pcp, nval) arch_this_cpu_xchg(pcp, nval)
109 #endif
110 
111 #define arch_this_cpu_cmpxchg_double(pcp1, pcp2, o1, o2, n1, n2) \
112 ({ \
113  typeof(pcp1) o1__ = (o1), n1__ = (n1); \
114  typeof(pcp2) o2__ = (o2), n2__ = (n2); \
115  typeof(pcp1) *p1__; \
116  typeof(pcp2) *p2__; \
117  int ret__; \
118  preempt_disable(); \
119  p1__ = __this_cpu_ptr(&(pcp1)); \
120  p2__ = __this_cpu_ptr(&(pcp2)); \
121  ret__ = __cmpxchg_double(p1__, p2__, o1__, o2__, n1__, n2__); \
122  preempt_enable(); \
123  ret__; \
124 })
125 
126 #define this_cpu_cmpxchg_double_4 arch_this_cpu_cmpxchg_double
127 #ifdef CONFIG_64BIT
128 #define this_cpu_cmpxchg_double_8 arch_this_cpu_cmpxchg_double
129 #endif
130 
131 #include <asm-generic/percpu.h>
132 
133 #endif /* __ARCH_S390_PERCPU__ */