^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) ===========================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) How CPU topology info is exported via sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ===========================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) Export CPU topology info via sysfs. Items (attributes) are similar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) to /proc/cpuinfo output of some architectures. They reside in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) /sys/devices/system/cpu/cpuX/topology/:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) physical_package_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) physical package id of cpuX. Typically corresponds to a physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) socket number, but the actual value is architecture and platform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) dependent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) die_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) the CPU die ID of cpuX. Typically it is the hardware platform's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) identifier (rather than the kernel's). The actual value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) architecture and platform dependent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) core_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) the CPU core ID of cpuX. Typically it is the hardware platform's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) identifier (rather than the kernel's). The actual value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) architecture and platform dependent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) book_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) the book ID of cpuX. Typically it is the hardware platform's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) identifier (rather than the kernel's). The actual value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) architecture and platform dependent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) drawer_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) the drawer ID of cpuX. Typically it is the hardware platform's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) identifier (rather than the kernel's). The actual value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) architecture and platform dependent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) core_cpus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) internal kernel map of CPUs within the same core.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) (deprecated name: "thread_siblings")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) core_cpus_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) human-readable list of CPUs within the same core.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) (deprecated name: "thread_siblings_list");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) package_cpus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) internal kernel map of the CPUs sharing the same physical_package_id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) (deprecated name: "core_siblings")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) package_cpus_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) human-readable list of CPUs sharing the same physical_package_id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) (deprecated name: "core_siblings_list")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) die_cpus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) internal kernel map of CPUs within the same die.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) die_cpus_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) human-readable list of CPUs within the same die.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) book_siblings:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) internal kernel map of cpuX's hardware threads within the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) book_id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) book_siblings_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) human-readable list of cpuX's hardware threads within the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) book_id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) drawer_siblings:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) internal kernel map of cpuX's hardware threads within the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) drawer_id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) drawer_siblings_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) human-readable list of cpuX's hardware threads within the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) drawer_id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) Architecture-neutral, drivers/base/topology.c, exports these attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) However, the book and drawer related sysfs files will only be created if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) CONFIG_SCHED_BOOK and CONFIG_SCHED_DRAWER are selected, respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) CONFIG_SCHED_BOOK and CONFIG_SCHED_DRAWER are currently only used on s390,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) where they reflect the cpu and cache hierarchy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) For an architecture to support this feature, it must define some of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) these macros in include/asm-XXX/topology.h::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define topology_physical_package_id(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define topology_die_id(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define topology_core_id(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define topology_book_id(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define topology_drawer_id(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define topology_sibling_cpumask(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define topology_core_cpumask(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define topology_die_cpumask(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define topology_book_cpumask(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define topology_drawer_cpumask(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) The type of ``**_id macros`` is int.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) The type of ``**_cpumask macros`` is ``(const) struct cpumask *``. The latter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) correspond with appropriate ``**_siblings`` sysfs attributes (except for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) topology_sibling_cpumask() which corresponds with thread_siblings).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) To be consistent on all architectures, include/linux/topology.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) provides default definitions for any of the above macros that are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) not defined by include/asm-XXX/topology.h:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 1) topology_physical_package_id: -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 2) topology_die_id: -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 3) topology_core_id: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 4) topology_sibling_cpumask: just the given CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 5) topology_core_cpumask: just the given CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 6) topology_die_cpumask: just the given CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) For architectures that don't support books (CONFIG_SCHED_BOOK) there are no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) default definitions for topology_book_id() and topology_book_cpumask().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) For architectures that don't support drawers (CONFIG_SCHED_DRAWER) there are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) no default definitions for topology_drawer_id() and topology_drawer_cpumask().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) Additionally, CPU topology information is provided under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /sys/devices/system/cpu and includes these files. The internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) source for the output is in brackets ("[]").
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) =========== ==========================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) kernel_max: the maximum CPU index allowed by the kernel configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) [NR_CPUS-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) offline: CPUs that are not online because they have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) HOTPLUGGED off (see cpu-hotplug.txt) or exceed the limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) of CPUs allowed by the kernel configuration (kernel_max
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) above). [~cpu_online_mask + cpus >= NR_CPUS]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) online: CPUs that are online and being scheduled [cpu_online_mask]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) possible: CPUs that have been allocated resources and can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) brought online if they are present. [cpu_possible_mask]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) present: CPUs that have been identified as being present in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) system. [cpu_present_mask]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) =========== ==========================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) The format for the above output is compatible with cpulist_parse()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) [see <linux/cpumask.h>]. Some examples follow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) In this example, there are 64 CPUs in the system but cpus 32-63 exceed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) the kernel max which is limited to 0..31 by the NR_CPUS config option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) being 32. Note also that CPUs 2 and 4-31 are not online but could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) brought online as they are both present and possible::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) kernel_max: 31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) offline: 2,4-31,32-63
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) online: 0-1,3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) possible: 0-31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) present: 0-31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) In this example, the NR_CPUS config option is 128, but the kernel was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) started with possible_cpus=144. There are 4 CPUs in the system and cpu2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) was manually taken offline (and is the only CPU that can be brought
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) online.)::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) kernel_max: 127
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) offline: 2,4-127,128-143
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) online: 0-1,3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) possible: 0-127
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) present: 0-3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) See cpu-hotplug.txt for the possible_cpus=NUM kernel start parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) as well as more information on the various cpumasks.