H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_PERCPU_H |
| 2 | #define _ASM_X86_PERCPU_H |
travis@sgi.com | 3334052 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 3 | |
Tejun Heo | 1a51e3a | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 4 | #ifdef CONFIG_X86_64 |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 5 | #define __percpu_seg gs |
| 6 | #define __percpu_mov_op movq |
Tejun Heo | 1a51e3a | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 7 | #else |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 8 | #define __percpu_seg fs |
| 9 | #define __percpu_mov_op movl |
Tejun Heo | 1a51e3a | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 10 | #endif |
travis@sgi.com | 3334052 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 11 | |
| 12 | #ifdef __ASSEMBLY__ |
| 13 | |
| 14 | /* |
| 15 | * PER_CPU finds an address of a per-cpu variable. |
| 16 | * |
| 17 | * Args: |
| 18 | * var - variable name |
| 19 | * reg - 32bit register |
| 20 | * |
| 21 | * The resulting address is stored in the "reg" argument. |
| 22 | * |
| 23 | * Example: |
| 24 | * PER_CPU(cpu_gdt_descr, %ebx) |
| 25 | */ |
| 26 | #ifdef CONFIG_SMP |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 27 | #define PER_CPU(var, reg) \ |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 28 | __percpu_mov_op %__percpu_seg:this_cpu_off, reg; \ |
| 29 | lea var(reg), reg |
| 30 | #define PER_CPU_VAR(var) %__percpu_seg:var |
travis@sgi.com | 3334052 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 31 | #else /* ! SMP */ |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 32 | #define PER_CPU(var, reg) __percpu_mov_op $var, reg |
| 33 | #define PER_CPU_VAR(var) var |
travis@sgi.com | 3334052 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 34 | #endif /* SMP */ |
| 35 | |
Brian Gerst | 2add8e2 | 2009-02-08 09:58:39 -0500 | [diff] [blame] | 36 | #ifdef CONFIG_X86_64_SMP |
| 37 | #define INIT_PER_CPU_VAR(var) init_per_cpu__##var |
| 38 | #else |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 39 | #define INIT_PER_CPU_VAR(var) var |
Brian Gerst | 2add8e2 | 2009-02-08 09:58:39 -0500 | [diff] [blame] | 40 | #endif |
| 41 | |
travis@sgi.com | 3334052 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 42 | #else /* ...!ASSEMBLY */ |
| 43 | |
Tejun Heo | e59a1bb | 2009-06-22 11:56:24 +0900 | [diff] [blame] | 44 | #include <linux/kernel.h> |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 45 | #include <linux/stringify.h> |
| 46 | |
travis@sgi.com | 3334052 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 47 | #ifdef CONFIG_SMP |
Christoph Lameter | d7c3f8c | 2011-03-26 20:57:18 -0500 | [diff] [blame] | 48 | #define __percpu_prefix "%%"__stringify(__percpu_seg)":" |
Alex Shi | c6ae41e | 2012-05-11 15:35:27 +0800 | [diff] [blame] | 49 | #define __my_cpu_offset this_cpu_read(this_cpu_off) |
Brian Gerst | db7829c | 2010-09-09 18:17:26 +0200 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * Compared to the generic __my_cpu_offset version, the following |
| 53 | * saves one instruction and avoids clobbering a temp register. |
| 54 | */ |
Tejun Heo | bbc344e | 2014-06-17 19:12:34 -0400 | [diff] [blame] | 55 | #define arch_raw_cpu_ptr(ptr) \ |
Brian Gerst | db7829c | 2010-09-09 18:17:26 +0200 | [diff] [blame] | 56 | ({ \ |
| 57 | unsigned long tcp_ptr__; \ |
Brian Gerst | db7829c | 2010-09-09 18:17:26 +0200 | [diff] [blame] | 58 | asm volatile("add " __percpu_arg(1) ", %0" \ |
| 59 | : "=r" (tcp_ptr__) \ |
| 60 | : "m" (this_cpu_off), "0" (ptr)); \ |
| 61 | (typeof(*(ptr)) __kernel __force *)tcp_ptr__; \ |
| 62 | }) |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 63 | #else |
Christoph Lameter | d7c3f8c | 2011-03-26 20:57:18 -0500 | [diff] [blame] | 64 | #define __percpu_prefix "" |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 65 | #endif |
travis@sgi.com | 3334052 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 66 | |
Jan Beulich | 97b67ae | 2014-11-04 08:50:48 +0000 | [diff] [blame] | 67 | #define __percpu_arg(x) __percpu_prefix "%" #x |
Christoph Lameter | d7c3f8c | 2011-03-26 20:57:18 -0500 | [diff] [blame] | 68 | |
Brian Gerst | 2add8e2 | 2009-02-08 09:58:39 -0500 | [diff] [blame] | 69 | /* |
| 70 | * Initialized pointers to per-cpu variables needed for the boot |
| 71 | * processor need to use these macros to get the proper address |
| 72 | * offset from __per_cpu_load on SMP. |
| 73 | * |
| 74 | * There also must be an entry in vmlinux_64.lds.S |
| 75 | */ |
| 76 | #define DECLARE_INIT_PER_CPU(var) \ |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 77 | extern typeof(var) init_per_cpu_var(var) |
Brian Gerst | 2add8e2 | 2009-02-08 09:58:39 -0500 | [diff] [blame] | 78 | |
| 79 | #ifdef CONFIG_X86_64_SMP |
| 80 | #define init_per_cpu_var(var) init_per_cpu__##var |
| 81 | #else |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 82 | #define init_per_cpu_var(var) var |
Brian Gerst | 2add8e2 | 2009-02-08 09:58:39 -0500 | [diff] [blame] | 83 | #endif |
| 84 | |
travis@sgi.com | 3334052 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 85 | /* For arch-specific code, we can use direct single-insn ops (they |
| 86 | * don't give an lvalue though). */ |
| 87 | extern void __bad_percpu_size(void); |
| 88 | |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 89 | #define percpu_to_op(op, var, val) \ |
| 90 | do { \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 91 | typedef typeof(var) pto_T__; \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 92 | if (0) { \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 93 | pto_T__ pto_tmp__; \ |
| 94 | pto_tmp__ = (val); \ |
Andi Kleen | 23b764d | 2010-06-10 13:10:36 +0200 | [diff] [blame] | 95 | (void)pto_tmp__; \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 96 | } \ |
| 97 | switch (sizeof(var)) { \ |
| 98 | case 1: \ |
Brian Gerst | 87b2640 | 2009-01-19 00:38:59 +0900 | [diff] [blame] | 99 | asm(op "b %1,"__percpu_arg(0) \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 100 | : "+m" (var) \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 101 | : "qi" ((pto_T__)(val))); \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 102 | break; \ |
| 103 | case 2: \ |
Brian Gerst | 87b2640 | 2009-01-19 00:38:59 +0900 | [diff] [blame] | 104 | asm(op "w %1,"__percpu_arg(0) \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 105 | : "+m" (var) \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 106 | : "ri" ((pto_T__)(val))); \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 107 | break; \ |
| 108 | case 4: \ |
Brian Gerst | 87b2640 | 2009-01-19 00:38:59 +0900 | [diff] [blame] | 109 | asm(op "l %1,"__percpu_arg(0) \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 110 | : "+m" (var) \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 111 | : "ri" ((pto_T__)(val))); \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 112 | break; \ |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 113 | case 8: \ |
Brian Gerst | 87b2640 | 2009-01-19 00:38:59 +0900 | [diff] [blame] | 114 | asm(op "q %1,"__percpu_arg(0) \ |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 115 | : "+m" (var) \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 116 | : "re" ((pto_T__)(val))); \ |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 117 | break; \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 118 | default: __bad_percpu_size(); \ |
| 119 | } \ |
| 120 | } while (0) |
travis@sgi.com | 3334052 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 121 | |
Christoph Lameter | 5917dae | 2010-01-05 15:34:50 +0900 | [diff] [blame] | 122 | /* |
| 123 | * Generate a percpu add to memory instruction and optimize code |
Justin P. Mattock | 40f0a5d | 2010-04-19 11:51:16 -0700 | [diff] [blame] | 124 | * if one is added or subtracted. |
Christoph Lameter | 5917dae | 2010-01-05 15:34:50 +0900 | [diff] [blame] | 125 | */ |
| 126 | #define percpu_add_op(var, val) \ |
| 127 | do { \ |
| 128 | typedef typeof(var) pao_T__; \ |
| 129 | const int pao_ID__ = (__builtin_constant_p(val) && \ |
Greg Thelen | bd09d9a | 2013-10-30 13:56:20 -0700 | [diff] [blame] | 130 | ((val) == 1 || (val) == -1)) ? \ |
| 131 | (int)(val) : 0; \ |
Christoph Lameter | 5917dae | 2010-01-05 15:34:50 +0900 | [diff] [blame] | 132 | if (0) { \ |
| 133 | pao_T__ pao_tmp__; \ |
| 134 | pao_tmp__ = (val); \ |
Andi Kleen | 23b764d | 2010-06-10 13:10:36 +0200 | [diff] [blame] | 135 | (void)pao_tmp__; \ |
Christoph Lameter | 5917dae | 2010-01-05 15:34:50 +0900 | [diff] [blame] | 136 | } \ |
| 137 | switch (sizeof(var)) { \ |
| 138 | case 1: \ |
| 139 | if (pao_ID__ == 1) \ |
| 140 | asm("incb "__percpu_arg(0) : "+m" (var)); \ |
| 141 | else if (pao_ID__ == -1) \ |
| 142 | asm("decb "__percpu_arg(0) : "+m" (var)); \ |
| 143 | else \ |
| 144 | asm("addb %1, "__percpu_arg(0) \ |
| 145 | : "+m" (var) \ |
| 146 | : "qi" ((pao_T__)(val))); \ |
| 147 | break; \ |
| 148 | case 2: \ |
| 149 | if (pao_ID__ == 1) \ |
| 150 | asm("incw "__percpu_arg(0) : "+m" (var)); \ |
| 151 | else if (pao_ID__ == -1) \ |
| 152 | asm("decw "__percpu_arg(0) : "+m" (var)); \ |
| 153 | else \ |
| 154 | asm("addw %1, "__percpu_arg(0) \ |
| 155 | : "+m" (var) \ |
| 156 | : "ri" ((pao_T__)(val))); \ |
| 157 | break; \ |
| 158 | case 4: \ |
| 159 | if (pao_ID__ == 1) \ |
| 160 | asm("incl "__percpu_arg(0) : "+m" (var)); \ |
| 161 | else if (pao_ID__ == -1) \ |
| 162 | asm("decl "__percpu_arg(0) : "+m" (var)); \ |
| 163 | else \ |
| 164 | asm("addl %1, "__percpu_arg(0) \ |
| 165 | : "+m" (var) \ |
| 166 | : "ri" ((pao_T__)(val))); \ |
| 167 | break; \ |
| 168 | case 8: \ |
| 169 | if (pao_ID__ == 1) \ |
| 170 | asm("incq "__percpu_arg(0) : "+m" (var)); \ |
| 171 | else if (pao_ID__ == -1) \ |
| 172 | asm("decq "__percpu_arg(0) : "+m" (var)); \ |
| 173 | else \ |
| 174 | asm("addq %1, "__percpu_arg(0) \ |
| 175 | : "+m" (var) \ |
| 176 | : "re" ((pao_T__)(val))); \ |
| 177 | break; \ |
| 178 | default: __bad_percpu_size(); \ |
| 179 | } \ |
| 180 | } while (0) |
| 181 | |
Jan Beulich | 97b67ae | 2014-11-04 08:50:48 +0000 | [diff] [blame] | 182 | #define percpu_from_op(op, var) \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 183 | ({ \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 184 | typeof(var) pfo_ret__; \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 185 | switch (sizeof(var)) { \ |
| 186 | case 1: \ |
Brian Gerst | 87b2640 | 2009-01-19 00:38:59 +0900 | [diff] [blame] | 187 | asm(op "b "__percpu_arg(1)",%0" \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 188 | : "=q" (pfo_ret__) \ |
Jan Beulich | 97b67ae | 2014-11-04 08:50:48 +0000 | [diff] [blame] | 189 | : "m" (var)); \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 190 | break; \ |
| 191 | case 2: \ |
Brian Gerst | 87b2640 | 2009-01-19 00:38:59 +0900 | [diff] [blame] | 192 | asm(op "w "__percpu_arg(1)",%0" \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 193 | : "=r" (pfo_ret__) \ |
Jan Beulich | 97b67ae | 2014-11-04 08:50:48 +0000 | [diff] [blame] | 194 | : "m" (var)); \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 195 | break; \ |
| 196 | case 4: \ |
Brian Gerst | 87b2640 | 2009-01-19 00:38:59 +0900 | [diff] [blame] | 197 | asm(op "l "__percpu_arg(1)",%0" \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 198 | : "=r" (pfo_ret__) \ |
Jan Beulich | 97b67ae | 2014-11-04 08:50:48 +0000 | [diff] [blame] | 199 | : "m" (var)); \ |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 200 | break; \ |
| 201 | case 8: \ |
Brian Gerst | 87b2640 | 2009-01-19 00:38:59 +0900 | [diff] [blame] | 202 | asm(op "q "__percpu_arg(1)",%0" \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 203 | : "=r" (pfo_ret__) \ |
Jan Beulich | 97b67ae | 2014-11-04 08:50:48 +0000 | [diff] [blame] | 204 | : "m" (var)); \ |
| 205 | break; \ |
| 206 | default: __bad_percpu_size(); \ |
| 207 | } \ |
| 208 | pfo_ret__; \ |
| 209 | }) |
| 210 | |
| 211 | #define percpu_stable_op(op, var) \ |
| 212 | ({ \ |
| 213 | typeof(var) pfo_ret__; \ |
| 214 | switch (sizeof(var)) { \ |
| 215 | case 1: \ |
| 216 | asm(op "b "__percpu_arg(P1)",%0" \ |
| 217 | : "=q" (pfo_ret__) \ |
| 218 | : "p" (&(var))); \ |
| 219 | break; \ |
| 220 | case 2: \ |
| 221 | asm(op "w "__percpu_arg(P1)",%0" \ |
| 222 | : "=r" (pfo_ret__) \ |
| 223 | : "p" (&(var))); \ |
| 224 | break; \ |
| 225 | case 4: \ |
| 226 | asm(op "l "__percpu_arg(P1)",%0" \ |
| 227 | : "=r" (pfo_ret__) \ |
| 228 | : "p" (&(var))); \ |
| 229 | break; \ |
| 230 | case 8: \ |
| 231 | asm(op "q "__percpu_arg(P1)",%0" \ |
| 232 | : "=r" (pfo_ret__) \ |
| 233 | : "p" (&(var))); \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 234 | break; \ |
| 235 | default: __bad_percpu_size(); \ |
| 236 | } \ |
Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 237 | pfo_ret__; \ |
Joe Perches | bc9e3be | 2008-03-23 01:03:06 -0700 | [diff] [blame] | 238 | }) |
travis@sgi.com | 3334052 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 239 | |
Jan Beulich | 402af0d | 2010-04-21 15:21:51 +0100 | [diff] [blame] | 240 | #define percpu_unary_op(op, var) \ |
| 241 | ({ \ |
| 242 | switch (sizeof(var)) { \ |
| 243 | case 1: \ |
| 244 | asm(op "b "__percpu_arg(0) \ |
| 245 | : "+m" (var)); \ |
| 246 | break; \ |
| 247 | case 2: \ |
| 248 | asm(op "w "__percpu_arg(0) \ |
| 249 | : "+m" (var)); \ |
| 250 | break; \ |
| 251 | case 4: \ |
| 252 | asm(op "l "__percpu_arg(0) \ |
| 253 | : "+m" (var)); \ |
| 254 | break; \ |
| 255 | case 8: \ |
| 256 | asm(op "q "__percpu_arg(0) \ |
| 257 | : "+m" (var)); \ |
| 258 | break; \ |
| 259 | default: __bad_percpu_size(); \ |
| 260 | } \ |
| 261 | }) |
| 262 | |
Linus Torvalds | ed8d9ad | 2009-08-03 14:08:48 +0900 | [diff] [blame] | 263 | /* |
Tejun Heo | 4030477 | 2010-12-17 15:47:04 +0100 | [diff] [blame] | 264 | * Add return operation |
| 265 | */ |
| 266 | #define percpu_add_return_op(var, val) \ |
| 267 | ({ \ |
| 268 | typeof(var) paro_ret__ = val; \ |
| 269 | switch (sizeof(var)) { \ |
| 270 | case 1: \ |
| 271 | asm("xaddb %0, "__percpu_arg(1) \ |
| 272 | : "+q" (paro_ret__), "+m" (var) \ |
| 273 | : : "memory"); \ |
| 274 | break; \ |
| 275 | case 2: \ |
| 276 | asm("xaddw %0, "__percpu_arg(1) \ |
| 277 | : "+r" (paro_ret__), "+m" (var) \ |
| 278 | : : "memory"); \ |
| 279 | break; \ |
| 280 | case 4: \ |
| 281 | asm("xaddl %0, "__percpu_arg(1) \ |
| 282 | : "+r" (paro_ret__), "+m" (var) \ |
| 283 | : : "memory"); \ |
| 284 | break; \ |
| 285 | case 8: \ |
| 286 | asm("xaddq %0, "__percpu_arg(1) \ |
| 287 | : "+re" (paro_ret__), "+m" (var) \ |
| 288 | : : "memory"); \ |
| 289 | break; \ |
| 290 | default: __bad_percpu_size(); \ |
| 291 | } \ |
| 292 | paro_ret__ += val; \ |
| 293 | paro_ret__; \ |
| 294 | }) |
| 295 | |
| 296 | /* |
Christoph Lameter | 8270137 | 2010-12-14 10:28:47 -0600 | [diff] [blame] | 297 | * xchg is implemented using cmpxchg without a lock prefix. xchg is |
| 298 | * expensive due to the implied lock prefix. The processor cannot prefetch |
| 299 | * cachelines if xchg is used. |
Christoph Lameter | 7296e08 | 2010-12-14 10:28:44 -0600 | [diff] [blame] | 300 | */ |
| 301 | #define percpu_xchg_op(var, nval) \ |
| 302 | ({ \ |
| 303 | typeof(var) pxo_ret__; \ |
| 304 | typeof(var) pxo_new__ = (nval); \ |
| 305 | switch (sizeof(var)) { \ |
| 306 | case 1: \ |
Eric Dumazet | 889a7a6 | 2011-01-25 17:31:54 +0100 | [diff] [blame] | 307 | asm("\n\tmov "__percpu_arg(1)",%%al" \ |
| 308 | "\n1:\tcmpxchgb %2, "__percpu_arg(1) \ |
Christoph Lameter | 8270137 | 2010-12-14 10:28:47 -0600 | [diff] [blame] | 309 | "\n\tjnz 1b" \ |
Eric Dumazet | 889a7a6 | 2011-01-25 17:31:54 +0100 | [diff] [blame] | 310 | : "=&a" (pxo_ret__), "+m" (var) \ |
Christoph Lameter | 7296e08 | 2010-12-14 10:28:44 -0600 | [diff] [blame] | 311 | : "q" (pxo_new__) \ |
| 312 | : "memory"); \ |
| 313 | break; \ |
| 314 | case 2: \ |
Eric Dumazet | 889a7a6 | 2011-01-25 17:31:54 +0100 | [diff] [blame] | 315 | asm("\n\tmov "__percpu_arg(1)",%%ax" \ |
| 316 | "\n1:\tcmpxchgw %2, "__percpu_arg(1) \ |
Christoph Lameter | 8270137 | 2010-12-14 10:28:47 -0600 | [diff] [blame] | 317 | "\n\tjnz 1b" \ |
Eric Dumazet | 889a7a6 | 2011-01-25 17:31:54 +0100 | [diff] [blame] | 318 | : "=&a" (pxo_ret__), "+m" (var) \ |
Christoph Lameter | 7296e08 | 2010-12-14 10:28:44 -0600 | [diff] [blame] | 319 | : "r" (pxo_new__) \ |
| 320 | : "memory"); \ |
| 321 | break; \ |
| 322 | case 4: \ |
Eric Dumazet | 889a7a6 | 2011-01-25 17:31:54 +0100 | [diff] [blame] | 323 | asm("\n\tmov "__percpu_arg(1)",%%eax" \ |
| 324 | "\n1:\tcmpxchgl %2, "__percpu_arg(1) \ |
Christoph Lameter | 8270137 | 2010-12-14 10:28:47 -0600 | [diff] [blame] | 325 | "\n\tjnz 1b" \ |
Eric Dumazet | 889a7a6 | 2011-01-25 17:31:54 +0100 | [diff] [blame] | 326 | : "=&a" (pxo_ret__), "+m" (var) \ |
Christoph Lameter | 7296e08 | 2010-12-14 10:28:44 -0600 | [diff] [blame] | 327 | : "r" (pxo_new__) \ |
| 328 | : "memory"); \ |
| 329 | break; \ |
| 330 | case 8: \ |
Eric Dumazet | 889a7a6 | 2011-01-25 17:31:54 +0100 | [diff] [blame] | 331 | asm("\n\tmov "__percpu_arg(1)",%%rax" \ |
| 332 | "\n1:\tcmpxchgq %2, "__percpu_arg(1) \ |
Christoph Lameter | 8270137 | 2010-12-14 10:28:47 -0600 | [diff] [blame] | 333 | "\n\tjnz 1b" \ |
Eric Dumazet | 889a7a6 | 2011-01-25 17:31:54 +0100 | [diff] [blame] | 334 | : "=&a" (pxo_ret__), "+m" (var) \ |
Christoph Lameter | 7296e08 | 2010-12-14 10:28:44 -0600 | [diff] [blame] | 335 | : "r" (pxo_new__) \ |
| 336 | : "memory"); \ |
| 337 | break; \ |
| 338 | default: __bad_percpu_size(); \ |
| 339 | } \ |
| 340 | pxo_ret__; \ |
| 341 | }) |
| 342 | |
| 343 | /* |
| 344 | * cmpxchg has no such implied lock semantics as a result it is much |
| 345 | * more efficient for cpu local operations. |
| 346 | */ |
| 347 | #define percpu_cmpxchg_op(var, oval, nval) \ |
| 348 | ({ \ |
| 349 | typeof(var) pco_ret__; \ |
| 350 | typeof(var) pco_old__ = (oval); \ |
| 351 | typeof(var) pco_new__ = (nval); \ |
| 352 | switch (sizeof(var)) { \ |
| 353 | case 1: \ |
| 354 | asm("cmpxchgb %2, "__percpu_arg(1) \ |
| 355 | : "=a" (pco_ret__), "+m" (var) \ |
| 356 | : "q" (pco_new__), "0" (pco_old__) \ |
| 357 | : "memory"); \ |
| 358 | break; \ |
| 359 | case 2: \ |
| 360 | asm("cmpxchgw %2, "__percpu_arg(1) \ |
| 361 | : "=a" (pco_ret__), "+m" (var) \ |
| 362 | : "r" (pco_new__), "0" (pco_old__) \ |
| 363 | : "memory"); \ |
| 364 | break; \ |
| 365 | case 4: \ |
| 366 | asm("cmpxchgl %2, "__percpu_arg(1) \ |
| 367 | : "=a" (pco_ret__), "+m" (var) \ |
| 368 | : "r" (pco_new__), "0" (pco_old__) \ |
| 369 | : "memory"); \ |
| 370 | break; \ |
| 371 | case 8: \ |
| 372 | asm("cmpxchgq %2, "__percpu_arg(1) \ |
| 373 | : "=a" (pco_ret__), "+m" (var) \ |
| 374 | : "r" (pco_new__), "0" (pco_old__) \ |
| 375 | : "memory"); \ |
| 376 | break; \ |
| 377 | default: __bad_percpu_size(); \ |
| 378 | } \ |
| 379 | pco_ret__; \ |
| 380 | }) |
| 381 | |
| 382 | /* |
Alex Shi | 641b695 | 2012-05-14 14:15:32 -0700 | [diff] [blame] | 383 | * this_cpu_read() makes gcc load the percpu variable every time it is |
Alex Shi | c6ae41e | 2012-05-11 15:35:27 +0800 | [diff] [blame] | 384 | * accessed while this_cpu_read_stable() allows the value to be cached. |
| 385 | * this_cpu_read_stable() is more efficient and can be used if its value |
Linus Torvalds | ed8d9ad | 2009-08-03 14:08:48 +0900 | [diff] [blame] | 386 | * is guaranteed to be valid across cpus. The current users include |
| 387 | * get_current() and get_thread_info() both of which are actually |
| 388 | * per-thread variables implemented as per-cpu variables and thus |
| 389 | * stable for the duration of the respective task. |
| 390 | */ |
Jan Beulich | 97b67ae | 2014-11-04 08:50:48 +0000 | [diff] [blame] | 391 | #define this_cpu_read_stable(var) percpu_stable_op("mov", var) |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 392 | |
Jan Beulich | 97b67ae | 2014-11-04 08:50:48 +0000 | [diff] [blame] | 393 | #define raw_cpu_read_1(pcp) percpu_from_op("mov", pcp) |
| 394 | #define raw_cpu_read_2(pcp) percpu_from_op("mov", pcp) |
| 395 | #define raw_cpu_read_4(pcp) percpu_from_op("mov", pcp) |
Christoph Lameter | 30ed1a7 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 396 | |
Christoph Lameter | b3ca1c1 | 2014-04-07 15:39:34 -0700 | [diff] [blame] | 397 | #define raw_cpu_write_1(pcp, val) percpu_to_op("mov", (pcp), val) |
| 398 | #define raw_cpu_write_2(pcp, val) percpu_to_op("mov", (pcp), val) |
| 399 | #define raw_cpu_write_4(pcp, val) percpu_to_op("mov", (pcp), val) |
| 400 | #define raw_cpu_add_1(pcp, val) percpu_add_op((pcp), val) |
| 401 | #define raw_cpu_add_2(pcp, val) percpu_add_op((pcp), val) |
| 402 | #define raw_cpu_add_4(pcp, val) percpu_add_op((pcp), val) |
| 403 | #define raw_cpu_and_1(pcp, val) percpu_to_op("and", (pcp), val) |
| 404 | #define raw_cpu_and_2(pcp, val) percpu_to_op("and", (pcp), val) |
| 405 | #define raw_cpu_and_4(pcp, val) percpu_to_op("and", (pcp), val) |
| 406 | #define raw_cpu_or_1(pcp, val) percpu_to_op("or", (pcp), val) |
| 407 | #define raw_cpu_or_2(pcp, val) percpu_to_op("or", (pcp), val) |
| 408 | #define raw_cpu_or_4(pcp, val) percpu_to_op("or", (pcp), val) |
| 409 | #define raw_cpu_xchg_1(pcp, val) percpu_xchg_op(pcp, val) |
| 410 | #define raw_cpu_xchg_2(pcp, val) percpu_xchg_op(pcp, val) |
| 411 | #define raw_cpu_xchg_4(pcp, val) percpu_xchg_op(pcp, val) |
Christoph Lameter | 30ed1a7 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 412 | |
Jan Beulich | 97b67ae | 2014-11-04 08:50:48 +0000 | [diff] [blame] | 413 | #define this_cpu_read_1(pcp) percpu_from_op("mov", pcp) |
| 414 | #define this_cpu_read_2(pcp) percpu_from_op("mov", pcp) |
| 415 | #define this_cpu_read_4(pcp) percpu_from_op("mov", pcp) |
Christoph Lameter | 30ed1a7 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 416 | #define this_cpu_write_1(pcp, val) percpu_to_op("mov", (pcp), val) |
| 417 | #define this_cpu_write_2(pcp, val) percpu_to_op("mov", (pcp), val) |
| 418 | #define this_cpu_write_4(pcp, val) percpu_to_op("mov", (pcp), val) |
Christoph Lameter | 5917dae | 2010-01-05 15:34:50 +0900 | [diff] [blame] | 419 | #define this_cpu_add_1(pcp, val) percpu_add_op((pcp), val) |
| 420 | #define this_cpu_add_2(pcp, val) percpu_add_op((pcp), val) |
| 421 | #define this_cpu_add_4(pcp, val) percpu_add_op((pcp), val) |
Christoph Lameter | 30ed1a7 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 422 | #define this_cpu_and_1(pcp, val) percpu_to_op("and", (pcp), val) |
| 423 | #define this_cpu_and_2(pcp, val) percpu_to_op("and", (pcp), val) |
| 424 | #define this_cpu_and_4(pcp, val) percpu_to_op("and", (pcp), val) |
| 425 | #define this_cpu_or_1(pcp, val) percpu_to_op("or", (pcp), val) |
| 426 | #define this_cpu_or_2(pcp, val) percpu_to_op("or", (pcp), val) |
| 427 | #define this_cpu_or_4(pcp, val) percpu_to_op("or", (pcp), val) |
Christoph Lameter | 7296e08 | 2010-12-14 10:28:44 -0600 | [diff] [blame] | 428 | #define this_cpu_xchg_1(pcp, nval) percpu_xchg_op(pcp, nval) |
| 429 | #define this_cpu_xchg_2(pcp, nval) percpu_xchg_op(pcp, nval) |
| 430 | #define this_cpu_xchg_4(pcp, nval) percpu_xchg_op(pcp, nval) |
Christoph Lameter | 30ed1a7 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 431 | |
Christoph Lameter | b3ca1c1 | 2014-04-07 15:39:34 -0700 | [diff] [blame] | 432 | #define raw_cpu_add_return_1(pcp, val) percpu_add_return_op(pcp, val) |
| 433 | #define raw_cpu_add_return_2(pcp, val) percpu_add_return_op(pcp, val) |
| 434 | #define raw_cpu_add_return_4(pcp, val) percpu_add_return_op(pcp, val) |
| 435 | #define raw_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(pcp, oval, nval) |
| 436 | #define raw_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(pcp, oval, nval) |
| 437 | #define raw_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(pcp, oval, nval) |
Christoph Lameter | 7296e08 | 2010-12-14 10:28:44 -0600 | [diff] [blame] | 438 | |
Christoph Lameter | b3ca1c1 | 2014-04-07 15:39:34 -0700 | [diff] [blame] | 439 | #define this_cpu_add_return_1(pcp, val) percpu_add_return_op(pcp, val) |
| 440 | #define this_cpu_add_return_2(pcp, val) percpu_add_return_op(pcp, val) |
| 441 | #define this_cpu_add_return_4(pcp, val) percpu_add_return_op(pcp, val) |
Christoph Lameter | 7296e08 | 2010-12-14 10:28:44 -0600 | [diff] [blame] | 442 | #define this_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(pcp, oval, nval) |
| 443 | #define this_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(pcp, oval, nval) |
| 444 | #define this_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(pcp, oval, nval) |
| 445 | |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 446 | #ifdef CONFIG_X86_CMPXCHG64 |
Jan Beulich | cebef5b | 2011-12-14 08:33:25 +0000 | [diff] [blame] | 447 | #define percpu_cmpxchg8b_double(pcp1, pcp2, o1, o2, n1, n2) \ |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 448 | ({ \ |
Jan Beulich | cebef5b | 2011-12-14 08:33:25 +0000 | [diff] [blame] | 449 | bool __ret; \ |
| 450 | typeof(pcp1) __o1 = (o1), __n1 = (n1); \ |
| 451 | typeof(pcp2) __o2 = (o2), __n2 = (n2); \ |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 452 | asm volatile("cmpxchg8b "__percpu_arg(1)"\n\tsetz %0\n\t" \ |
Jan Beulich | cebef5b | 2011-12-14 08:33:25 +0000 | [diff] [blame] | 453 | : "=a" (__ret), "+m" (pcp1), "+m" (pcp2), "+d" (__o2) \ |
| 454 | : "b" (__n1), "c" (__n2), "a" (__o1)); \ |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 455 | __ret; \ |
| 456 | }) |
| 457 | |
Christoph Lameter | b3ca1c1 | 2014-04-07 15:39:34 -0700 | [diff] [blame] | 458 | #define raw_cpu_cmpxchg_double_4 percpu_cmpxchg8b_double |
Jan Beulich | cebef5b | 2011-12-14 08:33:25 +0000 | [diff] [blame] | 459 | #define this_cpu_cmpxchg_double_4 percpu_cmpxchg8b_double |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 460 | #endif /* CONFIG_X86_CMPXCHG64 */ |
| 461 | |
Christoph Lameter | 30ed1a7 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 462 | /* |
| 463 | * Per cpu atomic 64 bit operations are only available under 64 bit. |
| 464 | * 32 bit must fall back to generic operations. |
| 465 | */ |
| 466 | #ifdef CONFIG_X86_64 |
Jan Beulich | 97b67ae | 2014-11-04 08:50:48 +0000 | [diff] [blame] | 467 | #define raw_cpu_read_8(pcp) percpu_from_op("mov", pcp) |
Christoph Lameter | b3ca1c1 | 2014-04-07 15:39:34 -0700 | [diff] [blame] | 468 | #define raw_cpu_write_8(pcp, val) percpu_to_op("mov", (pcp), val) |
| 469 | #define raw_cpu_add_8(pcp, val) percpu_add_op((pcp), val) |
| 470 | #define raw_cpu_and_8(pcp, val) percpu_to_op("and", (pcp), val) |
| 471 | #define raw_cpu_or_8(pcp, val) percpu_to_op("or", (pcp), val) |
| 472 | #define raw_cpu_add_return_8(pcp, val) percpu_add_return_op(pcp, val) |
| 473 | #define raw_cpu_xchg_8(pcp, nval) percpu_xchg_op(pcp, nval) |
| 474 | #define raw_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(pcp, oval, nval) |
Christoph Lameter | 30ed1a7 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 475 | |
Jan Beulich | 97b67ae | 2014-11-04 08:50:48 +0000 | [diff] [blame] | 476 | #define this_cpu_read_8(pcp) percpu_from_op("mov", pcp) |
Christoph Lameter | b3ca1c1 | 2014-04-07 15:39:34 -0700 | [diff] [blame] | 477 | #define this_cpu_write_8(pcp, val) percpu_to_op("mov", (pcp), val) |
| 478 | #define this_cpu_add_8(pcp, val) percpu_add_op((pcp), val) |
| 479 | #define this_cpu_and_8(pcp, val) percpu_to_op("and", (pcp), val) |
| 480 | #define this_cpu_or_8(pcp, val) percpu_to_op("or", (pcp), val) |
| 481 | #define this_cpu_add_return_8(pcp, val) percpu_add_return_op(pcp, val) |
| 482 | #define this_cpu_xchg_8(pcp, nval) percpu_xchg_op(pcp, nval) |
Christoph Lameter | 2485b64 | 2011-01-11 18:54:53 +0100 | [diff] [blame] | 483 | #define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(pcp, oval, nval) |
Christoph Lameter | 30ed1a7 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 484 | |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 485 | /* |
| 486 | * Pretty complex macro to generate cmpxchg16 instruction. The instruction |
| 487 | * is not supported on early AMD64 processors so we must be able to emulate |
| 488 | * it in software. The address used in the cmpxchg16 instruction must be |
| 489 | * aligned to a 16 byte boundary. |
| 490 | */ |
Jan Beulich | cebef5b | 2011-12-14 08:33:25 +0000 | [diff] [blame] | 491 | #define percpu_cmpxchg16b_double(pcp1, pcp2, o1, o2, n1, n2) \ |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 492 | ({ \ |
Jan Beulich | cebef5b | 2011-12-14 08:33:25 +0000 | [diff] [blame] | 493 | bool __ret; \ |
| 494 | typeof(pcp1) __o1 = (o1), __n1 = (n1); \ |
| 495 | typeof(pcp2) __o2 = (o2), __n2 = (n2); \ |
| 496 | alternative_io("leaq %P1,%%rsi\n\tcall this_cpu_cmpxchg16b_emu\n\t", \ |
| 497 | "cmpxchg16b " __percpu_arg(1) "\n\tsetz %0\n\t", \ |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 498 | X86_FEATURE_CX16, \ |
Jan Beulich | cebef5b | 2011-12-14 08:33:25 +0000 | [diff] [blame] | 499 | ASM_OUTPUT2("=a" (__ret), "+m" (pcp1), \ |
| 500 | "+m" (pcp2), "+d" (__o2)), \ |
| 501 | "b" (__n1), "c" (__n2), "a" (__o1) : "rsi"); \ |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 502 | __ret; \ |
| 503 | }) |
| 504 | |
Christoph Lameter | b3ca1c1 | 2014-04-07 15:39:34 -0700 | [diff] [blame] | 505 | #define raw_cpu_cmpxchg_double_8 percpu_cmpxchg16b_double |
Jan Beulich | cebef5b | 2011-12-14 08:33:25 +0000 | [diff] [blame] | 506 | #define this_cpu_cmpxchg_double_8 percpu_cmpxchg16b_double |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 507 | |
Christoph Lameter | 30ed1a7 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 508 | #endif |
| 509 | |
Tejun Heo | 49357d1 | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 510 | /* This is not atomic against other CPUs -- CPU preemption needs to be off */ |
| 511 | #define x86_test_and_clear_bit_percpu(bit, var) \ |
| 512 | ({ \ |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 513 | bool old__; \ |
H. Peter Anvin | 64be6d3 | 2016-06-08 12:38:43 -0700 | [diff] [blame] | 514 | asm volatile("btr %2,"__percpu_arg(1)"\n\t" \ |
| 515 | CC_SET(c) \ |
| 516 | : CC_OUT(c) (old__), "+m" (var) \ |
Brian Gerst | 87b2640 | 2009-01-19 00:38:59 +0900 | [diff] [blame] | 517 | : "dIr" (bit)); \ |
Tejun Heo | 49357d1 | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 518 | old__; \ |
| 519 | }) |
| 520 | |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 521 | static __always_inline bool x86_this_cpu_constant_test_bit(unsigned int nr, |
Christoph Lameter | 349c004 | 2011-03-12 12:50:10 +0100 | [diff] [blame] | 522 | const unsigned long __percpu *addr) |
| 523 | { |
Lance Richardson | 799bc3c | 2016-09-22 10:03:57 -0400 | [diff] [blame] | 524 | unsigned long __percpu *a = |
| 525 | (unsigned long __percpu *)addr + nr / BITS_PER_LONG; |
Christoph Lameter | 349c004 | 2011-03-12 12:50:10 +0100 | [diff] [blame] | 526 | |
Alex Shi | 641b695 | 2012-05-14 14:15:32 -0700 | [diff] [blame] | 527 | #ifdef CONFIG_X86_64 |
Christoph Lameter | b3ca1c1 | 2014-04-07 15:39:34 -0700 | [diff] [blame] | 528 | return ((1UL << (nr % BITS_PER_LONG)) & raw_cpu_read_8(*a)) != 0; |
Alex Shi | 641b695 | 2012-05-14 14:15:32 -0700 | [diff] [blame] | 529 | #else |
Christoph Lameter | b3ca1c1 | 2014-04-07 15:39:34 -0700 | [diff] [blame] | 530 | return ((1UL << (nr % BITS_PER_LONG)) & raw_cpu_read_4(*a)) != 0; |
Alex Shi | 641b695 | 2012-05-14 14:15:32 -0700 | [diff] [blame] | 531 | #endif |
Christoph Lameter | 349c004 | 2011-03-12 12:50:10 +0100 | [diff] [blame] | 532 | } |
| 533 | |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 534 | static inline bool x86_this_cpu_variable_test_bit(int nr, |
Christoph Lameter | 349c004 | 2011-03-12 12:50:10 +0100 | [diff] [blame] | 535 | const unsigned long __percpu *addr) |
| 536 | { |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 537 | bool oldbit; |
Christoph Lameter | 349c004 | 2011-03-12 12:50:10 +0100 | [diff] [blame] | 538 | |
| 539 | asm volatile("bt "__percpu_arg(2)",%1\n\t" |
H. Peter Anvin | 64be6d3 | 2016-06-08 12:38:43 -0700 | [diff] [blame] | 540 | CC_SET(c) |
| 541 | : CC_OUT(c) (oldbit) |
Lance Richardson | 799bc3c | 2016-09-22 10:03:57 -0400 | [diff] [blame] | 542 | : "m" (*(unsigned long __percpu *)addr), "Ir" (nr)); |
Christoph Lameter | 349c004 | 2011-03-12 12:50:10 +0100 | [diff] [blame] | 543 | |
| 544 | return oldbit; |
| 545 | } |
| 546 | |
| 547 | #define x86_this_cpu_test_bit(nr, addr) \ |
| 548 | (__builtin_constant_p((nr)) \ |
| 549 | ? x86_this_cpu_constant_test_bit((nr), (addr)) \ |
| 550 | : x86_this_cpu_variable_test_bit((nr), (addr))) |
| 551 | |
| 552 | |
Ingo Molnar | 6dbde35 | 2009-01-15 22:15:53 +0900 | [diff] [blame] | 553 | #include <asm-generic/percpu.h> |
| 554 | |
| 555 | /* We can use this directly for local CPU (faster). */ |
Jan Beulich | 2c773dd | 2014-11-04 08:26:42 +0000 | [diff] [blame] | 556 | DECLARE_PER_CPU_READ_MOSTLY(unsigned long, this_cpu_off); |
Ingo Molnar | 6dbde35 | 2009-01-15 22:15:53 +0900 | [diff] [blame] | 557 | |
travis@sgi.com | 3334052 | 2008-01-30 13:32:53 +0100 | [diff] [blame] | 558 | #endif /* !__ASSEMBLY__ */ |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 559 | |
| 560 | #ifdef CONFIG_SMP |
| 561 | |
| 562 | /* |
| 563 | * Define the "EARLY_PER_CPU" macros. These are used for some per_cpu |
| 564 | * variables that are initialized and accessed before there are per_cpu |
| 565 | * areas allocated. |
| 566 | */ |
| 567 | |
| 568 | #define DEFINE_EARLY_PER_CPU(_type, _name, _initvalue) \ |
| 569 | DEFINE_PER_CPU(_type, _name) = _initvalue; \ |
| 570 | __typeof__(_type) _name##_early_map[NR_CPUS] __initdata = \ |
| 571 | { [0 ... NR_CPUS-1] = _initvalue }; \ |
Marcin Slusarz | c6a92a2 | 2008-08-17 17:50:50 +0200 | [diff] [blame] | 572 | __typeof__(_type) *_name##_early_ptr __refdata = _name##_early_map |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 573 | |
Ido Yariv | c35f774 | 2012-06-11 12:56:45 +0300 | [diff] [blame] | 574 | #define DEFINE_EARLY_PER_CPU_READ_MOSTLY(_type, _name, _initvalue) \ |
| 575 | DEFINE_PER_CPU_READ_MOSTLY(_type, _name) = _initvalue; \ |
| 576 | __typeof__(_type) _name##_early_map[NR_CPUS] __initdata = \ |
| 577 | { [0 ... NR_CPUS-1] = _initvalue }; \ |
| 578 | __typeof__(_type) *_name##_early_ptr __refdata = _name##_early_map |
| 579 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 580 | #define EXPORT_EARLY_PER_CPU_SYMBOL(_name) \ |
| 581 | EXPORT_PER_CPU_SYMBOL(_name) |
| 582 | |
| 583 | #define DECLARE_EARLY_PER_CPU(_type, _name) \ |
| 584 | DECLARE_PER_CPU(_type, _name); \ |
| 585 | extern __typeof__(_type) *_name##_early_ptr; \ |
| 586 | extern __typeof__(_type) _name##_early_map[] |
| 587 | |
Ido Yariv | c35f774 | 2012-06-11 12:56:45 +0300 | [diff] [blame] | 588 | #define DECLARE_EARLY_PER_CPU_READ_MOSTLY(_type, _name) \ |
| 589 | DECLARE_PER_CPU_READ_MOSTLY(_type, _name); \ |
| 590 | extern __typeof__(_type) *_name##_early_ptr; \ |
| 591 | extern __typeof__(_type) _name##_early_map[] |
| 592 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 593 | #define early_per_cpu_ptr(_name) (_name##_early_ptr) |
| 594 | #define early_per_cpu_map(_name, _idx) (_name##_early_map[_idx]) |
| 595 | #define early_per_cpu(_name, _cpu) \ |
Tejun Heo | f10fcd4 | 2009-01-13 20:41:34 +0900 | [diff] [blame] | 596 | *(early_per_cpu_ptr(_name) ? \ |
| 597 | &early_per_cpu_ptr(_name)[_cpu] : \ |
| 598 | &per_cpu(_name, _cpu)) |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 599 | |
| 600 | #else /* !CONFIG_SMP */ |
| 601 | #define DEFINE_EARLY_PER_CPU(_type, _name, _initvalue) \ |
| 602 | DEFINE_PER_CPU(_type, _name) = _initvalue |
| 603 | |
Ido Yariv | c35f774 | 2012-06-11 12:56:45 +0300 | [diff] [blame] | 604 | #define DEFINE_EARLY_PER_CPU_READ_MOSTLY(_type, _name, _initvalue) \ |
| 605 | DEFINE_PER_CPU_READ_MOSTLY(_type, _name) = _initvalue |
| 606 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 607 | #define EXPORT_EARLY_PER_CPU_SYMBOL(_name) \ |
| 608 | EXPORT_PER_CPU_SYMBOL(_name) |
| 609 | |
| 610 | #define DECLARE_EARLY_PER_CPU(_type, _name) \ |
| 611 | DECLARE_PER_CPU(_type, _name) |
| 612 | |
Ido Yariv | c35f774 | 2012-06-11 12:56:45 +0300 | [diff] [blame] | 613 | #define DECLARE_EARLY_PER_CPU_READ_MOSTLY(_type, _name) \ |
| 614 | DECLARE_PER_CPU_READ_MOSTLY(_type, _name) |
| 615 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 616 | #define early_per_cpu(_name, _cpu) per_cpu(_name, _cpu) |
| 617 | #define early_per_cpu_ptr(_name) NULL |
| 618 | /* no early_per_cpu_map() */ |
| 619 | |
| 620 | #endif /* !CONFIG_SMP */ |
| 621 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 622 | #endif /* _ASM_X86_PERCPU_H */ |