topology.txt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. * Cores:
  46. A core consists of 1 or more threads. It does not matter whether the threads
  47. are SMT- or CMT-type threads.
  48. AMDs nomenclature for a CMT core is "Compute Unit". The kernel always uses
  49. "core".
  50. Core-related topology information in the kernel:
  51. - smp_num_siblings:
  52. The number of threads in a core. The number of threads in a package can be
  53. calculated by:
  54. threads_per_package = cpuinfo_x86.x86_max_cores * smp_num_siblings
  55. * Threads:
  56. A thread is a single scheduling unit. It's the equivalent to a logical Linux
  57. CPU.
  58. AMDs nomenclature for CMT threads is "Compute Unit Core". The kernel always
  59. uses "thread".
  60. Thread-related topology information in the kernel:
  61. - topology_core_cpumask():
  62. The cpumask contains all online threads in the package to which a thread
  63. belongs.
  64. The number of online threads is also printed in /proc/cpuinfo "siblings."
  65. - topology_sibling_mask():
  66. The cpumask contains all online threads in the core to which a thread
  67. belongs.
  68. - topology_logical_package_id():
  69. The logical package ID to which a thread belongs.
  70. - topology_physical_package_id():
  71. The physical package ID to which a thread belongs.
  72. - topology_core_id();
  73. The ID of the core to which a thread belongs. It is also printed in /proc/cpuinfo
  74. "core_id."
  75. System topology examples
  76. Note:
  77. The alternative Linux CPU enumeration depends on how the BIOS enumerates the
  78. threads. Many BIOSes enumerate all threads 0 first and then all threads 1.
  79. That has the "advantage" that the logical Linux CPU numbers of threads 0 stay
  80. the same whether threads are enabled or not. That's merely an implementation
  81. detail and has no practical impact.
  82. 1) Single Package, Single Core
  83. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  84. 2) Single Package, Dual Core
  85. a) One thread per core
  86. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  87. -> [core 1] -> [thread 0] -> Linux CPU 1
  88. b) Two threads per core
  89. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  90. -> [thread 1] -> Linux CPU 1
  91. -> [core 1] -> [thread 0] -> Linux CPU 2
  92. -> [thread 1] -> Linux CPU 3
  93. Alternative enumeration:
  94. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  95. -> [thread 1] -> Linux CPU 2
  96. -> [core 1] -> [thread 0] -> Linux CPU 1
  97. -> [thread 1] -> Linux CPU 3
  98. AMD nomenclature for CMT systems:
  99. [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
  100. -> [Compute Unit Core 1] -> Linux CPU 1
  101. -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
  102. -> [Compute Unit Core 1] -> Linux CPU 3
  103. 4) Dual Package, Dual Core
  104. a) One thread per core
  105. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  106. -> [core 1] -> [thread 0] -> Linux CPU 1
  107. [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
  108. -> [core 1] -> [thread 0] -> Linux CPU 3
  109. b) Two threads per core
  110. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  111. -> [thread 1] -> Linux CPU 1
  112. -> [core 1] -> [thread 0] -> Linux CPU 2
  113. -> [thread 1] -> Linux CPU 3
  114. [package 1] -> [core 0] -> [thread 0] -> Linux CPU 4
  115. -> [thread 1] -> Linux CPU 5
  116. -> [core 1] -> [thread 0] -> Linux CPU 6
  117. -> [thread 1] -> Linux CPU 7
  118. Alternative enumeration:
  119. [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
  120. -> [thread 1] -> Linux CPU 4
  121. -> [core 1] -> [thread 0] -> Linux CPU 1
  122. -> [thread 1] -> Linux CPU 5
  123. [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
  124. -> [thread 1] -> Linux CPU 6
  125. -> [core 1] -> [thread 0] -> Linux CPU 3
  126. -> [thread 1] -> Linux CPU 7
  127. AMD nomenclature for CMT systems:
  128. [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
  129. -> [Compute Unit Core 1] -> Linux CPU 1
  130. -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
  131. -> [Compute Unit Core 1] -> Linux CPU 3
  132. [node 1] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 4
  133. -> [Compute Unit Core 1] -> Linux CPU 5
  134. -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 6
  135. -> [Compute Unit Core 1] -> Linux CPU 7