diff options
-rw-r--r-- | Documentation/cputopology.txt | 26 | ||||
-rw-r--r-- | drivers/base/topology.c | 32 | ||||
-rw-r--r-- | include/linux/topology.h | 13 |
3 files changed, 28 insertions, 43 deletions
diff --git a/Documentation/cputopology.txt b/Documentation/cputopology.txt index b61cb9564023..bd699da24666 100644 --- a/Documentation/cputopology.txt +++ b/Documentation/cputopology.txt | |||
@@ -14,9 +14,8 @@ represent the thread siblings to cpu X in the same physical package; | |||
14 | To implement it in an architecture-neutral way, a new source file, | 14 | To implement it in an architecture-neutral way, a new source file, |
15 | drivers/base/topology.c, is to export the 4 attributes. | 15 | drivers/base/topology.c, is to export the 4 attributes. |
16 | 16 | ||
17 | If one architecture wants to support this feature, it just needs to | 17 | For an architecture to support this feature, it must define some of |
18 | implement 4 defines, typically in file include/asm-XXX/topology.h. | 18 | these macros in include/asm-XXX/topology.h: |
19 | The 4 defines are: | ||
20 | #define topology_physical_package_id(cpu) | 19 | #define topology_physical_package_id(cpu) |
21 | #define topology_core_id(cpu) | 20 | #define topology_core_id(cpu) |
22 | #define topology_thread_siblings(cpu) | 21 | #define topology_thread_siblings(cpu) |
@@ -25,17 +24,10 @@ The 4 defines are: | |||
25 | The type of **_id is int. | 24 | The type of **_id is int. |
26 | The type of siblings is cpumask_t. | 25 | The type of siblings is cpumask_t. |
27 | 26 | ||
28 | To be consistent on all architectures, the 4 attributes should have | 27 | To be consistent on all architectures, include/linux/topology.h |
29 | default values if their values are unavailable. Below is the rule. | 28 | provides default definitions for any of the above macros that are |
30 | 1) physical_package_id: If cpu has no physical package id, -1 is the | 29 | not defined by include/asm-XXX/topology.h: |
31 | default value. | 30 | 1) physical_package_id: -1 |
32 | 2) core_id: If cpu doesn't support multi-core, its core id is 0. | 31 | 2) core_id: 0 |
33 | 3) thread_siblings: Just include itself, if the cpu doesn't support | 32 | 3) thread_siblings: just the given CPU |
34 | HT/multi-thread. | 33 | 4) core_siblings: just the given CPU |
35 | 4) core_siblings: Just include itself, if the cpu doesn't support | ||
36 | multi-core and HT/Multi-thread. | ||
37 | |||
38 | So be careful when declaring the 4 defines in include/asm-XXX/topology.h. | ||
39 | |||
40 | If an attribute isn't defined on an architecture, it won't be exported. | ||
41 | |||
diff --git a/drivers/base/topology.c b/drivers/base/topology.c index 1efe162e16d7..3f6d9b0a6abe 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c | |||
@@ -93,47 +93,27 @@ static ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ | |||
93 | #define define_siblings_show_func(name) \ | 93 | #define define_siblings_show_func(name) \ |
94 | define_siblings_show_map(name); define_siblings_show_list(name) | 94 | define_siblings_show_map(name); define_siblings_show_list(name) |
95 | 95 | ||
96 | #ifdef topology_physical_package_id | ||
97 | define_id_show_func(physical_package_id); | 96 | define_id_show_func(physical_package_id); |
98 | define_one_ro(physical_package_id); | 97 | define_one_ro(physical_package_id); |
99 | #define ref_physical_package_id_attr &attr_physical_package_id.attr, | ||
100 | #else | ||
101 | #define ref_physical_package_id_attr | ||
102 | #endif | ||
103 | 98 | ||
104 | #ifdef topology_core_id | ||
105 | define_id_show_func(core_id); | 99 | define_id_show_func(core_id); |
106 | define_one_ro(core_id); | 100 | define_one_ro(core_id); |
107 | #define ref_core_id_attr &attr_core_id.attr, | ||
108 | #else | ||
109 | #define ref_core_id_attr | ||
110 | #endif | ||
111 | 101 | ||
112 | #ifdef topology_thread_siblings | ||
113 | define_siblings_show_func(thread_siblings); | 102 | define_siblings_show_func(thread_siblings); |
114 | define_one_ro(thread_siblings); | 103 | define_one_ro(thread_siblings); |
115 | define_one_ro(thread_siblings_list); | 104 | define_one_ro(thread_siblings_list); |
116 | #define ref_thread_siblings_attr \ | ||
117 | &attr_thread_siblings.attr, &attr_thread_siblings_list.attr, | ||
118 | #else | ||
119 | #define ref_thread_siblings_attr | ||
120 | #endif | ||
121 | 105 | ||
122 | #ifdef topology_core_siblings | ||
123 | define_siblings_show_func(core_siblings); | 106 | define_siblings_show_func(core_siblings); |
124 | define_one_ro(core_siblings); | 107 | define_one_ro(core_siblings); |
125 | define_one_ro(core_siblings_list); | 108 | define_one_ro(core_siblings_list); |
126 | #define ref_core_siblings_attr \ | ||
127 | &attr_core_siblings.attr, &attr_core_siblings_list.attr, | ||
128 | #else | ||
129 | #define ref_core_siblings_attr | ||
130 | #endif | ||
131 | 109 | ||
132 | static struct attribute *default_attrs[] = { | 110 | static struct attribute *default_attrs[] = { |
133 | ref_physical_package_id_attr | 111 | &attr_physical_package_id.attr, |
134 | ref_core_id_attr | 112 | &attr_core_id.attr, |
135 | ref_thread_siblings_attr | 113 | &attr_thread_siblings.attr, |
136 | ref_core_siblings_attr | 114 | &attr_thread_siblings_list.attr, |
115 | &attr_core_siblings.attr, | ||
116 | &attr_core_siblings_list.attr, | ||
137 | NULL | 117 | NULL |
138 | }; | 118 | }; |
139 | 119 | ||
diff --git a/include/linux/topology.h b/include/linux/topology.h index 24f3d2282e11..2158fc0d5a56 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h | |||
@@ -179,4 +179,17 @@ void arch_update_cpu_topology(void); | |||
179 | #endif | 179 | #endif |
180 | #endif /* CONFIG_NUMA */ | 180 | #endif /* CONFIG_NUMA */ |
181 | 181 | ||
182 | #ifndef topology_physical_package_id | ||
183 | #define topology_physical_package_id(cpu) ((void)(cpu), -1) | ||
184 | #endif | ||
185 | #ifndef topology_core_id | ||
186 | #define topology_core_id(cpu) ((void)(cpu), 0) | ||
187 | #endif | ||
188 | #ifndef topology_thread_siblings | ||
189 | #define topology_thread_siblings(cpu) cpumask_of_cpu(cpu) | ||
190 | #endif | ||
191 | #ifndef topology_core_siblings | ||
192 | #define topology_core_siblings(cpu) cpumask_of_cpu(cpu) | ||
193 | #endif | ||
194 | |||
182 | #endif /* _LINUX_TOPOLOGY_H */ | 195 | #endif /* _LINUX_TOPOLOGY_H */ |