Skip to contentSkip to conversation

hw/arm/acpi: Pack the SRAT processors structure by node_id ascending order

PATCH In review Zeng Tao 3 participants 11 messages Jan 7, 2020 – Jan 14, 2020

lore
Share & tools
lore

Zeng Tao

author
#0 lore raw

PATCH 1/1 hw/arm/acpi: Pack the SRAT processors structure by node_id ascending order

When booting the guest linux with the following numa configuration:
-numa node,node_id=1,cpus=0-3
-numa node,node_id=0,cpus=4-7
We can get the following numa topology in the guest system:

Architecture:          aarch64
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Socket(s):             1
NUMA node(s):          2
L1d cache:             unknown size
L1i cache:             unknown size
L2 cache:              unknown size
NUMA node0 CPU(s):     0-3
NUMA node1 CPU(s):     4-7

The Cpus 0-3 is assigned with NUMA node 1 in QEMU while it get NUMA node 0 in the guest.

In fact, In the linux kernel, numa_node_id is allocated per the ACPI SRAT processors structure order,so the cpu 0 will be the first one to allocate its NUMA node id, so it gets the NUMA node 0.

To fix this issue, we pack the SRAT processors structure in numa node id order but not the default cpu number order.

---
 hw/arm/virt-acpi-build.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +15 -8
index bd5f771..497192b 100644
@@ -520,7 +520,8 @@ build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     AcpiSystemResourceAffinityTable *srat;
     AcpiSratProcessorGiccAffinity *core;
     AcpiSratMemoryAffinity *numamem;
-    int i, srat_start;
+    int i, j, srat_start;
+    uint32_t node_id;
     uint64_t mem_base;
     MachineClass *mc = MACHINE_GET_CLASS(vms);
     MachineState *ms = MACHINE(vms);
@@ -530,13 +531,19 @@ build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     srat = acpi_data_push(table_data, sizeof(*srat));
     srat->reserved1 = cpu_to_le32(1);
 
