blob: 8e9704f6101755ba5626117603c2cfd06f396484 [file] [log] [blame]
Changbin Du848942c2019-05-08 23:21:17 +08001.. SPDX-License-Identifier: GPL-2.0
2
3============
Borislav Petkovf7be8612016-03-28 11:56:09 +02004x86 Topology
5============
6
7This documents and clarifies the main aspects of x86 topology modelling and
8representation in the kernel. Update/change when doing changes to the
9respective code.
10
11The architecture-agnostic topology definitions are in
12Documentation/cputopology.txt. This file holds x86-specific
13differences/specialities which must not necessarily apply to the generic
14definitions. Thus, the way to read up on Linux topology on x86 is to start
15with the generic one and look at this one in parallel for the x86 specifics.
16
17Needless to say, code should use the generic functions - this file is *only*
18here to *document* the inner workings of x86 topology.
19
20Started by Thomas Gleixner <tglx@linutronix.de> and Borislav Petkov <bp@alien8.de>.
21
22The main aim of the topology facilities is to present adequate interfaces to
23code which needs to know/query/use the structure of the running system wrt
24threads, cores, packages, etc.
25
26The kernel does not care about the concept of physical sockets because a
27socket has no relevance to software. It's an electromechanical component. In
28the past a socket always contained a single package (see below), but with the
29advent of Multi Chip Modules (MCM) a socket can hold more than one package. So
30there might be still references to sockets in the code, but they are of
31historical nature and should be cleaned up.
32
33The topology of a system is described in the units of:
34
35 - packages
36 - cores
37 - threads
38
Changbin Du848942c2019-05-08 23:21:17 +080039Package
40=======
41Packages contain a number of cores plus shared resources, e.g. DRAM
42controller, shared caches etc.
Borislav Petkovf7be8612016-03-28 11:56:09 +020043
Changbin Du848942c2019-05-08 23:21:17 +080044AMD nomenclature for package is 'Node'.
Borislav Petkovf7be8612016-03-28 11:56:09 +020045
Changbin Du848942c2019-05-08 23:21:17 +080046Package-related topology information in the kernel:
Borislav Petkovf7be8612016-03-28 11:56:09 +020047
48 - cpuinfo_x86.x86_max_cores:
49
50 The number of cores in a package. This information is retrieved via CPUID.
51
Len Brown7745f032019-05-13 13:58:45 -040052 - cpuinfo_x86.x86_max_dies:
53
54 The number of dies in a package. This information is retrieved via CPUID.
55
Borislav Petkovf7be8612016-03-28 11:56:09 +020056 - cpuinfo_x86.phys_proc_id:
57
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.
60
Len Brownef7c7722019-02-26 01:19:59 -050061 - cpuinfo_x86.logical_proc_id:
Borislav Petkovf7be8612016-03-28 11:56:09 +020062
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.
67
68 - topology_max_packages():
69
70 The maximum possible number of packages in the system. Helpful for per
71 package facilities to preallocate per package information.
72
Borislav Petkova268b5f2016-11-17 10:45:57 +010073 - cpu_llc_id:
74
75 A per-CPU variable containing:
Borislav Petkova268b5f2016-11-17 10:45:57 +010076
Changbin Du848942c2019-05-08 23:21:17 +080077 - On Intel, the first APIC ID of the list of CPUs sharing the Last Level
78 Cache
Borislav Petkovf7be8612016-03-28 11:56:09 +020079
Changbin Du848942c2019-05-08 23:21:17 +080080 - 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
82 system.
Borislav Petkovf7be8612016-03-28 11:56:09 +020083
Changbin Du848942c2019-05-08 23:21:17 +080084Cores
85=====
86A core consists of 1 or more threads. It does not matter whether the threads
87are SMT- or CMT-type threads.
Borislav Petkovf7be8612016-03-28 11:56:09 +020088
Changbin Du848942c2019-05-08 23:21:17 +080089AMDs nomenclature for a CMT core is "Compute Unit". The kernel always uses
90"core".
Borislav Petkovf7be8612016-03-28 11:56:09 +020091
Changbin Du848942c2019-05-08 23:21:17 +080092Core-related topology information in the kernel:
Borislav Petkovf7be8612016-03-28 11:56:09 +020093
94 - smp_num_siblings:
95
96 The number of threads in a core. The number of threads in a package can be
Changbin Du848942c2019-05-08 23:21:17 +080097 calculated by::
Borislav Petkovf7be8612016-03-28 11:56:09 +020098
99 threads_per_package = cpuinfo_x86.x86_max_cores * smp_num_siblings
100
101
Changbin Du848942c2019-05-08 23:21:17 +0800102Threads
103=======
104A thread is a single scheduling unit. It's the equivalent to a logical Linux
105CPU.
Borislav Petkovf7be8612016-03-28 11:56:09 +0200106
Changbin Du848942c2019-05-08 23:21:17 +0800107AMDs nomenclature for CMT threads is "Compute Unit Core". The kernel always
108uses "thread".
Borislav Petkovf7be8612016-03-28 11:56:09 +0200109
Changbin Du848942c2019-05-08 23:21:17 +0800110Thread-related topology information in the kernel:
Borislav Petkovf7be8612016-03-28 11:56:09 +0200111
112 - topology_core_cpumask():
113
114 The cpumask contains all online threads in the package to which a thread
115 belongs.
116
117 The number of online threads is also printed in /proc/cpuinfo "siblings."
118
Dou Liyang0c52f7c2018-02-22 16:48:12 +0800119 - topology_sibling_cpumask():
Borislav Petkovf7be8612016-03-28 11:56:09 +0200120
121 The cpumask contains all online threads in the core to which a thread
122 belongs.
123
Changbin Du848942c2019-05-08 23:21:17 +0800124 - topology_logical_package_id():
Borislav Petkovf7be8612016-03-28 11:56:09 +0200125
126 The logical package ID to which a thread belongs.
127
Changbin Du848942c2019-05-08 23:21:17 +0800128 - topology_physical_package_id():
Borislav Petkovf7be8612016-03-28 11:56:09 +0200129
130 The physical package ID to which a thread belongs.
131
Changbin Du848942c2019-05-08 23:21:17 +0800132 - topology_core_id();
Borislav Petkovf7be8612016-03-28 11:56:09 +0200133
134 The ID of the core to which a thread belongs. It is also printed in /proc/cpuinfo
135 "core_id."
136
137
138
139System topology examples
Changbin Du848942c2019-05-08 23:21:17 +0800140========================
Borislav Petkovf7be8612016-03-28 11:56:09 +0200141
Changbin Du848942c2019-05-08 23:21:17 +0800142.. note::
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.
Borislav Petkovf7be8612016-03-28 11:56:09 +0200148
Changbin Du848942c2019-05-08 23:21:17 +08001491) Single Package, Single Core::
Borislav Petkovf7be8612016-03-28 11:56:09 +0200150
151 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
152
1532) Single Package, Dual Core
154
Changbin Du848942c2019-05-08 23:21:17 +0800155 a) One thread per core::
Borislav Petkovf7be8612016-03-28 11:56:09 +0200156
157 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
158 -> [core 1] -> [thread 0] -> Linux CPU 1
159
Changbin Du848942c2019-05-08 23:21:17 +0800160 b) Two threads per core::
Borislav Petkovf7be8612016-03-28 11:56:09 +0200161
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
166
Changbin Du848942c2019-05-08 23:21:17 +0800167 Alternative enumeration::
Borislav Petkovf7be8612016-03-28 11:56:09 +0200168
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
173
Changbin Du848942c2019-05-08 23:21:17 +0800174 AMD nomenclature for CMT systems::
Borislav Petkovf7be8612016-03-28 11:56:09 +0200175
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
180
1814) Dual Package, Dual Core
182
Changbin Du848942c2019-05-08 23:21:17 +0800183 a) One thread per core::
Borislav Petkovf7be8612016-03-28 11:56:09 +0200184
185 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
186 -> [core 1] -> [thread 0] -> Linux CPU 1
187
188 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
189 -> [core 1] -> [thread 0] -> Linux CPU 3
190
Changbin Du848942c2019-05-08 23:21:17 +0800191 b) Two threads per core::
Borislav Petkovf7be8612016-03-28 11:56:09 +0200192
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
197
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
202
Changbin Du848942c2019-05-08 23:21:17 +0800203 Alternative enumeration::
Borislav Petkovf7be8612016-03-28 11:56:09 +0200204
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
209
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
214
Changbin Du848942c2019-05-08 23:21:17 +0800215 AMD nomenclature for CMT systems::
Borislav Petkovf7be8612016-03-28 11:56:09 +0200216
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
221
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