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