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