percpu.h 19 KB

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