percpu-defs.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. /*
  2. * linux/percpu-defs.h - basic definitions for percpu areas
  3. *
  4. * DO NOT INCLUDE DIRECTLY OUTSIDE PERCPU IMPLEMENTATION PROPER.
  5. *
  6. * This file is separate from linux/percpu.h to avoid cyclic inclusion
  7. * dependency from arch header files. Only to be included from
  8. * asm/percpu.h.
  9. *
  10. * This file includes macros necessary to declare percpu sections and
  11. * variables, and definitions of percpu accessors and operations. It
  12. * should provide enough percpu features to arch header files even when
  13. * they can only include asm/percpu.h to avoid cyclic inclusion dependency.
  14. */
  15. #ifndef _LINUX_PERCPU_DEFS_H
  16. #define _LINUX_PERCPU_DEFS_H
  17. #ifdef CONFIG_SMP
  18. #ifdef MODULE
  19. #define PER_CPU_SHARED_ALIGNED_SECTION ""
  20. #define PER_CPU_ALIGNED_SECTION ""
  21. #else
  22. #define PER_CPU_SHARED_ALIGNED_SECTION "..shared_aligned"
  23. #define PER_CPU_ALIGNED_SECTION "..shared_aligned"
  24. #endif
  25. #define PER_CPU_FIRST_SECTION "..first"
  26. #else
  27. #define PER_CPU_SHARED_ALIGNED_SECTION ""
  28. #define PER_CPU_ALIGNED_SECTION "..shared_aligned"
  29. #define PER_CPU_FIRST_SECTION ""
  30. #endif
  31. #ifdef CONFIG_PAGE_TABLE_ISOLATION
  32. #define USER_MAPPED_SECTION "..user_mapped"
  33. #else
  34. #define USER_MAPPED_SECTION ""
  35. #endif
  36. /*
  37. * Base implementations of per-CPU variable declarations and definitions, where
  38. * the section in which the variable is to be placed is provided by the
  39. * 'sec' argument. This may be used to affect the parameters governing the
  40. * variable's storage.
  41. *
  42. * NOTE! The sections for the DECLARE and for the DEFINE must match, lest
  43. * linkage errors occur due the compiler generating the wrong code to access
  44. * that section.
  45. */
  46. #define __PCPU_ATTRS(sec) \
  47. __percpu __attribute__((section(PER_CPU_BASE_SECTION sec))) \
  48. PER_CPU_ATTRIBUTES
  49. #define __PCPU_DUMMY_ATTRS \
  50. __attribute__((section(".discard"), unused))
  51. /*
  52. * s390 and alpha modules require percpu variables to be defined as
  53. * weak to force the compiler to generate GOT based external
  54. * references for them. This is necessary because percpu sections
  55. * will be located outside of the usually addressable area.
  56. *
  57. * This definition puts the following two extra restrictions when
  58. * defining percpu variables.
  59. *
  60. * 1. The symbol must be globally unique, even the static ones.
  61. * 2. Static percpu variables cannot be defined inside a function.
  62. *
  63. * Archs which need weak percpu definitions should define
  64. * ARCH_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary.
  65. *
  66. * To ensure that the generic code observes the above two
  67. * restrictions, if CONFIG_DEBUG_FORCE_WEAK_PER_CPU is set weak
  68. * definition is used for all cases.
  69. */
  70. #if defined(ARCH_NEEDS_WEAK_PER_CPU) || defined(CONFIG_DEBUG_FORCE_WEAK_PER_CPU)
  71. /*
  72. * __pcpu_scope_* dummy variable is used to enforce scope. It
  73. * receives the static modifier when it's used in front of
  74. * DEFINE_PER_CPU() and will trigger build failure if
  75. * DECLARE_PER_CPU() is used for the same variable.
  76. *
  77. * __pcpu_unique_* dummy variable is used to enforce symbol uniqueness
  78. * such that hidden weak symbol collision, which will cause unrelated
  79. * variables to share the same address, can be detected during build.
  80. */
  81. #define DECLARE_PER_CPU_SECTION(type, name, sec) \
  82. extern __PCPU_DUMMY_ATTRS char __pcpu_scope_##name; \
  83. extern __PCPU_ATTRS(sec) __typeof__(type) name
  84. #define DEFINE_PER_CPU_SECTION(type, name, sec) \
  85. __PCPU_DUMMY_ATTRS char __pcpu_scope_##name; \
  86. extern __PCPU_DUMMY_ATTRS char __pcpu_unique_##name; \
  87. __PCPU_DUMMY_ATTRS char __pcpu_unique_##name; \
  88. extern __PCPU_ATTRS(sec) __typeof__(type) name; \
  89. __PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES __weak \
  90. __typeof__(type) name
  91. #else
  92. /*
  93. * Normal declaration and definition macros.
  94. */
  95. #define DECLARE_PER_CPU_SECTION(type, name, sec) \
  96. extern __PCPU_ATTRS(sec) __typeof__(type) name
  97. #define DEFINE_PER_CPU_SECTION(type, name, sec) \
  98. __PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES \
  99. __typeof__(type) name
  100. #endif
  101. /*
  102. * Variant on the per-CPU variable declaration/definition theme used for
  103. * ordinary per-CPU variables.
  104. */
  105. #define DECLARE_PER_CPU(type, name) \
  106. DECLARE_PER_CPU_SECTION(type, name, "")
  107. #define DEFINE_PER_CPU(type, name) \
  108. DEFINE_PER_CPU_SECTION(type, name, "")
  109. #define DECLARE_PER_CPU_USER_MAPPED(type, name) \
  110. DECLARE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION)
  111. #define DEFINE_PER_CPU_USER_MAPPED(type, name) \
  112. DEFINE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION)
  113. /*
  114. * Declaration/definition used for per-CPU variables that must come first in
  115. * the set of variables.
  116. */
  117. #define DECLARE_PER_CPU_FIRST(type, name) \
  118. DECLARE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION)
  119. #define DEFINE_PER_CPU_FIRST(type, name) \
  120. DEFINE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION)
  121. /*
  122. * Declaration/definition used for per-CPU variables that must be cacheline
  123. * aligned under SMP conditions so that, whilst a particular instance of the
  124. * data corresponds to a particular CPU, inefficiencies due to direct access by
  125. * other CPUs are reduced by preventing the data from unnecessarily spanning
  126. * cachelines.
  127. *
  128. * An example of this would be statistical data, where each CPU's set of data
  129. * is updated by that CPU alone, but the data from across all CPUs is collated
  130. * by a CPU processing a read from a proc file.
  131. */
  132. #define DECLARE_PER_CPU_SHARED_ALIGNED(type, name) \
  133. DECLARE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \
  134. ____cacheline_aligned_in_smp
  135. #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name) \
  136. DEFINE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \
  137. ____cacheline_aligned_in_smp
  138. #define DECLARE_PER_CPU_SHARED_ALIGNED_USER_MAPPED(type, name) \
  139. DECLARE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION PER_CPU_SHARED_ALIGNED_SECTION) \
  140. ____cacheline_aligned_in_smp
  141. #define DEFINE_PER_CPU_SHARED_ALIGNED_USER_MAPPED(type, name) \
  142. DEFINE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION PER_CPU_SHARED_ALIGNED_SECTION) \
  143. ____cacheline_aligned_in_smp
  144. #define DECLARE_PER_CPU_ALIGNED(type, name) \
  145. DECLARE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION) \
  146. ____cacheline_aligned
  147. #define DEFINE_PER_CPU_ALIGNED(type, name) \
  148. DEFINE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION) \
  149. ____cacheline_aligned
  150. /*
  151. * Declaration/definition used for per-CPU variables that must be page aligned.
  152. */
  153. #define DECLARE_PER_CPU_PAGE_ALIGNED(type, name) \
  154. DECLARE_PER_CPU_SECTION(type, name, "..page_aligned") \
  155. __aligned(PAGE_SIZE)
  156. #define DEFINE_PER_CPU_PAGE_ALIGNED(type, name) \
  157. DEFINE_PER_CPU_SECTION(type, name, "..page_aligned") \
  158. __aligned(PAGE_SIZE)
  159. /*
  160. * Declaration/definition used for per-CPU variables that must be page aligned and need to be mapped in user mode.
  161. */
  162. #define DECLARE_PER_CPU_PAGE_ALIGNED_USER_MAPPED(type, name) \
  163. DECLARE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION"..page_aligned") \
  164. __aligned(PAGE_SIZE)
  165. #define DEFINE_PER_CPU_PAGE_ALIGNED_USER_MAPPED(type, name) \
  166. DEFINE_PER_CPU_SECTION(type, name, USER_MAPPED_SECTION"..page_aligned") \
  167. __aligned(PAGE_SIZE)
  168. /*
  169. * Declaration/definition used for per-CPU variables that must be read mostly.
  170. */
  171. #define DECLARE_PER_CPU_READ_MOSTLY(type, name) \
  172. DECLARE_PER_CPU_SECTION(type, name, "..read_mostly")
  173. #define DEFINE_PER_CPU_READ_MOSTLY(type, name) \
  174. DEFINE_PER_CPU_SECTION(type, name, "..read_mostly")
  175. /*
  176. * Intermodule exports for per-CPU variables. sparse forgets about
  177. * address space across EXPORT_SYMBOL(), change EXPORT_SYMBOL() to
  178. * noop if __CHECKER__.
  179. */
  180. #ifndef __CHECKER__
  181. #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(var)
  182. #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(var)
  183. #else
  184. #define EXPORT_PER_CPU_SYMBOL(var)
  185. #define EXPORT_PER_CPU_SYMBOL_GPL(var)
  186. #endif
  187. /*
  188. * Accessors and operations.
  189. */
  190. #ifndef __ASSEMBLY__
  191. /*
  192. * __verify_pcpu_ptr() verifies @ptr is a percpu pointer without evaluating
  193. * @ptr and is invoked once before a percpu area is accessed by all
  194. * accessors and operations. This is performed in the generic part of
  195. * percpu and arch overrides don't need to worry about it; however, if an
  196. * arch wants to implement an arch-specific percpu accessor or operation,
  197. * it may use __verify_pcpu_ptr() to verify the parameters.
  198. *
  199. * + 0 is required in order to convert the pointer type from a
  200. * potential array type to a pointer to a single item of the array.
  201. */
  202. #define __verify_pcpu_ptr(ptr) \
  203. do { \
  204. const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL; \
  205. (void)__vpp_verify; \
  206. } while (0)
  207. #ifdef CONFIG_SMP
  208. /*
  209. * Add an offset to a pointer but keep the pointer as-is. Use RELOC_HIDE()
  210. * to prevent the compiler from making incorrect assumptions about the
  211. * pointer value. The weird cast keeps both GCC and sparse happy.
  212. */
  213. #define SHIFT_PERCPU_PTR(__p, __offset) \
  214. RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
  215. #define per_cpu_ptr(ptr, cpu) \
  216. ({ \
  217. __verify_pcpu_ptr(ptr); \
  218. SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu))); \
  219. })
  220. #define raw_cpu_ptr(ptr) \
  221. ({ \
  222. __verify_pcpu_ptr(ptr); \
  223. arch_raw_cpu_ptr(ptr); \
  224. })
  225. #ifdef CONFIG_DEBUG_PREEMPT
  226. #define this_cpu_ptr(ptr) \
  227. ({ \
  228. __verify_pcpu_ptr(ptr); \
  229. SHIFT_PERCPU_PTR(ptr, my_cpu_offset); \
  230. })
  231. #else
  232. #define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
  233. #endif
  234. #else /* CONFIG_SMP */
  235. #define VERIFY_PERCPU_PTR(__p) \
  236. ({ \
  237. __verify_pcpu_ptr(__p); \
  238. (typeof(*(__p)) __kernel __force *)(__p); \
  239. })
  240. #define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); VERIFY_PERCPU_PTR(ptr); })
  241. #define raw_cpu_ptr(ptr) per_cpu_ptr(ptr, 0)
  242. #define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
  243. #endif /* CONFIG_SMP */
  244. #define per_cpu(var, cpu) (*per_cpu_ptr(&(var), cpu))
  245. /*
  246. * Must be an lvalue. Since @var must be a simple identifier,
  247. * we force a syntax error here if it isn't.
  248. */
  249. #define get_cpu_var(var) \
  250. (*({ \
  251. preempt_disable(); \
  252. this_cpu_ptr(&var); \
  253. }))
  254. /*
  255. * The weird & is necessary because sparse considers (void)(var) to be
  256. * a direct dereference of percpu variable (var).
  257. */
  258. #define put_cpu_var(var) \
  259. do { \
  260. (void)&(var); \
  261. preempt_enable(); \
  262. } while (0)
  263. #define get_cpu_ptr(var) \
  264. ({ \
  265. preempt_disable(); \
  266. this_cpu_ptr(var); \
  267. })
  268. #define put_cpu_ptr(var) \
  269. do { \
  270. (void)(var); \
  271. preempt_enable(); \
  272. } while (0)
  273. /*
  274. * Branching function to split up a function into a set of functions that
  275. * are called for different scalar sizes of the objects handled.
  276. */
  277. extern void __bad_size_call_parameter(void);
  278. #ifdef CONFIG_DEBUG_PREEMPT
  279. extern void __this_cpu_preempt_check(const char *op);
  280. #else
  281. static inline void __this_cpu_preempt_check(const char *op) { }
  282. #endif
  283. #define __pcpu_size_call_return(stem, variable) \
  284. ({ \
  285. typeof(variable) pscr_ret__; \
  286. __verify_pcpu_ptr(&(variable)); \
  287. switch(sizeof(variable)) { \
  288. case 1: pscr_ret__ = stem##1(variable); break; \
  289. case 2: pscr_ret__ = stem##2(variable); break; \
  290. case 4: pscr_ret__ = stem##4(variable); break; \
  291. case 8: pscr_ret__ = stem##8(variable); break; \
  292. default: \
  293. __bad_size_call_parameter(); break; \
  294. } \
  295. pscr_ret__; \
  296. })
  297. #define __pcpu_size_call_return2(stem, variable, ...) \
  298. ({ \
  299. typeof(variable) pscr2_ret__; \
  300. __verify_pcpu_ptr(&(variable)); \
  301. switch(sizeof(variable)) { \
  302. case 1: pscr2_ret__ = stem##1(variable, __VA_ARGS__); break; \
  303. case 2: pscr2_ret__ = stem##2(variable, __VA_ARGS__); break; \
  304. case 4: pscr2_ret__ = stem##4(variable, __VA_ARGS__); break; \
  305. case 8: pscr2_ret__ = stem##8(variable, __VA_ARGS__); break; \
  306. default: \
  307. __bad_size_call_parameter(); break; \
  308. } \
  309. pscr2_ret__; \
  310. })
  311. /*
  312. * Special handling for cmpxchg_double. cmpxchg_double is passed two
  313. * percpu variables. The first has to be aligned to a double word
  314. * boundary and the second has to follow directly thereafter.
  315. * We enforce this on all architectures even if they don't support
  316. * a double cmpxchg instruction, since it's a cheap requirement, and it
  317. * avoids breaking the requirement for architectures with the instruction.
  318. */
  319. #define __pcpu_double_call_return_bool(stem, pcp1, pcp2, ...) \
  320. ({ \
  321. bool pdcrb_ret__; \
  322. __verify_pcpu_ptr(&(pcp1)); \
  323. BUILD_BUG_ON(sizeof(pcp1) != sizeof(pcp2)); \
  324. VM_BUG_ON((unsigned long)(&(pcp1)) % (2 * sizeof(pcp1))); \
  325. VM_BUG_ON((unsigned long)(&(pcp2)) != \
  326. (unsigned long)(&(pcp1)) + sizeof(pcp1)); \
  327. switch(sizeof(pcp1)) { \
  328. case 1: pdcrb_ret__ = stem##1(pcp1, pcp2, __VA_ARGS__); break; \
  329. case 2: pdcrb_ret__ = stem##2(pcp1, pcp2, __VA_ARGS__); break; \
  330. case 4: pdcrb_ret__ = stem##4(pcp1, pcp2, __VA_ARGS__); break; \
  331. case 8: pdcrb_ret__ = stem##8(pcp1, pcp2, __VA_ARGS__); break; \
  332. default: \
  333. __bad_size_call_parameter(); break; \
  334. } \
  335. pdcrb_ret__; \
  336. })
  337. #define __pcpu_size_call(stem, variable, ...) \
  338. do { \
  339. __verify_pcpu_ptr(&(variable)); \
  340. switch(sizeof(variable)) { \
  341. case 1: stem##1(variable, __VA_ARGS__);break; \
  342. case 2: stem##2(variable, __VA_ARGS__);break; \
  343. case 4: stem##4(variable, __VA_ARGS__);break; \
  344. case 8: stem##8(variable, __VA_ARGS__);break; \
  345. default: \
  346. __bad_size_call_parameter();break; \
  347. } \
  348. } while (0)
  349. /*
  350. * this_cpu operations (C) 2008-2013 Christoph Lameter <cl@linux.com>
  351. *
  352. * Optimized manipulation for memory allocated through the per cpu
  353. * allocator or for addresses of per cpu variables.
  354. *
  355. * These operation guarantee exclusivity of access for other operations
  356. * on the *same* processor. The assumption is that per cpu data is only
  357. * accessed by a single processor instance (the current one).
  358. *
  359. * The arch code can provide optimized implementation by defining macros
  360. * for certain scalar sizes. F.e. provide this_cpu_add_2() to provide per
  361. * cpu atomic operations for 2 byte sized RMW actions. If arch code does
  362. * not provide operations for a scalar size then the fallback in the
  363. * generic code will be used.
  364. *
  365. * cmpxchg_double replaces two adjacent scalars at once. The first two
  366. * parameters are per cpu variables which have to be of the same size. A
  367. * truth value is returned to indicate success or failure (since a double
  368. * register result is difficult to handle). There is very limited hardware
  369. * support for these operations, so only certain sizes may work.
  370. */
  371. /*
  372. * Operations for contexts where we do not want to do any checks for
  373. * preemptions. Unless strictly necessary, always use [__]this_cpu_*()
  374. * instead.
  375. *
  376. * If there is no other protection through preempt disable and/or disabling
  377. * interupts then one of these RMW operations can show unexpected behavior
  378. * because the execution thread was rescheduled on another processor or an
  379. * interrupt occurred and the same percpu variable was modified from the
  380. * interrupt context.
  381. */
  382. #define raw_cpu_read(pcp) __pcpu_size_call_return(raw_cpu_read_, pcp)
  383. #define raw_cpu_write(pcp, val) __pcpu_size_call(raw_cpu_write_, pcp, val)
  384. #define raw_cpu_add(pcp, val) __pcpu_size_call(raw_cpu_add_, pcp, val)
  385. #define raw_cpu_and(pcp, val) __pcpu_size_call(raw_cpu_and_, pcp, val)
  386. #define raw_cpu_or(pcp, val) __pcpu_size_call(raw_cpu_or_, pcp, val)
  387. #define raw_cpu_add_return(pcp, val) __pcpu_size_call_return2(raw_cpu_add_return_, pcp, val)
  388. #define raw_cpu_xchg(pcp, nval) __pcpu_size_call_return2(raw_cpu_xchg_, pcp, nval)
  389. #define raw_cpu_cmpxchg(pcp, oval, nval) \
  390. __pcpu_size_call_return2(raw_cpu_cmpxchg_, pcp, oval, nval)
  391. #define raw_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) \
  392. __pcpu_double_call_return_bool(raw_cpu_cmpxchg_double_, pcp1, pcp2, oval1, oval2, nval1, nval2)
  393. #define raw_cpu_sub(pcp, val) raw_cpu_add(pcp, -(val))
  394. #define raw_cpu_inc(pcp) raw_cpu_add(pcp, 1)
  395. #define raw_cpu_dec(pcp) raw_cpu_sub(pcp, 1)
  396. #define raw_cpu_sub_return(pcp, val) raw_cpu_add_return(pcp, -(typeof(pcp))(val))
  397. #define raw_cpu_inc_return(pcp) raw_cpu_add_return(pcp, 1)
  398. #define raw_cpu_dec_return(pcp) raw_cpu_add_return(pcp, -1)
  399. /*
  400. * Operations for contexts that are safe from preemption/interrupts. These
  401. * operations verify that preemption is disabled.
  402. */
  403. #define __this_cpu_read(pcp) \
  404. ({ \
  405. __this_cpu_preempt_check("read"); \
  406. raw_cpu_read(pcp); \
  407. })
  408. #define __this_cpu_write(pcp, val) \
  409. ({ \
  410. __this_cpu_preempt_check("write"); \
  411. raw_cpu_write(pcp, val); \
  412. })
  413. #define __this_cpu_add(pcp, val) \
  414. ({ \
  415. __this_cpu_preempt_check("add"); \
  416. raw_cpu_add(pcp, val); \
  417. })
  418. #define __this_cpu_and(pcp, val) \
  419. ({ \
  420. __this_cpu_preempt_check("and"); \
  421. raw_cpu_and(pcp, val); \
  422. })
  423. #define __this_cpu_or(pcp, val) \
  424. ({ \
  425. __this_cpu_preempt_check("or"); \
  426. raw_cpu_or(pcp, val); \
  427. })
  428. #define __this_cpu_add_return(pcp, val) \
  429. ({ \
  430. __this_cpu_preempt_check("add_return"); \
  431. raw_cpu_add_return(pcp, val); \
  432. })
  433. #define __this_cpu_xchg(pcp, nval) \
  434. ({ \
  435. __this_cpu_preempt_check("xchg"); \
  436. raw_cpu_xchg(pcp, nval); \
  437. })
  438. #define __this_cpu_cmpxchg(pcp, oval, nval) \
  439. ({ \
  440. __this_cpu_preempt_check("cmpxchg"); \
  441. raw_cpu_cmpxchg(pcp, oval, nval); \
  442. })
  443. #define __this_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) \
  444. ({ __this_cpu_preempt_check("cmpxchg_double"); \
  445. raw_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2); \
  446. })
  447. #define __this_cpu_sub(pcp, val) __this_cpu_add(pcp, -(typeof(pcp))(val))
  448. #define __this_cpu_inc(pcp) __this_cpu_add(pcp, 1)
  449. #define __this_cpu_dec(pcp) __this_cpu_sub(pcp, 1)
  450. #define __this_cpu_sub_return(pcp, val) __this_cpu_add_return(pcp, -(typeof(pcp))(val))
  451. #define __this_cpu_inc_return(pcp) __this_cpu_add_return(pcp, 1)
  452. #define __this_cpu_dec_return(pcp) __this_cpu_add_return(pcp, -1)
  453. /*
  454. * Operations with implied preemption/interrupt protection. These
  455. * operations can be used without worrying about preemption or interrupt.
  456. */
  457. #define this_cpu_read(pcp) __pcpu_size_call_return(this_cpu_read_, pcp)
  458. #define this_cpu_write(pcp, val) __pcpu_size_call(this_cpu_write_, pcp, val)
  459. #define this_cpu_add(pcp, val) __pcpu_size_call(this_cpu_add_, pcp, val)
  460. #define this_cpu_and(pcp, val) __pcpu_size_call(this_cpu_and_, pcp, val)
  461. #define this_cpu_or(pcp, val) __pcpu_size_call(this_cpu_or_, pcp, val)
  462. #define this_cpu_add_return(pcp, val) __pcpu_size_call_return2(this_cpu_add_return_, pcp, val)
  463. #define this_cpu_xchg(pcp, nval) __pcpu_size_call_return2(this_cpu_xchg_, pcp, nval)
  464. #define this_cpu_cmpxchg(pcp, oval, nval) \
  465. __pcpu_size_call_return2(this_cpu_cmpxchg_, pcp, oval, nval)
  466. #define this_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) \
  467. __pcpu_double_call_return_bool(this_cpu_cmpxchg_double_, pcp1, pcp2, oval1, oval2, nval1, nval2)
  468. #define this_cpu_sub(pcp, val) this_cpu_add(pcp, -(typeof(pcp))(val))
  469. #define this_cpu_inc(pcp) this_cpu_add(pcp, 1)
  470. #define this_cpu_dec(pcp) this_cpu_sub(pcp, 1)
  471. #define this_cpu_sub_return(pcp, val) this_cpu_add_return(pcp, -(typeof(pcp))(val))
  472. #define this_cpu_inc_return(pcp) this_cpu_add_return(pcp, 1)
  473. #define this_cpu_dec_return(pcp) this_cpu_add_return(pcp, -1)
  474. #endif /* __ASSEMBLY__ */
  475. #endif /* _LINUX_PERCPU_DEFS_H */