4 This documents and clarifies the main aspects of x86 topology modelling and
5 representation in the kernel. Update/change when doing changes to the
8 The architecture-agnostic topology definitions are in
9 Documentation/cputopology.txt. This file holds x86-specific
10 differences/specialities which must not necessarily apply to the generic
11 definitions. Thus, the way to read up on Linux topology on x86 is to start
12 with the generic one and look at this one in parallel for the x86 specifics.
14 Needless to say, code should use the generic functions - this file is *only*
15 here to *document* the inner workings of x86 topology.
17 Started by Thomas Gleixner <tglx@linutronix.de> and Borislav Petkov <bp@alien8.de>.
19 The main aim of the topology facilities is to present adequate interfaces to
20 code which needs to know/query/use the structure of the running system wrt
21 threads, cores, packages, etc.
23 The kernel does not care about the concept of physical sockets because a
24 socket has no relevance to software. It's an electromechanical component. In
25 the past a socket always contained a single package (see below), but with the
26 advent of Multi Chip Modules (MCM) a socket can hold more than one package. So
27 there might be still references to sockets in the code, but they are of
28 historical nature and should be cleaned up.
30 The topology of a system is described in the units of:
38 Packages contain a number of cores plus shared resources, e.g. DRAM
39 controller, shared caches etc.
41 AMD nomenclature for package is 'Node'.
43 Package-related topology information in the kernel:
45 - cpuinfo_x86.x86_max_cores:
47 The number of cores in a package. This information is retrieved via CPUID.
49 - cpuinfo_x86.phys_proc_id:
51 The physical ID of the package. This information is retrieved via CPUID
52 and deduced from the APIC IDs of the cores in the package.
54 - cpuinfo_x86.logical_id:
56 The logical ID of the package. As we do not trust BIOSes to enumerate the
57 packages in a consistent way, we introduced the concept of logical package
58 ID so we can sanely calculate the number of maximum possible packages in
59 the system and have the packages enumerated linearly.
61 - topology_max_packages():
63 The maximum possible number of packages in the system. Helpful for per
64 package facilities to preallocate per package information.
68 A per-CPU variable containing:
69 - On Intel, the first APIC ID of the list of CPUs sharing the Last Level
72 - On AMD, the Node ID or Core Complex ID containing the Last Level
73 Cache. In general, it is a number identifying an LLC uniquely on the
78 A core consists of 1 or more threads. It does not matter whether the threads
79 are SMT- or CMT-type threads.
81 AMDs nomenclature for a CMT core is "Compute Unit". The kernel always uses
84 Core-related topology information in the kernel:
88 The number of threads in a core. The number of threads in a package can be
91 threads_per_package = cpuinfo_x86.x86_max_cores * smp_num_siblings
96 A thread is a single scheduling unit. It's the equivalent to a logical Linux
99 AMDs nomenclature for CMT threads is "Compute Unit Core". The kernel always
102 Thread-related topology information in the kernel:
104 - topology_core_cpumask():
106 The cpumask contains all online threads in the package to which a thread
109 The number of online threads is also printed in /proc/cpuinfo "siblings."
111 - topology_sibling_mask():
113 The cpumask contains all online threads in the core to which a thread
116 - topology_logical_package_id():
118 The logical package ID to which a thread belongs.
120 - topology_physical_package_id():
122 The physical package ID to which a thread belongs.
124 - topology_core_id();
126 The ID of the core to which a thread belongs. It is also printed in /proc/cpuinfo
131 System topology examples
135 The alternative Linux CPU enumeration depends on how the BIOS enumerates the
136 threads. Many BIOSes enumerate all threads 0 first and then all threads 1.
137 That has the "advantage" that the logical Linux CPU numbers of threads 0 stay
138 the same whether threads are enabled or not. That's merely an implementation
139 detail and has no practical impact.
141 1) Single Package, Single Core
143 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
145 2) Single Package, Dual Core
147 a) One thread per core
149 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
150 -> [core 1] -> [thread 0] -> Linux CPU 1
152 b) Two threads per core
154 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
155 -> [thread 1] -> Linux CPU 1
156 -> [core 1] -> [thread 0] -> Linux CPU 2
157 -> [thread 1] -> Linux CPU 3
159 Alternative enumeration:
161 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
162 -> [thread 1] -> Linux CPU 2
163 -> [core 1] -> [thread 0] -> Linux CPU 1
164 -> [thread 1] -> Linux CPU 3
166 AMD nomenclature for CMT systems:
168 [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
169 -> [Compute Unit Core 1] -> Linux CPU 1
170 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
171 -> [Compute Unit Core 1] -> Linux CPU 3
173 4) Dual Package, Dual Core
175 a) One thread per core
177 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
178 -> [core 1] -> [thread 0] -> Linux CPU 1
180 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
181 -> [core 1] -> [thread 0] -> Linux CPU 3
183 b) Two threads per core
185 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
186 -> [thread 1] -> Linux CPU 1
187 -> [core 1] -> [thread 0] -> Linux CPU 2
188 -> [thread 1] -> Linux CPU 3
190 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 4
191 -> [thread 1] -> Linux CPU 5
192 -> [core 1] -> [thread 0] -> Linux CPU 6
193 -> [thread 1] -> Linux CPU 7
195 Alternative enumeration:
197 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
198 -> [thread 1] -> Linux CPU 4
199 -> [core 1] -> [thread 0] -> Linux CPU 1
200 -> [thread 1] -> Linux CPU 5
202 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
203 -> [thread 1] -> Linux CPU 6
204 -> [core 1] -> [thread 0] -> Linux CPU 3
205 -> [thread 1] -> Linux CPU 7
207 AMD nomenclature for CMT systems:
209 [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
210 -> [Compute Unit Core 1] -> Linux CPU 1
211 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
212 -> [Compute Unit Core 1] -> Linux CPU 3
214 [node 1] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 4
215 -> [Compute Unit Core 1] -> Linux CPU 5
216 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 6
217 -> [Compute Unit Core 1] -> Linux CPU 7