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.
69 A core consists of 1 or more threads. It does not matter whether the threads
70 are SMT- or CMT-type threads.
72 AMDs nomenclature for a CMT core is "Compute Unit". The kernel always uses
75 Core-related topology information in the kernel:
79 The number of threads in a core. The number of threads in a package can be
82 threads_per_package = cpuinfo_x86.x86_max_cores * smp_num_siblings
87 A thread is a single scheduling unit. It's the equivalent to a logical Linux
90 AMDs nomenclature for CMT threads is "Compute Unit Core". The kernel always
93 Thread-related topology information in the kernel:
95 - topology_core_cpumask():
97 The cpumask contains all online threads in the package to which a thread
100 The number of online threads is also printed in /proc/cpuinfo "siblings."
102 - topology_sibling_mask():
104 The cpumask contains all online threads in the core to which a thread
107 - topology_logical_package_id():
109 The logical package ID to which a thread belongs.
111 - topology_physical_package_id():
113 The physical package ID to which a thread belongs.
115 - topology_core_id();
117 The ID of the core to which a thread belongs. It is also printed in /proc/cpuinfo
122 System topology examples
126 The alternative Linux CPU enumeration depends on how the BIOS enumerates the
127 threads. Many BIOSes enumerate all threads 0 first and then all threads 1.
128 That has the "advantage" that the logical Linux CPU numbers of threads 0 stay
129 the same whether threads are enabled or not. That's merely an implementation
130 detail and has no practical impact.
132 1) Single Package, Single Core
134 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
136 2) Single Package, Dual Core
138 a) One thread per core
140 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
141 -> [core 1] -> [thread 0] -> Linux CPU 1
143 b) Two threads per core
145 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
146 -> [thread 1] -> Linux CPU 1
147 -> [core 1] -> [thread 0] -> Linux CPU 2
148 -> [thread 1] -> Linux CPU 3
150 Alternative enumeration:
152 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
153 -> [thread 1] -> Linux CPU 2
154 -> [core 1] -> [thread 0] -> Linux CPU 1
155 -> [thread 1] -> Linux CPU 3
157 AMD nomenclature for CMT systems:
159 [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
160 -> [Compute Unit Core 1] -> Linux CPU 1
161 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
162 -> [Compute Unit Core 1] -> Linux CPU 3
164 4) Dual Package, Dual Core
166 a) One thread per core
168 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
169 -> [core 1] -> [thread 0] -> Linux CPU 1
171 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
172 -> [core 1] -> [thread 0] -> Linux CPU 3
174 b) Two threads per core
176 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
177 -> [thread 1] -> Linux CPU 1
178 -> [core 1] -> [thread 0] -> Linux CPU 2
179 -> [thread 1] -> Linux CPU 3
181 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 4
182 -> [thread 1] -> Linux CPU 5
183 -> [core 1] -> [thread 0] -> Linux CPU 6
184 -> [thread 1] -> Linux CPU 7
186 Alternative enumeration:
188 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
189 -> [thread 1] -> Linux CPU 4
190 -> [core 1] -> [thread 0] -> Linux CPU 1
191 -> [thread 1] -> Linux CPU 5
193 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
194 -> [thread 1] -> Linux CPU 6
195 -> [core 1] -> [thread 0] -> Linux CPU 3
196 -> [thread 1] -> Linux CPU 7
198 AMD nomenclature for CMT systems:
200 [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
201 -> [Compute Unit Core 1] -> Linux CPU 1
202 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
203 -> [Compute Unit Core 1] -> Linux CPU 3
205 [node 1] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 4
206 -> [Compute Unit Core 1] -> Linux CPU 5
207 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 6
208 -> [Compute Unit Core 1] -> Linux CPU 7