Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 1 | |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 2 | Export CPU topology info via sysfs. Items (attributes) are similar |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 3 | to /proc/cpuinfo. |
| 4 | |
| 5 | 1) /sys/devices/system/cpu/cpuX/topology/physical_package_id: |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 6 | |
| 7 | physical package id of cpuX. Typically corresponds to a physical |
| 8 | socket number, but the actual value is architecture and platform |
| 9 | dependent. |
| 10 | |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 11 | 2) /sys/devices/system/cpu/cpuX/topology/core_id: |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 12 | |
| 13 | the CPU core ID of cpuX. Typically it is the hardware platform's |
| 14 | identifier (rather than the kernel's). The actual value is |
| 15 | architecture and platform dependent. |
| 16 | |
Heiko Carstens | b40d8ed | 2010-08-31 10:28:17 +0200 | [diff] [blame] | 17 | 3) /sys/devices/system/cpu/cpuX/topology/book_id: |
| 18 | |
| 19 | the book ID of cpuX. Typically it is the hardware platform's |
| 20 | identifier (rather than the kernel's). The actual value is |
| 21 | architecture and platform dependent. |
| 22 | |
| 23 | 4) /sys/devices/system/cpu/cpuX/topology/thread_siblings: |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 24 | |
Xishi Qiu | f8ea61e6 | 2013-09-04 18:58:29 +0800 | [diff] [blame] | 25 | internal kernel map of cpuX's hardware threads within the same |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 26 | core as cpuX |
| 27 | |
Heiko Carstens | b40d8ed | 2010-08-31 10:28:17 +0200 | [diff] [blame] | 28 | 5) /sys/devices/system/cpu/cpuX/topology/core_siblings: |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 29 | |
| 30 | internal kernel map of cpuX's hardware threads within the same |
| 31 | physical_package_id. |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 32 | |
Heiko Carstens | b40d8ed | 2010-08-31 10:28:17 +0200 | [diff] [blame] | 33 | 6) /sys/devices/system/cpu/cpuX/topology/book_siblings: |
| 34 | |
| 35 | internal kernel map of cpuX's hardware threads within the same |
| 36 | book_id. |
| 37 | |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 38 | To implement it in an architecture-neutral way, a new source file, |
Heiko Carstens | b40d8ed | 2010-08-31 10:28:17 +0200 | [diff] [blame] | 39 | drivers/base/topology.c, is to export the 4 or 6 attributes. The two book |
| 40 | related sysfs files will only be created if CONFIG_SCHED_BOOK is selected. |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 41 | |
Ben Hutchings | c50cbb0 | 2008-06-04 21:47:29 -0700 | [diff] [blame] | 42 | For an architecture to support this feature, it must define some of |
| 43 | these macros in include/asm-XXX/topology.h: |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 44 | #define topology_physical_package_id(cpu) |
| 45 | #define topology_core_id(cpu) |
Heiko Carstens | b40d8ed | 2010-08-31 10:28:17 +0200 | [diff] [blame] | 46 | #define topology_book_id(cpu) |
Rusty Russell | fbd59a8 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 47 | #define topology_thread_cpumask(cpu) |
| 48 | #define topology_core_cpumask(cpu) |
Heiko Carstens | b40d8ed | 2010-08-31 10:28:17 +0200 | [diff] [blame] | 49 | #define topology_book_cpumask(cpu) |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 50 | |
| 51 | The type of **_id is int. |
Rusty Russell | fbd59a8 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 52 | The type of siblings is (const) struct cpumask *. |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 53 | |
Ben Hutchings | c50cbb0 | 2008-06-04 21:47:29 -0700 | [diff] [blame] | 54 | To be consistent on all architectures, include/linux/topology.h |
| 55 | provides default definitions for any of the above macros that are |
| 56 | not defined by include/asm-XXX/topology.h: |
| 57 | 1) physical_package_id: -1 |
| 58 | 2) core_id: 0 |
| 59 | 3) thread_siblings: just the given CPU |
| 60 | 4) core_siblings: just the given CPU |
Mike Travis | d62720a | 2008-12-17 14:14:30 -0800 | [diff] [blame] | 61 | |
Heiko Carstens | b40d8ed | 2010-08-31 10:28:17 +0200 | [diff] [blame] | 62 | For architectures that don't support books (CONFIG_SCHED_BOOK) there are no |
| 63 | default definitions for topology_book_id() and topology_book_cpumask(). |
| 64 | |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 65 | Additionally, CPU topology information is provided under |
Mike Travis | d62720a | 2008-12-17 14:14:30 -0800 | [diff] [blame] | 66 | /sys/devices/system/cpu and includes these files. The internal |
| 67 | source for the output is in brackets ("[]"). |
| 68 | |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 69 | kernel_max: the maximum CPU index allowed by the kernel configuration. |
Mike Travis | d62720a | 2008-12-17 14:14:30 -0800 | [diff] [blame] | 70 | [NR_CPUS-1] |
| 71 | |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 72 | offline: CPUs that are not online because they have been |
Mike Travis | d62720a | 2008-12-17 14:14:30 -0800 | [diff] [blame] | 73 | HOTPLUGGED off (see cpu-hotplug.txt) or exceed the limit |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 74 | of CPUs allowed by the kernel configuration (kernel_max |
Mike Travis | d62720a | 2008-12-17 14:14:30 -0800 | [diff] [blame] | 75 | above). [~cpu_online_mask + cpus >= NR_CPUS] |
| 76 | |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 77 | online: CPUs that are online and being scheduled [cpu_online_mask] |
Mike Travis | d62720a | 2008-12-17 14:14:30 -0800 | [diff] [blame] | 78 | |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 79 | possible: CPUs that have been allocated resources and can be |
Mike Travis | d62720a | 2008-12-17 14:14:30 -0800 | [diff] [blame] | 80 | brought online if they are present. [cpu_possible_mask] |
| 81 | |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 82 | present: CPUs that have been identified as being present in the |
Mike Travis | d62720a | 2008-12-17 14:14:30 -0800 | [diff] [blame] | 83 | system. [cpu_present_mask] |
| 84 | |
| 85 | The format for the above output is compatible with cpulist_parse() |
| 86 | [see <linux/cpumask.h>]. Some examples follow. |
| 87 | |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 88 | 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] | 89 | 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] | 90 | being 32. Note also that CPUs 2 and 4-31 are not online but could be |
Mike Travis | d62720a | 2008-12-17 14:14:30 -0800 | [diff] [blame] | 91 | brought online as they are both present and possible. |
| 92 | |
| 93 | kernel_max: 31 |
| 94 | offline: 2,4-31,32-63 |
| 95 | online: 0-1,3 |
| 96 | possible: 0-31 |
| 97 | present: 0-31 |
| 98 | |
| 99 | 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] | 100 | started with possible_cpus=144. There are 4 CPUs in the system and cpu2 |
| 101 | was manually taken offline (and is the only CPU that can be brought |
Mike Travis | d62720a | 2008-12-17 14:14:30 -0800 | [diff] [blame] | 102 | online.) |
| 103 | |
| 104 | kernel_max: 127 |
| 105 | offline: 2,4-127,128-143 |
| 106 | online: 0-1,3 |
| 107 | possible: 0-127 |
| 108 | present: 0-3 |
| 109 | |
| 110 | See cpu-hotplug.txt for the possible_cpus=NUM kernel start parameter |
Alex Chiang | 663fb2f | 2009-10-21 21:45:31 -0600 | [diff] [blame] | 111 | as well as more information on the various cpumasks. |