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

powerpc/smp: Use nid as fallback for package_id

package_id is to match cores that are part of the same chip. On
PowerNV machines, package_id defaults to chip_id. However ibm,chip_id
property is not present in device-tree of PowerVM LPARs. Hence lscpu
output shows one core per socket and multiple cores.

To overcome this, use nid as the package_id on PowerVM LPARs.

Before the patch:

Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 128
On-line CPU(s) list: 0-127
Thread(s) per core: 8
Core(s) per socket: 1 <----------------------
Socket(s): 16 <----------------------
NUMA node(s): 2
Model: 2.2 (pvr 004e 0202)
Model name: POWER9 (architected), altivec supported
Hypervisor vendor: pHyp
Virtualization type: para
L1d cache: 32K
L1i cache: 32K
L2 cache: 512K
L3 cache: 10240K
NUMA node0 CPU(s): 0-63
NUMA node1 CPU(s): 64-127
#
# cat /sys/devices/system/cpu/cpu0/topology/physical_package_id
-1

After the patch:

Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 128
On-line CPU(s) list: 0-127
Thread(s) per core: 8 <---------------------
Core(s) per socket: 8 <---------------------
Socket(s): 2
NUMA node(s): 2
Model: 2.2 (pvr 004e 0202)
Model name: POWER9 (architected), altivec supported
Hypervisor vendor: pHyp
Virtualization type: para
L1d cache: 32K
L1i cache: 32K
L2 cache: 512K
L3 cache: 10240K
NUMA node0 CPU(s): 0-63
NUMA node1 CPU(s): 64-127
#
# cat /sys/devices/system/cpu/cpu0/topology/physical_package_id
0

Now lscpu output is more in line with the system configuration.

Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
[mpe: Use pkg_id instead of ppid, tweak change log and comment]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200129135121.24617-1-srikar@linux.vnet.ibm.com

authored by

Srikar Dronamraju and committed by
Michael Ellerman
a05f0e5b 532d43a7

+33 -3
+6
arch/powerpc/include/asm/topology.h
··· 134 134 #ifdef CONFIG_PPC64 135 135 #include <asm/smp.h> 136 136 137 + #ifdef CONFIG_PPC_SPLPAR 138 + int get_physical_package_id(int cpu); 139 + #define topology_physical_package_id(cpu) (get_physical_package_id(cpu)) 140 + #else 137 141 #define topology_physical_package_id(cpu) (cpu_to_chip_id(cpu)) 142 + #endif 143 + 138 144 #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu)) 139 145 #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) 140 146 #define topology_core_id(cpu) (cpu_to_core_id(cpu))
+27 -3
arch/powerpc/kernel/smp.c
··· 1185 1185 } 1186 1186 } 1187 1187 1188 + int get_physical_package_id(int cpu) 1189 + { 1190 + int pkg_id = cpu_to_chip_id(cpu); 1191 + 1192 + #ifdef CONFIG_PPC_SPLPAR 1193 + /* 1194 + * If the platform is PowerNV or Guest on KVM, ibm,chip-id is 1195 + * defined. Hence we would return the chip-id as the result of 1196 + * get_physical_package_id. 1197 + */ 1198 + if (pkg_id == -1 && firmware_has_feature(FW_FEATURE_LPAR)) { 1199 + struct device_node *np = of_get_cpu_node(cpu, NULL); 1200 + 1201 + if (np) { 1202 + pkg_id = of_node_to_nid(np); 1203 + of_node_put(np); 1204 + } 1205 + } 1206 + #endif /* CONFIG_PPC_SPLPAR */ 1207 + 1208 + return pkg_id; 1209 + } 1210 + EXPORT_SYMBOL_GPL(get_physical_package_id); 1211 + 1188 1212 static void add_cpu_to_masks(int cpu) 1189 1213 { 1190 1214 int first_thread = cpu_first_thread_sibling(cpu); 1191 - int chipid = cpu_to_chip_id(cpu); 1215 + int pkg_id = get_physical_package_id(cpu); 1192 1216 int i; 1193 1217 1194 1218 /* ··· 1241 1217 for_each_cpu(i, cpu_l2_cache_mask(cpu)) 1242 1218 set_cpus_related(cpu, i, cpu_core_mask); 1243 1219 1244 - if (chipid == -1) 1220 + if (pkg_id == -1) 1245 1221 return; 1246 1222 1247 1223 for_each_cpu(i, cpu_online_mask) 1248 - if (cpu_to_chip_id(i) == chipid) 1224 + if (get_physical_package_id(i) == pkg_id) 1249 1225 set_cpus_related(cpu, i, cpu_core_mask); 1250 1226 } 1251 1227