| David Howells | 5028eaa | 2009-04-21 23:00:29 +0100 | [diff] [blame] | 1 | #ifndef _LINUX_PERCPU_DEFS_H | 
 | 2 | #define _LINUX_PERCPU_DEFS_H | 
 | 3 |  | 
 | 4 | /* | 
| David Howells | 5028eaa | 2009-04-21 23:00:29 +0100 | [diff] [blame] | 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 | 
| Tejun Heo | 7c756e6 | 2009-06-24 15:13:50 +0900 | [diff] [blame] | 7 |  * 'sec' argument.  This may be used to affect the parameters governing the | 
| David Howells | 5028eaa | 2009-04-21 23:00:29 +0100 | [diff] [blame] | 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 |  */ | 
| Tejun Heo | 7c756e6 | 2009-06-24 15:13:50 +0900 | [diff] [blame] | 14 | #define __PCPU_ATTRS(sec)						\ | 
| Rusty Russell | e0fdb0e | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 15 | 	__percpu __attribute__((section(PER_CPU_BASE_SECTION sec)))	\ | 
| Tejun Heo | 7c756e6 | 2009-06-24 15:13:50 +0900 | [diff] [blame] | 16 | 	PER_CPU_ATTRIBUTES | 
| David Howells | 5028eaa | 2009-04-21 23:00:29 +0100 | [diff] [blame] | 17 |  | 
| Tejun Heo | 7c756e6 | 2009-06-24 15:13:50 +0900 | [diff] [blame] | 18 | #define __PCPU_DUMMY_ATTRS						\ | 
 | 19 | 	__attribute__((section(".discard"), unused)) | 
 | 20 |  | 
 | 21 | /* | 
| Tejun Heo | 545695f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 22 |  * Macro which verifies @ptr is a percpu pointer without evaluating | 
 | 23 |  * @ptr.  This is to be used in percpu accessors to verify that the | 
 | 24 |  * input parameter is a percpu pointer. | 
 | 25 |  */ | 
 | 26 | #define __verify_pcpu_ptr(ptr)	do {					\ | 
| Tejun Heo | 8543859 | 2009-11-18 17:53:21 +0900 | [diff] [blame] | 27 | 	const void __percpu *__vpp_verify = (typeof(ptr))NULL;		\ | 
| Tejun Heo | 545695f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 28 | 	(void)__vpp_verify;						\ | 
 | 29 | } while (0) | 
 | 30 |  | 
 | 31 | /* | 
| Tejun Heo | 7c756e6 | 2009-06-24 15:13:50 +0900 | [diff] [blame] | 32 |  * s390 and alpha modules require percpu variables to be defined as | 
 | 33 |  * weak to force the compiler to generate GOT based external | 
 | 34 |  * references for them.  This is necessary because percpu sections | 
 | 35 |  * will be located outside of the usually addressable area. | 
 | 36 |  * | 
 | 37 |  * This definition puts the following two extra restrictions when | 
 | 38 |  * defining percpu variables. | 
 | 39 |  * | 
 | 40 |  * 1. The symbol must be globally unique, even the static ones. | 
 | 41 |  * 2. Static percpu variables cannot be defined inside a function. | 
 | 42 |  * | 
 | 43 |  * Archs which need weak percpu definitions should define | 
 | 44 |  * ARCH_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary. | 
 | 45 |  * | 
 | 46 |  * To ensure that the generic code observes the above two | 
 | 47 |  * restrictions, if CONFIG_DEBUG_FORCE_WEAK_PER_CPU is set weak | 
 | 48 |  * definition is used for all cases. | 
 | 49 |  */ | 
 | 50 | #if defined(ARCH_NEEDS_WEAK_PER_CPU) || defined(CONFIG_DEBUG_FORCE_WEAK_PER_CPU) | 
 | 51 | /* | 
 | 52 |  * __pcpu_scope_* dummy variable is used to enforce scope.  It | 
 | 53 |  * receives the static modifier when it's used in front of | 
 | 54 |  * DEFINE_PER_CPU() and will trigger build failure if | 
 | 55 |  * DECLARE_PER_CPU() is used for the same variable. | 
 | 56 |  * | 
 | 57 |  * __pcpu_unique_* dummy variable is used to enforce symbol uniqueness | 
 | 58 |  * such that hidden weak symbol collision, which will cause unrelated | 
 | 59 |  * variables to share the same address, can be detected during build. | 
 | 60 |  */ | 
 | 61 | #define DECLARE_PER_CPU_SECTION(type, name, sec)			\ | 
 | 62 | 	extern __PCPU_DUMMY_ATTRS char __pcpu_scope_##name;		\ | 
| Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 63 | 	extern __PCPU_ATTRS(sec) __typeof__(type) name | 
| Tejun Heo | 7c756e6 | 2009-06-24 15:13:50 +0900 | [diff] [blame] | 64 |  | 
 | 65 | #define DEFINE_PER_CPU_SECTION(type, name, sec)				\ | 
 | 66 | 	__PCPU_DUMMY_ATTRS char __pcpu_scope_##name;			\ | 
| Tejun Heo | 0f5e481 | 2009-10-29 22:34:12 +0900 | [diff] [blame] | 67 | 	extern __PCPU_DUMMY_ATTRS char __pcpu_unique_##name;		\ | 
| Tejun Heo | 7c756e6 | 2009-06-24 15:13:50 +0900 | [diff] [blame] | 68 | 	__PCPU_DUMMY_ATTRS char __pcpu_unique_##name;			\ | 
| Tejun Heo | c43768c | 2009-07-04 07:13:18 +0900 | [diff] [blame] | 69 | 	__PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES __weak			\ | 
| Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 70 | 	__typeof__(type) name | 
| Tejun Heo | 7c756e6 | 2009-06-24 15:13:50 +0900 | [diff] [blame] | 71 | #else | 
 | 72 | /* | 
 | 73 |  * Normal declaration and definition macros. | 
 | 74 |  */ | 
 | 75 | #define DECLARE_PER_CPU_SECTION(type, name, sec)			\ | 
| Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 76 | 	extern __PCPU_ATTRS(sec) __typeof__(type) name | 
| Tejun Heo | 7c756e6 | 2009-06-24 15:13:50 +0900 | [diff] [blame] | 77 |  | 
 | 78 | #define DEFINE_PER_CPU_SECTION(type, name, sec)				\ | 
| Tejun Heo | c43768c | 2009-07-04 07:13:18 +0900 | [diff] [blame] | 79 | 	__PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES			\ | 
| Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 80 | 	__typeof__(type) name | 
| Tejun Heo | 7c756e6 | 2009-06-24 15:13:50 +0900 | [diff] [blame] | 81 | #endif | 
| David Howells | 5028eaa | 2009-04-21 23:00:29 +0100 | [diff] [blame] | 82 |  | 
 | 83 | /* | 
 | 84 |  * Variant on the per-CPU variable declaration/definition theme used for | 
 | 85 |  * ordinary per-CPU variables. | 
 | 86 |  */ | 
 | 87 | #define DECLARE_PER_CPU(type, name)					\ | 
 | 88 | 	DECLARE_PER_CPU_SECTION(type, name, "") | 
 | 89 |  | 
 | 90 | #define DEFINE_PER_CPU(type, name)					\ | 
 | 91 | 	DEFINE_PER_CPU_SECTION(type, name, "") | 
 | 92 |  | 
 | 93 | /* | 
 | 94 |  * Declaration/definition used for per-CPU variables that must come first in | 
 | 95 |  * the set of variables. | 
 | 96 |  */ | 
 | 97 | #define DECLARE_PER_CPU_FIRST(type, name)				\ | 
 | 98 | 	DECLARE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION) | 
 | 99 |  | 
 | 100 | #define DEFINE_PER_CPU_FIRST(type, name)				\ | 
 | 101 | 	DEFINE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION) | 
 | 102 |  | 
 | 103 | /* | 
 | 104 |  * Declaration/definition used for per-CPU variables that must be cacheline | 
 | 105 |  * aligned under SMP conditions so that, whilst a particular instance of the | 
 | 106 |  * data corresponds to a particular CPU, inefficiencies due to direct access by | 
 | 107 |  * other CPUs are reduced by preventing the data from unnecessarily spanning | 
 | 108 |  * cachelines. | 
 | 109 |  * | 
 | 110 |  * An example of this would be statistical data, where each CPU's set of data | 
 | 111 |  * is updated by that CPU alone, but the data from across all CPUs is collated | 
 | 112 |  * by a CPU processing a read from a proc file. | 
 | 113 |  */ | 
 | 114 | #define DECLARE_PER_CPU_SHARED_ALIGNED(type, name)			\ | 
 | 115 | 	DECLARE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \ | 
 | 116 | 	____cacheline_aligned_in_smp | 
 | 117 |  | 
 | 118 | #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name)			\ | 
 | 119 | 	DEFINE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \ | 
 | 120 | 	____cacheline_aligned_in_smp | 
 | 121 |  | 
