Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 1 | |
Jesper Juhl | ded23ac | 2006-03-28 01:56:52 -0800 | [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: |
| 6 | represent the physical package id of cpu X; |
| 7 | 2) /sys/devices/system/cpu/cpuX/topology/core_id: |
| 8 | represent the cpu core id to cpu X; |
| 9 | 3) /sys/devices/system/cpu/cpuX/topology/thread_siblings: |
| 10 | represent the thread siblings to cpu X in the same core; |
| 11 | 4) /sys/devices/system/cpu/cpuX/topology/core_siblings: |
| 12 | represent the thread siblings to cpu X in the same physical package; |
| 13 | |
| 14 | To implement it in an architecture-neutral way, a new source file, |
Jesper Juhl | ded23ac | 2006-03-28 01:56:52 -0800 | [diff] [blame] | 15 | drivers/base/topology.c, is to export the 4 attributes. |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 16 | |
Ben Hutchings | c50cbb0 | 2008-06-04 21:47:29 -0700 | [diff] [blame] | 17 | For an architecture to support this feature, it must define some of |
| 18 | these macros in include/asm-XXX/topology.h: |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 19 | #define topology_physical_package_id(cpu) |
| 20 | #define topology_core_id(cpu) |
Rusty Russell | fbd59a8 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 21 | #define topology_thread_cpumask(cpu) |
| 22 | #define topology_core_cpumask(cpu) |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 23 | |
| 24 | The type of **_id is int. |
Rusty Russell | fbd59a8 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 25 | The type of siblings is (const) struct cpumask *. |
Zhang, Yanmin | 69dcc99 | 2006-02-03 03:04:36 -0800 | [diff] [blame] | 26 | |
Ben Hutchings | c50cbb0 | 2008-06-04 21:47:29 -0700 | [diff] [blame] | 27 | To be consistent on all architectures, include/linux/topology.h |
| 28 | provides default definitions for any of the above macros that are |
| 29 | not defined by include/asm-XXX/topology.h: |
| 30 | 1) physical_package_id: -1 |
| 31 | 2) core_id: 0 |
| 32 | 3) thread_siblings: just the given CPU |
| 33 | 4) core_siblings: just the given CPU |
Mike Travis | d62720a | 2008-12-17 14:14:30 -0800 | [diff] [blame] | 34 | |
| 35 | Additionally, cpu topology information is provided under |
| 36 | /sys/devices/system/cpu and includes these files. The internal |
| 37 | source for the output is in brackets ("[]"). |
| 38 | |
| 39 | kernel_max: the maximum cpu index allowed by the kernel configuration. |
| 40 | [NR_CPUS-1] |
| 41 | |
| 42 | offline: cpus that are not online because they have been |
| 43 | HOTPLUGGED off (see cpu-hotplug.txt) or exceed the limit |
| 44 | of cpus allowed by the kernel configuration (kernel_max |
| 45 | above). [~cpu_online_mask + cpus >= NR_CPUS] |
| 46 | |
| 47 | online: cpus that are online and being scheduled [cpu_online_mask] |
| 48 | |
| 49 | possible: cpus that have been allocated resources and can be |
| 50 | brought online if they are present. [cpu_possible_mask] |
| 51 | |
| 52 | present: cpus that have been identified as being present in the |
| 53 | system. [cpu_present_mask] |
| 54 | |
| 55 | The format for the above output is compatible with cpulist_parse() |
| 56 | [see <linux/cpumask.h>]. Some examples follow. |
| 57 | |
| 58 | In this example, there are 64 cpus in the system but cpus 32-63 exceed |
| 59 | the kernel max which is limited to 0..31 by the NR_CPUS config option |
| 60 | being 32. Note also that cpus 2 and 4-31 are not online but could be |
| 61 | brought online as they are both present and possible. |
| 62 | |
| 63 | kernel_max: 31 |
| 64 | offline: 2,4-31,32-63 |
| 65 | online: 0-1,3 |
| 66 | possible: 0-31 |
| 67 | present: 0-31 |
| 68 | |
| 69 | In this example, the NR_CPUS config option is 128, but the kernel was |
| 70 | started with possible_cpus=144. There are 4 cpus in the system and cpu2 |
| 71 | was manually taken offline (and is the only cpu that can be brought |
| 72 | online.) |
| 73 | |
| 74 | kernel_max: 127 |
| 75 | offline: 2,4-127,128-143 |
| 76 | online: 0-1,3 |
| 77 | possible: 0-127 |
| 78 | present: 0-3 |
| 79 | |
| 80 | See cpu-hotplug.txt for the possible_cpus=NUM kernel start parameter |
| 81 | as well as more information on the various cpumask's. |