<!DOCTYPE html>
<html lang="en" data-content_root="../../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>4. x86 Topology — The Linux Kernel documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/alabaster.css?v=3918102e" />
<script src="../../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../../_static/doctools.js?v=9bcbadda"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="5. Kernel level exception handling" href="exception-tables.html" />
<link rel="prev" title="3. x86 Feature Flags" href="cpuinfo.html" />
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
</head><body>
<div class="document">
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../../index.html">
<img class="logo" src="../../_static/logo.svg" alt="Logo of The Linux Kernel"/>
</a></p>
<h1 class="logo"><a href="../../index.html">The Linux Kernel</a></h1>
<p class="blurb">6.18.50</p>
<search id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
<p>
<h3 class="kernel-toc-contents">Contents</h3>
<input type="checkbox" class="kernel-toc-toggle" id = "kernel-toc-toggle" checked>
<label class="kernel-toc-title" for="kernel-toc-toggle"></label>
<div class="kerneltoc" id="kerneltoc">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../process/development-process.html">Development process</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/submitting-patches.html">Submitting patches</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/code-of-conduct.html">Code of conduct</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../maintainer/index.html">Maintainer handbook</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/index.html">All development-process docs</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../core-api/index.html">Core API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../driver-api/index.html">Driver APIs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../subsystem-apis.html">Subsystems</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../locking/index.html">Locking</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../process/license-rules.html">Licensing rules</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../doc-guide/index.html">Writing documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev-tools/index.html">Development tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev-tools/testing-overview.html">Testing guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../kernel-hacking/index.html">Hacking guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../trace/index.html">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fault-injection/index.html">Fault injection</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livepatch/index.html">Livepatching</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rust/index.html">Rust</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../admin-guide/index.html">Administration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../kbuild/index.html">Build system</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../admin-guide/reporting-issues.html">Reporting issues</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../tools/index.html">Userspace tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../userspace-api/index.html">Userspace API</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../firmware-guide/index.html">Firmware</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../devicetree/index.html">Firmware and Devicetree</a></li>
</ul>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">CPU architectures</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../arc/index.html">ARC architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../arm/index.html">ARM Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../arm64/index.html">ARM64 Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../loongarch/index.html">LoongArch Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../m68k/index.html">m68k Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mips/index.html">MIPS-specific Documentation</a></li>
<li class="toctree-l2"><a class="reference internal" href="../nios2/index.html">Nios II Specific Documentation</a></li>
<li class="toctree-l2"><a class="reference internal" href="../openrisc/index.html">OpenRISC Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../parisc/index.html">PA-RISC Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../powerpc/index.html">powerpc</a></li>
<li class="toctree-l2"><a class="reference internal" href="../riscv/index.html">RISC-V architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../s390/index.html">s390 Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../sh/index.html">SuperH Interfaces Guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="../sparc/index.html">Sparc Architecture</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">x86-specific Documentation</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="boot.html">1. The Linux/x86 Boot Protocol</a></li>
<li class="toctree-l3"><a class="reference internal" href="booting-dt.html">2. DeviceTree Booting</a></li>
<li class="toctree-l3"><a class="reference internal" href="cpuinfo.html">3. x86 Feature Flags</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">4. x86 Topology</a></li>
<li class="toctree-l3"><a class="reference internal" href="exception-tables.html">5. Kernel level exception handling</a></li>
<li class="toctree-l3"><a class="reference internal" href="kernel-stacks.html">6. Kernel Stacks</a></li>
<li class="toctree-l3"><a class="reference internal" href="entry_64.html">7. Kernel Entries</a></li>
<li class="toctree-l3"><a class="reference internal" href="earlyprintk.html">8. Early Printk</a></li>
<li class="toctree-l3"><a class="reference internal" href="orc-unwinder.html">9. ORC unwinder</a></li>
<li class="toctree-l3"><a class="reference internal" href="zero-page.html">10. Zero Page</a></li>
<li class="toctree-l3"><a class="reference internal" href="tlb.html">11. The TLB</a></li>
<li class="toctree-l3"><a class="reference internal" href="mtrr.html">12. MTRR (Memory Type Range Register) control</a></li>
<li class="toctree-l3"><a class="reference internal" href="pat.html">13. PAT (Page Attribute Table)</a></li>
<li class="toctree-l3"><a class="reference internal" href="intel-hfi.html">14. Hardware-Feedback Interface for scheduling on Intel Hardware</a></li>
<li class="toctree-l3"><a class="reference internal" href="shstk.html">15. Control-flow Enforcement Technology (CET) Shadow Stack</a></li>
<li class="toctree-l3"><a class="reference internal" href="iommu.html">16. x86 IOMMU Support</a></li>
<li class="toctree-l3"><a class="reference internal" href="intel_txt.html">17. Intel(R) TXT Overview</a></li>
<li class="toctree-l3"><a class="reference internal" href="amd-debugging.html">18. Debugging AMD Zen systems</a></li>
<li class="toctree-l3"><a class="reference internal" href="amd-memory-encryption.html">19. AMD Memory Encryption</a></li>
<li class="toctree-l3"><a class="reference internal" href="amd_hsmp.html">20. AMD HSMP interface</a></li>
<li class="toctree-l3"><a class="reference internal" href="amd-hfi.html">21. Hardware Feedback Interface For Hetero Core Scheduling On AMD Platform</a></li>
<li class="toctree-l3"><a class="reference internal" href="tdx.html">22. Intel Trust Domain Extensions (TDX)</a></li>
<li class="toctree-l3"><a class="reference internal" href="pti.html">23. Page Table Isolation (PTI)</a></li>
<li class="toctree-l3"><a class="reference internal" href="mds.html">24. Microarchitectural Data Sampling (MDS) mitigation</a></li>
<li class="toctree-l3"><a class="reference internal" href="microcode.html">25. The Linux Microcode Loader</a></li>
<li class="toctree-l3"><a class="reference internal" href="tsx_async_abort.html">26. TSX Async Abort (TAA) mitigation</a></li>
<li class="toctree-l3"><a class="reference internal" href="buslock.html">27. Bus lock detection and handling</a></li>
<li class="toctree-l3"><a class="reference internal" href="usb-legacy-support.html">28. USB Legacy support</a></li>
<li class="toctree-l3"><a class="reference internal" href="i386/index.html">29. i386 Support</a></li>
<li class="toctree-l3"><a class="reference internal" href="x86_64/index.html">30. x86_64 Support</a></li>
<li class="toctree-l3"><a class="reference internal" href="ifs.html">31. In-Field Scan</a></li>
<li class="toctree-l3"><a class="reference internal" href="sva.html">32. Shared Virtual Addressing (SVA) with ENQCMD</a></li>
<li class="toctree-l3"><a class="reference internal" href="sgx.html">33. Software Guard eXtensions (SGX)</a></li>
<li class="toctree-l3"><a class="reference internal" href="features.html">34. Feature status on x86 architecture</a></li>
<li class="toctree-l3"><a class="reference internal" href="elf_auxvec.html">35. x86-specific ELF Auxiliary Vectors</a></li>
<li class="toctree-l3"><a class="reference internal" href="xstate.html">36. Using XSTATE features in user space applications</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../xtensa/index.html">Xtensa Architecture</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../staging/index.html">Unsorted documentation</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../translations/index.html">Translations</a></li>
</ul>
</div>
<script type="text/javascript"> <!--
var sbar = document.getElementsByClassName("sphinxsidebar")[0];
let currents = document.getElementsByClassName("current")
if (currents.length) {
sbar.scrollTop = currents[currents.length - 1].offsetTop;
}
--> </script>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../_sources/arch/x86/topology.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
</div>
</div>
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="x86-topology">
<h1><span class="section-number">4. </span>x86 Topology<a class="headerlink" href="#x86-topology" title="Link to this heading">¶</a></h1>
<p>This documents and clarifies the main aspects of x86 topology modelling and
representation in the kernel. Update/change when doing changes to the
respective code.</p>
<p>The architecture-agnostic topology definitions are in
<a class="reference internal" href="../../admin-guide/cputopology.html"><span class="doc">How CPU topology info is exported via sysfs</span></a>. This file holds x86-specific
differences/specialities which must not necessarily apply to the generic
definitions. Thus, the way to read up on Linux topology on x86 is to start
with the generic one and look at this one in parallel for the x86 specifics.</p>
<p>Needless to say, code should use the generic functions - this file is <em>only</em>
here to <em>document</em> the inner workings of x86 topology.</p>
<p>Started by Thomas Gleixner <<a class="reference external" href="mailto:tglx%40linutronix.de">tglx<span>@</span>linutronix<span>.</span>de</a>> and Borislav Petkov <<a class="reference external" href="mailto:bp%40alien8.de">bp<span>@</span>alien8<span>.</span>de</a>>.</p>
<p>The main aim of the topology facilities is to present adequate interfaces to
code which needs to know/query/use the structure of the running system wrt
threads, cores, packages, etc.</p>
<p>The kernel does not care about the concept of physical sockets because a
socket has no relevance to software. It’s an electromechanical component. In
the past a socket always contained a single package (see below), but with the
advent of Multi Chip Modules (MCM) a socket can hold more than one package. So
there might be still references to sockets in the code, but they are of
historical nature and should be cleaned up.</p>
<p>The topology of a system is described in the units of:</p>
<blockquote>
<div><ul class="simple">
<li><p>packages</p></li>
<li><p>cores</p></li>
<li><p>threads</p></li>
</ul>
</div></blockquote>
<section id="package">
<h2><span class="section-number">4.1. </span>Package<a class="headerlink" href="#package" title="Link to this heading">¶</a></h2>
<p>Packages contain a number of cores plus shared resources, e.g. DRAM
controller, shared caches etc.</p>
<p>Modern systems may also use the term ‘Die’ for package.</p>
<p>AMD nomenclature for package is ‘Node’.</p>
<p>Package-related topology information in the kernel:</p>
<blockquote>
<div><ul>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">topology_num_threads_per_package()</span></code></p>
<p>The number of threads in a package.</p>
</li>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">topology_num_cores_per_package()</span></code></p>
<p>The number of cores in a package.</p>
</li>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">topology_max_dies_per_package()</span></code></p>
<p>The maximum number of dies in a package.</p>
</li>
<li><p>cpuinfo_x86.topo.die_id:</p>
<p>The physical ID of the die.</p>
</li>
<li><p>cpuinfo_x86.topo.pkg_id:</p>
<p>The physical ID of the package. This information is retrieved via CPUID
and deduced from the APIC IDs of the cores in the package.</p>
<p>Modern systems use this value for the socket. There may be multiple
packages within a socket. This value may differ from topo.die_id.</p>
</li>
<li><p>cpuinfo_x86.topo.logical_pkg_id:</p>
<p>The logical ID of the package. As we do not trust BIOSes to enumerate the
packages in a consistent way, we introduced the concept of logical package
ID so we can sanely calculate the number of maximum possible packages in
the system and have the packages enumerated linearly.</p>
</li>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">topology_max_packages()</span></code>:</p>
<p>The maximum possible number of packages in the system. Helpful for per
package facilities to preallocate per package information.</p>
</li>
<li><p>cpuinfo_x86.topo.llc_id:</p>
<blockquote>
<div><ul class="simple">
<li><p>On Intel, the first APIC ID of the list of CPUs sharing the Last Level
Cache</p></li>
<li><p>On AMD, the Node ID or Core Complex ID containing the Last Level
Cache. In general, it is a number identifying an LLC uniquely on the
system.</p></li>
</ul>
</div></blockquote>
</li>
</ul>
</div></blockquote>
</section>
<section id="cores">
<h2><span class="section-number">4.2. </span>Cores<a class="headerlink" href="#cores" title="Link to this heading">¶</a></h2>
<p>A core consists of 1 or more threads. It does not matter whether the threads
are SMT- or CMT-type threads.</p>
<p>AMDs nomenclature for a CMT core is “Compute Unit”. The kernel always uses
“core”.</p>
</section>
<section id="threads">
<h2><span class="section-number">4.3. </span>Threads<a class="headerlink" href="#threads" title="Link to this heading">¶</a></h2>
<p>A thread is a single scheduling unit. It’s the equivalent to a logical Linux
CPU.</p>
<p>AMDs nomenclature for CMT threads is “Compute Unit Core”. The kernel always
uses “thread”.</p>
<p>Thread-related topology information in the kernel:</p>
<blockquote>
<div><ul>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">topology_core_cpumask()</span></code>:</p>
<p>The cpumask contains all online threads in the package to which a thread
belongs.</p>
<p>The number of online threads is also printed in /proc/cpuinfo “siblings.”</p>
</li>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">topology_sibling_cpumask()</span></code>:</p>
<p>The cpumask contains all online threads in the core to which a thread
belongs.</p>
</li>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">topology_logical_package_id()</span></code>:</p>
<p>The logical package ID to which a thread belongs.</p>
</li>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">topology_physical_package_id()</span></code>:</p>
<p>The physical package ID to which a thread belongs.</p>
</li>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">topology_core_id()</span></code>;</p>
<p>The ID of the core to which a thread belongs. It is also printed in /proc/cpuinfo
“core_id.”</p>
</li>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">topology_logical_core_id()</span></code>;</p>
<p>The logical core ID to which a thread belongs.</p>
</li>
</ul>
</div></blockquote>
</section>
<section id="system-topology-enumeration">
<h2><span class="section-number">4.4. </span>System topology enumeration<a class="headerlink" href="#system-topology-enumeration" title="Link to this heading">¶</a></h2>
<p>The topology on x86 systems can be discovered using a combination of vendor
specific CPUID leaves which enumerate the processor topology and the cache
hierarchy.</p>
<p>The CPUID leaves in their preferred order of parsing for each x86 vendor is as
follows:</p>
<ol class="arabic">
<li><p>AMD</p>
<ol class="arabic">
<li><p>CPUID leaf 0x80000026 [Extended CPU Topology] (Core::X86::Cpuid::ExCpuTopology)</p>
<p>The extended CPUID leaf 0x80000026 is the extension of the CPUID leaf 0xB
and provides the topology information of Core, Complex, CCD (Die), and
Socket in each level.</p>
<p>Support for the leaf is discovered by checking if the maximum extended
CPUID level is >= 0x80000026 and then checking if <cite>LogProcAtThisLevel</cite>
in <cite>EBX[15:0]</cite> at a particular level (starting from 0) is non-zero.</p>
<p>The <cite>LevelType</cite> in <cite>ECX[15:8]</cite> at the level provides the topology domain
the level describes - Core, Complex, CCD(Die), or the Socket.</p>
<p>The kernel uses the <cite>CoreMaskWidth</cite> from <cite>EAX[4:0]</cite> to discover the
number of bits that need to be right-shifted from <cite>ExtendedLocalApicId</cite>
in <cite>EDX[31:0]</cite> in order to get a unique Topology ID for the topology
level. CPUs with the same Topology ID share the resources at that level.</p>
<p>CPUID leaf 0x80000026 also provides more information regarding the power
and efficiency rankings, and about the core type on AMD processors with
heterogeneous characteristics.</p>
<p>If CPUID leaf 0x80000026 is supported, further parsing is not required.</p>
</li>
<li><p>CPUID leaf 0x0000000B [Extended Topology Enumeration] (Core::X86::Cpuid::ExtTopEnum)</p>
<p>The extended CPUID leaf 0x0000000B is the predecessor on the extended
CPUID leaf 0x80000026 and only describes the core, and the socket domains
of the processor topology.</p>
<p>The support for the leaf is discovered by checking if the maximum supported
CPUID level is >= 0xB and then if <cite>EBX[31:0]</cite> at a particular level
(starting from 0) is non-zero.</p>
<p>The <cite>LevelType</cite> in <cite>ECX[15:8]</cite> at the level provides the topology domain
that the level describes - Thread, or Processor (Socket).</p>
<p>The kernel uses the <cite>CoreMaskWidth</cite> from <cite>EAX[4:0]</cite> to discover the
number of bits that need to be right-shifted from the <cite>ExtendedLocalApicId</cite>
in <cite>EDX[31:0]</cite> to get a unique Topology ID for that topology level. CPUs
sharing the Topology ID share the resources at that level.</p>
<p>If CPUID leaf 0xB is supported, further parsing is not required.</p>
</li>
<li><p>CPUID leaf 0x80000008 ECX [Size Identifiers] (Core::X86::Cpuid::SizeId)</p>
<p>If neither the CPUID leaf 0x80000026 nor 0xB is supported, the number of
CPUs on the package is detected using the Size Identifier leaf
0x80000008 ECX.</p>
<p>The support for the leaf is discovered by checking if the supported
extended CPUID level is >= 0x80000008.</p>
<p>The shifts from the APIC ID for the Socket ID is calculated from the
<cite>ApicIdSize</cite> field in <cite>ECX[15:12]</cite> if it is non-zero.</p>
<p>If <cite>ApicIdSize</cite> is reported to be zero, the shift is calculated as the
order of the <cite>number of threads</cite> calculated from <cite>NC</cite> field in
<cite>ECX[7:0]</cite> which describes the <cite>number of threads - 1</cite> on the package.</p>
<p>Unless Extended APIC ID is supported, the APIC ID used to find the
Socket ID is from the <cite>LocalApicId</cite> field of CPUID leaf 0x00000001
<cite>EBX[31:24]</cite>.</p>
<p>The topology parsing continues to detect if Extended APIC ID is
supported or not.</p>
</li>
<li><p>CPUID leaf 0x8000001E [Extended APIC ID, Core Identifiers, Node Identifiers]
(Core::X86::Cpuid::{ExtApicId,CoreId,NodeId})</p>
<p>The support for Extended APIC ID can be detected by checking for the
presence of <cite>TopologyExtensions</cite> in <cite>ECX[22]</cite> of CPUID leaf 0x80000001
[Feature Identifiers] (Core::X86::Cpuid::FeatureExtIdEcx).</p>
<p>If Topology Extensions is supported, the APIC ID from <cite>ExtendedApicId</cite>
from CPUID leaf 0x8000001E <cite>EAX[31:0]</cite> should be preferred over that from
<cite>LocalApicId</cite> field of CPUID leaf 0x00000001 <cite>EBX[31:24]</cite> for topology
enumeration.</p>
<p>On processors of Family 0x17 and above that do not support CPUID leaf
0x80000026 or CPUID leaf 0xB, the shifts from the APIC ID for the Core
ID is calculated using the order of <cite>number of threads per core</cite>
calculated using the <cite>ThreadsPerCore</cite> field in <cite>EBX[15:8]</cite> which
describes <cite>number of threads per core - 1</cite>.</p>
<p>On Processors of Family 0x15, the Core ID from <cite>EBX[7:0]</cite> is used as the
<cite>cu_id</cite> (Compute Unit ID) to detect CPUs that share the compute units.</p>
</li>
</ol>
<p>All AMD processors that support the <cite>TopologyExtensions</cite> feature store the
<cite>NodeId</cite> from the <cite>ECX[7:0]</cite> of CPUID leaf 0x8000001E
(Core::X86::Cpuid::NodeId) as the per-CPU <cite>node_id</cite>. On older processors,
the <cite>node_id</cite> was discovered using MSR_FAM10H_NODE_ID MSR (MSR
0x0xc001_100c). The presence of the NODE_ID MSR was detected by checking
<cite>ECX[19]</cite> of CPUID leaf 0x80000001 [Feature Identifiers]
(Core::X86::Cpuid::FeatureExtIdEcx).</p>
</li>
<li><p>Intel</p>
<p>On Intel platforms, the CPUID leaves that enumerate the processor
topology are as follows:</p>
<ol class="arabic">
<li><p>CPUID leaf 0x1F (V2 Extended Topology Enumeration Leaf)</p>
<p>The CPUID leaf 0x1F is the extension of the CPUID leaf 0xB and provides
the topology information of Core, Module, Tile, Die, DieGrp, and Socket
in each level.</p>
<p>The support for the leaf is discovered by checking if the supported
CPUID level is >= 0x1F and then <cite>EBX[31:0]</cite> at a particular level
(starting from 0) is non-zero.</p>
<p>The <cite>Domain Type</cite> in <cite>ECX[15:8]</cite> of the sub-leaf provides the topology
domain that the level describes - Core, Module, Tile, Die, DieGrp, and
Socket.</p>
<p>The kernel uses the value from <cite>EAX[4:0]</cite> to discover the number of
bits that need to be right shifted from the <cite>x2APIC ID</cite> in <cite>EDX[31:0]</cite>
to get a unique Topology ID for the topology level. CPUs with the same
Topology ID share the resources at that level.</p>
<p>If CPUID leaf 0x1F is supported, further parsing is not required.</p>
</li>
<li><p>CPUID leaf 0x0000000B (Extended Topology Enumeration Leaf)</p>
<p>The extended CPUID leaf 0x0000000B is the predecessor of the V2 Extended
Topology Enumeration Leaf 0x1F and only describes the core, and the
socket domains of the processor topology.</p>
<p>The support for the leaf is iscovered by checking if the supported CPUID
level is >= 0xB and then checking if <cite>EBX[31:0]</cite> at a particular level
(starting from 0) is non-zero.</p>
<p>CPUID leaf 0x0000000B shares the same layout as CPUID leaf 0x1F and
should be enumerated in a similar manner.</p>
<p>If CPUID leaf 0xB is supported, further parsing is not required.</p>
</li>
<li><p>CPUID leaf 0x00000004 (Deterministic Cache Parameters Leaf)</p>
<p>On Intel processors that support neither CPUID leaf 0x1F, nor CPUID leaf
0xB, the shifts for the SMT domains is calculated using the number of
CPUs sharing the L1 cache.</p>
<p>Processors that feature Hyper-Threading is detected using <cite>EDX[28]</cite> of
CPUID leaf 0x1 (Basic CPUID Information).</p>
<p>The order of <cite>Maximum number of addressable IDs for logical processors
sharing this cache</cite> from <cite>EAX[25:14]</cite> of level-0 of CPUID 0x4 provides
the shifts from the APIC ID required to compute the Core ID.</p>
<p>The APIC ID and Package information is computed using the data from
CPUID leaf 0x1.</p>
</li>
<li><p>CPUID leaf 0x00000001 (Basic CPUID Information)</p>
<p>The mask and shifts to derive the Physical Package (socket) ID is
computed using the <cite>Maximum number of addressable IDs for logical
processors in this physical package</cite> from <cite>EBX[23:16]</cite> of CPUID leaf
0x1.</p>
</li>
</ol>
<blockquote>
<div><p>The APIC ID on the legacy platforms is derived from the <cite>Initial APIC
ID</cite> field from <cite>EBX[31:24]</cite> of CPUID leaf 0x1.</p>
</div></blockquote>
</li>
<li><p>Centaur and Zhaoxin</p>
<p>Similar to Intel, Centaur and Zhaoxin use a combination of CPUID leaf
0x00000004 (Deterministic Cache Parameters Leaf) and CPUID leaf 0x00000001
(Basic CPUID Information) to derive the topology information.</p>
</li>
</ol>
</section>
<section id="system-topology-examples">
<h2><span class="section-number">4.5. </span>System topology examples<a class="headerlink" href="#system-topology-examples" title="Link to this heading">¶</a></h2>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The alternative Linux CPU enumeration depends on how the BIOS enumerates the
threads. Many BIOSes enumerate all threads 0 first and then all threads 1.
That has the “advantage” that the logical Linux CPU numbers of threads 0 stay
the same whether threads are enabled or not. That’s merely an implementation
detail and has no practical impact.</p>
</div>
<ol class="arabic">
<li><p>Single Package, Single Core:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
</pre></div>
</div>
</li>
<li><p>Single Package, Dual Core</p>
<ol class="loweralpha">
<li><p>One thread per core:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
-> [core 1] -> [thread 0] -> Linux CPU 1
</pre></div>
</div>
</li>
<li><p>Two threads per core:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
-> [thread 1] -> Linux CPU 1
-> [core 1] -> [thread 0] -> Linux CPU 2
-> [thread 1] -> Linux CPU 3
</pre></div>
</div>
<p>Alternative enumeration:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
-> [thread 1] -> Linux CPU 2
-> [core 1] -> [thread 0] -> Linux CPU 1
-> [thread 1] -> Linux CPU 3
</pre></div>
</div>
<p>AMD nomenclature for CMT systems:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
-> [Compute Unit Core 1] -> Linux CPU 1
-> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
-> [Compute Unit Core 1] -> Linux CPU 3
</pre></div>
</div>
</li>
</ol>
</li>
</ol>
<ol class="arabic" start="4">
<li><p>Dual Package, Dual Core</p>
<ol class="loweralpha">
<li><p>One thread per core:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
-> [core 1] -> [thread 0] -> Linux CPU 1
[package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
-> [core 1] -> [thread 0] -> Linux CPU 3
</pre></div>
</div>
</li>
<li><p>Two threads per core:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
-> [thread 1] -> Linux CPU 1
-> [core 1] -> [thread 0] -> Linux CPU 2
-> [thread 1] -> Linux CPU 3
[package 1] -> [core 0] -> [thread 0] -> Linux CPU 4
-> [thread 1] -> Linux CPU 5
-> [core 1] -> [thread 0] -> Linux CPU 6
-> [thread 1] -> Linux CPU 7
</pre></div>
</div>
<p>Alternative enumeration:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
-> [thread 1] -> Linux CPU 4
-> [core 1] -> [thread 0] -> Linux CPU 1
-> [thread 1] -> Linux CPU 5
[package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
-> [thread 1] -> Linux CPU 6
-> [core 1] -> [thread 0] -> Linux CPU 3
-> [thread 1] -> Linux CPU 7
</pre></div>
</div>
<p>AMD nomenclature for CMT systems:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
-> [Compute Unit Core 1] -> Linux CPU 1
-> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
-> [Compute Unit Core 1] -> Linux CPU 3
[node 1] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 4
-> [Compute Unit Core 1] -> Linux CPU 5
-> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 6
-> [Compute Unit Core 1] -> Linux CPU 7
</pre></div>
</div>
</li>
</ol>
</li>
</ol>
</section>
</section>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
©The kernel development community.
|
Powered by <a href="https://www.sphinx-doc.org/">Sphinx 8.1.3</a>
& <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a>
|
<a href="../../_sources/arch/x86/topology.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>