]>
Commit | Line | Data |
---|---|---|
5028eaa9 DH |
1 | #ifndef _LINUX_PERCPU_DEFS_H |
2 | #define _LINUX_PERCPU_DEFS_H | |
3 | ||
5028eaa9 DH |
4 | /* |
5 | * Base implementations of per-CPU variable declarations and definitions, where | |
6 | * the section in which the variable is to be placed is provided by the | |
7c756e6e | 7 | * 'sec' argument. This may be used to affect the parameters governing the |
5028eaa9 DH |
8 | * variable's storage. |
9 | * | |
10 | * NOTE! The sections for the DECLARE and for the DEFINE must match, lest | |
11 | * linkage errors occur due the compiler generating the wrong code to access | |
12 | * that section. | |
13 | */ | |
7c756e6e TH |
14 | #define __PCPU_ATTRS(sec) \ |
15 | __attribute__((section(PER_CPU_BASE_SECTION sec))) \ | |
16 | PER_CPU_ATTRIBUTES | |
17 | ||
18 | #define __PCPU_DUMMY_ATTRS \ | |
19 | __attribute__((section(".discard"), unused)) | |
20 | ||
21 | /* | |
22 | * s390 and alpha modules require percpu variables to be defined as | |
23 | * weak to force the compiler to generate GOT based external | |
24 | * references for them. This is necessary because percpu sections | |
25 | * will be located outside of the usually addressable area. | |
26 | * | |
27 | * This definition puts the following two extra restrictions when | |
28 | * defining percpu variables. | |
29 | * | |
30 | * 1. The symbol must be globally unique, even the static ones. | |
31 | * 2. Static percpu variables cannot be defined inside a function. | |
32 | * | |
33 | * Archs which need weak percpu definitions should define | |
34 | * ARCH_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary. | |
35 | * | |
36 | * To ensure that the generic code observes the above two | |
37 | * restrictions, if CONFIG_DEBUG_FORCE_WEAK_PER_CPU is set weak | |
38 | * definition is used for all cases. | |
39 | */ | |
40 | #if defined(ARCH_NEEDS_WEAK_PER_CPU) || defined(CONFIG_DEBUG_FORCE_WEAK_PER_CPU) | |
41 | /* | |
42 | * __pcpu_scope_* dummy variable is used to enforce scope. It | |
43 | * receives the static modifier when it's used in front of | |
44 | * DEFINE_PER_CPU() and will trigger build failure if | |
45 | * DECLARE_PER_CPU() is used for the same variable. | |
46 | * | |
47 | * __pcpu_unique_* dummy variable is used to enforce symbol uniqueness | |
48 | * such that hidden weak symbol collision, which will cause unrelated | |
49 | * variables to share the same address, can be detected during build. | |
50 | */ | |
51 | #define DECLARE_PER_CPU_SECTION(type, name, sec) \ | |
52 | extern __PCPU_DUMMY_ATTRS char __pcpu_scope_##name; \ | |
dd17c8f7 | 53 | extern __PCPU_ATTRS(sec) __typeof__(type) name |
7c756e6e TH |
54 | |
55 | #define DEFINE_PER_CPU_SECTION(type, name, sec) \ | |
56 | __PCPU_DUMMY_ATTRS char __pcpu_scope_##name; \ | |
0f5e4816 | 57 | extern __PCPU_DUMMY_ATTRS char __pcpu_unique_##name; \ |
7c756e6e | 58 | __PCPU_DUMMY_ATTRS char __pcpu_unique_##name; \ |
c43768cb | 59 | __PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES __weak \ |
dd17c8f7 | 60 | __typeof__(type) name |
7c756e6e TH |
61 | #else |
62 | /* | |
63 | * Normal declaration and definition macros. | |
64 | */ | |
65 | #define DECLARE_PER_CPU_SECTION(type, name, sec) \ | |
dd17c8f7 | 66 | extern __PCPU_ATTRS(sec) __typeof__(type) name |
7c756e6e TH |
67 | |
68 | #define DEFINE_PER_CPU_SECTION(type, name, sec) \ | |
c43768cb | 69 | __PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES \ |
dd17c8f7 | 70 | __typeof__(type) name |
7c756e6e | 71 | #endif |
5028eaa9 DH |
72 | |
73 | /* | |
74 | * Variant on the per-CPU variable declaration/definition theme used for | |
75 | * ordinary per-CPU variables. | |
76 | */ | |
77 | #define DECLARE_PER_CPU(type, name) \ | |
78 | DECLARE_PER_CPU_SECTION(type, name, "") | |
79 | ||
80 | #define DEFINE_PER_CPU(type, name) \ | |
81 | DEFINE_PER_CPU_SECTION(type, name, "") | |
82 | ||
83 | /* | |
84 | * Declaration/definition used for per-CPU variables that must come first in | |
85 | * the set of variables. | |
86 | */ | |
87 | #define DECLARE_PER_CPU_FIRST(type, name) \ | |
88 | DECLARE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION) | |
89 | ||
90 | #define DEFINE_PER_CPU_FIRST(type, name) \ | |
91 | DEFINE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION) | |
92 | ||
93 | /* | |
94 | * Declaration/definition used for per-CPU variables that must be cacheline | |
95 | * aligned under SMP conditions so that, whilst a particular instance of the | |
96 | * data corresponds to a particular CPU, inefficiencies due to direct access by | |
97 | * other CPUs are reduced by preventing the data from unnecessarily spanning | |
98 | * cachelines. | |
99 | * | |
100 | * An example of this would be statistical data, where each CPU's set of data | |
101 | * is updated by that CPU alone, but the data from across all CPUs is collated | |
102 | * by a CPU processing a read from a proc file. | |
103 | */ | |
104 | #define DECLARE_PER_CPU_SHARED_ALIGNED(type, name) \ | |
105 | DECLARE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \ | |
106 | ____cacheline_aligned_in_smp | |
107 | ||
108 | #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name) \ | |
109 | DEFINE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \ | |
110 | ____cacheline_aligned_in_smp | |
111 | ||
53f82452 JF |
112 | #define DECLARE_PER_CPU_ALIGNED(type, name) \ |
113 | DECLARE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION) \ | |
114 | ____cacheline_aligned | |
115 | ||
116 | #define DEFINE_PER_CPU_ALIGNED(type, name) \ | |
117 | DEFINE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION) \ | |
118 | ____cacheline_aligned | |
119 | ||
5028eaa9 DH |
120 | /* |
121 | * Declaration/definition used for per-CPU variables that must be page aligned. | |
122 | */ | |
3e352aa8 TH |
123 | #define DECLARE_PER_CPU_PAGE_ALIGNED(type, name) \ |
124 | DECLARE_PER_CPU_SECTION(type, name, ".page_aligned") \ | |
125 | __aligned(PAGE_SIZE) | |
5028eaa9 DH |
126 | |
127 | #define DEFINE_PER_CPU_PAGE_ALIGNED(type, name) \ | |
3e352aa8 TH |
128 | DEFINE_PER_CPU_SECTION(type, name, ".page_aligned") \ |
129 | __aligned(PAGE_SIZE) | |
5028eaa9 DH |
130 | |
131 | /* | |
132 | * Intermodule exports for per-CPU variables. | |
133 | */ | |
dd17c8f7 RR |
134 | #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(var) |
135 | #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(var) | |
5028eaa9 DH |
136 | |
137 | ||
138 | #endif /* _LINUX_PERCPU_DEFS_H */ |