topology.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. x86 Topology
  2. ============
  3. This documents and clarifies the main aspects of x86 topology modelling and
  4. representation in the kernel. Update/change when doing changes to the
  5. respective code.
  6. The architecture-agnostic topology definitions are in
  7. Documentation/cputopology.txt. This file holds x86-specific
  8. differences/specialities which must not necessarily apply to the generic
  9. definitions. Thus, the way to read up on Linux topology on x86 is to start
  10. with the generic one and look at this one in parallel for the x86 specifics.
  11. Needless to say, code should use the generic functions - this file is *only*
  12. here to *document* the inner workings of x86 topology.
  13. Started by Thomas Gleixner <tglx@linutronix.de> and Borislav Petkov <bp@alien8.de>.
  14. The main aim of the topology facilities is to present adequate interfaces to
  15. code which needs to know/query/use the structure of the running system wrt
  16. threads, cores, packages, etc.
  17. The kernel does not care about the concept of physical sockets because a
  18. socket has no relevance to software. It's an electromechanical component. In
  19. the past a socket always contained a single package (see below), but with the
  20. advent of Multi Chip Modules (MCM) a socket can hold more than one package. So
  21. there might be still references to sockets in the code, but they are of
  22. historical nature and should be cleaned up.
  23. The topology of a system is described in the units of:
  24. - packages
  25. - cores
  26. - threads
  27. * Package:
  28. Packages contain a number of cores plus shared resources, e.g. DRAM
  29. controller, shared caches etc.
  30. AMD nomenclature for package is 'Node'.
  31. Package-related topology information in the kernel:
  32. - cpuinfo_x86.x86_max_cores:
  33. The number of cores in a package. This information is retrieved via CPUID.
  34. - cpuinfo_x86.phys_proc_id:
  35. The physical ID of the package. This information is retrieved via CPUID
  36. and deduced from the APIC IDs of the cores in the package.
  37. - cpuinfo_x86.logical_id:
  38. The logical ID of the package. As we do not trust BIOSes to enumerate the
  39. packages in a consistent way, we introduced the concept of logical package
  40. ID so we can sanely calculate the number of maximum possible packages in
  41. the system and have the packages enumerated linearly.
  42. - topology_max_packages():
  43. The maximum possible number of packages in the system. Helpful for per
  44. package facilities to preallocate per package information.
  45. - cpu_llc_id:
  46. A per-CPU variable containing:
  47. - On Intel, the first APIC ID of the list of CPUs sharing the Last Level
  48. Cache
  49. - On AMD, the Node ID or Core Complex ID containing the Last Level
  50. Cache. In general, it is a number identifying an LLC uniquely on the
  51. system.
  52. * Cores:
  53. A core consists of 1 or more threads. It does not matter whether the threads
  54. are SMT- or CMT-type threads.
  55. AMDs nomenclature for a CMT core is "Compute Unit". The kernel always uses
  56. "core".
  57. Core-related topology information in the kernel:
  58. - smp_num_siblings:
  59. The number of threads in a core. The number of threads in a package can be
  60. calculated by:
  61. threads_per_package = cpuinfo_x86.x86_max_cores * smp_num_siblings
  62. * Threads:
  63. A thread is a single scheduling unit. It's the equivalent to a logical Linux
  64. CPU.
  65. AMDs nomenclature for CMT threads is "Compute Unit Core". The kernel always
  66. uses "thread".
  67. Thread-related topology information in the kernel:
  68. - topology_core_cpumask():
  69. The cpumask contains all online threads in the package to which a thread
  70. belongs.
  71. The number of online threads is also printed in /proc/cpuinfo "siblings."
  72. - topology_sibling_cpumask():
  73. The cpumask contains all online threads in the core to which a thread
  74. belongs.
  75. - topology_logical_package_id():
  76. The logical package ID to which a thread belongs.
  77. - topology_physical_package_id():
  78. The physical package ID to which a thread belongs.
  79. - topology_core_id();
  80. The ID of the core to which a thread belongs. It is also printed in /proc/cpuinfo
  81. "core_id."
  82. System topology examples
  83. Note:
  84. The alternative Linux CPU enumeration depends on how the BIOS enumerates the
  85. threads. Many BIOSes enumerate all threads 0 first and then all threads 1.
  86. That has the "advantage" that the logical Linux CPU numbers of threads 0 stay
  87. the same whether threads are enabled or not. That's merely an implementation
  88. detail and has no practical impact.
  89. 1) Single Package, Single Core
  90. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  91. 2) Single Package, Dual Core
  92. a) One thread per core
  93. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  94. -> [core 1] -> [thread 0] -> Linux CPU 1
  95. b) Two threads per core
  96. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  97. -> [thread 1] -> Linux CPU 1
  98. -> [core 1] -> [thread 0] -> Linux CPU 2
  99. -> [thread 1] -> Linux CPU 3
  100. Alternative enumeration:
  101. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  102. -> [thread 1] -> Linux CPU 2
  103. -> [core 1] -> [thread 0] -> Linux CPU 1
  104. -> [thread 1] -> Linux CPU 3
  105. AMD nomenclature for CMT systems:
  106. [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
  107. -> [Compute Unit Core 1] -> Linux CPU 1
  108. -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
  109. -> [Compute Unit Core 1] -> Linux CPU 3
  110. 4) Dual Package, Dual Core
  111. a) One thread per core
  112. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  113. -> [core 1] -> [thread 0] -> Linux CPU 1
  114. [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
  115. -> [core 1] -> [thread 0] -> Linux CPU 3
  116. b) Two threads per core
  117. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  118. -> [thread 1] -> Linux CPU 1
  119. -> [core 1] -> [thread 0] -> Linux CPU 2
  120. -> [thread 1] -> Linux CPU 3
  121. [package 1] -> [core 0] -> [thread 0] -> Linux CPU 4
  122. -> [thread 1] -> Linux CPU 5
  123. -> [core 1] -> [thread 0] -> Linux CPU 6
  124. -> [thread 1] -> Linux CPU 7
  125. Alternative enumeration:
  126. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  127. -> [thread 1] -> Linux CPU 4
  128. -> [core 1] -> [thread 0] -> Linux CPU 1
  129. -> [thread 1] -> Linux CPU 5
  130. [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
  131. -> [thread 1] -> Linux CPU 6
  132. -> [core 1] -> [thread 0] -> Linux CPU 3
  133. -> [thread 1] -> Linux CPU 7
  134. AMD nomenclature for CMT systems:
  135. [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
  136. -> [Compute Unit Core 1] -> Linux CPU 1
  137. -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
  138. -> [Compute Unit Core 1] -> Linux CPU 3
  139. [node 1] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 4
  140. -> [Compute Unit Core 1] -> Linux CPU 5
  141. -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 6
  142. -> [Compute Unit Core 1] -> Linux CPU 7