percpu-defs.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 __typeof__(type) per_cpu__##name
  25. /*
  26. * Variant on the per-CPU variable declaration/definition theme used for
  27. * ordinary per-CPU variables.
  28. */
  29. #define DECLARE_PER_CPU(type, name) \
  30. DECLARE_PER_CPU_SECTION(type, name, "")
  31. #define DEFINE_PER_CPU(type, name) \
  32. DEFINE_PER_CPU_SECTION(type, name, "")
  33. /*
  34. * Declaration/definition used for per-CPU variables that must come first in
  35. * the set of variables.
  36. */
  37. #define DECLARE_PER_CPU_FIRST(type, name) \
  38. DECLARE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION)
  39. #define DEFINE_PER_CPU_FIRST(type, name) \
  40. DEFINE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION)
  41. /*
  42. * Declaration/definition used for per-CPU variables that must be cacheline
  43. * aligned under SMP conditions so that, whilst a particular instance of the
  44. * data corresponds to a particular CPU, inefficiencies due to direct access by
  45. * other CPUs are reduced by preventing the data from unnecessarily spanning
  46. * cachelines.
  47. *
  48. * An example of this would be statistical data, where each CPU's set of data
  49. * is updated by that CPU alone, but the data from across all CPUs is collated
  50. * by a CPU processing a read from a proc file.
  51. */
  52. #define DECLARE_PER_CPU_SHARED_ALIGNED(type, name) \
  53. DECLARE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \
  54. ____cacheline_aligned_in_smp
  55. #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name) \
  56. DEFINE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \
  57. ____cacheline_aligned_in_smp
  58. /*
  59. * Declaration/definition used for per-CPU variables that must be page aligned.
  60. */
  61. #define DECLARE_PER_CPU_PAGE_ALIGNED(type, name) \
  62. DECLARE_PER_CPU_SECTION(type, name, ".page_aligned")
  63. #define DEFINE_PER_CPU_PAGE_ALIGNED(type, name) \
  64. DEFINE_PER_CPU_SECTION(type, name, ".page_aligned")
  65. /*
  66. * Intermodule exports for per-CPU variables.
  67. */
  68. #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(per_cpu__##var)
  69. #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(per_cpu__##var)
  70. #endif /* _LINUX_PERCPU_DEFS_H */