diff options
-rw-r--r-- | Documentation/cputopology.txt | 26 | ||||
-rw-r--r-- | drivers/base/topology.c | 38 | ||||
-rw-r--r-- | include/linux/topology.h | 13 |
3 files changed, 32 insertions, 45 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 fdf4044d2e74..24d29a9fc25b 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c | |||
@@ -59,60 +59,42 @@ static ssize_t show_cpumap(int type, cpumask_t *mask, char *buf) | |||
59 | static inline ssize_t show_##name(struct sys_device *dev, char *buf) \ | 59 | static inline ssize_t show_##name(struct sys_device *dev, char *buf) \ |
60 | { \ | 60 | { \ |
61 | unsigned int cpu = dev->id; \ | 61 | unsigned int cpu = dev->id; \ |
62 | return show_cpumap(0, &(topology_##name(cpu)), buf); \ | 62 | cpumask_t siblings = topology_##name(cpu); \ |
63 | return show_cpumap(0, &siblings, buf); \ | ||
63 | } | 64 | } |
64 | 65 | ||
65 | #define define_siblings_show_list(name) \ | 66 | #define define_siblings_show_list(name) \ |
66 | static inline ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ | 67 | static inline ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ |
67 | { \ | 68 | { \ |
68 | unsigned int cpu = dev->id; \ | 69 | unsigned int cpu = dev->id; \ |
69 | return show_cpumap(1, &(topology_##name(cpu)), buf); \ | 70 | cpumask_t siblings = topology_##name(cpu); \ |
71 | return show_cpumap(1, &siblings, buf); \ | ||
70 | } | 72 | } |
71 | 73 | ||
72 | #define define_siblings_show_func(name) \ | 74 | #define define_siblings_show_func(name) \ |
73 | define_siblings_show_map(name); define_siblings_show_list(name) | 75 | define_siblings_show_map(name); define_siblings_show_list(name) |
74 | 76 | ||
75 | #ifdef topology_physical_package_id | ||
76 | define_id_show_func(physical_package_id); | 77 | define_id_show_func(physical_package_id); |
77 | define_one_ro(physical_package_id); | 78 | define_one_ro(physical_package_id); |
78 | #define ref_physical_package_id_attr &attr_physical_package_id.attr, | ||
79 | #else | ||
80 | #define ref_physical_package_id_attr | ||
81 | #endif | ||
82 | 79 | ||
83 | #ifdef topology_core_id | ||
84 | define_id_show_func(core_id); | 80 | define_id_show_func(core_id); |
85 | define_one_ro(core_id); | 81 | define_one_ro(core_id); |
86 | #define ref_core_id_attr &attr_core_id.attr, | ||
87 | #else | ||
88 | #define ref_core_id_attr | ||
89 | #endif | ||
90 | 82 | ||
91 | #ifdef topology_thread_siblings | ||
92 | define_siblings_show_func(thread_siblings); | 83 | define_siblings_show_func(thread_siblings); |
93 | define_one_ro(thread_siblings); | 84 | define_one_ro(thread_siblings); |
94 | define_one_ro(thread_siblings_list); | 85 | define_one_ro(thread_siblings_list); |
95 | #define ref_thread_siblings_attr \ | ||
96 | &attr_thread_siblings.attr, &attr_thread_siblings_list.attr, | ||
97 | #else | ||
98 | #define ref_thread_siblings_attr | ||
99 | #endif | ||
100 | 86 | ||
101 | #ifdef topology_core_siblings | ||
102 | define_siblings_show_func(core_siblings); | 87 | define_siblings_show_func(core_siblings); |
103 | define_one_ro(core_siblings); | 88 | define_one_ro(core_siblings); |
104 | define_one_ro(core_siblings_list); | 89 | define_one_ro(core_siblings_list); |
105 | #define ref_core_siblings_attr \ | ||
106 | &attr_core_siblings.attr, &attr_core_siblings_list.attr, | ||
107 | #else | ||
108 | #define ref_core_siblings_attr | ||
109 | #endif | ||
110 | 90 | ||
111 | static struct attribute *default_attrs[] = { | 91 | static struct attribute *default_attrs[] = { |
112 | ref_physical_package_id_attr | 92 | &attr_physical_package_id.attr, |
113 | ref_core_id_attr | 93 | &attr_core_id.attr, |
114 | ref_thread_siblings_attr | 94 | &attr_thread_siblings.attr, |
115 | ref_core_siblings_attr | 95 | &attr_thread_siblings_list.attr, |
96 | &attr_core_siblings.attr, | ||
97 | &attr_core_siblings_list.attr, | ||
116 | NULL | 98 | NULL |
117 | }; | 99 | }; |
118 | 100 | ||
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 */ |