* [PATCH v4] powerpc/smp: Use nid as fallback for package_id
@ 2020-01-29 13:51 Srikar Dronamraju
2020-01-30 10:57 ` Gautham R Shenoy
2020-03-06 0:27 ` Michael Ellerman
0 siblings, 2 replies; 4+ messages in thread
From: Srikar Dronamraju @ 2020-01-29 13:51 UTC (permalink / raw)
To: Michael Ellerman
Cc: Vasant Hegde, Vaidyanathan Srinivasan, linuxppc-dev, Srikar Dronamraju
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.
Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
---
Changelog from v3: https://lore.kernel.org/linuxppc-dev/20191216142119.5937-1-srikar@linux.vnet.ibm.com/t/#u
- Handled comments from Michael Ellerman.
- Rename function cpu_to_nid to get_physical_package_id
- Moved code back to arch/powerpc/kernel/smp.c from pseries/lpar.c
- Use export_symbol_gpl instead of export_symbol.
- Rebased to v5.5-rc6
Changelog from v2: https://patchwork.ozlabs.org/patch/1151649
- Rebased to v5.5-rc2
- Renamed the new function to cpu_to_nid
- Removed checks to fadump property. (Looked too excessive)
- Moved pseries specific code to pseries/lpar.c
Changelog from v1: https://patchwork.ozlabs.org/patch/1126145
- 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 | 6 ++++++
arch/powerpc/kernel/smp.c | 30 ++++++++++++++++++++++++++---
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h
index 2f7e1ea5089e..e2e1ccd4a18d 100644
--- a/arch/powerpc/include/asm/topology.h
+++ b/arch/powerpc/include/asm/topology.h
@@ -134,7 +134,13 @@ static inline void shared_proc_topology_init(void) {}
#ifdef CONFIG_PPC64
#include <asm/smp.h>
+#ifdef CONFIG_PPC_SPLPAR
+int get_physical_package_id(int cpu);
+#define topology_physical_package_id(cpu) (get_physical_package_id(cpu))
+#else
#define topology_physical_package_id(cpu) (cpu_to_chip_id(cpu))
+#endif
+
#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..d75fc8fd8168 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -1185,10 +1185,34 @@ static inline void add_cpu_to_smallcore_masks(int cpu)
}
}
+int get_physical_package_id(int cpu)
+{
+ int ppid = cpu_to_chip_id(cpu);
+
+#ifdef CONFIG_PPC_SPLPAR
+ /*
+ * 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 (ppid == -1 && firmware_has_feature(FW_FEATURE_LPAR)) {
+ struct device_node *np = of_get_cpu_node(cpu, NULL);
+
+ if (np) {
+ ppid = of_node_to_nid(np);
+ of_node_put(np);
+ }
+ }
+#endif /* CONFIG_PPC_SPLPAR */
+
+ return ppid;
+}
+EXPORT_SYMBOL_GPL(get_physical_package_id);
+
static void add_cpu_to_masks(int cpu)
{
int first_thread = cpu_first_thread_sibling(cpu);
- int chipid = cpu_to_chip_id(cpu);
+ int ppid = get_physical_package_id(cpu);
int i;
/*
@@ -1217,11 +1241,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 (ppid == -1)
return;
for_each_cpu(i, cpu_online_mask)
- if (cpu_to_chip_id(i) == chipid)
+ if (get_physical_package_id(i) == ppid)
set_cpus_related(cpu, i, cpu_core_mask);
}
--
2.18.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v4] powerpc/smp: Use nid as fallback for package_id
2020-01-29 13:51 [PATCH v4] powerpc/smp: Use nid as fallback for package_id Srikar Dronamraju
@ 2020-01-30 10:57 ` Gautham R Shenoy
2020-01-30 13:18 ` Srikar Dronamraju
2020-03-06 0:27 ` Michael Ellerman
1 sibling, 1 reply; 4+ messages in thread
From: Gautham R Shenoy @ 2020-01-30 10:57 UTC (permalink / raw)
To: Srikar Dronamraju; +Cc: Vasant Hegde, Vaidyanathan Srinivasan, linuxppc-dev
Hello Srikar,
On Wed, Jan 29, 2020 at 07:21:21PM +0530, Srikar Dronamraju wrote:
[..snip..]
> --- a/arch/powerpc/kernel/smp.c
> +++ b/arch/powerpc/kernel/smp.c
> @@ -1185,10 +1185,34 @@ static inline void add_cpu_to_smallcore_masks(int cpu)
> }
> }
>
> +int get_physical_package_id(int cpu)
> +{
> + int ppid = cpu_to_chip_id(cpu);
> +
> +#ifdef CONFIG_PPC_SPLPAR
> + /*
> + * 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 (ppid == -1 && firmware_has_feature(FW_FEATURE_LPAR)) {
> + struct device_node *np = of_get_cpu_node(cpu, NULL);
> +
> + if (np) {
> + ppid = of_node_to_nid(np);
> + of_node_put(np);
> + }
> + }
> +#endif /* CONFIG_PPC_SPLPAR */
> +
> + return ppid;
> +}
> +EXPORT_SYMBOL_GPL(get_physical_package_id);
> +
> static void add_cpu_to_masks(int cpu)
> {
> int first_thread = cpu_first_thread_sibling(cpu);
> - int chipid = cpu_to_chip_id(cpu);
> + int ppid = get_physical_package_id(cpu);
> int i;
>
> /*
> @@ -1217,11 +1241,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 (ppid == -1)
> return;
Can get_physical_package_id() return -1 ?
>
> for_each_cpu(i, cpu_online_mask)
> - if (cpu_to_chip_id(i) == chipid)
> + if (get_physical_package_id(i) == ppid)
> set_cpus_related(cpu, i, cpu_core_mask);
> }
>
> --
> 2.18.1
>
--
Thanks and Regards
gautham.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4] powerpc/smp: Use nid as fallback for package_id
2020-01-30 10:57 ` Gautham R Shenoy
@ 2020-01-30 13:18 ` Srikar Dronamraju
0 siblings, 0 replies; 4+ messages in thread
From: Srikar Dronamraju @ 2020-01-30 13:18 UTC (permalink / raw)
To: Gautham R Shenoy; +Cc: Vasant Hegde, Vaidyanathan Srinivasan, linuxppc-dev
* Gautham R Shenoy <ego@linux.vnet.ibm.com> [2020-01-30 16:27:47]:
> On Wed, Jan 29, 2020 at 07:21:21PM +0530, Srikar Dronamraju wrote:
>
> [..snip..]
>
> > --- a/arch/powerpc/kernel/smp.c
> > +++ b/arch/powerpc/kernel/smp.c
> > @@ -1185,10 +1185,34 @@ static inline void add_cpu_to_smallcore_masks(int cpu)
> > }
> > }
> >
> > +int get_physical_package_id(int cpu)
> > +{
> > + int ppid = cpu_to_chip_id(cpu);
> > +
> > +#ifdef CONFIG_PPC_SPLPAR
> > + /*
> > + * 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 (ppid == -1 && firmware_has_feature(FW_FEATURE_LPAR)) {
> > + struct device_node *np = of_get_cpu_node(cpu, NULL);
> > +
> > + if (np) {
> > + ppid = of_node_to_nid(np);
> > + of_node_put(np);
> > + }
> > + }
> > +#endif /* CONFIG_PPC_SPLPAR */
> > +
> > + return ppid;
> > +}
> > static void add_cpu_to_masks(int cpu)
> > {
> > int first_thread = cpu_first_thread_sibling(cpu);
> > - int chipid = cpu_to_chip_id(cpu);
> > + int ppid = get_physical_package_id(cpu);
> > int i;
> >
> > /*
> > @@ -1217,11 +1241,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 (ppid == -1)
> > return;
>
> Can get_physical_package_id() return -1 ?
>
Yes, it can return -1,
1. A System doesnt have CONFIG_PPC_SPLPAR: cpu_to_chip_id() might return -1.
2. A System with CONFIG_PPC_SPLPAR: Still can return -1 for following cases.
a. Not having firmware feature FW_FEATURE_LPAR
b. If for some reason, of_get_cpu_node property is not present.
> >
> > for_each_cpu(i, cpu_online_mask)
> > - if (cpu_to_chip_id(i) == chipid)
> > + if (get_physical_package_id(i) == ppid)
> > set_cpus_related(cpu, i, cpu_core_mask);
> > }
--
Thanks and Regards
Srikar Dronamraju
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4] powerpc/smp: Use nid as fallback for package_id
2020-01-29 13:51 [PATCH v4] powerpc/smp: Use nid as fallback for package_id Srikar Dronamraju
2020-01-30 10:57 ` Gautham R Shenoy
@ 2020-03-06 0:27 ` Michael Ellerman
1 sibling, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2020-03-06 0:27 UTC (permalink / raw)
To: Srikar Dronamraju
Cc: Vasant Hegde, Vaidyanathan Srinivasan, linuxppc-dev, Srikar Dronamraju
On Wed, 2020-01-29 at 13:51:21 UTC, Srikar Dronamraju wrote:
> 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.
>
> Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
> Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/a05f0e5be4e81e4977d3f92aaf7688ee0cb7d5db
cheers
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-03-06 0:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-29 13:51 [PATCH v4] powerpc/smp: Use nid as fallback for package_id Srikar Dronamraju
2020-01-30 10:57 ` Gautham R Shenoy
2020-01-30 13:18 ` Srikar Dronamraju
2020-03-06 0:27 ` Michael Ellerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).