percpu.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. #ifndef __LINUX_PERCPU_H
  2. #define __LINUX_PERCPU_H
  3. #include <linux/preempt.h>
  4. #include <linux/smp.h>
  5. #include <linux/cpumask.h>
  6. #include <linux/pfn.h>
  7. #include <linux/init.h>
  8. #include <asm/percpu.h>
  9. /* enough to cover all DEFINE_PER_CPUs in modules */
  10. #ifdef CONFIG_MODULES
  11. #define PERCPU_MODULE_RESERVE (8 << 10)
  12. #else
  13. #define PERCPU_MODULE_RESERVE 0
  14. #endif
  15. #ifndef PERCPU_ENOUGH_ROOM
  16. #define PERCPU_ENOUGH_ROOM \
  17. (ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES) + \
  18. PERCPU_MODULE_RESERVE)
  19. #endif
  20. /*
  21. * Must be an lvalue. Since @var must be a simple identifier,
  22. * we force a syntax error here if it isn't.
  23. */
  24. #define get_cpu_var(var) (*({ \
  25. preempt_disable(); \
  26. &__get_cpu_var(var); }))
  27. /*
  28. * The weird & is necessary because sparse considers (void)(var) to be
  29. * a direct dereference of percpu variable (var).
  30. */
  31. #define put_cpu_var(var) do { \
  32. (void)&(var); \
  33. preempt_enable(); \
  34. } while (0)
  35. #ifdef CONFIG_SMP
  36. /* minimum unit size, also is the maximum supported allocation size */
  37. #define PCPU_MIN_UNIT_SIZE PFN_ALIGN(64 << 10)
  38. /*
  39. * PERCPU_DYNAMIC_RESERVE indicates the amount of free area to piggy
  40. * back on the first chunk for dynamic percpu allocation if arch is
  41. * manually allocating and mapping it for faster access (as a part of
  42. * large page mapping for example).
  43. *
  44. * The following values give between one and two pages of free space
  45. * after typical minimal boot (2-way SMP, single disk and NIC) with
  46. * both defconfig and a distro config on x86_64 and 32. More
  47. * intelligent way to determine this would be nice.
  48. */
  49. #if BITS_PER_LONG > 32
  50. #define PERCPU_DYNAMIC_RESERVE (20 << 10)
  51. #else
  52. #define PERCPU_DYNAMIC_RESERVE (12 << 10)
  53. #endif
  54. extern void *pcpu_base_addr;
  55. extern const unsigned long *pcpu_unit_offsets;
  56. struct pcpu_group_info {
  57. int nr_units; /* aligned # of units */
  58. unsigned long base_offset; /* base address offset */
  59. unsigned int *cpu_map; /* unit->cpu map, empty
  60. * entries contain NR_CPUS */
  61. };
  62. struct pcpu_alloc_info {
  63. size_t static_size;
  64. size_t reserved_size;
  65. size_t dyn_size;
  66. size_t unit_size;
  67. size_t atom_size;
  68. size_t alloc_size;
  69. size_t __ai_size; /* internal, don't use */
  70. int nr_groups; /* 0 if grouping unnecessary */
  71. struct pcpu_group_info groups[];
  72. };
  73. enum pcpu_fc {
  74. PCPU_FC_AUTO,
  75. PCPU_FC_EMBED,
  76. PCPU_FC_PAGE,
  77. PCPU_FC_NR,
  78. };
  79. extern const char *pcpu_fc_names[PCPU_FC_NR];
  80. extern enum pcpu_fc pcpu_chosen_fc;
  81. typedef void * (*pcpu_fc_alloc_fn_t)(unsigned int cpu, size_t size,
  82. size_t align);
  83. typedef void (*pcpu_fc_free_fn_t)(void *ptr, size_t size);
  84. typedef void (*pcpu_fc_populate_pte_fn_t)(unsigned long addr);
  85. typedef int (pcpu_fc_cpu_distance_fn_t)(unsigned int from, unsigned int to);
  86. extern struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups,
  87. int nr_units);
  88. extern void __init pcpu_free_alloc_info(struct pcpu_alloc_info *ai);
  89. extern struct pcpu_alloc_info * __init pcpu_build_alloc_info(
  90. size_t reserved_size, ssize_t dyn_size,
  91. size_t atom_size,
  92. pcpu_fc_cpu_distance_fn_t cpu_distance_fn);
  93. extern int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
  94. void *base_addr);
  95. #ifdef CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK
  96. extern int __init pcpu_embed_first_chunk(size_t reserved_size, ssize_t dyn_size,
  97. size_t atom_size,
  98. pcpu_fc_cpu_distance_fn_t cpu_distance_fn,
  99. pcpu_fc_alloc_fn_t alloc_fn,
  100. pcpu_fc_free_fn_t free_fn);
  101. #endif
  102. #ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
  103. extern int __init pcpu_page_first_chunk(size_t reserved_size,
  104. pcpu_fc_alloc_fn_t alloc_fn,
  105. pcpu_fc_free_fn_t free_fn,
  106. pcpu_fc_populate_pte_fn_t populate_pte_fn);
  107. #endif
  108. /*
  109. * Use this to get to a cpu's version of the per-cpu object
  110. * dynamically allocated. Non-atomic access to the current CPU's
  111. * version should probably be combined with get_cpu()/put_cpu().
  112. */
  113. #define per_cpu_ptr(ptr, cpu) SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)))
  114. extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align);
  115. #ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
  116. extern void __init setup_per_cpu_areas(void);
  117. #endif
  118. #else /* CONFIG_SMP */
  119. #define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); (ptr); })
  120. static inline void __init setup_per_cpu_areas(void) { }
  121. static inline void *pcpu_lpage_remapped(void *kaddr)
  122. {
  123. return NULL;
  124. }
  125. #endif /* CONFIG_SMP */
  126. extern void __percpu *__alloc_percpu(size_t size, size_t align);
  127. extern void free_percpu(void __percpu *__pdata);
  128. extern phys_addr_t per_cpu_ptr_to_phys(void *addr);
  129. #define alloc_percpu(type) \
  130. (typeof(type) __percpu *)__alloc_percpu(sizeof(type), __alignof__(type))
  131. /*
  132. * Optional methods for optimized non-lvalue per-cpu variable access.
  133. *
  134. * @var can be a percpu variable or a field of it and its size should
  135. * equal char, int or long. percpu_read() evaluates to a lvalue and
  136. * all others to void.
  137. *
  138. * These operations are guaranteed to be atomic w.r.t. preemption.
  139. * The generic versions use plain get/put_cpu_var(). Archs are
  140. * encouraged to implement single-instruction alternatives which don't
  141. * require preemption protection.
  142. */
  143. #ifndef percpu_read
  144. # define percpu_read(var) \
  145. ({ \
  146. typeof(var) *pr_ptr__ = &(var); \
  147. typeof(var) pr_ret__; \
  148. pr_ret__ = get_cpu_var(*pr_ptr__); \
  149. put_cpu_var(*pr_ptr__); \
  150. pr_ret__; \
  151. })
  152. #endif
  153. #define __percpu_generic_to_op(var, val, op) \
  154. do { \
  155. typeof(var) *pgto_ptr__ = &(var); \
  156. get_cpu_var(*pgto_ptr__) op val; \
  157. put_cpu_var(*pgto_ptr__); \
  158. } while (0)
  159. #ifndef percpu_write
  160. # define percpu_write(var, val) __percpu_generic_to_op(var, (val), =)
  161. #endif
  162. #ifndef percpu_add
  163. # define percpu_add(var, val) __percpu_generic_to_op(var, (val), +=)
  164. #endif
  165. #ifndef percpu_sub
  166. # define percpu_sub(var, val) __percpu_generic_to_op(var, (val), -=)
  167. #endif
  168. #ifndef percpu_and
  169. # define percpu_and(var, val) __percpu_generic_to_op(var, (val), &=)
  170. #endif
  171. #ifndef percpu_or
  172. # define percpu_or(var, val) __percpu_generic_to_op(var, (val), |=)
  173. #endif
  174. #ifndef percpu_xor
  175. # define percpu_xor(var, val) __percpu_generic_to_op(var, (val), ^=)
  176. #endif
  177. /*
  178. * Branching function to split up a function into a set of functions that
  179. * are called for different scalar sizes of the objects handled.
  180. */
  181. extern void __bad_size_call_parameter(void);
  182. #define __pcpu_size_call_return(stem, variable) \
  183. ({ typeof(variable) pscr_ret__; \
  184. __verify_pcpu_ptr(&(variable)); \
  185. switch(sizeof(variable)) { \
  186. case 1: pscr_ret__ = stem##1(variable);break; \
  187. case 2: pscr_ret__ = stem##2(variable);break; \
  188. case 4: pscr_ret__ = stem##4(variable);break; \
  189. case 8: pscr_ret__ = stem##8(variable);break; \
  190. default: \
  191. __bad_size_call_parameter();break; \
  192. } \
  193. pscr_ret__; \
  194. })
  195. #define __pcpu_size_call(stem, variable, ...) \
  196. do { \
  197. __verify_pcpu_ptr(&(variable)); \
  198. switch(sizeof(variable)) { \
  199. case 1: stem##1(variable, __VA_ARGS__);break; \
  200. case 2: stem##2(variable, __VA_ARGS__);break; \
  201. case 4: stem##4(variable, __VA_ARGS__);break; \
  202. case 8: stem##8(variable, __VA_ARGS__);break; \
  203. default: \
  204. __bad_size_call_parameter();break; \
  205. } \
  206. } while (0)
  207. /*
  208. * Optimized manipulation for memory allocated through the per cpu
  209. * allocator or for addresses of per cpu variables.
  210. *
  211. * These operation guarantee exclusivity of access for other operations
  212. * on the *same* processor. The assumption is that per cpu data is only
  213. * accessed by a single processor instance (the current one).
  214. *
  215. * The first group is used for accesses that must be done in a
  216. * preemption safe way since we know that the context is not preempt
  217. * safe. Interrupts may occur. If the interrupt modifies the variable
  218. * too then RMW actions will not be reliable.
  219. *
  220. * The arch code can provide optimized functions in two ways:
  221. *
  222. * 1. Override the function completely. F.e. define this_cpu_add().
  223. * The arch must then ensure that the various scalar format passed
  224. * are handled correctly.
  225. *
  226. * 2. Provide functions for certain scalar sizes. F.e. provide
  227. * this_cpu_add_2() to provide per cpu atomic operations for 2 byte
  228. * sized RMW actions. If arch code does not provide operations for
  229. * a scalar size then the fallback in the generic code will be
  230. * used.
  231. */
  232. #define _this_cpu_generic_read(pcp) \
  233. ({ typeof(pcp) ret__; \
  234. preempt_disable(); \
  235. ret__ = *this_cpu_ptr(&(pcp)); \
  236. preempt_enable(); \
  237. ret__; \
  238. })
  239. #ifndef this_cpu_read
  240. # ifndef this_cpu_read_1
  241. # define this_cpu_read_1(pcp) _this_cpu_generic_read(pcp)
  242. # endif
  243. # ifndef this_cpu_read_2
  244. # define this_cpu_read_2(pcp) _this_cpu_generic_read(pcp)
  245. # endif
  246. # ifndef this_cpu_read_4
  247. # define this_cpu_read_4(pcp) _this_cpu_generic_read(pcp)
  248. # endif
  249. # ifndef this_cpu_read_8
  250. # define this_cpu_read_8(pcp) _this_cpu_generic_read(pcp)
  251. # endif
  252. # define this_cpu_read(pcp) __pcpu_size_call_return(this_cpu_read_, (pcp))
  253. #endif
  254. #define _this_cpu_generic_to_op(pcp, val, op) \
  255. do { \
  256. preempt_disable(); \
  257. *__this_cpu_ptr(&(pcp)) op val; \
  258. preempt_enable(); \
  259. } while (0)
  260. #ifndef this_cpu_write
  261. # ifndef this_cpu_write_1
  262. # define this_cpu_write_1(pcp, val) _this_cpu_generic_to_op((pcp), (val), =)
  263. # endif
  264. # ifndef this_cpu_write_2
  265. # define this_cpu_write_2(pcp, val) _this_cpu_generic_to_op((pcp), (val), =)
  266. # endif
  267. # ifndef this_cpu_write_4
  268. # define this_cpu_write_4(pcp, val) _this_cpu_generic_to_op((pcp), (val), =)
  269. # endif
  270. # ifndef this_cpu_write_8
  271. # define this_cpu_write_8(pcp, val) _this_cpu_generic_to_op((pcp), (val), =)
  272. # endif
  273. # define this_cpu_write(pcp, val) __pcpu_size_call(this_cpu_write_, (pcp), (val))
  274. #endif
  275. #ifndef this_cpu_add
  276. # ifndef this_cpu_add_1
  277. # define this_cpu_add_1(pcp, val) _this_cpu_generic_to_op((pcp), (val), +=)
  278. # endif
  279. # ifndef this_cpu_add_2
  280. # define this_cpu_add_2(pcp, val) _this_cpu_generic_to_op((pcp), (val), +=)
  281. # endif
  282. # ifndef this_cpu_add_4
  283. # define this_cpu_add_4(pcp, val) _this_cpu_generic_to_op((pcp), (val), +=)
  284. # endif
  285. # ifndef this_cpu_add_8
  286. # define this_cpu_add_8(pcp, val) _this_cpu_generic_to_op((pcp), (val), +=)
  287. # endif
  288. # define this_cpu_add(pcp, val) __pcpu_size_call(this_cpu_add_, (pcp), (val))
  289. #endif
  290. #ifndef this_cpu_sub
  291. # define this_cpu_sub(pcp, val) this_cpu_add((pcp), -(val))
  292. #endif
  293. #ifndef this_cpu_inc
  294. # define this_cpu_inc(pcp) this_cpu_add((pcp), 1)
  295. #endif
  296. #ifndef this_cpu_dec
  297. # define this_cpu_dec(pcp) this_cpu_sub((pcp), 1)
  298. #endif
  299. #ifndef this_cpu_and
  300. # ifndef this_cpu_and_1
  301. # define this_cpu_and_1(pcp, val) _this_cpu_generic_to_op((pcp), (val), &=)
  302. # endif
  303. # ifndef this_cpu_and_2
  304. # define this_cpu_and_2(pcp, val) _this_cpu_generic_to_op((pcp), (val), &=)
  305. # endif
  306. # ifndef this_cpu_and_4
  307. # define this_cpu_and_4(pcp, val) _this_cpu_generic_to_op((pcp), (val), &=)
  308. # endif
  309. # ifndef this_cpu_and_8
  310. # define this_cpu_and_8(pcp, val) _this_cpu_generic_to_op((pcp), (val), &=)
  311. # endif
  312. # define this_cpu_and(pcp, val) __pcpu_size_call(this_cpu_and_, (pcp), (val))
  313. #endif
  314. #ifndef this_cpu_or
  315. # ifndef this_cpu_or_1
  316. # define this_cpu_or_1(pcp, val) _this_cpu_generic_to_op((pcp), (val), |=)
  317. # endif
  318. # ifndef this_cpu_or_2
  319. # define this_cpu_or_2(pcp, val) _this_cpu_generic_to_op((pcp), (val), |=)
  320. # endif
  321. # ifndef this_cpu_or_4
  322. # define this_cpu_or_4(pcp, val) _this_cpu_generic_to_op((pcp), (val), |=)
  323. # endif
  324. # ifndef this_cpu_or_8
  325. # define this_cpu_or_8(pcp, val) _this_cpu_generic_to_op((pcp), (val), |=)
  326. # endif
  327. # define this_cpu_or(pcp, val) __pcpu_size_call(this_cpu_or_, (pcp), (val))
  328. #endif
  329. #ifndef this_cpu_xor
  330. # ifndef this_cpu_xor_1
  331. # define this_cpu_xor_1(pcp, val) _this_cpu_generic_to_op((pcp), (val), ^=)
  332. # endif
  333. # ifndef this_cpu_xor_2
  334. # define this_cpu_xor_2(pcp, val) _this_cpu_generic_to_op((pcp), (val), ^=)
  335. # endif
  336. # ifndef this_cpu_xor_4
  337. # define this_cpu_xor_4(pcp, val) _this_cpu_generic_to_op((pcp), (val), ^=)
  338. # endif
  339. # ifndef this_cpu_xor_8
  340. # define this_cpu_xor_8(pcp, val) _this_cpu_generic_to_op((pcp), (val), ^=)
  341. # endif
  342. # define this_cpu_xor(pcp, val) __pcpu_size_call(this_cpu_or_, (pcp), (val))
  343. #endif
  344. /*
  345. * Generic percpu operations that do not require preemption handling.
  346. * Either we do not care about races or the caller has the
  347. * responsibility of handling preemptions issues. Arch code can still
  348. * override these instructions since the arch per cpu code may be more
  349. * efficient and may actually get race freeness for free (that is the
  350. * case for x86 for example).
  351. *
  352. * If there is no other protection through preempt disable and/or
  353. * disabling interupts then one of these RMW operations can show unexpected
  354. * behavior because the execution thread was rescheduled on another processor
  355. * or an interrupt occurred and the same percpu variable was modified from
  356. * the interrupt context.
  357. */
  358. #ifndef __this_cpu_read
  359. # ifndef __this_cpu_read_1
  360. # define __this_cpu_read_1(pcp) (*__this_cpu_ptr(&(pcp)))
  361. # endif
  362. # ifndef __this_cpu_read_2
  363. # define __this_cpu_read_2(pcp) (*__this_cpu_ptr(&(pcp)))
  364. # endif
  365. # ifndef __this_cpu_read_4
  366. # define __this_cpu_read_4(pcp) (*__this_cpu_ptr(&(pcp)))
  367. # endif
  368. # ifndef __this_cpu_read_8
  369. # define __this_cpu_read_8(pcp) (*__this_cpu_ptr(&(pcp)))
  370. # endif
  371. # define __this_cpu_read(pcp) __pcpu_size_call_return(__this_cpu_read_, (pcp))
  372. #endif
  373. #define __this_cpu_generic_to_op(pcp, val, op) \
  374. do { \
  375. *__this_cpu_ptr(&(pcp)) op val; \
  376. } while (0)
  377. #ifndef __this_cpu_write
  378. # ifndef __this_cpu_write_1
  379. # define __this_cpu_write_1(pcp, val) __this_cpu_generic_to_op((pcp), (val), =)
  380. # endif
  381. # ifndef __this_cpu_write_2
  382. # define __this_cpu_write_2(pcp, val) __this_cpu_generic_to_op((pcp), (val), =)
  383. # endif
  384. # ifndef __this_cpu_write_4
  385. # define __this_cpu_write_4(pcp, val) __this_cpu_generic_to_op((pcp), (val), =)
  386. # endif
  387. # ifndef __this_cpu_write_8
  388. # define __this_cpu_write_8(pcp, val) __this_cpu_generic_to_op((pcp), (val), =)
  389. # endif
  390. # define __this_cpu_write(pcp, val) __pcpu_size_call(__this_cpu_write_, (pcp), (val))
  391. #endif
  392. #ifndef __this_cpu_add
  393. # ifndef __this_cpu_add_1
  394. # define __this_cpu_add_1(pcp, val) __this_cpu_generic_to_op((pcp), (val), +=)
  395. # endif
  396. # ifndef __this_cpu_add_2
  397. # define __this_cpu_add_2(pcp, val) __this_cpu_generic_to_op((pcp), (val), +=)
  398. # endif
  399. # ifndef __this_cpu_add_4
  400. # define __this_cpu_add_4(pcp, val) __this_cpu_generic_to_op((pcp), (val), +=)
  401. # endif
  402. # ifndef __this_cpu_add_8
  403. # define __this_cpu_add_8(pcp, val) __this_cpu_generic_to_op((pcp), (val), +=)
  404. # endif
  405. # define __this_cpu_add(pcp, val) __pcpu_size_call(__this_cpu_add_, (pcp), (val))
  406. #endif
  407. #ifndef __this_cpu_sub
  408. # define __this_cpu_sub(pcp, val) __this_cpu_add((pcp), -(val))
  409. #endif
  410. #ifndef __this_cpu_inc
  411. # define __this_cpu_inc(pcp) __this_cpu_add((pcp), 1)
  412. #endif
  413. #ifndef __this_cpu_dec
  414. # define __this_cpu_dec(pcp) __this_cpu_sub((pcp), 1)
  415. #endif
  416. #ifndef __this_cpu_and
  417. # ifndef __this_cpu_and_1
  418. # define __this_cpu_and_1(pcp, val) __this_cpu_generic_to_op((pcp), (val), &=)
  419. # endif
  420. # ifndef __this_cpu_and_2
  421. # define __this_cpu_and_2(pcp, val) __this_cpu_generic_to_op((pcp), (val), &=)
  422. # endif
  423. # ifndef __this_cpu_and_4
  424. # define __this_cpu_and_4(pcp, val) __this_cpu_generic_to_op((pcp), (val), &=)
  425. # endif
  426. # ifndef __this_cpu_and_8
  427. # define __this_cpu_and_8(pcp, val) __this_cpu_generic_to_op((pcp), (val), &=)
  428. # endif
  429. # define __this_cpu_and(pcp, val) __pcpu_size_call(__this_cpu_and_, (pcp), (val))
  430. #endif
  431. #ifndef __this_cpu_or
  432. # ifndef __this_cpu_or_1
  433. # define __this_cpu_or_1(pcp, val) __this_cpu_generic_to_op((pcp), (val), |=)
  434. # endif
  435. # ifndef __this_cpu_or_2
  436. # define __this_cpu_or_2(pcp, val) __this_cpu_generic_to_op((pcp), (val), |=)
  437. # endif
  438. # ifndef __this_cpu_or_4
  439. # define __this_cpu_or_4(pcp, val) __this_cpu_generic_to_op((pcp), (val), |=)
  440. # endif
  441. # ifndef __this_cpu_or_8
  442. # define __this_cpu_or_8(pcp, val) __this_cpu_generic_to_op((pcp), (val), |=)
  443. # endif
  444. # define __this_cpu_or(pcp, val) __pcpu_size_call(__this_cpu_or_, (pcp), (val))
  445. #endif
  446. #ifndef __this_cpu_xor
  447. # ifndef __this_cpu_xor_1
  448. # define __this_cpu_xor_1(pcp, val) __this_cpu_generic_to_op((pcp), (val), ^=)
  449. # endif
  450. # ifndef __this_cpu_xor_2
  451. # define __this_cpu_xor_2(pcp, val) __this_cpu_generic_to_op((pcp), (val), ^=)
  452. # endif
  453. # ifndef __this_cpu_xor_4
  454. # define __this_cpu_xor_4(pcp, val) __this_cpu_generic_to_op((pcp), (val), ^=)
  455. # endif
  456. # ifndef __this_cpu_xor_8
  457. # define __this_cpu_xor_8(pcp, val) __this_cpu_generic_to_op((pcp), (val), ^=)
  458. # endif
  459. # define __this_cpu_xor(pcp, val) __pcpu_size_call(__this_cpu_xor_, (pcp), (val))
  460. #endif
  461. /*
  462. * IRQ safe versions of the per cpu RMW operations. Note that these operations
  463. * are *not* safe against modification of the same variable from another
  464. * processors (which one gets when using regular atomic operations)
  465. . They are guaranteed to be atomic vs. local interrupts and
  466. * preemption only.
  467. */
  468. #define irqsafe_cpu_generic_to_op(pcp, val, op) \
  469. do { \
  470. unsigned long flags; \
  471. local_irq_save(flags); \
  472. *__this_cpu_ptr(&(pcp)) op val; \
  473. local_irq_restore(flags); \
  474. } while (0)
  475. #ifndef irqsafe_cpu_add
  476. # ifndef irqsafe_cpu_add_1
  477. # define irqsafe_cpu_add_1(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), +=)
  478. # endif
  479. # ifndef irqsafe_cpu_add_2
  480. # define irqsafe_cpu_add_2(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), +=)
  481. # endif
  482. # ifndef irqsafe_cpu_add_4
  483. # define irqsafe_cpu_add_4(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), +=)
  484. # endif
  485. # ifndef irqsafe_cpu_add_8
  486. # define irqsafe_cpu_add_8(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), +=)
  487. # endif
  488. # define irqsafe_cpu_add(pcp, val) __pcpu_size_call(irqsafe_cpu_add_, (pcp), (val))
  489. #endif
  490. #ifndef irqsafe_cpu_sub
  491. # define irqsafe_cpu_sub(pcp, val) irqsafe_cpu_add((pcp), -(val))
  492. #endif
  493. #ifndef irqsafe_cpu_inc
  494. # define irqsafe_cpu_inc(pcp) irqsafe_cpu_add((pcp), 1)
  495. #endif
  496. #ifndef irqsafe_cpu_dec
  497. # define irqsafe_cpu_dec(pcp) irqsafe_cpu_sub((pcp), 1)
  498. #endif
  499. #ifndef irqsafe_cpu_and
  500. # ifndef irqsafe_cpu_and_1
  501. # define irqsafe_cpu_and_1(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), &=)
  502. # endif
  503. # ifndef irqsafe_cpu_and_2
  504. # define irqsafe_cpu_and_2(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), &=)
  505. # endif
  506. # ifndef irqsafe_cpu_and_4
  507. # define irqsafe_cpu_and_4(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), &=)
  508. # endif
  509. # ifndef irqsafe_cpu_and_8
  510. # define irqsafe_cpu_and_8(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), &=)
  511. # endif
  512. # define irqsafe_cpu_and(pcp, val) __pcpu_size_call(irqsafe_cpu_and_, (val))
  513. #endif
  514. #ifndef irqsafe_cpu_or
  515. # ifndef irqsafe_cpu_or_1
  516. # define irqsafe_cpu_or_1(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), |=)
  517. # endif
  518. # ifndef irqsafe_cpu_or_2
  519. # define irqsafe_cpu_or_2(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), |=)
  520. # endif
  521. # ifndef irqsafe_cpu_or_4
  522. # define irqsafe_cpu_or_4(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), |=)
  523. # endif
  524. # ifndef irqsafe_cpu_or_8
  525. # define irqsafe_cpu_or_8(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), |=)
  526. # endif
  527. # define irqsafe_cpu_or(pcp, val) __pcpu_size_call(irqsafe_cpu_or_, (val))
  528. #endif
  529. #ifndef irqsafe_cpu_xor
  530. # ifndef irqsafe_cpu_xor_1
  531. # define irqsafe_cpu_xor_1(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), ^=)
  532. # endif
  533. # ifndef irqsafe_cpu_xor_2
  534. # define irqsafe_cpu_xor_2(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), ^=)
  535. # endif
  536. # ifndef irqsafe_cpu_xor_4
  537. # define irqsafe_cpu_xor_4(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), ^=)
  538. # endif
  539. # ifndef irqsafe_cpu_xor_8
  540. # define irqsafe_cpu_xor_8(pcp, val) irqsafe_cpu_generic_to_op((pcp), (val), ^=)
  541. # endif
  542. # define irqsafe_cpu_xor(pcp, val) __pcpu_size_call(irqsafe_cpu_xor_, (val))
  543. #endif
  544. #endif /* __LINUX_PERCPU_H */