-    for (i = 0; i < cpu_list->len; ++i) {
-        core = acpi_data_push(table_data, sizeof(*core));
-        core->type = ACPI_SRAT_PROCESSOR_GICC;
-        core->length = sizeof(*core);
-        core->proximity = cpu_to_le32(cpu_list->cpus[i].props.node_id);
-        core->acpi_processor_uid = cpu_to_le32(i);
-        core->flags = cpu_to_le32(1);
+    for (i = 0; i < ms->numa_state->num_nodes; ++i) {
+        for (j = 0; j < cpu_list->len; ++j) {
+            node_id = cpu_to_le32(cpu_list->cpus[j].props.node_id);
+            if (node_id != i) {
+                continue;
+            }
+            core = acpi_data_push(table_data, sizeof(*core));
+            core->type = ACPI_SRAT_PROCESSOR_GICC;
+            core->length = sizeof(*core);
+            core->proximity = node_id;
+            core->acpi_processor_uid = cpu_to_le32(j);
+            core->flags = cpu_to_le32(1);
+        }
     }
 
     mem_base = vms->memmap[VIRT_MEM].base;
Signature · 1 line
2.8.1
#1 lore raw
Quoted 20 lines · Zeng Tao

When booting the guest linux with the following numa configuration:

(quoted diff) +0 -2
-numa node,node_id=1,cpus=0-3
-numa node,node_id=0,cpus=4-7

We can get the following numa topology in the guest system:

Architecture:          aarch64
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Socket(s):             1
NUMA node(s):          2
L1d cache:             unknown size
L1i cache:             unknown size
L2 cache:              unknown size
NUMA node0 CPU(s):     0-3
NUMA node1 CPU(s):     4-7

The Cpus 0-3 is assigned with NUMA node 1 in QEMU while it get NUMA node 0 in the guest.

Quoted 8 lines

In fact, In the linux kernel, numa_node_id is allocated per the ACPI SRAT processors structure order,so the cpu 0 will be the first one to allocate its NUMA node id, so it gets the NUMA node 0.

To fix this issue, we pack the SRAT processors structure in numa node id order but not the default cpu number order.

Does this matter? If yes fixing linux to take node id from proximity field in ACPI seems cleaner ...

Quoted 21 lines
---
 hw/arm/virt-acpi-build.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +2 -1
index bd5f771..497192b 100644
@@ -520,7 +520,8 @@ build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     AcpiSystemResourceAffinityTable *srat;
     AcpiSratProcessorGiccAffinity *core;
     AcpiSratMemoryAffinity *numamem;
-    int i, srat_start;
+    int i, j, srat_start;
+    uint32_t node_id;
     uint64_t mem_base;
     MachineClass *mc = MACHINE_GET_CLASS(vms);
     MachineState *ms = MACHINE(vms);
@@ -530,13 +531,19 @@ build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     srat = acpi_data_push(table_data, sizeof(*srat));
     srat->reserved1 = cpu_to_le32(1);

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 535

Quoted 10 lines
hw/arm/virt-acpi-build.c +2 -7
 
-    for (i = 0; i < cpu_list->len; ++i) {
-        core = acpi_data_push(table_data, sizeof(*core));
-        core->type = ACPI_SRAT_PROCESSOR_GICC;
-        core->length = sizeof(*core);
-        core->proximity = cpu_to_le32(cpu_list->cpus[i].props.node_id);
-        core->acpi_processor_uid = cpu_to_le32(i);
-        core->flags = cpu_to_le32(1);
+    for (i = 0; i < ms->numa_state->num_nodes; ++i) {
+        for (j = 0; j < cpu_list->len; ++j) {

Hmm O(n ^2) isn't great ...

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 547

Quoted 12 lines
hw/arm/virt-acpi-build.c +11 -0
+            node_id = cpu_to_le32(cpu_list->cpus[j].props.node_id);
+            if (node_id != i) {
+                continue;
+            }
+            core = acpi_data_push(table_data, sizeof(*core));
+            core->type = ACPI_SRAT_PROCESSOR_GICC;
+            core->length = sizeof(*core);
+            core->proximity = node_id;
+            core->acpi_processor_uid = cpu_to_le32(j);
+            core->flags = cpu_to_le32(1);
+        }
     }

is the issue arm specific? wouldn't it affect x86 too?

Quoted 3 lines
hw/arm/virt-acpi-build.c +0 -0
     mem_base = vms->memmap[VIRT_MEM].base;
Signature · 1 line
2.8.1
#2 lore raw
Quoted 35 lines

-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 5:33 PM
To: Zengtao (B)
Cc: [email protected]; [email protected]; Shannon Zhao; Peter Maydell; Igor Mammedov; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure by node_id ascending order

Quoted 17 lines · Zeng Tao

When booting the guest linux with the following numa configuration:

(quoted diff) +0 -2
-numa node,node_id=1,cpus=0-3
-numa node,node_id=0,cpus=4-7

We can get the following numa topology in the guest system:

Architecture:          aarch64
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Socket(s):             1
NUMA node(s):          2
L1d cache:             unknown size
L1i cache:             unknown size
L2 cache:              unknown size
NUMA node0 CPU(s):     0-3
NUMA node1 CPU(s):     4-7
Quoted 1 line

The Cpus 0-3 is assigned with NUMA node 1 in QEMU while it get NUMA

node

Quoted 6 lines

0 in the guest.

In fact, In the linux kernel, numa_node_id is allocated per the ACPI SRAT processors structure order,so the cpu 0 will be the first one to allocate its NUMA node id, so it gets the NUMA node 0.

Quoted 9 lines
Quoted 4 lines

To fix this issue, we pack the SRAT processors structure in numa node id order but not the default cpu number order.

Does this matter? If yes fixing linux to take node id from proximity field in ACPI seems cleaner ...

In fact, I just want to align the node_id concept in QEMU and Linux. If we fix the kernel side, we need to align with all platforms. i think maybe not a good idea.

Quoted 29 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker

Quoted 9 lines
---
 hw/arm/virt-acpi-build.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +0 -0
index bd5f771..497192b 100644
@@ -520,7 +520,8 @@ build_srat(GArray *table_data, BIOSLinker

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker

Quoted 10 lines
hw/arm/virt-acpi-build.c +2 -1
     AcpiSystemResourceAffinityTable *srat;
     AcpiSratProcessorGiccAffinity *core;
     AcpiSratMemoryAffinity *numamem;
-    int i, srat_start;
+    int i, j, srat_start;
+    uint32_t node_id;
     uint64_t mem_base;
     MachineClass *mc = MACHINE_GET_CLASS(vms);
     MachineState *ms = MACHINE(vms);
@@ -530,13 +531,19 @@ build_srat(GArray *table_data, BIOSLinker

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)

Quoted 8 lines
hw/arm/virt-acpi-build.c +0 -5
     srat = acpi_data_push(table_data, sizeof(*srat));
     srat->reserved1 = cpu_to_le32(1);
 
-    for (i = 0; i < cpu_list->len; ++i) {
-        core = acpi_data_push(table_data, sizeof(*core));
-        core->type = ACPI_SRAT_PROCESSOR_GICC;
-        core->length = sizeof(*core);
-        core->proximity =
Quoted 7 lines

cpu_to_le32(cpu_list->cpus[i].props.node_id);

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 535

Quoted 4 lines
hw/arm/virt-acpi-build.c +2 -2
-        core->acpi_processor_uid = cpu_to_le32(i);
-        core->flags = cpu_to_le32(1);
+    for (i = 0; i < ms->numa_state->num_nodes; ++i) {
+        for (j = 0; j < cpu_list->len; ++j) {

Hmm O(n ^2) isn't great ...

Good suggestion, 3Q.

Quoted 14 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 547

Quoted 13 lines
hw/arm/virt-acpi-build.c +11 -0
+            node_id = cpu_to_le32(cpu_list->cpus[j].props.node_id);
+            if (node_id != i) {
+                continue;
+            }
+            core = acpi_data_push(table_data, sizeof(*core));
+            core->type = ACPI_SRAT_PROCESSOR_GICC;
+            core->length = sizeof(*core);
+            core->proximity = node_id;
+            core->acpi_processor_uid = cpu_to_le32(j);
+            core->flags = cpu_to_le32(1);
+        }
     }
Quoted 2 lines

is the issue arm specific? wouldn't it affect x86 too?

Good question, I think it will affect x86, but I need to confirm.

Quoted 3 lines
Quoted 3 lines
hw/arm/virt-acpi-build.c +0 -1
     mem_base = vms->memmap[VIRT_MEM].base;
--

2.8.1

#3 lore raw
Quoted 41 lines · On Tue, 7 Jan 2020 10:29:22 +0000 "Zengtao (B)" <[email protected]>…
Quoted 41 lines

-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 5:33 PM
To: Zengtao (B)
Cc: [email protected]; [email protected]; Shannon Zhao; Peter Maydell; Igor Mammedov; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure by node_id ascending order

Quoted 17 lines · Zeng Tao

When booting the guest linux with the following numa configuration:

(quoted diff) +0 -2
-numa node,node_id=1,cpus=0-3
-numa node,node_id=0,cpus=4-7

We can get the following numa topology in the guest system:

Architecture:          aarch64
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Socket(s):             1
NUMA node(s):          2
L1d cache:             unknown size
L1i cache:             unknown size
L2 cache:              unknown size
NUMA node0 CPU(s):     0-3
NUMA node1 CPU(s):     4-7
Quoted 1 line

The Cpus 0-3 is assigned with NUMA node 1 in QEMU while it get NUMA

node

Quoted 10 lines

0 in the guest.

In fact, In the linux kernel, numa_node_id is allocated per the ACPI SRAT processors structure order,so the cpu 0 will be the first one to allocate its NUMA node id, so it gets the NUMA node 0.

To fix this issue, we pack the SRAT processors structure in numa node id order but not the default cpu number order.

Quoted 7 lines
Quoted 3 lines

Does this matter? If yes fixing linux to take node id from proximity field in ACPI seems cleaner ...

In fact, I just want to align the node_id concept in QEMU and Linux. If we fix the kernel side, we need to align with all platforms. i think maybe not a good idea.

if linux makes up node ID's on it's own, it would be hard for it to map SRAT entries to other tables that use proximity id as well.

So it would need to maintain map of [proximity id] -> [node id] (and reverse) somewhere to resolve mappings on other tables.
If it doesn't do this then it's broken and works just by accident, if it does the fix probably should be in that code and not in QEMU.

Quoted 60 lines
Quoted 30 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker

Quoted 10 lines
 
---
 hw/arm/virt-acpi-build.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +0 -0
index bd5f771..497192b 100644
@@ -520,7 +520,8 @@ build_srat(GArray *table_data, BIOSLinker  

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker

Quoted 10 lines
hw/arm/virt-acpi-build.c +2 -1
     AcpiSystemResourceAffinityTable *srat;
     AcpiSratProcessorGiccAffinity *core;
     AcpiSratMemoryAffinity *numamem;
-    int i, srat_start;
+    int i, j, srat_start;
+    uint32_t node_id;
     uint64_t mem_base;
     MachineClass *mc = MACHINE_GET_CLASS(vms);
     MachineState *ms = MACHINE(vms);
@@ -530,13 +531,19 @@ build_srat(GArray *table_data, BIOSLinker  

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)

Quoted 8 lines
hw/arm/virt-acpi-build.c +0 -5
     srat = acpi_data_push(table_data, sizeof(*srat));
     srat->reserved1 = cpu_to_le32(1);
 
-    for (i = 0; i < cpu_list->len; ++i) {
-        core = acpi_data_push(table_data, sizeof(*core));
-        core->type = ACPI_SRAT_PROCESSOR_GICC;
-        core->length = sizeof(*core);
-        core->proximity =  
Quoted 7 lines

cpu_to_le32(cpu_list->cpus[i].props.node_id);

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 535

Quoted 4 lines
hw/arm/virt-acpi-build.c +2 -2
-        core->acpi_processor_uid = cpu_to_le32(i);
-        core->flags = cpu_to_le32(1);
+    for (i = 0; i < ms->numa_state->num_nodes; ++i) {
+        for (j = 0; j < cpu_list->len; ++j) {  

Hmm O(n ^2) isn't great ...

Good suggestion, 3Q.

Quoted 14 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 547

Quoted 13 lines
hw/arm/virt-acpi-build.c +11 -0
+            node_id = cpu_to_le32(cpu_list->cpus[j].props.node_id);
+            if (node_id != i) {
+                continue;
+            }
+            core = acpi_data_push(table_data, sizeof(*core));
+            core->type = ACPI_SRAT_PROCESSOR_GICC;
+            core->length = sizeof(*core);
+            core->proximity = node_id;
+            core->acpi_processor_uid = cpu_to_le32(j);
+            core->flags = cpu_to_le32(1);
+        }
     }  
Quoted 2 lines

is the issue arm specific? wouldn't it affect x86 too?

Good question, I think it will affect x86, but I need to confirm.

Quoted 3 lines
Quoted 3 lines
hw/arm/virt-acpi-build.c +0 -1
     mem_base = vms->memmap[VIRT_MEM].base;
--

2.8.1

#4 lore raw
Quoted 64 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 11:50 PM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected]; [email protected]; Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure by node_id ascending order

Quoted 5 lines · On Tue, 7 Jan 2020 10:29:22 +0000 "Zengtao (B)" <[email protected]>…
Quoted 5 lines

-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 5:33 PM
To: Zengtao (B)
Cc: [email protected]; [email protected]; Shannon

Zhao;

Quoted 2 lines
Quoted 2 lines

Peter Maydell; Igor Mammedov; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure

by

Quoted 13 lines
Quoted 13 lines

node_id ascending order

Quoted 10 lines · Zeng Tao

When booting the guest linux with the following numa configuration:

(quoted diff) +0 -2
-numa node,node_id=1,cpus=0-3
-numa node,node_id=0,cpus=4-7

We can get the following numa topology in the guest system:

Architecture:          aarch64
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Socket(s):             1
NUMA node(s):          2
L1d cache:             unknown size
L1i cache:             unknown size
L2 cache:              unknown size
NUMA node0 CPU(s):     0-3
NUMA node1 CPU(s):     4-7

The Cpus 0-3 is assigned with NUMA node 1 in QEMU while it get

NUMA

Quoted 8 lines
Quoted 8 lines

node

Quoted 7 lines

0 in the guest.

In fact, In the linux kernel, numa_node_id is allocated per the ACPI SRAT processors structure order,so the cpu 0 will be the first one to allocate its NUMA node id, so it gets the NUMA node 0.

To fix this issue, we pack the SRAT processors structure in numa node

id

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

order but not the default cpu number order.

Quoted 7 lines
Quoted 3 lines

Does this matter? If yes fixing linux to take node id from proximity field in ACPI seems cleaner ...

In fact, I just want to align the node_id concept in QEMU and Linux. If we fix the kernel side, we need to align with all platforms. i think maybe not a good idea.

Quoted 8 lines

if linux makes up node ID's on it's own, it would be hard for it to map SRAT entries to other tables that use proximity id as well.

So it would need to maintain map of [proximity id] -> [node id] (and reverse) somewhere to resolve mappings on other tables.
If it doesn't do this then it's broken and works just by accident, if it does the fix probably should be in that code and not in QEMU.

Hmm, the problem is how to understand the concept of node id.
1. In dts, there is node id. Both the QEMU and Linux can use it directly, so no conflict.
2. In ACPI, there is only proximity domain, but no node id, there should be a mapping between them, while kernel and QEMU maintain their own rule, and unfortunately they conflict with each other sometimes.

There is no specification to indicate what we should do to maintain the mapping, so it's hard to align the QEMU and Linux.

Any suggestion, or we just accept it as a rule since it don't affect much?

Quoted 61 lines
Quoted 30 lines
Quoted 30 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker

Quoted 10 lines
---
 hw/arm/virt-acpi-build.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +0 -0
index bd5f771..497192b 100644
@@ -520,7 +520,8 @@ build_srat(GArray *table_data, BIOSLinker

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker

Quoted 10 lines
hw/arm/virt-acpi-build.c +2 -1
     AcpiSystemResourceAffinityTable *srat;
     AcpiSratProcessorGiccAffinity *core;
     AcpiSratMemoryAffinity *numamem;
-    int i, srat_start;
+    int i, j, srat_start;
+    uint32_t node_id;
     uint64_t mem_base;
     MachineClass *mc = MACHINE_GET_CLASS(vms);
     MachineState *ms = MACHINE(vms);
@@ -530,13 +531,19 @@ build_srat(GArray *table_data, BIOSLinker

*linker, VirtMachineState *vms)

Quoted 8 lines
hw/arm/virt-acpi-build.c +0 -5
     srat = acpi_data_push(table_data, sizeof(*srat));
     srat->reserved1 = cpu_to_le32(1);
 
-    for (i = 0; i < cpu_list->len; ++i) {
-        core = acpi_data_push(table_data, sizeof(*core));
-        core->type = ACPI_SRAT_PROCESSOR_GICC;
-        core->length = sizeof(*core);
-        core->proximity =
Quoted 10 lines
Quoted 7 lines

cpu_to_le32(cpu_list->cpus[i].props.node_id);

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 535

Quoted 4 lines
hw/arm/virt-acpi-build.c +2 -2
-        core->acpi_processor_uid = cpu_to_le32(i);
-        core->flags = cpu_to_le32(1);
+    for (i = 0; i < ms->numa_state->num_nodes; ++i) {
+        for (j = 0; j < cpu_list->len; ++j) {

Hmm O(n ^2) isn't great ...

Good suggestion, 3Q.

Quoted 2 lines
Quoted 2 lines
hw/arm/virt-acpi-build.c +1 -0
+            node_id =

cpu_to_le32(cpu_list->cpus[j].props.node_id);

Quoted 20 lines
Quoted 12 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 547

Quoted 11 lines
hw/arm/virt-acpi-build.c +10 -0
+            if (node_id != i) {
+                continue;
+            }
+            core = acpi_data_push(table_data, sizeof(*core));
+            core->type = ACPI_SRAT_PROCESSOR_GICC;
+            core->length = sizeof(*core);
+            core->proximity = node_id;
+            core->acpi_processor_uid = cpu_to_le32(j);
+            core->flags = cpu_to_le32(1);
+        }
     }
Quoted 2 lines

is the issue arm specific? wouldn't it affect x86 too?

Good question, I think it will affect x86, but I need to confirm.

Quoted 3 lines
Quoted 3 lines
hw/arm/virt-acpi-build.c +0 -1
     mem_base = vms->memmap[VIRT_MEM].base;
--

2.8.1

#5 lore raw
Quoted 81 lines · On Wed, 8 Jan 2020 04:02:10 +0000 "Zengtao (B)" <[email protected]>…
Quoted 64 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 11:50 PM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected]; [email protected]; Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure by node_id ascending order

Quoted 5 lines · On Tue, 7 Jan 2020 10:29:22 +0000 "Zengtao (B)" <[email protected]>…
Quoted 5 lines

-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 5:33 PM
To: Zengtao (B)
Cc: [email protected]; [email protected]; Shannon

Zhao;

Quoted 2 lines
Quoted 2 lines

Peter Maydell; Igor Mammedov; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure

by

Quoted 13 lines
Quoted 13 lines

node_id ascending order

Quoted 10 lines · Zeng Tao

When booting the guest linux with the following numa configuration:

(quoted diff) +0 -2
-numa node,node_id=1,cpus=0-3
-numa node,node_id=0,cpus=4-7

We can get the following numa topology in the guest system:

Architecture:          aarch64
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Socket(s):             1
NUMA node(s):          2
L1d cache:             unknown size
L1i cache:             unknown size
L2 cache:              unknown size
NUMA node0 CPU(s):     0-3
NUMA node1 CPU(s):     4-7

The Cpus 0-3 is assigned with NUMA node 1 in QEMU while it get

NUMA

Quoted 8 lines
Quoted 8 lines

node

Quoted 7 lines

0 in the guest.

In fact, In the linux kernel, numa_node_id is allocated per the ACPI SRAT processors structure order,so the cpu 0 will be the first one to allocate its NUMA node id, so it gets the NUMA node 0.

To fix this issue, we pack the SRAT processors structure in numa node

id

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

order but not the default cpu number order.

Quoted 7 lines
Quoted 3 lines

Does this matter? If yes fixing linux to take node id from proximity field in ACPI seems cleaner ...

In fact, I just want to align the node_id concept in QEMU and Linux. If we fix the kernel side, we need to align with all platforms. i think maybe not a good idea.

Quoted 8 lines

if linux makes up node ID's on it's own, it would be hard for it to map SRAT entries to other tables that use proximity id as well.

So it would need to maintain map of [proximity id] -> [node id] (and reverse) somewhere to resolve mappings on other tables.
If it doesn't do this then it's broken and works just by accident, if it does the fix probably should be in that code and not in QEMU.

Hmm, the problem is how to understand the concept of node id.
1. In dts, there is node id. Both the QEMU and Linux can use it directly, so no conflict.
2. In ACPI, there is only proximity domain, but no node id, there should be a mapping between them, while kernel and QEMU maintain their own rule, and unfortunately they conflict with each other sometimes.

Quoted 4 lines

There is no specification to indicate what we should do to maintain the mapping, so it's hard to align the QEMU and Linux.

Any suggestion, or we just accept it as a rule since it don't affect much?

If node id generation is driven by SRAT content, it might be reasonable to ask for SRAT parser in kernel to create node ids using proximity value instead of the order ACPI_SRAT_PROCESSOR_GICC structures are enumerated. That way node id would match ACPI spec.

But even with that I'd wouldn't expect cpu ids match as its basically arbitrary numbers on both sided. One would need to use arch specific ids to reliably match cpus on both sides (MPIDR in ARM case or APICID in x86).

Quoted 62 lines
Quoted 61 lines
Quoted 30 lines
Quoted 30 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker

Quoted 10 lines
 
---
 hw/arm/virt-acpi-build.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +0 -0
index bd5f771..497192b 100644
@@ -520,7 +520,8 @@ build_srat(GArray *table_data, BIOSLinker  

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker

Quoted 10 lines
hw/arm/virt-acpi-build.c +2 -1
     AcpiSystemResourceAffinityTable *srat;
     AcpiSratProcessorGiccAffinity *core;
     AcpiSratMemoryAffinity *numamem;
-    int i, srat_start;
+    int i, j, srat_start;
+    uint32_t node_id;
     uint64_t mem_base;
     MachineClass *mc = MACHINE_GET_CLASS(vms);
     MachineState *ms = MACHINE(vms);
@@ -530,13 +531,19 @@ build_srat(GArray *table_data, BIOSLinker  

*linker, VirtMachineState *vms)

Quoted 8 lines
hw/arm/virt-acpi-build.c +0 -5
     srat = acpi_data_push(table_data, sizeof(*srat));
     srat->reserved1 = cpu_to_le32(1);
 
-    for (i = 0; i < cpu_list->len; ++i) {
-        core = acpi_data_push(table_data, sizeof(*core));
-        core->type = ACPI_SRAT_PROCESSOR_GICC;
-        core->length = sizeof(*core);
-        core->proximity =  
Quoted 10 lines
Quoted 7 lines

cpu_to_le32(cpu_list->cpus[i].props.node_id);

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 535

Quoted 4 lines
hw/arm/virt-acpi-build.c +2 -2
-        core->acpi_processor_uid = cpu_to_le32(i);
-        core->flags = cpu_to_le32(1);
+    for (i = 0; i < ms->numa_state->num_nodes; ++i) {
+        for (j = 0; j < cpu_list->len; ++j) {  

Hmm O(n ^2) isn't great ...

Good suggestion, 3Q.

Quoted 2 lines
Quoted 2 lines
hw/arm/virt-acpi-build.c +1 -0
+            node_id =  

cpu_to_le32(cpu_list->cpus[j].props.node_id);

Quoted 20 lines
Quoted 12 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 547

Quoted 11 lines
hw/arm/virt-acpi-build.c +10 -0
+            if (node_id != i) {
+                continue;
+            }
+            core = acpi_data_push(table_data, sizeof(*core));
+            core->type = ACPI_SRAT_PROCESSOR_GICC;
+            core->length = sizeof(*core);
+            core->proximity = node_id;
+            core->acpi_processor_uid = cpu_to_le32(j);
+            core->flags = cpu_to_le32(1);
+        }
     }  
Quoted 2 lines

is the issue arm specific? wouldn't it affect x86 too?

Good question, I think it will affect x86, but I need to confirm.

Quoted 3 lines
Quoted 3 lines
hw/arm/virt-acpi-build.c +0 -1
     mem_base = vms->memmap[VIRT_MEM].base;
--

2.8.1

#6 lore raw
Quoted 104 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Thursday, January 09, 2020 12:39 AM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected]; [email protected]; Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure by node_id ascending order

Quoted 5 lines · On Wed, 8 Jan 2020 04:02:10 +0000 "Zengtao (B)" <[email protected]>…
Quoted 5 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 11:50 PM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure

by

Quoted 5 lines
Quoted 5 lines

node_id ascending order

On Tue, 7 Jan 2020 10:29:22 +0000
"Zengtao (B)" <[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 5:33 PM
To: Zengtao (B)
Cc: [email protected]; [email protected]; Shannon

Zhao;

Quoted 2 lines
Quoted 2 lines

Peter Maydell; Igor Mammedov; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors

structure

Quoted 5 lines
Quoted 5 lines

by

Quoted 4 lines
Quoted 4 lines

node_id ascending order

Quoted 1 line · Zeng Tao

When booting the guest linux with the following numa

configuration:

Quoted 18 lines
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +0 -2
-numa node,node_id=1,cpus=0-3
-numa node,node_id=0,cpus=4-7

We can get the following numa topology in the guest system:

Architecture:          aarch64
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Socket(s):             1
NUMA node(s):          2
L1d cache:             unknown size
L1i cache:             unknown size
L2 cache:              unknown size
NUMA node0 CPU(s):     0-3
NUMA node1 CPU(s):     4-7

The Cpus 0-3 is assigned with NUMA node 1 in QEMU while it get

NUMA

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

node

Quoted 3 lines

0 in the guest.

In fact, In the linux kernel, numa_node_id is allocated per the

ACPI

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

SRAT processors structure order,so the cpu 0 will be the first one

to

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

allocate its NUMA node id, so it gets the NUMA node 0.

To fix this issue, we pack the SRAT processors structure in numa

node

Quoted 10 lines
Quoted 10 lines

id

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

order but not the default cpu number order.

Does this matter? If yes fixing linux to take node id from proximity field in ACPI seems cleaner ...

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

In fact, I just want to align the node_id concept in QEMU and Linux. If we fix the kernel side, we need to align with all platforms. i think maybe not a good idea.

if linux makes up node ID's on it's own, it would be hard for it to map SRAT entries to other tables that use proximity id as well.

So it would need to maintain map of [proximity id] -> [node id] (and

reverse)

Quoted 16 lines
Quoted 4 lines

somewhere to resolve mappings on other tables.
If it doesn't do this then it's broken and works just by accident, if it does the fix probably should be in that code and not in QEMU.

Hmm, the problem is how to understand the concept of node id.
1. In dts, there is node id. Both the QEMU and Linux can use it directly, so no conflict.
2. In ACPI, there is only proximity domain, but no node id, there should be a mapping between them, while kernel and QEMU maintain their own rule, and unfortunately they conflict with each other sometimes.

There is no specification to indicate what we should do to maintain the mapping, so it's hard to align the QEMU and Linux.

Quoted 8 lines
Quoted 1 line

Any suggestion, or we just accept it as a rule since it don't affect much?

If node id generation is driven by SRAT content, it might be reasonable to ask for SRAT parser in kernel to create node ids using proximity value instead of the order ACPI_SRAT_PROCESSOR_GICC structures are enumerated.
That way node id would match ACPI spec.

I don't quite understand "That way node id would match ACPI spec." I check the ACPI 6.3 spec, I didn't find any description that node id should be equal to proximity value, in section 6.2.15, there is indeed an example which node numbers equals to proximity value.

Thanks

Quoted 68 lines

But even with that I'd wouldn't expect cpu ids match as its basically arbitrary numbers on both sided. One would need to use arch specific ids to reliably match cpus on both sides (MPIDR in ARM case or APICID in x86). .

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data,

Quoted 10 lines
---
 hw/arm/virt-acpi-build.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +0 -0
index bd5f771..497192b 100644
@@ -520,7 +520,8 @@ build_srat(GArray *table_data,

BIOSLinker

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data,

Quoted 10 lines
hw/arm/virt-acpi-build.c +2 -1
     AcpiSystemResourceAffinityTable *srat;
     AcpiSratProcessorGiccAffinity *core;
     AcpiSratMemoryAffinity *numamem;
-    int i, srat_start;
+    int i, j, srat_start;
+    uint32_t node_id;
     uint64_t mem_base;
     MachineClass *mc = MACHINE_GET_CLASS(vms);
     MachineState *ms = MACHINE(vms);
@@ -530,13 +531,19 @@ build_srat(GArray *table_data,

BIOSLinker

Quoted 41 lines
Quoted 40 lines
Quoted 9 lines
Quoted 9 lines

*linker, VirtMachineState *vms)

Quoted 8 lines
hw/arm/virt-acpi-build.c +0 -5
     srat = acpi_data_push(table_data, sizeof(*srat));
     srat->reserved1 = cpu_to_le32(1);
 
-    for (i = 0; i < cpu_list->len; ++i) {
-        core = acpi_data_push(table_data, sizeof(*core));
-        core->type = ACPI_SRAT_PROCESSOR_GICC;
-        core->length = sizeof(*core);
-        core->proximity =
Quoted 10 lines
Quoted 7 lines

cpu_to_le32(cpu_list->cpus[i].props.node_id);

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 535

Quoted 4 lines
hw/arm/virt-acpi-build.c +2 -2
-        core->acpi_processor_uid = cpu_to_le32(i);
-        core->flags = cpu_to_le32(1);
+    for (i = 0; i < ms->numa_state->num_nodes; ++i) {
+        for (j = 0; j < cpu_list->len; ++j) {

Hmm O(n ^2) isn't great ...

Good suggestion, 3Q.

Quoted 2 lines
Quoted 2 lines
hw/arm/virt-acpi-build.c +1 -0
+            node_id =

cpu_to_le32(cpu_list->cpus[j].props.node_id);

Quoted 20 lines
Quoted 12 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 547

Quoted 11 lines
hw/arm/virt-acpi-build.c +10 -0
+            if (node_id != i) {
+                continue;
+            }
+            core = acpi_data_push(table_data, sizeof(*core));
+            core->type = ACPI_SRAT_PROCESSOR_GICC;
+            core->length = sizeof(*core);
+            core->proximity = node_id;
+            core->acpi_processor_uid = cpu_to_le32(j);
+            core->flags = cpu_to_le32(1);
+        }
     }
Quoted 2 lines

is the issue arm specific? wouldn't it affect x86 too?

Good question, I think it will affect x86, but I need to confirm.

Quoted 3 lines
Quoted 3 lines
hw/arm/virt-acpi-build.c +0 -1
     mem_base = vms->memmap[VIRT_MEM].base;
--

2.8.1

#7 lore raw
Quoted 113 lines · On Thu, 9 Jan 2020 02:45:58 +0000 "Zengtao (B)" <[email protected]>…
Quoted 104 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Thursday, January 09, 2020 12:39 AM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected]; [email protected]; Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure by node_id ascending order

Quoted 5 lines · On Wed, 8 Jan 2020 04:02:10 +0000 "Zengtao (B)" <[email protected]>…
Quoted 5 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 11:50 PM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure

by

Quoted 5 lines
Quoted 5 lines

node_id ascending order

On Tue, 7 Jan 2020 10:29:22 +0000
"Zengtao (B)" <[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 5:33 PM
To: Zengtao (B)
Cc: [email protected]; [email protected]; Shannon

Zhao;

Quoted 2 lines
Quoted 2 lines

Peter Maydell; Igor Mammedov; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors

structure

Quoted 5 lines
Quoted 5 lines

by

Quoted 4 lines
Quoted 4 lines

node_id ascending order

Quoted 1 line · Zeng Tao

When booting the guest linux with the following numa

configuration:

Quoted 18 lines
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +0 -2
-numa node,node_id=1,cpus=0-3
-numa node,node_id=0,cpus=4-7

We can get the following numa topology in the guest system:

Architecture:          aarch64
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Socket(s):             1
NUMA node(s):          2
L1d cache:             unknown size
L1i cache:             unknown size
L2 cache:              unknown size
NUMA node0 CPU(s):     0-3
NUMA node1 CPU(s):     4-7

The Cpus 0-3 is assigned with NUMA node 1 in QEMU while it get

NUMA

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

node

Quoted 3 lines

0 in the guest.

In fact, In the linux kernel, numa_node_id is allocated per the

ACPI

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

SRAT processors structure order,so the cpu 0 will be the first one

to

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

allocate its NUMA node id, so it gets the NUMA node 0.

To fix this issue, we pack the SRAT processors structure in numa

node

Quoted 10 lines
Quoted 10 lines

id

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

order but not the default cpu number order.

Does this matter? If yes fixing linux to take node id from proximity field in ACPI seems cleaner ...

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

In fact, I just want to align the node_id concept in QEMU and Linux. If we fix the kernel side, we need to align with all platforms. i think maybe not a good idea.

if linux makes up node ID's on it's own, it would be hard for it to map SRAT entries to other tables that use proximity id as well.

So it would need to maintain map of [proximity id] -> [node id] (and

reverse)

Quoted 16 lines
Quoted 4 lines

somewhere to resolve mappings on other tables.
If it doesn't do this then it's broken and works just by accident, if it does the fix probably should be in that code and not in QEMU.

Hmm, the problem is how to understand the concept of node id.
1. In dts, there is node id. Both the QEMU and Linux can use it directly, so no conflict.
2. In ACPI, there is only proximity domain, but no node id, there should be a mapping between them, while kernel and QEMU maintain their own rule, and unfortunately they conflict with each other sometimes.

There is no specification to indicate what we should do to maintain the mapping, so it's hard to align the QEMU and Linux.

Quoted 8 lines
Quoted 1 line

Any suggestion, or we just accept it as a rule since it don't affect much?

If node id generation is driven by SRAT content, it might be reasonable to ask for SRAT parser in kernel to create node ids using proximity value instead of the order ACPI_SRAT_PROCESSOR_GICC structures are enumerated.
That way node id would match ACPI spec.

Quoted 4 lines

I don't quite understand "That way node id would match ACPI spec." I check the ACPI 6.3 spec, I didn't find any description that node id should be equal to proximity value, in section 6.2.15, there is indeed an example which node numbers equals to proximity value.

There is only proximity id in spec (which conceptually is the same as node id). What I'm saying is that linux kernel ACPI parser could use it as node id instead of using counter for making up node ids.

(issue with it is that proximity values could be sparse, so one would need to audit current node id users to make sure that using proximity id won't break anything)

Quoted 71 lines

Thanks

Quoted 68 lines

But even with that I'd wouldn't expect cpu ids match as its basically arbitrary numbers on both sided. One would need to use arch specific ids to reliably match cpus on both sides (MPIDR in ARM case or APICID in x86). .

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data,

Quoted 10 lines
 
---
 hw/arm/virt-acpi-build.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +0 -0
index bd5f771..497192b 100644
@@ -520,7 +520,8 @@ build_srat(GArray *table_data,  

BIOSLinker

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data,

Quoted 10 lines
hw/arm/virt-acpi-build.c +2 -1
     AcpiSystemResourceAffinityTable *srat;
     AcpiSratProcessorGiccAffinity *core;
     AcpiSratMemoryAffinity *numamem;
-    int i, srat_start;
+    int i, j, srat_start;
+    uint32_t node_id;
     uint64_t mem_base;
     MachineClass *mc = MACHINE_GET_CLASS(vms);
     MachineState *ms = MACHINE(vms);
@@ -530,13 +531,19 @@ build_srat(GArray *table_data,  

BIOSLinker

Quoted 41 lines
Quoted 40 lines
Quoted 9 lines
Quoted 9 lines

*linker, VirtMachineState *vms)

Quoted 8 lines
hw/arm/virt-acpi-build.c +0 -5
     srat = acpi_data_push(table_data, sizeof(*srat));
     srat->reserved1 = cpu_to_le32(1);
 
-    for (i = 0; i < cpu_list->len; ++i) {
-        core = acpi_data_push(table_data, sizeof(*core));
-        core->type = ACPI_SRAT_PROCESSOR_GICC;
-        core->length = sizeof(*core);
-        core->proximity =  
Quoted 10 lines
Quoted 7 lines

cpu_to_le32(cpu_list->cpus[i].props.node_id);

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, · line 535

Quoted 4 lines
hw/arm/virt-acpi-build.c +2 -2
-        core->acpi_processor_uid = cpu_to_le32(i);
-        core->flags = cpu_to_le32(1);
+    for (i = 0; i < ms->numa_state->num_nodes; ++i) {
+        for (j = 0; j < cpu_list->len; ++j) {  

Hmm O(n ^2) isn't great ...

Good suggestion, 3Q.

Quoted 2 lines
Quoted 2 lines
hw/arm/virt-acpi-build.c +1 -0
+            node_id =  

cpu_to_le32(cpu_list->cpus[j].props.node_id);

Quoted 20 lines
Quoted 12 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, · line 547

Quoted 11 lines
hw/arm/virt-acpi-build.c +10 -0
+            if (node_id != i) {
+                continue;
+            }
+            core = acpi_data_push(table_data, sizeof(*core));
+            core->type = ACPI_SRAT_PROCESSOR_GICC;
+            core->length = sizeof(*core);
+            core->proximity = node_id;
+            core->acpi_processor_uid = cpu_to_le32(j);
+            core->flags = cpu_to_le32(1);
+        }
     }  
Quoted 2 lines

is the issue arm specific? wouldn't it affect x86 too?

Good question, I think it will affect x86, but I need to confirm.

Quoted 3 lines
Quoted 3 lines
hw/arm/virt-acpi-build.c +0 -1
     mem_base = vms->memmap[VIRT_MEM].base;
--

2.8.1

#8 lore raw
Quoted 143 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Thursday, January 09, 2020 5:54 PM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected]; [email protected]; Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure by node_id ascending order

Quoted 5 lines · On Thu, 9 Jan 2020 02:45:58 +0000 "Zengtao (B)" <[email protected]>…
Quoted 5 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Thursday, January 09, 2020 12:39 AM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure

by

Quoted 5 lines
Quoted 5 lines

node_id ascending order

On Wed, 8 Jan 2020 04:02:10 +0000
"Zengtao (B)" <[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 11:50 PM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors

structure

Quoted 11 lines
Quoted 11 lines

by

Quoted 10 lines
Quoted 10 lines

node_id ascending order

Quoted 5 lines · On Tue, 7 Jan 2020 10:29:22 +0000 "Zengtao (B)" <[email protected]>…
Quoted 5 lines

-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 5:33 PM
To: Zengtao (B)
Cc: [email protected]; [email protected];

Shannon

Quoted 19 lines
Quoted 19 lines
Quoted 3 lines
Quoted 3 lines

Zhao;

Quoted 2 lines
Quoted 2 lines

Peter Maydell; Igor Mammedov; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors

structure

Quoted 5 lines
Quoted 5 lines

by

Quoted 4 lines
Quoted 4 lines

node_id ascending order

Quoted 1 line · Zeng Tao

When booting the guest linux with the following numa

configuration:

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +0 -2
-numa node,node_id=1,cpus=0-3
-numa node,node_id=0,cpus=4-7

We can get the following numa topology in the guest system:

Architecture:          aarch64
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Socket(s):             1
NUMA node(s):          2
L1d cache:             unknown size
L1i cache:             unknown size
L2 cache:              unknown size
NUMA node0 CPU(s):     0-3
NUMA node1 CPU(s):     4-7

The Cpus 0-3 is assigned with NUMA node 1 in QEMU while it

get

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

NUMA

Quoted 4 lines
Quoted 4 lines

node

Quoted 3 lines

0 in the guest.

In fact, In the linux kernel, numa_node_id is allocated per the

ACPI

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

SRAT processors structure order,so the cpu 0 will be the first

one

Quoted 4 lines
Quoted 4 lines

to

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

allocate its NUMA node id, so it gets the NUMA node 0.

To fix this issue, we pack the SRAT processors structure in

numa

Quoted 8 lines
Quoted 8 lines

node

Quoted 7 lines
Quoted 7 lines

id

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

order but not the default cpu number order.

Does this matter? If yes fixing linux to take node id from

proximity

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

field in ACPI seems cleaner ...

In fact, I just want to align the node_id concept in QEMU and

Linux.

Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

If we fix the kernel side, we need to align with all platforms. i think maybe not a good idea.

if linux makes up node ID's on it's own, it would be hard for it to map SRAT entries to other tables that use proximity id as well.

So it would need to maintain map of [proximity id] -> [node id] (and

reverse)

Quoted 5 lines
Quoted 4 lines

somewhere to resolve mappings on other tables.
If it doesn't do this then it's broken and works just by accident, if it does the fix probably should be in that code and not in QEMU.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Hmm, the problem is how to understand the concept of node id.
1. In dts, there is node id. Both the QEMU and Linux can use it directly, so no conflict.
2. In ACPI, there is only proximity domain, but no node id, there should be a mapping between them, while kernel and QEMU

maintain

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

their own rule, and unfortunately they conflict with each other sometimes.

There is no specification to indicate what we should do to maintain

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mapping, so it's hard to align the QEMU and Linux.

Any suggestion, or we just accept it as a rule since it don't affect

much?

Quoted 2 lines
Quoted 2 lines

If node id generation is driven by SRAT content, it might be reasonable

to

Quoted 10 lines
Quoted 5 lines

ask for SRAT parser in kernel to create node ids using proximity value instead of the order ACPI_SRAT_PROCESSOR_GICC structures are enumerated.
That way node id would match ACPI spec.

I don't quite understand "That way node id would match ACPI spec." I check the ACPI 6.3 spec, I didn't find any description that node id should be equal to proximity value, in section 6.2.15, there is indeed an example which node numbers equals to proximity value.

Quoted 9 lines

There is only proximity id in spec (which conceptually is the same as node id).
What I'm saying is that linux kernel ACPI parser could use it as node id instead of using counter for making up node ids.

(issue with it is that proximity values could be sparse, so one would need to audit current node id users to make sure that using proximity id won't break anything)

I think that is really a problem, in linux kernel:
#if MAX_NUMNODEs > 256
#define MAX_PXM_DOMAINS MAX_NUMNODEs
#else
#define MAX_PXM_DOMAINS 256
#endif
It seems that using counter is a better choice.

Quoted 74 lines
Quoted 4 lines

Thanks

Quoted 2 lines

But even with that I'd wouldn't expect cpu ids match as its basically arbitrary numbers on both sided. One would need to use arch specific

ids

Quoted 1 line
Quoted 1 line

to reliably match cpus on both sides (MPIDR in ARM case or APICID in

x86).

Quoted 40 lines
Quoted 40 lines

.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data,

Quoted 10 lines
---
 hw/arm/virt-acpi-build.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +0 -0
index bd5f771..497192b 100644
@@ -520,7 +520,8 @@ build_srat(GArray *table_data,

BIOSLinker

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data,

Quoted 10 lines
hw/arm/virt-acpi-build.c +2 -1
     AcpiSystemResourceAffinityTable *srat;
     AcpiSratProcessorGiccAffinity *core;
     AcpiSratMemoryAffinity *numamem;
-    int i, srat_start;
+    int i, j, srat_start;
+    uint32_t node_id;
     uint64_t mem_base;
     MachineClass *mc = MACHINE_GET_CLASS(vms);
     MachineState *ms = MACHINE(vms);
@@ -530,13 +531,19 @@ build_srat(GArray *table_data,

BIOSLinker

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, · line 537

Quoted 8 lines
hw/arm/virt-acpi-build.c +0 -5
     srat = acpi_data_push(table_data, sizeof(*srat));
     srat->reserved1 = cpu_to_le32(1);
 
-    for (i = 0; i < cpu_list->len; ++i) {
-        core = acpi_data_push(table_data, sizeof(*core));
-        core->type = ACPI_SRAT_PROCESSOR_GICC;
-        core->length = sizeof(*core);
-        core->proximity =

cpu_to_le32(cpu_list->cpus[i].props.node_id);

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, · line 535

Quoted 4 lines
hw/arm/virt-acpi-build.c +2 -2
-        core->acpi_processor_uid = cpu_to_le32(i);
-        core->flags = cpu_to_le32(1);
+    for (i = 0; i < ms->numa_state->num_nodes; ++i) {
+        for (j = 0; j < cpu_list->len; ++j) {

Hmm O(n ^2) isn't great ...

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Good suggestion, 3Q.

Quoted 2 lines
Quoted 2 lines
hw/arm/virt-acpi-build.c +1 -0
+            node_id =

cpu_to_le32(cpu_list->cpus[j].props.node_id);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/arm/virt-acpi-build.c +4 -0
+            if (node_id != i) {
+                continue;
+            }
+            core = acpi_data_push(table_data,

sizeof(*core));

Quoted 18 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
Quoted 10 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, · line 547

Quoted 7 lines
hw/arm/virt-acpi-build.c +6 -0
+            core->type = ACPI_SRAT_PROCESSOR_GICC;
+            core->length = sizeof(*core);
+            core->proximity = node_id;
+            core->acpi_processor_uid = cpu_to_le32(j);
+            core->flags = cpu_to_le32(1);
+        }
     }

is the issue arm specific? wouldn't it affect x86 too?

Good question, I think it will affect x86, but I need to confirm.

Quoted 3 lines
Quoted 3 lines
hw/arm/virt-acpi-build.c +0 -1
     mem_base = vms->memmap[VIRT_MEM].base;
--

2.8.1

#9 lore raw
Quoted 152 lines · On Fri, 10 Jan 2020 02:56:35 +0000 "Zengtao (B)" <[email protected]>…
Quoted 143 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Thursday, January 09, 2020 5:54 PM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected]; [email protected]; Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure by node_id ascending order

Quoted 5 lines · On Thu, 9 Jan 2020 02:45:58 +0000 "Zengtao (B)" <[email protected]>…
Quoted 5 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Thursday, January 09, 2020 12:39 AM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure

by

Quoted 5 lines
Quoted 5 lines

node_id ascending order

On Wed, 8 Jan 2020 04:02:10 +0000
"Zengtao (B)" <[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 11:50 PM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors

structure

Quoted 11 lines
Quoted 11 lines

by

Quoted 10 lines
Quoted 10 lines

node_id ascending order

Quoted 5 lines · On Tue, 7 Jan 2020 10:29:22 +0000 "Zengtao (B)" <[email protected]>…
Quoted 5 lines

-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 5:33 PM
To: Zengtao (B)
Cc: [email protected]; [email protected];

Shannon

Quoted 19 lines
Quoted 19 lines
Quoted 3 lines
Quoted 3 lines

Zhao;

Quoted 2 lines
Quoted 2 lines

Peter Maydell; Igor Mammedov; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors

structure

Quoted 5 lines
Quoted 5 lines

by

Quoted 4 lines
Quoted 4 lines

node_id ascending order

Quoted 1 line · Zeng Tao

When booting the guest linux with the following numa

configuration:

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +0 -2
-numa node,node_id=1,cpus=0-3
-numa node,node_id=0,cpus=4-7

We can get the following numa topology in the guest system:

Architecture:          aarch64
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Socket(s):             1
NUMA node(s):          2
L1d cache:             unknown size
L1i cache:             unknown size
L2 cache:              unknown size
NUMA node0 CPU(s):     0-3
NUMA node1 CPU(s):     4-7

The Cpus 0-3 is assigned with NUMA node 1 in QEMU while it

get

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

NUMA

Quoted 4 lines
Quoted 4 lines

node

Quoted 3 lines

0 in the guest.

In fact, In the linux kernel, numa_node_id is allocated per the

ACPI

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

SRAT processors structure order,so the cpu 0 will be the first

one

Quoted 4 lines
Quoted 4 lines

to

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

allocate its NUMA node id, so it gets the NUMA node 0.

To fix this issue, we pack the SRAT processors structure in

numa

Quoted 8 lines
Quoted 8 lines

node

Quoted 7 lines
Quoted 7 lines

id

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

order but not the default cpu number order.

Does this matter? If yes fixing linux to take node id from

proximity

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

field in ACPI seems cleaner ...

In fact, I just want to align the node_id concept in QEMU and

Linux.

Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

If we fix the kernel side, we need to align with all platforms. i think maybe not a good idea.

if linux makes up node ID's on it's own, it would be hard for it to map SRAT entries to other tables that use proximity id as well.

So it would need to maintain map of [proximity id] -> [node id] (and

reverse)

Quoted 5 lines
Quoted 4 lines

somewhere to resolve mappings on other tables.
If it doesn't do this then it's broken and works just by accident, if it does the fix probably should be in that code and not in QEMU.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Hmm, the problem is how to understand the concept of node id.
1. In dts, there is node id. Both the QEMU and Linux can use it directly, so no conflict.
2. In ACPI, there is only proximity domain, but no node id, there should be a mapping between them, while kernel and QEMU

maintain

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

their own rule, and unfortunately they conflict with each other sometimes.

There is no specification to indicate what we should do to maintain

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mapping, so it's hard to align the QEMU and Linux.

Any suggestion, or we just accept it as a rule since it don't affect

much?

Quoted 2 lines
Quoted 2 lines

If node id generation is driven by SRAT content, it might be reasonable

to

Quoted 10 lines
Quoted 5 lines

ask for SRAT parser in kernel to create node ids using proximity value instead of the order ACPI_SRAT_PROCESSOR_GICC structures are enumerated.
That way node id would match ACPI spec.

I don't quite understand "That way node id would match ACPI spec." I check the ACPI 6.3 spec, I didn't find any description that node id should be equal to proximity value, in section 6.2.15, there is indeed an example which node numbers equals to proximity value.

Quoted 9 lines

There is only proximity id in spec (which conceptually is the same as node id).
What I'm saying is that linux kernel ACPI parser could use it as node id instead of using counter for making up node ids.

(issue with it is that proximity values could be sparse, so one would need to audit current node id users to make sure that using proximity id won't break anything)

Quoted 7 lines

I think that is really a problem, in linux kernel:
#if MAX_NUMNODEs > 256
#define MAX_PXM_DOMAINS MAX_NUMNODEs
#else
#define MAX_PXM_DOMAINS 256
#endif
It seems that using counter is a better choice.

In QEMU case nodeid isn't sparse. So even if kernel uses counter, it will work fine as far as it sorts SRAT by proximity value (same thing you are trying to do in this patch but on kernel side).
That way it would match what HW vendors think about node numbering in most cases.

(We a comparing apples to oranges, so arguing for one case vs another is rather pointless)

Another question, does this patch fixes anything? (if it is not, it might be better to just drop this idea)

Quoted 77 lines
Quoted 75 lines
Quoted 5 lines

Thanks

Quoted 2 lines

But even with that I'd wouldn't expect cpu ids match as its basically arbitrary numbers on both sided. One would need to use arch specific

ids

Quoted 1 line
Quoted 1 line

to reliably match cpus on both sides (MPIDR in ARM case or APICID in

x86).

Quoted 40 lines
Quoted 40 lines

.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data,

Quoted 10 lines
 
---
 hw/arm/virt-acpi-build.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +0 -0
index bd5f771..497192b 100644
@@ -520,7 +520,8 @@ build_srat(GArray *table_data,  

BIOSLinker

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data,

Quoted 10 lines
hw/arm/virt-acpi-build.c +2 -1
     AcpiSystemResourceAffinityTable *srat;
     AcpiSratProcessorGiccAffinity *core;
     AcpiSratMemoryAffinity *numamem;
-    int i, srat_start;
+    int i, j, srat_start;
+    uint32_t node_id;
     uint64_t mem_base;
     MachineClass *mc = MACHINE_GET_CLASS(vms);
     MachineState *ms = MACHINE(vms);
@@ -530,13 +531,19 @@ build_srat(GArray *table_data,  

BIOSLinker

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

*linker, VirtMachineState *vms)

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, · line 537

Quoted 8 lines
hw/arm/virt-acpi-build.c +0 -5
     srat = acpi_data_push(table_data, sizeof(*srat));
     srat->reserved1 = cpu_to_le32(1);
 
-    for (i = 0; i < cpu_list->len; ++i) {
-        core = acpi_data_push(table_data, sizeof(*core));
-        core->type = ACPI_SRAT_PROCESSOR_GICC;
-        core->length = sizeof(*core);
-        core->proximity =  

cpu_to_le32(cpu_list->cpus[i].props.node_id);

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, · line 535

Quoted 4 lines
hw/arm/virt-acpi-build.c +2 -2
-        core->acpi_processor_uid = cpu_to_le32(i);
-        core->flags = cpu_to_le32(1);
+    for (i = 0; i < ms->numa_state->num_nodes; ++i) {
+        for (j = 0; j < cpu_list->len; ++j) {  

Hmm O(n ^2) isn't great ...

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Good suggestion, 3Q.

Quoted 2 lines
Quoted 2 lines
hw/arm/virt-acpi-build.c +1 -0
+            node_id =  

cpu_to_le32(cpu_list->cpus[j].props.node_id);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/arm/virt-acpi-build.c +4 -0
+            if (node_id != i) {
+                continue;
+            }
+            core = acpi_data_push(table_data,  

sizeof(*core));

Quoted 18 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
Quoted 10 lines

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, · line 547

Quoted 7 lines
hw/arm/virt-acpi-build.c +6 -0
+            core->type = ACPI_SRAT_PROCESSOR_GICC;
+            core->length = sizeof(*core);
+            core->proximity = node_id;
+            core->acpi_processor_uid = cpu_to_le32(j);
+            core->flags = cpu_to_le32(1);
+        }
     }  

is the issue arm specific? wouldn't it affect x86 too?

Good question, I think it will affect x86, but I need to confirm.

Quoted 3 lines
Quoted 3 lines
hw/arm/virt-acpi-build.c +0 -1
     mem_base = vms->memmap[VIRT_MEM].base;
--

2.8.1

#10 lore raw
Quoted 206 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Monday, January 13, 2020 5:06 PM
To: Zengtao (B)
Cc: Peter Maydell; Michael S. Tsirkin; [email protected]; [email protected]; Shannon Zhao; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors structure by node_id ascending order

Quoted 5 lines · On Fri, 10 Jan 2020 02:56:35 +0000 "Zengtao (B)" <[email protected]>…
Quoted 5 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Thursday, January 09, 2020 5:54 PM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors

structure by

Quoted 5 lines
Quoted 5 lines

node_id ascending order

On Thu, 9 Jan 2020 02:45:58 +0000
"Zengtao (B)" <[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Thursday, January 09, 2020 12:39 AM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors

structure

Quoted 26 lines
Quoted 26 lines

by

Quoted 5 lines
Quoted 5 lines

node_id ascending order

On Wed, 8 Jan 2020 04:02:10 +0000
"Zengtao (B)" <[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 11:50 PM
To: Zengtao (B)
Cc: Michael S. Tsirkin; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Shannon Zhao; Peter Maydell; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT processors

structure

Quoted 11 lines
Quoted 11 lines

by

Quoted 10 lines
Quoted 10 lines

node_id ascending order

Quoted 5 lines · On Tue, 7 Jan 2020 10:29:22 +0000 "Zengtao (B)" <[email protected]>…
Quoted 5 lines

-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, January 07, 2020 5:33 PM
To: Zengtao (B)
Cc: [email protected]; [email protected];

Quoted 4 lines
Quoted 4 lines

Shannon

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Zhao;

Quoted 2 lines
Quoted 2 lines

Peter Maydell; Igor Mammedov; [email protected]
Subject: Re: [PATCH] hw/arm/acpi: Pack the SRAT

processors

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

structure

Quoted 4 lines
Quoted 4 lines

by

Quoted 3 lines
Quoted 3 lines

node_id ascending order

On Tue, Jan 07, 2020 at 05:18:49PM +0800, Zeng Tao

Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

When booting the guest linux with the following numa

configuration:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +0 -2
-numa node,node_id=1,cpus=0-3
-numa node,node_id=0,cpus=4-7

We can get the following numa topology in the guest

system:

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Architecture:          aarch64
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Socket(s):             1
NUMA node(s):          2
L1d cache:             unknown size
L1i cache:             unknown size
L2 cache:              unknown size
NUMA node0 CPU(s):     0-3
NUMA node1 CPU(s):     4-7

The Cpus 0-3 is assigned with NUMA node 1 in QEMU

while it

Quoted 6 lines
Quoted 6 lines

get

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

NUMA

Quoted 4 lines
Quoted 4 lines

node

Quoted 3 lines

0 in the guest.

In fact, In the linux kernel, numa_node_id is allocated

per the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

ACPI

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

SRAT processors structure order,so the cpu 0 will be the

first

Quoted 5 lines
Quoted 5 lines

one

Quoted 4 lines
Quoted 4 lines

to

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

allocate its NUMA node id, so it gets the NUMA node 0.

To fix this issue, we pack the SRAT processors structure

in

Quoted 8 lines
Quoted 8 lines

numa

Quoted 7 lines
Quoted 7 lines

node

Quoted 6 lines
Quoted 6 lines

id

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

order but not the default cpu number order.

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Does this matter? If yes fixing linux to take node id from

proximity

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

field in ACPI seems cleaner ...

In fact, I just want to align the node_id concept in QEMU

and

Quoted 4 lines
Quoted 4 lines

Linux.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

If we fix the kernel side, we need to align with all platforms. i think maybe not a good idea.

if linux makes up node ID's on it's own, it would be hard for it

to

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

map SRAT entries to other tables that use proximity id as

well.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

So it would need to maintain map of [proximity id] -> [node

id] (and

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

reverse)

Quoted 2 lines
Quoted 2 lines

somewhere to resolve mappings on other tables. If it doesn't do this then it's broken and works just by

accident,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

if it does the fix probably should be in that code and not in

QEMU.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

Hmm, the problem is how to understand the concept of node

id.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

1. In dts, there is node id. Both the QEMU and Linux can use it directly, so no conflict.
2. In ACPI, there is only proximity domain, but no node id, there should be a mapping between them, while kernel and QEMU

maintain

Quoted 1 line
Quoted 1 line
Quoted 1 line

their own rule, and unfortunately they conflict with each

other

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

sometimes.

There is no specification to indicate what we should do to

maintain

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mapping, so it's hard to align the QEMU and Linux.

Any suggestion, or we just accept it as a rule since it don't

affect

Quoted 3 lines
Quoted 3 lines

much?

Quoted 2 lines
Quoted 2 lines

If node id generation is driven by SRAT content, it might be

reasonable

Quoted 2 lines
Quoted 2 lines

to

Quoted 1 line
Quoted 1 line

ask for SRAT parser in kernel to create node ids using proximity

value

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

instead of the order ACPI_SRAT_PROCESSOR_GICC structures are enumerated.
That way node id would match ACPI spec.

I don't quite understand "That way node id would match ACPI

spec."

Quoted 1 line
Quoted 1 line
Quoted 1 line

I check the ACPI 6.3 spec, I didn't find any description that node id

should

Quoted 1 line
Quoted 1 line
Quoted 1 line

be equal to proximity value, in section 6.2.15, there is indeed an

example

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

which node numbers equals to proximity value.

There is only proximity id in spec (which conceptually is the same as

node

Quoted 2 lines
Quoted 2 lines

id).
What I'm saying is that linux kernel ACPI parser could use it as node

id

Quoted 6 lines
Quoted 6 lines

instead of using counter for making up node ids.

(issue with it is that proximity values could be sparse, so one would need to audit current node id users to make sure that using proximity id won't break anything)

Quoted 7 lines

I think that is really a problem, in linux kernel:
#if MAX_NUMNODEs > 256
#define MAX_PXM_DOMAINS MAX_NUMNODEs
#else
#define MAX_PXM_DOMAINS 256
#endif
It seems that using counter is a better choice.

In QEMU case nodeid isn't sparse. So even if kernel uses counter, it will work fine as far as it sorts SRAT by proximity value (same thing you are trying
to do in this patch but on kernel side).
That way it would match what HW vendors think about node numbering in most cases.

Quoted 6 lines

(We a comparing apples to oranges, so arguing for one case vs another is rather pointless)

Another question, does this patch fixes anything? (if it is not, it might be better to just drop this idea)

:) I am not persist on this patch, but I think you have provide me an important clue. "Most HW vendors number pxm and node in the same way, and so does QEMU", so i think it's reasonable for linux kernel to do the same.

So i think we can end the discussion and just ignore this patch. Thanks very much.

Regards
Zengtao