spapr, spapr_numa: fix max-associativity-domains
v2 cover spapr, spapr_numa: fix max-associativity-domains
changes from v1:
- Patch 01: added Greg's R-b
- Patch 02:
* removed trivial comment in spapr.c
* removed the 'NUMA' caps in spapr_numa_initial_nvgpu_numa_id
* added Greg's R-b
- Patch 03:
* open-coded the logic inside spapr_numa_write_rtas_dt() instead of creating a helper
- added Cédric's 'Tested-by' in all patches
v1 link: https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg07324.html
Daniel Henrique Barboza (3):
spapr: move spapr_machine_using_legacy_numa() to spapr_numa.c spapr_numa.c: create spapr_numa_initial_nvgpu_numa_id() helper spapr_numa.c: fix ibm,max-associativity-domains calculation
hw/ppc/spapr.c | 20 +------------------- hw/ppc/spapr_numa.c | 27 ++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 1 - include/hw/ppc/spapr_numa.h | 1 + 4 files changed, 28 insertions(+), 21 deletions(-)
Signature · 1 line
2.26.2
PATCH v2 1/3 spapr: move spapr_machine_using_legacy_numa() to spapr_numa.c
This function is used only in spapr_numa.c.
--- hw/ppc/spapr.c | 9 --------- hw/ppc/spapr_numa.c | 9 +++++++++ include/hw/ppc/spapr.h | 1 - 3 files changed, 9 insertions(+), 10 deletions(-)
hw/ppc/spapr.c +0 -9
@@ -295,15 +295,6 @@ static hwaddr spapr_node0_size(MachineState *machine)return machine->ram_size; } -bool spapr_machine_using_legacy_numa (SpaprMachineState *spapr) -{ -MachineState *machine =MACHINE (spapr); -SpaprMachineClass *smc =SPAPR_MACHINE_GET_CLASS (machine); - -return smc->pre_5_2_numa_associativity || - machine->numa_state->num_nodes <=1 ; -} -static void add_str (GString *s,const gchar *s1) {g_string_append_len (s, s1,strlen (s1) +1 );
hw/ppc/spapr_numa.c +9 -0
@@ -19,6 +19,15 @@/* Moved from hw/ppc/spapr_pci_nvlink2.c */ #define SPAPR_GPU_NUMA_ID (cpu_to_be32(1)) +static bool spapr_machine_using_legacy_numa (SpaprMachineState *spapr) +{ +MachineState *machine =MACHINE (spapr); +SpaprMachineClass *smc =SPAPR_MACHINE_GET_CLASS (machine); + +return smc->pre_5_2_numa_associativity || + machine->numa_state->num_nodes <=1 ; +} +static bool spapr_numa_is_symmetrical (MachineState *ms) {int src, dst;
include/hw/ppc/spapr.h +0 -1
@@ -851,7 +851,6 @@ int spapr_max_server_number(SpaprMachineState *spapr);void spapr_store_hpte (PowerPCCPU *cpu,hwaddr ptex,uint64_t pte0,uint64_t pte1);void spapr_mce_req_event (PowerPCCPU *cpu,bool recovered); -bool spapr_machine_using_legacy_numa (SpaprMachineState *spapr);/* DRC callbacks. */ void spapr_core_release (DeviceState *dev);
Signature · 1 line
2.26.2
PATCH v2 2/3 spapr_numa.c: create spapr_numa_initial_nvgpu_numa_id() helper
In reply to Daniel Henrique BarbozaWe'll need to check the initial value given to spapr->gpu_numa_id when building the rtas DT, so put it in a helper for easier access and to avoid repetition.
--- hw/ppc/spapr.c | 11 +---------- hw/ppc/spapr_numa.c | 14 ++++++++++++++ include/hw/ppc/spapr_numa.h | 1 + 3 files changed, 16 insertions(+), 10 deletions(-)
hw/ppc/spapr.c +1 -10
@@ -2765,16 +2765,7 @@ static void spapr_machine_init(MachineState *machine) } -/* -* NVLink2-connected GPU RAM needs to be placed on a separate NUMA node. -* We assign a new numa ID per GPU in spapr_pci_collect_nvgpu() which is -* called from vPHB reset handler so we initialize the counter here. -* If no NUMA is configured from the QEMU side, we start from 1 as GPU RAM -* must be equally distant from any other node. -* The final value of spapr->gpu_numa_id is going to be written to -* max-associativity-domains in spapr_build_fdt(). -*/ - spapr->gpu_numa_id =MAX (1 , machine->numa_state->num_nodes); + spapr->gpu_numa_id =spapr_numa_initial_nvgpu_numa_id (machine);/* Init numa_assoc_array */ spapr_numa_associativity_init (spapr, machine);
hw/ppc/spapr_numa.c +14 -0
@@ -46,6 +46,20 @@ static bool spapr_numa_is_symmetrical(MachineState *ms)return true; } +/* +* NVLink2-connected GPU RAM needs to be placed on a separate NUMA node. +* We assign a new numa ID per GPU in spapr_pci_collect_nvgpu() which is +* called from vPHB reset handler so we initialize the counter here. +* If no NUMA is configured from the QEMU side, we start from 1 as GPU RAM +* must be equally distant from any other node. +* The final value of spapr->gpu_numa_id is going to be written to +* max-associativity-domains in spapr_build_fdt(). +*/ +unsigned int spapr_numa_initial_nvgpu_numa_id (MachineState *machine) +{ +return MAX (1 , machine->numa_state->num_nodes); +} +/* * This function will translate the user distances into * what the kernel understand as possible values: 10
include/hw/ppc/spapr_numa.h +1 -0
@@ -31,5 +31,6 @@ int spapr_numa_fixup_cpu_dt(SpaprMachineState *spapr, void *fdt, int offset, PowerPCCPU *cpu);int spapr_numa_write_assoc_lookup_arrays (SpaprMachineState *spapr,void *fdt,int offset); +unsigned int spapr_numa_initial_nvgpu_numa_id (MachineState *machine);#endif /* HW_SPAPR_NUMA_H */
Signature · 1 line
2.26.2
David Gibson
AppliedRe: [PATCH v2 2/3] spapr_numa.c: create spapr_numa_initial_nvgpu_numa_id() helper
Quoted 7 lines · Daniel Henrique Barboza
We'll need to check the initial value given to
spapr->gpu_numa_idwhen building the rtas DT, so put it in a helper for easier access and to avoid repetition.Tested-by Cédric Le Goater <[email protected]>Reviewed-by Greg Kurz <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>
Applied to ppc-for-6.0, thanks.
Quoted 64 lines
--- hw/ppc/spapr.c | 11 +---------- hw/ppc/spapr_numa.c | 14 ++++++++++++++ include/hw/ppc/spapr_numa.h | 1 + 3 files changed, 16 insertions(+), 10 deletions(-)hw/ppc/spapr.c +1
-10@@ -2765,16 +2765,7 @@ static void spapr_machine_init(MachineState *machine) } -/* -* NVLink2-connected GPU RAM needs to be placed on a separate NUMA node. -* We assign a new numa ID per GPU in spapr_pci_collect_nvgpu() which is -* called from vPHB reset handler so we initialize the counter here. -* If no NUMA is configured from the QEMU side, we start from 1 as GPU RAM -* must be equally distant from any other node. -* The final value of spapr->gpu_numa_id is going to be written to -* max-associativity-domains in spapr_build_fdt(). -*/ - spapr->gpu_numa_id =MAX (1 , machine->numa_state->num_nodes); + spapr->gpu_numa_id =spapr_numa_initial_nvgpu_numa_id (machine);/* Init numa_assoc_array */ spapr_numa_associativity_init (spapr, machine);hw/ppc/spapr_numa.c +14
-0@@ -46,6 +46,20 @@ static bool spapr_numa_is_symmetrical(MachineState *ms)return true; } +/* +* NVLink2-connected GPU RAM needs to be placed on a separate NUMA node. +* We assign a new numa ID per GPU in spapr_pci_collect_nvgpu() which is +* called from vPHB reset handler so we initialize the counter here. +* If no NUMA is configured from the QEMU side, we start from 1 as GPU RAM +* must be equally distant from any other node. +* The final value of spapr->gpu_numa_id is going to be written to +* max-associativity-domains in spapr_build_fdt(). +*/ +unsigned int spapr_numa_initial_nvgpu_numa_id (MachineState *machine) +{ +return MAX (1 , machine->numa_state->num_nodes); +} +/* * This function will translate the user distances into * what the kernel understand as possible values: 10 include/hw/ppc/spapr_numa.h +1
-0@@ -31,5 +31,6 @@ int spapr_numa_fixup_cpu_dt(SpaprMachineState *spapr, void *fdt, int offset, PowerPCCPU *cpu);int spapr_numa_write_assoc_lookup_arrays (SpaprMachineState *spapr,void *fdt,int offset); +unsigned int spapr_numa_initial_nvgpu_numa_id (MachineState *machine);#endif /* HW_SPAPR_NUMA_H */
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v2 3/3 spapr_numa.c: fix ibm, max-associativity-domains calculation
In reply to Daniel Henrique BarbozaThe current logic for calculating 'maxdomain' making it a sum of numa_state->num_nodes with spapr->gpu_numa_id. spapr->gpu_numa_id is used as a index to determine the next available NUMA id that a given NVGPU can use.
The problem is that the initial value of gpu_numa_id, for any topology that has more than one NUMA node, is equal to numa_state->num_nodes. This means that our maxdomain will always be, at least, twice the amount of existing NUMA nodes. This means that a guest with 4 NUMA nodes will end up with the following max-associativity-domains:
rtas/ibm,max-associativity-domains
00000004 00000008 00000008 00000008 00000008
This overtuning of maxdomains doesn't go unnoticed in the guest, being detected in SLUB during boot:
dmesg | grep SLUB
[ 0.000000] SLUB: HWalign=128, Order=0-3, MinObjects=0, CPUs=4, Nodes=8
SLUB is detecting 8 total nodes, with 4 nodes being online.
This patch fixes ibm,max-associativity-domains by considering the amount of NVGPUs NUMA nodes presented in the guest, instead of just spapr->gpu_numa_id.
--- hw/ppc/spapr_numa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ppc/spapr_numa.c +3 -1
@@ -311,6 +311,8 @@ void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rtas) {MachineState *ms =MACHINE (spapr);SpaprMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr); +uint32_t number_nvgpus_nodes = spapr->gpu_numa_id - +spapr_numa_initial_nvgpu_numa_id (ms);uint32_t refpoints[] = {cpu_to_be32 (0x4 ),cpu_to_be32 (0x3 ),
@@ -318,7 +320,7 @@ void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rtas) cpu_to_be32(0x1), };uint32_t nr_refpoints =ARRAY_SIZE (refpoints); -uint32_t maxdomain = ms->numa_state->num_nodes + spapr->gpu_numa_id; +uint32_t maxdomain = ms->numa_state->num_nodes + number_nvgpus_nodes;uint32_t maxdomains[] = {cpu_to_be32 (4 ),cpu_to_be32 (maxdomain),
Signature · 1 line
2.26.2
Re: [PATCH v2 3/3] spapr_numa.c: fix ibm,max-associativity-domains calculation
Quoted 22 lines · On Thu, 28 Jan 2021 14:42:13 -0300 Daniel Henrique Barboza…
The current logic for calculating 'maxdomain' making it a sum of
numa_state->num_nodeswithspapr->gpu_numa_id.spapr->gpu_numa_idis used as a index to determine the next available NUMA id that a given NVGPU can use.The problem is that the initial value of
gpu_numa_id, for any topology that has more than one NUMA node, is equal tonuma_state->num_nodes. This means that our maxdomain will always be, at least, twice the amount of existing NUMA nodes. This means that a guest with 4 NUMA nodes will end up with the following max-associativity-domains:rtas/ibm,max-associativity-domains
00000004 00000008 00000008 00000008 00000008This overtuning of maxdomains doesn't go unnoticed in the guest, being detected in SLUB during boot:
dmesg | grep SLUB
[ 0.000000] SLUB: HWalign=128, Order=0-3, MinObjects=0, CPUs=4, Nodes=8SLUB is detecting 8 total nodes, with 4 nodes being online.
Quoted 8 lines
This patch fixes ibm,max-associativity-domains by considering the amount of NVGPUs NUMA nodes presented in the guest, instead of just
spapr->gpu_numa_id.Reported-by Cédric Le Goater <[email protected]>Tested-by Cédric Le Goater <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>---
Quoted 25 lines
hw/ppc/spapr_numa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/ppc/spapr_numa.c +3
-1@@ -311,6 +311,8 @@ void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rtas) {MachineState *ms =MACHINE (spapr);SpaprMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr); +uint32_t number_nvgpus_nodes = spapr->gpu_numa_id - +spapr_numa_initial_nvgpu_numa_id (ms);uint32_t refpoints[] = {cpu_to_be32 (0x4 ),cpu_to_be32 (0x3 ),@@ -318,7 +320,7 @@ void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rtas) cpu_to_be32(0x1), };uint32_t nr_refpoints =ARRAY_SIZE (refpoints); -uint32_t maxdomain = ms->numa_state->num_nodes + spapr->gpu_numa_id; +uint32_t maxdomain = ms->numa_state->num_nodes + number_nvgpus_nodes;uint32_t maxdomains[] = {cpu_to_be32 (4 ),cpu_to_be32 (maxdomain),
David Gibson
AppliedRe: [PATCH v2 3/3] spapr_numa.c: fix ibm,max-associativity-domains calculation
In reply to Daniel Henrique BarbozaQuoted 22 lines · Daniel Henrique Barboza
The current logic for calculating 'maxdomain' making it a sum of
numa_state->num_nodeswithspapr->gpu_numa_id.spapr->gpu_numa_idis used as a index to determine the next available NUMA id that a given NVGPU can use.The problem is that the initial value of
gpu_numa_id, for any topology that has more than one NUMA node, is equal tonuma_state->num_nodes. This means that our maxdomain will always be, at least, twice the amount of existing NUMA nodes. This means that a guest with 4 NUMA nodes will end up with the following max-associativity-domains:rtas/ibm,max-associativity-domains
00000004 00000008 00000008 00000008 00000008This overtuning of maxdomains doesn't go unnoticed in the guest, being detected in SLUB during boot:
dmesg | grep SLUB
[ 0.000000] SLUB: HWalign=128, Order=0-3, MinObjects=0, CPUs=4, Nodes=8SLUB is detecting 8 total nodes, with 4 nodes being online.
Quoted 7 lines
This patch fixes ibm,max-associativity-domains by considering the amount of NVGPUs NUMA nodes presented in the guest, instead of just
spapr->gpu_numa_id.Reported-by Cédric Le Goater <[email protected]>Tested-by Cédric Le Goater <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>
Applied, thanks.
Quoted 26 lines
--- hw/ppc/spapr_numa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/ppc/spapr_numa.c +3
-1@@ -311,6 +311,8 @@ void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rtas) {MachineState *ms =MACHINE (spapr);SpaprMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr); +uint32_t number_nvgpus_nodes = spapr->gpu_numa_id - +spapr_numa_initial_nvgpu_numa_id (ms);uint32_t refpoints[] = {cpu_to_be32 (0x4 ),cpu_to_be32 (0x3 ),@@ -318,7 +320,7 @@ void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rtas) cpu_to_be32(0x1), };uint32_t nr_refpoints =ARRAY_SIZE (refpoints); -uint32_t maxdomain = ms->numa_state->num_nodes + spapr->gpu_numa_id; +uint32_t maxdomain = ms->numa_state->num_nodes + number_nvgpus_nodes;uint32_t maxdomains[] = {cpu_to_be32 (4 ),cpu_to_be32 (maxdomain),
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson