Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/smp: Expose die_id and die_cpumask

>From Power10 processors onwards, each chip has 2 hemispheres. For LPARs
running on PowerVM Hypervisor, hypervisor determines the allocation of
CPU groups to each LPAR, resulting in two LPARs with the same number of
CPUs potentially having different numbers of CPUs from each hemisphere.
Additionally, it is not feasible to ascertain the hemisphere based
solely on the CPU number.

Users wishing to assign their workload to all CPUs, or a subset of CPUs
within a specific hemisphere, encounter difficulties in identifying the
cpumask. To address this, it is proposed to expose hemisphere
information as a die in sysfs. This aligns with other architectures
and facilitates the identification of CPUs within the same hemisphere.
Tools such as lstopo can also access this information.

Please note: The hypervisor reveals the locality of the CPUs to
hemispheres only in dedicated mode. Consequently, in systems where
hemisphere information is unavailable, such as shared LPARs, the
die_cpus information in sysfs will mirror package_cpus, with
die_id set to -1.

Without this change.
$ grep . /sys/devices/system/cpu/cpu16/topology/{die*,package*} 2>/dev/null
/sys/devices/system/cpu/cpu16/topology/package_cpus:000000,000000ff,ffff0000
/sys/devices/system/cpu/cpu16/topology/package_cpus_list:16-39

With this change.
$ grep . /sys/devices/system/cpu/cpu16/topology/{die*,package*} 2>/dev/null
/sys/devices/system/cpu/cpu16/topology/die_cpus:000000,00000000,00ff0000
/sys/devices/system/cpu/cpu16/topology/die_cpus_list:16-23
/sys/devices/system/cpu/cpu16/topology/die_id:2
/sys/devices/system/cpu/cpu16/topology/package_cpus:000000,000000ff,ffff0000
/sys/devices/system/cpu/cpu16/topology/package_cpus_list:16-39

snipped lstopo-no-graphics o/p
Group0 L#0 (total=8747584KB)
Package L#0 (total=3564096KB CPUModel="POWER10 (architected), altivec supported" CPURevision="2.0 (pvr 0080 0200)")
NUMANode L#0 (P#0 local=3564096KB total=3564096KB)
Die L#0 (P#0)
Core L#0 (P#0)
<snipped>
Package L#1 (total=5183488KB CPUModel="POWER10 (architected), altivec supported" CPURevision="2.0 (pvr 0080 0200)")
NUMANode L#1 (P#1 local=5183488KB total=5183488KB)
Die L#2 (P#2)
Core L#2 (P#16)
L3Cache L#4 (size=4096KB linesize=128 ways=16)
L2Cache L#4 (size=1024KB linesize=128 ways=8)
L1dCache L#4 (size=32KB linesize=128 ways=8)
L1iCache L#4 (size=48KB linesize=128 ways=6)
PU L#16 (P#16)
PU L#17 (P#18)
PU L#18 (P#20)
PU L#19 (P#22)
L3Cache L#5 (size=4096KB linesize=128 ways=16)
L2Cache L#5 (size=1024KB linesize=128 ways=8)
L1dCache L#5 (size=32KB linesize=128 ways=8)
L1iCache L#5 (size=48KB linesize=128 ways=6)
PU L#20 (P#17)
PU L#21 (P#19)
PU L#22 (P#21)
PU L#23 (P#23)
Die L#3 (P#3)
Core L#3 (P#24)
L3Cache L#6 (size=4096KB linesize=128 ways=16)
L2Cache L#6 (size=1024KB linesize=128 ways=8)
L1dCache L#6 (size=32KB linesize=128 ways=8)
L1iCache L#6 (size=48KB linesize=128 ways=6)
PU L#24 (P#24)
PU L#25 (P#26)
PU L#26 (P#28)
PU L#27 (P#30)
L3Cache L#7 (size=4096KB linesize=128 ways=16)
L2Cache L#7 (size=1024KB linesize=128 ways=8)
L1dCache L#7 (size=32KB linesize=128 ways=8)
L1iCache L#7 (size=48KB linesize=128 ways=6)
PU L#28 (P#25)
PU L#29 (P#27)
PU L#30 (P#29)
PU L#31 (P#31)
Core L#4 (P#32)
L3Cache L#8 (size=4096KB linesize=128 ways=16)
L2Cache L#8 (size=1024KB linesize=128 ways=8)
L1dCache L#8 (size=32KB linesize=128 ways=8)
L1iCache L#8 (size=48KB linesize=128 ways=6)
PU L#32 (P#32)
PU L#33 (P#34)
PU L#34 (P#36)
PU L#35 (P#38)
L3Cache L#9 (size=4096KB linesize=128 ways=16)
L2Cache L#9 (size=1024KB linesize=128 ways=8)
L1dCache L#9 (size=32KB linesize=128 ways=8)
L1iCache L#9 (size=48KB linesize=128 ways=6)
PU L#36 (P#33)
PU L#37 (P#35)
PU L#38 (P#37)
PU L#39 (P#39)
Group0 L#1 (total=7736896KB)
Package L#2 (total=5170880KB CPUModel="POWER10 (architected), altivec supported" CPURevision="2.0 (pvr 0080 0200)")
NUMANode L#2 (P#2 local=5170880KB total=5170880KB)
Die L#4 (P#4)
<snipped>

Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Signed-off-by: Srikar Dronamraju <srikar@linux.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/20251112074859.814087-1-srikar@linux.ibm.com

