aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/cputopology.txt26
-rw-r--r--drivers/base/topology.c38
-rw-r--r--include/linux/topology.h13
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;
14To implement it in an architecture-neutral way, a new source file, 14To implement it in an architecture-neutral way, a new source file,
15drivers/base/topology.c, is to export the 4 attributes. 15drivers/base/topology.c, is to export the 4 attributes.
16 16
17If one architecture wants to support this feature, it just needs to 17For an architecture to support this feature, it must define some of
18implement 4 defines, typically in file include/asm-XXX/topology.h. 18these macros in include/asm-XXX/topology.h:
19The 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:
25The type of **_id is int. 24The type of **_id is int.
26The type of siblings is cpumask_t. 25The type of siblings is cpumask_t.
27 26
28To be consistent on all architectures, the 4 attributes should have 27To be consistent on all architectures, include/linux/topology.h
29default values if their values are unavailable. Below is the rule. 28provides default definitions for any of the above macros that are
301) physical_package_id: If cpu has no physical package id, -1 is the 29not defined by include/asm-XXX/topology.h:
31default value. 301) physical_package_id: -1
322) core_id: If cpu doesn't support multi-core, its core id is 0. 312) core_id: 0
333) thread_siblings: Just include itself, if the cpu doesn't support 323) thread_siblings: just the given CPU
34HT/multi-thread. 334) core_siblings: just the given CPU
354) core_siblings: Just include itself, if the cpu doesn't support
36multi-core and HT/Multi-thread.
37
38So be careful when declaring the 4 defines in include/asm-XXX/topology.h.
39
40If 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)
59static inline ssize_t show_##name(struct sys_device *dev, char *buf) \ 59static 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) \
66static inline ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ 67static 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
76define_id_show_func(physical_package_id); 77define_id_show_func(physical_package_id);
77define_one_ro(physical_package_id); 78define_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
84define_id_show_func(core_id); 80define_id_show_func(core_id);
85define_one_ro(core_id); 81define_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
92define_siblings_show_func(thread_siblings); 83define_siblings_show_func(thread_siblings);
93define_one_ro(thread_siblings); 84define_one_ro(thread_siblings);
94define_one_ro(thread_siblings_list); 85define_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
102define_siblings_show_func(core_siblings); 87define_siblings_show_func(core_siblings);
103define_one_ro(core_siblings); 88define_one_ro(core_siblings);
104define_one_ro(core_siblings_list); 89define_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
111static struct attribute *default_attrs[] = { 91static 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 */