1 .. SPDX-License-Identifier: GPL-2.0
7 This documents and clarifies the main aspects of x86 topology modelling and
8 representation in the kernel. Update/change when doing changes to the
11 The architecture-agnostic topology definitions are in
12 Documentation/admin-guide/cputopology.rst. This file holds x86-specific
13 differences/specialities which must not necessarily apply to the generic
14 definitions. Thus, the way to read up on Linux topology on x86 is to start
15 with the generic one and look at this one in parallel for the x86 specifics.
17 Needless to say, code should use the generic functions - this file is *only*
18 here to *document* the inner workings of x86 topology.
20 Started by Thomas Gleixner <tglx@linutronix.de> and Borislav Petkov <bp@alien8.de>.
22 The main aim of the topology facilities is to present adequate interfaces to
23 code which needs to know/query/use the structure of the running system wrt
24 threads, cores, packages, etc.
26 The kernel does not care about the concept of physical sockets because a
27 socket has no relevance to software. It's an electromechanical component. In
28 the past a socket always contained a single package (see below), but with the
29 advent of Multi Chip Modules (MCM) a socket can hold more than one package. So
30 there might be still references to sockets in the code, but they are of
31 historical nature and should be cleaned up.
33 The topology of a system is described in the units of:
41 Packages contain a number of cores plus shared resources, e.g. DRAM
42 controller, shared caches etc.
44 AMD nomenclature for package is 'Node'.
46 Package-related topology information in the kernel:
48 - cpuinfo_x86.x86_max_cores:
50 The number of cores in a package. This information is retrieved via CPUID.
52 - cpuinfo_x86.x86_max_dies:
54 The number of dies in a package. This information is retrieved via CPUID.
56 - cpuinfo_x86.phys_proc_id:
58 The physical ID of the package. This information is retrieved via CPUID
59 and deduced from the APIC IDs of the cores in the package.
61 - cpuinfo_x86.logical_proc_id:
63 The logical ID of the package. As we do not trust BIOSes to enumerate the
64 packages in a consistent way, we introduced the concept of logical package
65 ID so we can sanely calculate the number of maximum possible packages in
66 the system and have the packages enumerated linearly.
68 - topology_max_packages():
70 The maximum possible number of packages in the system. Helpful for per
71 package facilities to preallocate per package information.
75 A per-CPU variable containing:
77 - On Intel, the first APIC ID of the list of CPUs sharing the Last Level
80 - On AMD, the Node ID or Core Complex ID containing the Last Level
81 Cache. In general, it is a number identifying an LLC uniquely on the
86 A core consists of 1 or more threads. It does not matter whether the threads
87 are SMT- or CMT-type threads.
89 AMDs nomenclature for a CMT core is "Compute Unit". The kernel always uses
92 Core-related topology information in the kernel:
96 The number of threads in a core. The number of threads in a package can be
99 threads_per_package = cpuinfo_x86.x86_max_cores * smp_num_siblings
104 A thread is a single scheduling unit. It's the equivalent to a logical Linux
107 AMDs nomenclature for CMT threads is "Compute Unit Core". The kernel always
110 Thread-related topology information in the kernel:
112 - topology_core_cpumask():
114 The cpumask contains all online threads in the package to which a thread
117 The number of online threads is also printed in /proc/cpuinfo "siblings."
119 - topology_sibling_cpumask():
121 The cpumask contains all online threads in the core to which a thread
124 - topology_logical_package_id():
126 The logical package ID to which a thread belongs.
128 - topology_physical_package_id():
130 The physical package ID to which a thread belongs.
132 - topology_core_id();
134 The ID of the core to which a thread belongs. It is also printed in /proc/cpuinfo
139 System topology examples
140 ========================
143 The alternative Linux CPU enumeration depends on how the BIOS enumerates the
144 threads. Many BIOSes enumerate all threads 0 first and then all threads 1.
145 That has the "advantage" that the logical Linux CPU numbers of threads 0 stay
146 the same whether threads are enabled or not. That's merely an implementation
147 detail and has no practical impact.
149 1) Single Package, Single Core::
151 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
153 2) Single Package, Dual Core
155 a) One thread per core::
157 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
158 -> [core 1] -> [thread 0] -> Linux CPU 1
160 b) Two threads per core::
162 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
163 -> [thread 1] -> Linux CPU 1
164 -> [core 1] -> [thread 0] -> Linux CPU 2
165 -> [thread 1] -> Linux CPU 3
167 Alternative enumeration::
169 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
170 -> [thread 1] -> Linux CPU 2
171 -> [core 1] -> [thread 0] -> Linux CPU 1
172 -> [thread 1] -> Linux CPU 3
174 AMD nomenclature for CMT systems::
176 [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
177 -> [Compute Unit Core 1] -> Linux CPU 1
178 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
179 -> [Compute Unit Core 1] -> Linux CPU 3
181 4) Dual Package, Dual Core
183 a) One thread per core::
185 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
186 -> [core 1] -> [thread 0] -> Linux CPU 1
188 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
189 -> [core 1] -> [thread 0] -> Linux CPU 3
191 b) Two threads per core::
193 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
194 -> [thread 1] -> Linux CPU 1
195 -> [core 1] -> [thread 0] -> Linux CPU 2
196 -> [thread 1] -> Linux CPU 3
198 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 4
199 -> [thread 1] -> Linux CPU 5
200 -> [core 1] -> [thread 0] -> Linux CPU 6
201 -> [thread 1] -> Linux CPU 7
203 Alternative enumeration::
205 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
206 -> [thread 1] -> Linux CPU 4
207 -> [core 1] -> [thread 0] -> Linux CPU 1
208 -> [thread 1] -> Linux CPU 5
210 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
211 -> [thread 1] -> Linux CPU 6
212 -> [core 1] -> [thread 0] -> Linux CPU 3
213 -> [thread 1] -> Linux CPU 7
215 AMD nomenclature for CMT systems::
217 [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
218 -> [Compute Unit Core 1] -> Linux CPU 1
219 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
220 -> [Compute Unit Core 1] -> Linux CPU 3
222 [node 1] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 4
223 -> [Compute Unit Core 1] -> Linux CPU 5
224 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 6
225 -> [Compute Unit Core 1] -> Linux CPU 7