percpu.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #define SHIFT_PERCPU_PTR(__p, __offset) RELOC_HIDE((__p), (__offset))
  39. #endif
  40. /*
  41. * A percpu variable may point to a discarded regions. The following are
  42. * established ways to produce a usable pointer from the percpu variable
  43. * offset.
  44. */
  45. #define per_cpu(var, cpu) \
  46. (*SHIFT_PERCPU_PTR(&per_cpu_var(var), per_cpu_offset(cpu)))
  47. #define __get_cpu_var(var) \
  48. (*SHIFT_PERCPU_PTR(&per_cpu_var(var), my_cpu_offset))
  49. #define __raw_get_cpu_var(var) \
  50. (*SHIFT_PERCPU_PTR(&per_cpu_var(var), __my_cpu_offset))
  51. #ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
  52. extern void setup_per_cpu_areas(void);
  53. #endif
  54. #else /* ! SMP */
  55. #define per_cpu(var, cpu) (*((void)(cpu), &per_cpu_var(var)))
  56. #define __get_cpu_var(var) per_cpu_var(var)
  57. #define __raw_get_cpu_var(var) per_cpu_var(var)
  58. #endif /* SMP */
  59. #ifndef PER_CPU_BASE_SECTION
  60. #ifdef CONFIG_SMP
  61. #define PER_CPU_BASE_SECTION ".data.percpu"
  62. #else
  63. #define PER_CPU_BASE_SECTION ".data"
  64. #endif
  65. #endif
  66. #ifdef CONFIG_SMP
  67. #ifdef MODULE
  68. #define PER_CPU_SHARED_ALIGNED_SECTION ""
  69. #else
  70. #define PER_CPU_SHARED_ALIGNED_SECTION ".shared_aligned"
  71. #endif
  72. #define PER_CPU_FIRST_SECTION ".first"
  73. #else
  74. #define PER_CPU_SHARED_ALIGNED_SECTION ""
  75. #define PER_CPU_FIRST_SECTION ""
  76. #endif
  77. #ifndef PER_CPU_ATTRIBUTES
  78. #define PER_CPU_ATTRIBUTES
  79. #endif
  80. #ifndef PER_CPU_DEF_ATTRIBUTES
  81. #define PER_CPU_DEF_ATTRIBUTES
  82. #endif
  83. #endif /* _ASM_GENERIC_PERCPU_H_ */