| Jeremy Fitzhardinge | 53f8245 | 2009-09-03 14:31:44 -0700 | [diff] [blame] | 122 | #define DECLARE_PER_CPU_ALIGNED(type, name)				\ | 
 | 123 | 	DECLARE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION)	\ | 
 | 124 | 	____cacheline_aligned | 
 | 125 |  | 
 | 126 | #define DEFINE_PER_CPU_ALIGNED(type, name)				\ | 
 | 127 | 	DEFINE_PER_CPU_SECTION(type, name, PER_CPU_ALIGNED_SECTION)	\ | 
 | 128 | 	____cacheline_aligned | 
 | 129 |  | 
| David Howells | 5028eaa | 2009-04-21 23:00:29 +0100 | [diff] [blame] | 130 | /* | 
 | 131 |  * Declaration/definition used for per-CPU variables that must be page aligned. | 
 | 132 |  */ | 
| Tejun Heo | 3e352aa | 2009-08-03 14:10:11 +0900 | [diff] [blame] | 133 | #define DECLARE_PER_CPU_PAGE_ALIGNED(type, name)			\ | 
| Denys Vlasenko | 3d9a854 | 2010-02-20 01:03:43 +0100 | [diff] [blame] | 134 | 	DECLARE_PER_CPU_SECTION(type, name, "..page_aligned")		\ | 
| Tejun Heo | 3e352aa | 2009-08-03 14:10:11 +0900 | [diff] [blame] | 135 | 	__aligned(PAGE_SIZE) | 
| David Howells | 5028eaa | 2009-04-21 23:00:29 +0100 | [diff] [blame] | 136 |  | 
 | 137 | #define DEFINE_PER_CPU_PAGE_ALIGNED(type, name)				\ | 
| Denys Vlasenko | 3d9a854 | 2010-02-20 01:03:43 +0100 | [diff] [blame] | 138 | 	DEFINE_PER_CPU_SECTION(type, name, "..page_aligned")		\ | 
| Tejun Heo | 3e352aa | 2009-08-03 14:10:11 +0900 | [diff] [blame] | 139 | 	__aligned(PAGE_SIZE) | 
| David Howells | 5028eaa | 2009-04-21 23:00:29 +0100 | [diff] [blame] | 140 |  | 
 | 141 | /* | 
| Shaohua Li | c957ef2 | 2010-10-20 11:07:02 +0800 | [diff] [blame] | 142 |  * Declaration/definition used for per-CPU variables that must be read mostly. | 
 | 143 |  */ | 
 | 144 | #define DECLARE_PER_CPU_READ_MOSTLY(type, name)			\ | 
 | 145 | 	DECLARE_PER_CPU_SECTION(type, name, "..readmostly") | 
 | 146 |  | 
 | 147 | #define DEFINE_PER_CPU_READ_MOSTLY(type, name)				\ | 
 | 148 | 	DEFINE_PER_CPU_SECTION(type, name, "..readmostly") | 
 | 149 |  | 
 | 150 | /* | 
| Tejun Heo | 545695f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 151 |  * Intermodule exports for per-CPU variables.  sparse forgets about | 
 | 152 |  * address space across EXPORT_SYMBOL(), change EXPORT_SYMBOL() to | 
 | 153 |  * noop if __CHECKER__. | 
| David Howells | 5028eaa | 2009-04-21 23:00:29 +0100 | [diff] [blame] | 154 |  */ | 
| Tejun Heo | 545695f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 155 | #ifndef __CHECKER__ | 
| Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 156 | #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(var) | 
 | 157 | #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(var) | 
| Tejun Heo | 545695f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 158 | #else | 
 | 159 | #define EXPORT_PER_CPU_SYMBOL(var) | 
 | 160 | #define EXPORT_PER_CPU_SYMBOL_GPL(var) | 
 | 161 | #endif | 
| David Howells | 5028eaa | 2009-04-21 23:00:29 +0100 | [diff] [blame] | 162 |  | 
 | 163 | #endif /* _LINUX_PERCPU_DEFS_H */ |