1===========================================
2How CPU topology info is exported via sysfs
3===========================================
4
5CPU topology info is exported via sysfs. Items (attributes) are similar
6to /proc/cpuinfo output of some architectures. They reside in
7/sys/devices/system/cpu/cpuX/topology/. Please refer to the ABI file:
8Documentation/ABI/stable/sysfs-devices-system-cpu.
9
10Architecture-neutral, drivers/base/topology.c, exports these attributes.
11However, the book and drawer related sysfs files will only be created if
12CONFIG_SCHED_BOOK and CONFIG_SCHED_DRAWER are selected, respectively.
13
14CONFIG_SCHED_BOOK and CONFIG_SCHED_DRAWER are currently only used on s390,
15where they reflect the cpu and cache hierarchy.
16
17For an architecture to support this feature, it must define some of
18these macros in include/asm-XXX/topology.h::
19
20	#define topology_physical_package_id(cpu)
21	#define topology_die_id(cpu)
22	#define topology_cluster_id(cpu)
23	#define topology_core_id(cpu)
24	#define topology_book_id(cpu)
25	#define topology_drawer_id(cpu)
26	#define topology_sibling_cpumask(cpu)
27	#define topology_core_cpumask(cpu)
28	#define topology_cluster_cpumask(cpu)
29	#define topology_die_cpumask(cpu)
30	#define topology_book_cpumask(cpu)
31	#define topology_drawer_cpumask(cpu)
32
33The type of ``**_id macros`` is int.
34The type of ``**_cpumask macros`` is ``(const) struct cpumask *``. The latter
35correspond with appropriate ``**_siblings`` sysfs attributes (except for
36topology_sibling_cpumask() which corresponds with thread_siblings).
37
38To be consistent on all architectures, include/linux/topology.h
39provides default definitions for any of the above macros that are
40not defined by include/asm-XXX/topology.h:
41
421) topology_physical_package_id: -1
432) topology_die_id: -1
443) topology_cluster_id: -1
454) topology_core_id: 0
465) topology_sibling_cpumask: just the given CPU
476) topology_core_cpumask: just the given CPU
487) topology_cluster_cpumask: just the given CPU
498) topology_die_cpumask: just the given CPU
50
51For architectures that don't support books (CONFIG_SCHED_BOOK) there are no
52default definitions for topology_book_id() and topology_book_cpumask().
53For architectures that don't support drawers (CONFIG_SCHED_DRAWER) there are
54no default definitions for topology_drawer_id() and topology_drawer_cpumask().
55
56Additionally, CPU topology information is provided under
57/sys/devices/system/cpu and includes these files.  The internal
58source for the output is in brackets ("[]").
59
60    =========== ==========================================================
61    kernel_max: the maximum CPU index allowed by the kernel configuration.
62		[NR_CPUS-1]
63
64    offline:	CPUs that are not online because they have been
65		HOTPLUGGED off or exceed the limit of CPUs allowed by the
66		kernel configuration (kernel_max above).
67		[~cpu_online_mask + cpus >= NR_CPUS]
68
69    online:	CPUs that are online and being scheduled [cpu_online_mask]
70
71    possible:	CPUs that have been allocated resources and can be
72		brought online if they are present. [cpu_possible_mask]
73
74    present:	CPUs that have been identified as being present in the
75		system. [cpu_present_mask]
76    =========== ==========================================================
77
78The format for the above output is compatible with cpulist_parse()
79[see <linux/cpumask.h>].  Some examples follow.
80
81In this example, there are 64 CPUs in the system but cpus 32-63 exceed
82the kernel max which is limited to 0..31 by the NR_CPUS config option
83being 32.  Note also that CPUs 2 and 4-31 are not online but could be
84brought online as they are both present and possible::
85
86     kernel_max: 31
87        offline: 2,4-31,32-63
88         online: 0-1,3
89       possible: 0-31
90        present: 0-31
91
92In this example, the NR_CPUS config option is 128, but the kernel was
93started with possible_cpus=144.  There are 4 CPUs in the system and cpu2
94was manually taken offline (and is the only CPU that can be brought
95online.)::
96
97     kernel_max: 127
98        offline: 2,4-127,128-143
99         online: 0-1,3
100       possible: 0-127
101        present: 0-3
102
103See Documentation/core-api/cpu_hotplug.rst for the possible_cpus=NUM
104kernel start parameter as well as more information on the various cpumasks.
105