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