xref: /OK3568_Linux_fs/kernel/Documentation/admin-guide/cputopology.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun===========================================
2*4882a593SmuzhiyunHow CPU topology info is exported via sysfs
3*4882a593Smuzhiyun===========================================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunExport CPU topology info via sysfs. Items (attributes) are similar
6*4882a593Smuzhiyunto /proc/cpuinfo output of some architectures.  They reside in
7*4882a593Smuzhiyun/sys/devices/system/cpu/cpuX/topology/:
8*4882a593Smuzhiyun
9*4882a593Smuzhiyunphysical_package_id:
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun	physical package id of cpuX. Typically corresponds to a physical
12*4882a593Smuzhiyun	socket number, but the actual value is architecture and platform
13*4882a593Smuzhiyun	dependent.
14*4882a593Smuzhiyun
15*4882a593Smuzhiyundie_id:
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun	the CPU die ID of cpuX. Typically it is the hardware platform's
18*4882a593Smuzhiyun	identifier (rather than the kernel's).  The actual value is
19*4882a593Smuzhiyun	architecture and platform dependent.
20*4882a593Smuzhiyun
21*4882a593Smuzhiyuncore_id:
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun	the CPU core ID of cpuX. Typically it is the hardware platform's
24*4882a593Smuzhiyun	identifier (rather than the kernel's).  The actual value is
25*4882a593Smuzhiyun	architecture and platform dependent.
26*4882a593Smuzhiyun
27*4882a593Smuzhiyunbook_id:
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun	the book ID of cpuX. Typically it is the hardware platform's
30*4882a593Smuzhiyun	identifier (rather than the kernel's).	The actual value is
31*4882a593Smuzhiyun	architecture and platform dependent.
32*4882a593Smuzhiyun
33*4882a593Smuzhiyundrawer_id:
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun	the drawer ID of cpuX. Typically it is the hardware platform's
36*4882a593Smuzhiyun	identifier (rather than the kernel's).	The actual value is
37*4882a593Smuzhiyun	architecture and platform dependent.
38*4882a593Smuzhiyun
39*4882a593Smuzhiyuncore_cpus:
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun	internal kernel map of CPUs within the same core.
42*4882a593Smuzhiyun	(deprecated name: "thread_siblings")
43*4882a593Smuzhiyun
44*4882a593Smuzhiyuncore_cpus_list:
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun	human-readable list of CPUs within the same core.
47*4882a593Smuzhiyun	(deprecated name: "thread_siblings_list");
48*4882a593Smuzhiyun
49*4882a593Smuzhiyunpackage_cpus:
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun	internal kernel map of the CPUs sharing the same physical_package_id.
52*4882a593Smuzhiyun	(deprecated name: "core_siblings")
53*4882a593Smuzhiyun
54*4882a593Smuzhiyunpackage_cpus_list:
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun	human-readable list of CPUs sharing the same physical_package_id.
57*4882a593Smuzhiyun	(deprecated name: "core_siblings_list")
58*4882a593Smuzhiyun
59*4882a593Smuzhiyundie_cpus:
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun	internal kernel map of CPUs within the same die.
62*4882a593Smuzhiyun
63*4882a593Smuzhiyundie_cpus_list:
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun	human-readable list of CPUs within the same die.
66*4882a593Smuzhiyun
67*4882a593Smuzhiyunbook_siblings:
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun	internal kernel map of cpuX's hardware threads within the same
70*4882a593Smuzhiyun	book_id.
71*4882a593Smuzhiyun
72*4882a593Smuzhiyunbook_siblings_list:
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun	human-readable list of cpuX's hardware threads within the same
75*4882a593Smuzhiyun	book_id.
76*4882a593Smuzhiyun
77*4882a593Smuzhiyundrawer_siblings:
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun	internal kernel map of cpuX's hardware threads within the same
80*4882a593Smuzhiyun	drawer_id.
81*4882a593Smuzhiyun
82*4882a593Smuzhiyundrawer_siblings_list:
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun	human-readable list of cpuX's hardware threads within the same
85*4882a593Smuzhiyun	drawer_id.
86*4882a593Smuzhiyun
87*4882a593SmuzhiyunArchitecture-neutral, drivers/base/topology.c, exports these attributes.
88*4882a593SmuzhiyunHowever, the book and drawer related sysfs files will only be created if
89*4882a593SmuzhiyunCONFIG_SCHED_BOOK and CONFIG_SCHED_DRAWER are selected, respectively.
90*4882a593Smuzhiyun
91*4882a593SmuzhiyunCONFIG_SCHED_BOOK and CONFIG_SCHED_DRAWER are currently only used on s390,
92*4882a593Smuzhiyunwhere they reflect the cpu and cache hierarchy.
93*4882a593Smuzhiyun
94*4882a593SmuzhiyunFor an architecture to support this feature, it must define some of
95*4882a593Smuzhiyunthese macros in include/asm-XXX/topology.h::
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun	#define topology_physical_package_id(cpu)
98*4882a593Smuzhiyun	#define topology_die_id(cpu)
99*4882a593Smuzhiyun	#define topology_core_id(cpu)
100*4882a593Smuzhiyun	#define topology_book_id(cpu)
101*4882a593Smuzhiyun	#define topology_drawer_id(cpu)
102*4882a593Smuzhiyun	#define topology_sibling_cpumask(cpu)
103*4882a593Smuzhiyun	#define topology_core_cpumask(cpu)
104*4882a593Smuzhiyun	#define topology_die_cpumask(cpu)
105*4882a593Smuzhiyun	#define topology_book_cpumask(cpu)
106*4882a593Smuzhiyun	#define topology_drawer_cpumask(cpu)
107*4882a593Smuzhiyun
108*4882a593SmuzhiyunThe type of ``**_id macros`` is int.
109*4882a593SmuzhiyunThe type of ``**_cpumask macros`` is ``(const) struct cpumask *``. The latter
110*4882a593Smuzhiyuncorrespond with appropriate ``**_siblings`` sysfs attributes (except for
111*4882a593Smuzhiyuntopology_sibling_cpumask() which corresponds with thread_siblings).
112*4882a593Smuzhiyun
113*4882a593SmuzhiyunTo be consistent on all architectures, include/linux/topology.h
114*4882a593Smuzhiyunprovides default definitions for any of the above macros that are
115*4882a593Smuzhiyunnot defined by include/asm-XXX/topology.h:
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun1) topology_physical_package_id: -1
118*4882a593Smuzhiyun2) topology_die_id: -1
119*4882a593Smuzhiyun3) topology_core_id: 0
120*4882a593Smuzhiyun4) topology_sibling_cpumask: just the given CPU
121*4882a593Smuzhiyun5) topology_core_cpumask: just the given CPU
122*4882a593Smuzhiyun6) topology_die_cpumask: just the given CPU
123*4882a593Smuzhiyun
124*4882a593SmuzhiyunFor architectures that don't support books (CONFIG_SCHED_BOOK) there are no
125*4882a593Smuzhiyundefault definitions for topology_book_id() and topology_book_cpumask().
126*4882a593SmuzhiyunFor architectures that don't support drawers (CONFIG_SCHED_DRAWER) there are
127*4882a593Smuzhiyunno default definitions for topology_drawer_id() and topology_drawer_cpumask().
128*4882a593Smuzhiyun
129*4882a593SmuzhiyunAdditionally, CPU topology information is provided under
130*4882a593Smuzhiyun/sys/devices/system/cpu and includes these files.  The internal
131*4882a593Smuzhiyunsource for the output is in brackets ("[]").
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun    =========== ==========================================================
134*4882a593Smuzhiyun    kernel_max: the maximum CPU index allowed by the kernel configuration.
135*4882a593Smuzhiyun		[NR_CPUS-1]
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun    offline:	CPUs that are not online because they have been
138*4882a593Smuzhiyun		HOTPLUGGED off (see cpu-hotplug.txt) or exceed the limit
139*4882a593Smuzhiyun		of CPUs allowed by the kernel configuration (kernel_max
140*4882a593Smuzhiyun		above). [~cpu_online_mask + cpus >= NR_CPUS]
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun    online:	CPUs that are online and being scheduled [cpu_online_mask]
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun    possible:	CPUs that have been allocated resources and can be
145*4882a593Smuzhiyun		brought online if they are present. [cpu_possible_mask]
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun    present:	CPUs that have been identified as being present in the
148*4882a593Smuzhiyun		system. [cpu_present_mask]
149*4882a593Smuzhiyun    =========== ==========================================================
150*4882a593Smuzhiyun
151*4882a593SmuzhiyunThe format for the above output is compatible with cpulist_parse()
152*4882a593Smuzhiyun[see <linux/cpumask.h>].  Some examples follow.
153*4882a593Smuzhiyun
154*4882a593SmuzhiyunIn this example, there are 64 CPUs in the system but cpus 32-63 exceed
155*4882a593Smuzhiyunthe kernel max which is limited to 0..31 by the NR_CPUS config option
156*4882a593Smuzhiyunbeing 32.  Note also that CPUs 2 and 4-31 are not online but could be
157*4882a593Smuzhiyunbrought online as they are both present and possible::
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun     kernel_max: 31
160*4882a593Smuzhiyun        offline: 2,4-31,32-63
161*4882a593Smuzhiyun         online: 0-1,3
162*4882a593Smuzhiyun       possible: 0-31
163*4882a593Smuzhiyun        present: 0-31
164*4882a593Smuzhiyun
165*4882a593SmuzhiyunIn this example, the NR_CPUS config option is 128, but the kernel was
166*4882a593Smuzhiyunstarted with possible_cpus=144.  There are 4 CPUs in the system and cpu2
167*4882a593Smuzhiyunwas manually taken offline (and is the only CPU that can be brought
168*4882a593Smuzhiyunonline.)::
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun     kernel_max: 127
171*4882a593Smuzhiyun        offline: 2,4-127,128-143
172*4882a593Smuzhiyun         online: 0-1,3
173*4882a593Smuzhiyun       possible: 0-127
174*4882a593Smuzhiyun        present: 0-3
175*4882a593Smuzhiyun
176*4882a593SmuzhiyunSee cpu-hotplug.txt for the possible_cpus=NUM kernel start parameter
177*4882a593Smuzhiyunas well as more information on the various cpumasks.
178