diff mbox series

[v2] powerpc/smp: Use nid as fallback for package_id

Message ID 20190822143853.19138-1-srikar@linux.vnet.ibm.com (mailing list archive)
State Superseded
Headers show
Series [v2] powerpc/smp: Use nid as fallback for package_id | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch next (0e4523c0b4f64eaf7abe59e143e6bdf8f972acff)
snowpatch_ozlabs/build-ppc64le warning Build succeeded but added 5 new sparse warnings
snowpatch_ozlabs/build-ppc64be warning Build succeeded but added 5 new sparse warnings
snowpatch_ozlabs/build-ppc64e warning Build succeeded but added 5 new sparse warnings
snowpatch_ozlabs/build-pmac32 success Build succeeded
snowpatch_ozlabs/checkpatch warning total: 0 errors, 0 warnings, 3 checks, 73 lines checked

Commit Message

Srikar Dronamraju Aug. 22, 2019, 2:38 p.m. UTC
Package_id is to find out all 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.

Link to previous posting: https://patchwork.ozlabs.org/patch/1126145

Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
---
Changelog from v1:
In V1 cpu_to_chip_id was overloaded to fallback on nid.  Michael Ellerman
wasn't comfortable with nid being shown up as chip_id.

 arch/powerpc/include/asm/topology.h |  3 +-
 arch/powerpc/kernel/smp.c           | 46 +++++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 4 deletions(-)

Comments

Srikar Dronamraju Nov. 15, 2019, 1:41 p.m. UTC | #1
Hey Michael,

* Srikar Dronamraju <srikar@linux.vnet.ibm.com> [2019-08-22 20:08:53]:

> Package_id is to find out all 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.
> 

Can you let me know if you have any comments on this patch?
diff mbox series

Patch

diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h
index 2f7e1ea5089e..f0c4b2f06665 100644
--- a/arch/powerpc/include/asm/topology.h
+++ b/arch/powerpc/include/asm/topology.h
@@ -134,7 +134,8 @@  static inline void shared_proc_topology_init(void) {}
 #ifdef CONFIG_PPC64
 #include <asm/smp.h>
 
-#define topology_physical_package_id(cpu)	(cpu_to_chip_id(cpu))
+extern int get_physical_package_id(int);
+#define topology_physical_package_id(cpu)	(get_physical_package_id(cpu))
 #define topology_sibling_cpumask(cpu)	(per_cpu(cpu_sibling_map, cpu))
 #define topology_core_cpumask(cpu)	(per_cpu(cpu_core_map, cpu))
 #define topology_core_id(cpu)		(cpu_to_core_id(cpu))
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index ea6adbf6a221..4d1541cc5e95 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -1185,10 +1185,50 @@  static inline void add_cpu_to_smallcore_masks(int cpu)
 	}
 }
 
+#ifdef CONFIG_PPC64
+int get_physical_package_id(cpu)
+{
+	struct device_node *np, *root;
+	struct property *pp;
+	int gppid = cpu_to_chip_id(cpu);
+
+	/*
+	 * If the platform is PowerNV or Guest on KVM, ibm,chip-id is
+	 * defined. Hence we would return the chip-id as the
+	 * get_physical_package_id.
+	 */
+	if (gppid == -1 && firmware_has_feature(FW_FEATURE_LPAR) &&
+				machine_is(pseries)) {
+		/*
+		 * PowerVM hypervisor doesn't export ibm,chip-id property.
+		 * Currently only PowerVM hypervisor supports
+		 * /rtas/ibm,configure-kernel-dump property. Use this
+		 * property to identify PowerVM LPARs within pseries
+		 * platform.
+		 */
+		root = of_find_node_by_path("/rtas");
+		if (root) {
+			pp = of_find_property(root,
+					"ibm,configure-kernel-dump", NULL);
+			if (pp) {
+				np = of_get_cpu_node(cpu, NULL);
+				if (np) {
+					gppid = of_node_to_nid(np);
+					of_node_put(np);
+				}
+			}
+			of_node_put(root);
+		}
+	}
+	return gppid;
+}
+EXPORT_SYMBOL(get_physical_package_id);
+#endif
+
 static void add_cpu_to_masks(int cpu)
 {
 	int first_thread = cpu_first_thread_sibling(cpu);
-	int chipid = cpu_to_chip_id(cpu);
+	int gppid = get_physical_package_id(cpu);
 	int i;
 
 	/*
@@ -1217,11 +1257,11 @@  static void add_cpu_to_masks(int cpu)
 	for_each_cpu(i, cpu_l2_cache_mask(cpu))
 		set_cpus_related(cpu, i, cpu_core_mask);
 
-	if (chipid == -1)
+	if (gppid == -1)
 		return;
 
 	for_each_cpu(i, cpu_online_mask)
-		if (cpu_to_chip_id(i) == chipid)
+		if (get_physical_package_id(i) == gppid)
 			set_cpus_related(cpu, i, cpu_core_mask);
 }