authored by

Srikar Dronamraju and committed by
Madhavan Srinivasan
fb2ff9fa 2617bd81

+30 -4
+7 -4
arch/powerpc/include/asm/topology.h
··· 132 132 #include <asm/cputable.h> 133 133 134 134 struct cpumask *cpu_coregroup_mask(int cpu); 135 + const struct cpumask *cpu_die_mask(int cpu); 136 + int cpu_die_id(int cpu); 135 137 136 138 #ifdef CONFIG_PPC64 137 139 #include <asm/smp.h> 138 140 139 141 #define topology_physical_package_id(cpu) (cpu_to_chip_id(cpu)) 140 - 141 - #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu)) 142 - #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) 143 - #define topology_core_id(cpu) (cpu_to_core_id(cpu)) 142 + #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu)) 143 + #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) 144 + #define topology_core_id(cpu) (cpu_to_core_id(cpu)) 145 + #define topology_die_id(cpu) (cpu_die_id(cpu)) 146 + #define topology_die_cpumask(cpu) (cpu_die_mask(cpu)) 144 147 145 148 #endif 146 149 #endif
+23
arch/powerpc/kernel/smp.c
··· 1085 1085 return 0; 1086 1086 } 1087 1087 1088 + /* 1089 + * die_mask and die_id are only available on systems which support 1090 + * multiple coregroups within a same package. On all other systems, die_mask 1091 + * would be same as package mask and die_id would be set to -1. 1092 + */ 1093 + const struct cpumask *cpu_die_mask(int cpu) 1094 + { 1095 + if (has_coregroup_support()) 1096 + return per_cpu(cpu_coregroup_map, cpu); 1097 + else 1098 + return cpu_node_mask(cpu); 1099 + } 1100 + EXPORT_SYMBOL_GPL(cpu_die_mask); 1101 + 1102 + int cpu_die_id(int cpu) 1103 + { 1104 + if (has_coregroup_support()) 1105 + return cpu_to_coregroup_id(cpu); 1106 + else 1107 + return -1; 1108 + } 1109 + EXPORT_SYMBOL_GPL(cpu_die_id); 1110 + 1088 1111 void __init smp_prepare_cpus(unsigned int max_cpus) 1089 1112 { 1090 1113 unsigned int cpu, num_threads;