percpu-defs.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef _LINUX_PERCPU_DEFS_H
  2. #define _LINUX_PERCPU_DEFS_H
  3. /*
  4. * Determine the real variable name from the name visible in the
  5. * kernel sources.
  6. */
  7. #define per_cpu_var(var) per_cpu__##var
  8. /*
  9. * Base implementations of per-CPU variable declarations and definitions, where
  10. * the section in which the variable is to be placed is provided by the
  11. * 'section' argument. This may be used to affect the parameters governing the
  12. * variable's storage.
  13. *
  14. * NOTE! The sections for the DECLARE and for the DEFINE must match, lest
  15. * linkage errors occur due the compiler generating the wrong code to access
  16. * that section.
  17. */
  18. #define DECLARE_PER_CPU_SECTION(type, name, section) \
  19. extern \
  20. __attribute__((__section__(PER_CPU_BASE_SECTION section))) \
  21. PER_CPU_ATTRIBUTES __typeof__(type) per_cpu__##name
  22. #define DEFINE_PER_CPU_SECTION(type, name, section) \
  23. __attribute__((__section__(PER_CPU_BASE_SECTION section))) \
  24. PER_CPU_ATTRIBUTES PER_CPU_DEF_ATTRIBUTES \
  25. __typeof__(type) per_cpu__##name
  26. /*
  27. * Variant on the per-CPU variable declaration/definition theme used for
  28. * ordinary per-CPU variables.
  29. */
  30. #define DECLARE_PER_CPU(type, name) \
  31. DECLARE_PER_CPU_SECTION(type, name, "")
  32. #define DEFINE_PER_CPU(type, name) \
  33. DEFINE_PER_CPU_SECTION(type, name, "")
  34. /*
  35. * Declaration/definition used for per-CPU variables that must come first in
  36. * the set of variables.
  37. */
  38. #define DECLARE_PER_CPU_FIRST(type, name) \
  39. DECLARE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION)
  40. #define DEFINE_PER_CPU_FIRST(type, name) \
  41. DEFINE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION)
  42. /*
  43. * Declaration/definition used for per-CPU variables that must be cacheline
  44. * aligned under SMP conditions so that, whilst a particular instance of the
  45. * data corresponds to a particular CPU, inefficiencies due to direct access by
  46. * other CPUs are reduced by preventing the data from unnecessarily spanning
  47. * cachelines.
  48. *
  49. * An example of this would be statistical data, where each CPU's set of data
  50. * is updated by that CPU alone, but the data from across all CPUs is collated
  51. * by a CPU processing a read from a proc file.
  52. */
  53. #define DECLARE_PER_CPU_SHARED_ALIGNED(type, name) \
  54. DECLARE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \
  55. ____cacheline_aligned_in_smp
  56. #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name) \
  57. DEFINE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \
  58. ____cacheline_aligned_in_smp
  59. #define DECLARE_PER_CPU_ALIGNED(type, name) \
  60. DECLARE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION) \
  61. ____cacheline_aligned
  62. #define DEFINE_PER_CPU_ALIGNED(type, name) \
  63. DEFINE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION) \
  64. ____cacheline_aligned
  65. /*
  66. * Declaration/definition used for per-CPU variables that must be page aligned.
  67. */
  68. #define DECLARE_PER_CPU_PAGE_ALIGNED(type, name) \
  69. DECLARE_PER_CPU_SECTION(type, name, ".page_aligned")
  70. #define DEFINE_PER_CPU_PAGE_ALIGNED(type, name) \
  71. DEFINE_PER_CPU_SECTION(type, name, ".page_aligned")
  72. /*
  73. * Intermodule exports for per-CPU variables.
  74. */
  75. #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(per_cpu__##var)
  76. #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(per_cpu__##var)
  77. #endif /* _LINUX_PERCPU_DEFS_H */