diff mbox series

hw/loongarch: Refine default numa id calculation

Message ID 20240319022606.2994565-1-maobibo@loongson.cn
State New
Headers show
Series hw/loongarch: Refine default numa id calculation | expand

Commit Message

Bibo Mao March 19, 2024, 2:26 a.m. UTC
With numa_test test case, there is subcase named test_def_cpu_split(),
there are 8 sockets and 2 numa nodes. Here is command line:
"-machine smp.cpus=8,smp.sockets=8 -numa node,memdev=ram -numa node"

The required result is:
  node 0 cpus: 0 2 4 6
  node 1 cpus: 1 3 5 7
Test case numa_test fails on LoongArch, since the actual result is:
  node 0 cpus: 0 1 2 3
  node 1 cpus: 4 5 6 7

It will be better if all the cpus in one socket share the same numa
node. Here socket id is used to calculate numa id in function
virt_get_default_cpu_node_id().

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 hw/loongarch/virt.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

gaosong April 30, 2024, 3:59 a.m. UTC | #1
在 2024/3/19 上午10:26, Bibo Mao 写道:
> With numa_test test case, there is subcase named test_def_cpu_split(),
> there are 8 sockets and 2 numa nodes. Here is command line:
> "-machine smp.cpus=8,smp.sockets=8 -numa node,memdev=ram -numa node"
>
> The required result is:
>    node 0 cpus: 0 2 4 6
>    node 1 cpus: 1 3 5 7
> Test case numa_test fails on LoongArch, since the actual result is:
>    node 0 cpus: 0 1 2 3
>    node 1 cpus: 4 5 6 7
>
> It will be better if all the cpus in one socket share the same numa
> node. Here socket id is used to calculate numa id in function
> virt_get_default_cpu_node_id().
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>   hw/loongarch/virt.c | 11 +++++------
>   1 file changed, 5 insertions(+), 6 deletions(-)
Reviewed-by: Song Gao <gaosong@loongson.cn>

Thanks.
Song Gao
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index deb3750d81..29885f6777 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -1219,15 +1219,14 @@ virt_cpu_index_to_props(MachineState *ms, unsigned cpu_index)
>   
>   static int64_t virt_get_default_cpu_node_id(const MachineState *ms, int idx)
>   {
> -    int64_t nidx = 0;
> +    int64_t socket_id;
>   
>       if (ms->numa_state->num_nodes) {
> -        nidx = idx / (ms->smp.cpus / ms->numa_state->num_nodes);
> -        if (ms->numa_state->num_nodes <= nidx) {
> -            nidx = ms->numa_state->num_nodes - 1;
> -        }
> +        socket_id = ms->possible_cpus->cpus[idx].props.socket_id;
> +        return socket_id % ms->numa_state->num_nodes;
> +    } else {
> +        return 0;
>       }
> -    return nidx;
>   }
>   
>   static void loongarch_class_init(ObjectClass *oc, void *data)
diff mbox series

Patch

diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index deb3750d81..29885f6777 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -1219,15 +1219,14 @@  virt_cpu_index_to_props(MachineState *ms, unsigned cpu_index)
 
 static int64_t virt_get_default_cpu_node_id(const MachineState *ms, int idx)
 {
-    int64_t nidx = 0;
+    int64_t socket_id;
 
     if (ms->numa_state->num_nodes) {
-        nidx = idx / (ms->smp.cpus / ms->numa_state->num_nodes);
-        if (ms->numa_state->num_nodes <= nidx) {
-            nidx = ms->numa_state->num_nodes - 1;
-        }
+        socket_id = ms->possible_cpus->cpus[idx].props.socket_id;
+        return socket_id % ms->numa_state->num_nodes;
+    } else {
+        return 0;
     }
-    return nidx;
 }
 
 static void loongarch_class_init(ObjectClass *oc, void *data)