percpu.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef _ASM_GENERIC_PERCPU_H_
  2. #define _ASM_GENERIC_PERCPU_H_
  3. #include <linux/compiler.h>
  4. #include <linux/threads.h>
  5. #include <linux/percpu-defs.h>
  6. #ifdef CONFIG_SMP
  7. /*
  8. * per_cpu_offset() is the offset that has to be added to a
  9. * percpu variable to get to the instance for a certain processor.
  10. *
  11. * Most arches use the __per_cpu_offset array for those offsets but
  12. * some arches have their own ways of determining the offset (x86_64, s390).
  13. */
  14. #ifndef __per_cpu_offset
  15. extern unsigned long __per_cpu_offset[NR_CPUS];
  16. #define per_cpu_offset(x) (__per_cpu_offset[x])
  17. #endif
  18. /*
  19. * Determine the offset for the currently active processor.
  20. * An arch may define __my_cpu_offset to provide a more effective
  21. * means of obtaining the offset to the per cpu variables of the
  22. * current processor.
  23. */
  24. #ifndef __my_cpu_offset
  25. #define __my_cpu_offset per_cpu_offset(raw_smp_processor_id())
  26. #endif
  27. #ifdef CONFIG_DEBUG_PREEMPT
  28. #define my_cpu_offset per_cpu_offset(smp_processor_id())
  29. #else
  30. #define my_cpu_offset __my_cpu_offset
  31. #endif
  32. /*
  33. * Add a offset to a pointer but keep the pointer as is.
  34. *
  35. * Only S390 provides its own means of moving the pointer.
  36. */
  37. #ifndef SHIFT_PERCPU_PTR
  38. /* Weird cast keeps both GCC and sparse happy. */
  39. #define SHIFT_PERCPU_PTR(__p, __offset) \
  40. RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
  41. #endif
  42. /*
  43. * A percpu variable may point to a discarded regions. The following are
  44. * established ways to produce a usable pointer from the percpu variable
  45. * offset.
  46. */
  47. #define per_cpu(var, cpu) \
  48. (*SHIFT_PERCPU_PTR(&(var), per_cpu_offset(cpu)))
  49. #define __get_cpu_var(var) \
  50. (*SHIFT_PERCPU_PTR(&(var), my_cpu_offset))
  51. #define __raw_get_cpu_var(var) \
  52. (*SHIFT_PERCPU_PTR(&(var), __my_cpu_offset))
  53. #define this_cpu_ptr(ptr) SHIFT_PERCPU_PTR(ptr, my_cpu_offset)
  54. #define __this_cpu_ptr(ptr) SHIFT_PERCPU_PTR(ptr, __my_cpu_offset)
  55. #ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
  56. extern void setup_per_cpu_areas(void);
  57. #endif
  58. #else /* ! SMP */
  59. #define per_cpu(var, cpu) (*((void)(cpu), &(var)))
  60. #define __get_cpu_var(var) (var)
  61. #define __raw_get_cpu_var(var) (var)
  62. #define this_cpu_ptr(ptr) per_cpu_ptr(ptr, 0)
  63. #define __this_cpu_ptr(ptr) this_cpu_ptr(ptr)
  64. #endif /* SMP */
  65. #ifndef PER_CPU_BASE_SECTION
  66. #ifdef CONFIG_SMP
  67. #define PER_CPU_BASE_SECTION ".data.percpu"
  68. #else
  69. #define PER_CPU_BASE_SECTION ".data"
  70. #endif
  71. #endif
  72. #ifdef CONFIG_SMP
  73. #ifdef MODULE
  74. #define PER_CPU_SHARED_ALIGNED_SECTION ""
  75. #define PER_CPU_ALIGNED_SECTION ""
  76. #else
  77. #define PER_CPU_SHARED_ALIGNED_SECTION ".shared_aligned"
  78. #define PER_CPU_ALIGNED_SECTION ".shared_aligned"
  79. #endif
  80. #define PER_CPU_FIRST_SECTION ".first"
  81. #else
  82. #define PER_CPU_SHARED_ALIGNED_SECTION ""
  83. #define PER_CPU_ALIGNED_SECTION ".shared_aligned"
  84. #define PER_CPU_FIRST_SECTION ""
  85. #endif
  86. #ifndef PER_CPU_ATTRIBUTES
  87. #define PER_CPU_ATTRIBUTES
  88. #endif
  89. #ifndef PER_CPU_DEF_ATTRIBUTES
  90. #define PER_CPU_DEF_ATTRIBUTES
  91. #endif
  92. #endif /* _ASM_GENERIC_PERCPU_H_ */