Skip to contentSkip to conversation

fix numa node mapping for hotplugged CPUs

PATCH Superseded Igor Mammedov 4 participants 13 messages Jul 1, 2016 – Jul 7, 2016

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover fix numa node mapping for hotplugged CPUs

Changelog:
v1->v3:
- fix commit message for 4/5
- add numa_get_node_for_cpu() helper
- add comment in code explaining why _PXM is being added

Series adds acpi tables tests for CPU hotplug and
makes hotplugged CPUs assigned to correct numa nodes for Linux guests
+ extends CPU hotplug test with numa options

Igor Mammedov (5):
tests: acpi: add CPU hotplug testcase
tests: DO NOT APPLY: add APIC.cphp and DSDT.cphp blobs
numa: reduce code duplication by adding helper numa_get_node_for_cpu()
acpi: provide _PXM method for CPU devices if QEMU is started numa
enabled
tests: acpi: extend cphp testcase with numa check

 hw/acpi/cpu.c                      |  12 ++++++++++++
 hw/arm/virt-acpi-build.c           |   6 ++----
 hw/arm/virt.c                      |   7 +++----
 hw/i386/acpi-build.c               |   7 ++-----
 hw/i386/pc.c                       |   8 +++-----
 hw/ppc/spapr_cpu_core.c            |   6 ++----
 include/sysemu/numa.h              |   3 +++
 numa.c                             |  12 ++++++++++++
 tests/acpi-test-data/pc/APIC.cphp  | Bin 0 -> 160 bytes
 tests/acpi-test-data/pc/DSDT.cphp  | Bin 0 -> 6435 bytes
 tests/acpi-test-data/pc/SRAT.cphp  | Bin 0 -> 304 bytes
 tests/acpi-test-data/q35/APIC.cphp | Bin 0 -> 160 bytes
 tests/acpi-test-data/q35/DSDT.cphp | Bin 0 -> 9197 bytes
 tests/acpi-test-data/q35/SRAT.cphp | Bin 0 -> 304 bytes
 tests/bios-tables-test.c           |  30 ++++++++++++++++++++++++++++++
 15 files changed, 69 insertions(+), 22 deletions(-)
 create mode 100644 tests/acpi-test-data/pc/APIC.cphp
 create mode 100644 tests/acpi-test-data/pc/DSDT.cphp
 create mode 100644 tests/acpi-test-data/pc/SRAT.cphp
 create mode 100644 tests/acpi-test-data/q35/APIC.cphp
 create mode 100644 tests/acpi-test-data/q35/DSDT.cphp
 create mode 100644 tests/acpi-test-data/q35/SRAT.cphp
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v3 1/5 tests: acpi: add CPU hotplug testcase

Test with:

    -smp 2,cores=3,sockets=2,maxcpus=6

to capture sparse APIC ID values that default
AMD CPU has in above configuration.

---
NOTE to maintainer:

following table blobs should be added to git tree as poart of this commit after running ./tests/acpi-test-data/rebuild-expected-aml.sh

tests/acpi-test-data/q35/APIC.cphp
tests/acpi-test-data/q35/DSDT.cphp
tests/acpi-test-data/pc/APIC.cphp
tests/acpi-test-data/pc/DSDT.cphp

---
 tests/bios-tables-test.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
tests/bios-tables-test.c +28 -0
index 92c90dd..de4019e 100644
@@ -801,6 +801,32 @@ static void test_acpi_q35_tcg_bridge(void)
     free_test_data(&data);
 }
 
+static void test_acpi_piix4_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_PC;
+    data.variant = ".cphp";
+    test_acpi_one("-machine accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
+static void test_acpi_q35_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".cphp";
+    test_acpi_one("-machine q35,accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
 static uint8_t ipmi_required_struct_types[] = {
     0, 1, 3, 4, 16, 17, 19, 32, 38, 127
 };
@@ -856,6 +882,8 @@ int main(int argc, char *argv[])
         qtest_add_func("acpi/q35/tcg/bridge", test_acpi_q35_tcg_bridge);
         qtest_add_func("acpi/piix4/tcg/ipmi", test_acpi_piix4_tcg_ipmi);
         qtest_add_func("acpi/q35/tcg/ipmi", test_acpi_q35_tcg_ipmi);
+        qtest_add_func("acpi/piix4/tcg/cpuhp", test_acpi_piix4_tcg_cphp);
+        qtest_add_func("acpi/q35/tcg/cpuhp", test_acpi_q35_tcg_cphp);
     }
     ret = g_test_run();
     boot_sector_cleanup(disk);
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v3 2/5 tests: DO NOT APPLY: add APIC.cphp and DSDT.cphp blobs

In reply to Igor Mammedov
---
 tests/acpi-test-data/pc/APIC.cphp  | Bin 0 -> 160 bytes
 tests/acpi-test-data/pc/DSDT.cphp  | Bin 0 -> 6435 bytes
 tests/acpi-test-data/q35/APIC.cphp | Bin 0 -> 160 bytes
 tests/acpi-test-data/q35/DSDT.cphp | Bin 0 -> 9197 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 tests/acpi-test-data/pc/APIC.cphp
 create mode 100644 tests/acpi-test-data/pc/DSDT.cphp
 create mode 100644 tests/acpi-test-data/q35/APIC.cphp
 create mode 100644 tests/acpi-test-data/q35/DSDT.cphp
tests/acpi-test-data/pc/APIC.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..1bf8a0a63bc1c9b716d937b96eb34b05016b9366
GIT binary patch
tests/acpi-test-data/pc/DSDT.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..e8b146208eb3877e1cde2cc361c5afd270d194c6
GIT binary patch
tests/acpi-test-data/q35/APIC.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..1bf8a0a63bc1c9b716d937b96eb34b05016b9366
GIT binary patch
tests/acpi-test-data/q35/DSDT.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..6cc28c6daec2b331030ab0600a4d79034c1dfc40
GIT binary patch
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v3 3/5 numa: reduce code duplication by adding helper numa_get_node_for_cpu()

In reply to Igor Mammedov

Replace repeated pattern

    for (i = 0; i < nb_numa_nodes; i++) {
        if (test_bit(idx, numa_info[i].node_cpu)) {
           ...
           break;

with a helper function to lookup numa node index for cpu.

---
 hw/arm/virt-acpi-build.c |  6 ++----
 hw/arm/virt.c            |  7 +++----
 hw/i386/acpi-build.c     |  7 ++-----
 hw/i386/pc.c             |  8 +++-----
 hw/ppc/spapr_cpu_core.c  |  6 ++----
 include/sysemu/numa.h    |  3 +++
 numa.c                   | 12 ++++++++++++
 7 files changed, 27 insertions(+), 22 deletions(-)
hw/arm/virt-acpi-build.c +2 -4
index 28fc59c..5923b3d 100644
@@ -426,11 +426,9 @@ build_srat(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info)
     uint32_t *cpu_node = g_malloc0(guest_info->smp_cpus * sizeof(uint32_t));
 
     for (i = 0; i < guest_info->smp_cpus; i++) {
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
+        j = numa_get_node_for_cpu(i);
+        if (j < nb_numa_nodes) {
                 cpu_node[i] = j;
-                break;
-            }
         }
     }
 
hw/arm/virt.c +3 -4
index c5c125e..b066f15 100644
@@ -411,10 +411,9 @@ static void fdt_add_cpu_nodes(const VirtBoardInfo *vbi)
                                   armcpu->mp_affinity);
         }
 
-        for (i = 0; i < nb_numa_nodes; i++) {
-            if (test_bit(cpu, numa_info[i].node_cpu)) {
-                qemu_fdt_setprop_cell(vbi->fdt, nodename, "numa-node-id", i);
-            }
+        i = numa_get_node_for_cpu(cpu);
+        if (i < nb_numa_nodes) {
+            qemu_fdt_setprop_cell(vbi->fdt, nodename, "numa-node-id", i);
         }
 
         g_free(nodename);
hw/i386/acpi-build.c +2 -5
index 5a594be..60be550 100644
@@ -2344,18 +2344,15 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
     srat->reserved1 = cpu_to_le32(1);
 
     for (i = 0; i < apic_ids->len; i++) {
-        int j;
+        int j = numa_get_node_for_cpu(i);
         int apic_id = apic_ids->cpus[i].arch_id;
 
         core = acpi_data_push(table_data, sizeof *core);
         core->type = ACPI_SRAT_PROCESSOR_APIC;
         core->length = sizeof(*core);
         core->local_apic_id = apic_id;
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
+        if (j < nb_numa_nodes) {
                 core->proximity_lo = j;
-                break;
-            }
         }
         memset(core->proximity_hi, 0, 3);
         core->local_sapic_eid = 0;
hw/i386/pc.c +3 -5
index 44a8f3b..fef34e7 100644
@@ -780,11 +780,9 @@ static FWCfgState *bochs_bios_init(AddressSpace *as, PCMachineState *pcms)
     for (i = 0; i < max_cpus; i++) {
         unsigned int apic_id = x86_cpu_apic_id_from_index(i);
         assert(apic_id < pcms->apic_id_limit);
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
-                numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
-                break;
-            }
+        j = numa_get_node_for_cpu(i);
+        if (j < nb_numa_nodes) {
+            numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
         }
     }
     for (i = 0; i < nb_numa_nodes; i++) {
hw/ppc/spapr_cpu_core.c +2 -4
index 3a5da09..030016c 100644
@@ -69,11 +69,9 @@ void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
     }
 
     /* Set NUMA node for the added CPUs  */
-    for (i = 0; i < nb_numa_nodes; i++) {
-        if (test_bit(cs->cpu_index, numa_info[i].node_cpu)) {
+    i = numa_get_node_for_cpu(cs->cpu_index);
+    if (i < nb_numa_nodes) {
             cs->numa_node = i;
-            break;
-        }
     }
 
     xics_cpu_setup(spapr->icp, cpu);
include/sysemu/numa.h +3 -0
index bb184c9..4da808a 100644
@@ -32,4 +32,7 @@ void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node);
 void numa_unset_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node);
 uint32_t numa_get_node(ram_addr_t addr, Error **errp);
 
+/* on success returns node index in numa_info,
+ * on failure returns nb_numa_nodes */
+int numa_get_node_for_cpu(int idx);
 #endif
numa.c +12 -0
index 572712c..5790858 100644
@@ -548,3 +548,15 @@ MemdevList *qmp_query_memdev(Error **errp)
     object_child_foreach(obj, query_memdev, &list);
     return list;
 }
+
+int numa_get_node_for_cpu(int idx)
+{
+    int i;
+
+    for (i = 0; i < nb_numa_nodes; i++) {
+        if (test_bit(idx, numa_info[i].node_cpu)) {
+            break;
+        }
+    }
+    return i;
+}
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH v3 4/5 acpi: provide _PXM method for CPU devices if QEMU is started numa enabled

In reply to Igor Mammedov

Workaround for long standing issue where Linux kernel assigns hotplugged CPU to 1st numa node as it discards proximity for possible CPUs from SRAT after it's parsed.

_PXM method allows linux query proximity directly from hotplugged CPU object, which allows Linux to assing CPU to the correct numa node.

---
v3:
- use numa_get_node_for_cpu() instead of duplicating lookup code
- added comment in code blaming linux

---
 hw/acpi/cpu.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/acpi/cpu.c +12 -0
index c13b65c..902f5c9 100644
@@ -4,6 +4,7 @@
 #include "qapi/error.h"
 #include "qapi-event.h"
 #include "trace.h"
+#include "sysemu/numa.h"
 
 #define ACPI_CPU_HOTPLUG_REG_LEN 12
 #define ACPI_CPU_SELECTOR_OFFSET_WR 0
@@ -503,6 +504,7 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
 
         /* build Processor object for each processor */
         for (i = 0; i < arch_ids->len; i++) {
+            int j;
             Aml *dev;
             Aml *uid = aml_int(i);
             GArray *madt_buf = g_array_new(0, 1, 1);
@@ -546,6 +548,16 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                           aml_arg(1), aml_arg(2))
             );
             aml_append(dev, method);
+
+            /* Linux guests discard SRAT info for non-present CPUs
+             * as a result _PXM is required for all CPUs which might
+             * be hot-plugged. For simplicity, add it for all CPUs.
+             */
+            j = numa_get_node_for_cpu(i);
+            if (j < nb_numa_nodes) {
+                aml_append(dev, aml_name_decl("_PXM", aml_int(j)));
+            }
+
             aml_append(cpus_dev, dev);
         }
     }
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH v3 5/5 tests: acpi: extend cphp testcase with numa check

In reply to Igor Mammedov

so it would be possible to verify _PXM generation in DSDT and SRAT tables.

---
NOTE to maintainer:
SRAT table is included in patch as it doesn't have any chance for conflicts compared to often changing DSDT

following table blobs should be updated in git tree as part
of this commit after running ./tests/acpi-test-data/rebuild-expected-aml.sh

tests/acpi-test-data/q35/DSDT.cphp
tests/acpi-test-data/pc/DSDT.cphp

---
 tests/acpi-test-data/pc/SRAT.cphp  | Bin 0 -> 304 bytes
 tests/acpi-test-data/q35/SRAT.cphp | Bin 0 -> 304 bytes
 tests/bios-tables-test.c           |   6 ++++--
 3 files changed, 4 insertions(+), 2 deletions(-)
 create mode 100644 tests/acpi-test-data/pc/SRAT.cphp
 create mode 100644 tests/acpi-test-data/q35/SRAT.cphp
tests/acpi-test-data/pc/SRAT.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..ff2137642f488ec70b85207ed6c20e7351d61e98
GIT binary patch
tests/acpi-test-data/q35/SRAT.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..ff2137642f488ec70b85207ed6c20e7351d61e98
GIT binary patch
tests/bios-tables-test.c +4 -2
index de4019e..3796089 100644
@@ -809,7 +809,8 @@ static void test_acpi_piix4_tcg_cphp(void)
     data.machine = MACHINE_PC;
     data.variant = ".cphp";
     test_acpi_one("-machine accel=tcg"
-                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  " -smp 2,cores=3,sockets=2,maxcpus=6"
+                  " -numa node -numa node",
                   &data);
     free_test_data(&data);
 }
@@ -822,7 +823,8 @@ static void test_acpi_q35_tcg_cphp(void)
     data.machine = MACHINE_Q35;
     data.variant = ".cphp";
     test_acpi_one("-machine q35,accel=tcg"
-                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  " -smp 2,cores=3,sockets=2,maxcpus=6"
+                  " -numa node -numa node",
                   &data);
     free_test_data(&data);
 }
Signature · 1 line
1.8.3.1
#4 lore raw

Re: [Qemu-devel] [PATCH v3 3/5] numa: reduce code duplication by adding helper numa_get_node_for_cpu()

In reply to Igor Mammedov
Quoted 26 lines · Igor Mammedov

Replace repeated pattern

    for (i = 0; i < nb_numa_nodes; i++) {
        if (test_bit(idx, numa_info[i].node_cpu)) {
           ...
           break;

with a helper function to lookup numa node index for cpu.

---
 hw/arm/virt-acpi-build.c |  6 ++----
 hw/arm/virt.c            |  7 +++----
 hw/i386/acpi-build.c     |  7 ++-----
 hw/i386/pc.c             |  8 +++-----
 hw/ppc/spapr_cpu_core.c  |  6 ++----
 include/sysemu/numa.h    |  3 +++
 numa.c                   | 12 ++++++++++++
 7 files changed, 27 insertions(+), 22 deletions(-)
hw/arm/virt-acpi-build.c +0 -0
index 28fc59c..5923b3d 100644

hw/arm/virt-acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info) · line 431

Quoted 8 lines
hw/arm/virt-acpi-build.c +2 -2
@@ -426,11 +426,9 @@ build_srat(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info)
     uint32_t *cpu_node = g_malloc0(guest_info->smp_cpus * sizeof(uint32_t));
 
     for (i = 0; i < guest_info->smp_cpus; i++) {
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
+        j = numa_get_node_for_cpu(i);
+        if (j < nb_numa_nodes) {
                 cpu_node[i] = j;

I think this, and all other occurrences, would read nicer like

 if (numa_enabled()) {
     cpu_node[i] = numa_get_node_for_cpu(i);

}

We just need to also add

bool numa_enabled()

 {
    return nb_numa_nodes != 0;

}

Quoted 10 lines
hw/arm/virt-acpi-build.c +0 -2
-                break;
-            }
         }
     }
 
hw/arm/virt.c +0 -0
index c5c125e..b066f15 100644

hw/arm/virt.c static void fdt_add_cpu_nodes(const VirtBoardInfo *vbi) · line 416

Quoted 6 lines
hw/arm/virt.c +0 -3
@@ -411,10 +411,9 @@ static void fdt_add_cpu_nodes(const VirtBoardInfo *vbi)
                                   armcpu->mp_affinity);
         }
 
-        for (i = 0; i < nb_numa_nodes; i++) {
-            if (test_bit(cpu, numa_info[i].node_cpu)) {
-                qemu_fdt_setprop_cell(vbi->fdt, nodename, "numa-node-id", i);

We were missing the break here, which I had queued to send some day, now I don't need to :-)

Quoted 74 lines
hw/arm/virt.c +3 -1
-            }
+        i = numa_get_node_for_cpu(cpu);
+        if (i < nb_numa_nodes) {
+            qemu_fdt_setprop_cell(vbi->fdt, nodename, "numa-node-id", i);
         }
 
         g_free(nodename);
hw/i386/acpi-build.c +2 -5
index 5a594be..60be550 100644
@@ -2344,18 +2344,15 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
     srat->reserved1 = cpu_to_le32(1);
 
     for (i = 0; i < apic_ids->len; i++) {
-        int j;
+        int j = numa_get_node_for_cpu(i);
         int apic_id = apic_ids->cpus[i].arch_id;
 
         core = acpi_data_push(table_data, sizeof *core);
         core->type = ACPI_SRAT_PROCESSOR_APIC;
         core->length = sizeof(*core);
         core->local_apic_id = apic_id;
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
+        if (j < nb_numa_nodes) {
                 core->proximity_lo = j;
-                break;
-            }
         }
         memset(core->proximity_hi, 0, 3);
         core->local_sapic_eid = 0;
hw/i386/pc.c +3 -5
index 44a8f3b..fef34e7 100644
@@ -780,11 +780,9 @@ static FWCfgState *bochs_bios_init(AddressSpace *as, PCMachineState *pcms)
     for (i = 0; i < max_cpus; i++) {
         unsigned int apic_id = x86_cpu_apic_id_from_index(i);
         assert(apic_id < pcms->apic_id_limit);
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
-                numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
-                break;
-            }
+        j = numa_get_node_for_cpu(i);
+        if (j < nb_numa_nodes) {
+            numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
         }
     }
     for (i = 0; i < nb_numa_nodes; i++) {
hw/ppc/spapr_cpu_core.c +2 -4
index 3a5da09..030016c 100644
@@ -69,11 +69,9 @@ void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
     }
 
     /* Set NUMA node for the added CPUs  */
-    for (i = 0; i < nb_numa_nodes; i++) {
-        if (test_bit(cs->cpu_index, numa_info[i].node_cpu)) {
+    i = numa_get_node_for_cpu(cs->cpu_index);
+    if (i < nb_numa_nodes) {
             cs->numa_node = i;
-            break;
-        }
     }
 
     xics_cpu_setup(spapr->icp, cpu);
include/sysemu/numa.h +0 -0
index bb184c9..4da808a 100644

include/sysemu/numa.h void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node); · line 36

Quoted 5 lines
include/sysemu/numa.h +2 -0
@@ -32,4 +32,7 @@ void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node);
 void numa_unset_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node);
 uint32_t numa_get_node(ram_addr_t addr, Error **errp);
 
+/* on success returns node index in numa_info,
+ * on failure returns nb_numa_nodes */

Or zero when nb_numa_nodes == 0, which requires another condition to disambiguate it from node=0. You could return -1 for both failure to find the node and for when nb_numa_nodes == 0, but no users are checking for error right now, only for nb_numa_nodes == 0, which, as I said above, would look better with numa_enabled()

Quoted 26 lines
include/sysemu/numa.h +1 -0
+int numa_get_node_for_cpu(int idx);
 #endif
numa.c +12 -0
index 572712c..5790858 100644
@@ -548,3 +548,15 @@ MemdevList *qmp_query_memdev(Error **errp)
     object_child_foreach(obj, query_memdev, &list);
     return list;
 }
+
+int numa_get_node_for_cpu(int idx)
+{
+    int i;
+
+    for (i = 0; i < nb_numa_nodes; i++) {
+        if (test_bit(idx, numa_info[i].node_cpu)) {
+            break;
+        }
+    }
+    return i;
+}
Signature · 1 line
1.8.3.1

numa.c has one of these patterns too in numa_post_machine_init that could be replaced.

Thanks,
drew

Reviewed-by on v3 3/5
#7 lore raw

Re: [Qemu-devel] [PATCH v3 3/5] numa: reduce code duplication by adding helper numa_get_node_for_cpu()

In reply to Igor Mammedov
Quoted 11 lines · Igor Mammedov

Replace repeated pattern

    for (i = 0; i < nb_numa_nodes; i++) {
        if (test_bit(idx, numa_info[i].node_cpu)) {
           ...
           break;

with a helper function to lookup numa node index for cpu.

Quoted 140 lines
---
 hw/arm/virt-acpi-build.c |  6 ++----
 hw/arm/virt.c            |  7 +++----
 hw/i386/acpi-build.c     |  7 ++-----
 hw/i386/pc.c             |  8 +++-----
 hw/ppc/spapr_cpu_core.c  |  6 ++----
 include/sysemu/numa.h    |  3 +++
 numa.c                   | 12 ++++++++++++
 7 files changed, 27 insertions(+), 22 deletions(-)
hw/arm/virt-acpi-build.c +2 -4
index 28fc59c..5923b3d 100644
@@ -426,11 +426,9 @@ build_srat(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info)
     uint32_t *cpu_node = g_malloc0(guest_info->smp_cpus * sizeof(uint32_t));
 
     for (i = 0; i < guest_info->smp_cpus; i++) {
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
+        j = numa_get_node_for_cpu(i);
+        if (j < nb_numa_nodes) {
                 cpu_node[i] = j;
-                break;
-            }
         }
     }
 
hw/arm/virt.c +3 -4
index c5c125e..b066f15 100644
@@ -411,10 +411,9 @@ static void fdt_add_cpu_nodes(const VirtBoardInfo *vbi)
                                   armcpu->mp_affinity);
         }
 
-        for (i = 0; i < nb_numa_nodes; i++) {
-            if (test_bit(cpu, numa_info[i].node_cpu)) {
-                qemu_fdt_setprop_cell(vbi->fdt, nodename, "numa-node-id", i);
-            }
+        i = numa_get_node_for_cpu(cpu);
+        if (i < nb_numa_nodes) {
+            qemu_fdt_setprop_cell(vbi->fdt, nodename, "numa-node-id", i);
         }
 
         g_free(nodename);
hw/i386/acpi-build.c +2 -5
index 5a594be..60be550 100644
@@ -2344,18 +2344,15 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
     srat->reserved1 = cpu_to_le32(1);
 
     for (i = 0; i < apic_ids->len; i++) {
-        int j;
+        int j = numa_get_node_for_cpu(i);
         int apic_id = apic_ids->cpus[i].arch_id;
 
         core = acpi_data_push(table_data, sizeof *core);
         core->type = ACPI_SRAT_PROCESSOR_APIC;
         core->length = sizeof(*core);
         core->local_apic_id = apic_id;
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
+        if (j < nb_numa_nodes) {
                 core->proximity_lo = j;
-                break;
-            }
         }
         memset(core->proximity_hi, 0, 3);
         core->local_sapic_eid = 0;
hw/i386/pc.c +3 -5
index 44a8f3b..fef34e7 100644
@@ -780,11 +780,9 @@ static FWCfgState *bochs_bios_init(AddressSpace *as, PCMachineState *pcms)
     for (i = 0; i < max_cpus; i++) {
         unsigned int apic_id = x86_cpu_apic_id_from_index(i);
         assert(apic_id < pcms->apic_id_limit);
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
-                numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
-                break;
-            }
+        j = numa_get_node_for_cpu(i);
+        if (j < nb_numa_nodes) {
+            numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
         }
     }
     for (i = 0; i < nb_numa_nodes; i++) {
hw/ppc/spapr_cpu_core.c +2 -4
index 3a5da09..030016c 100644
@@ -69,11 +69,9 @@ void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
     }
 
     /* Set NUMA node for the added CPUs  */
-    for (i = 0; i < nb_numa_nodes; i++) {
-        if (test_bit(cs->cpu_index, numa_info[i].node_cpu)) {
+    i = numa_get_node_for_cpu(cs->cpu_index);
+    if (i < nb_numa_nodes) {
             cs->numa_node = i;
-            break;
-        }
     }
 
     xics_cpu_setup(spapr->icp, cpu);
include/sysemu/numa.h +3 -0
index bb184c9..4da808a 100644
@@ -32,4 +32,7 @@ void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node);
 void numa_unset_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node);
 uint32_t numa_get_node(ram_addr_t addr, Error **errp);
 
+/* on success returns node index in numa_info,
+ * on failure returns nb_numa_nodes */
+int numa_get_node_for_cpu(int idx);
 #endif
numa.c +12 -0
index 572712c..5790858 100644
@@ -548,3 +548,15 @@ MemdevList *qmp_query_memdev(Error **errp)
     object_child_foreach(obj, query_memdev, &list);
     return list;
 }
+
+int numa_get_node_for_cpu(int idx)
+{
+    int i;
+
+    for (i = 0; i < nb_numa_nodes; i++) {
+        if (test_bit(idx, numa_info[i].node_cpu)) {
+            break;
+        }
+    }
+    return i;
+}
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
#5 lore raw

Re: [Qemu-devel] [PATCH v3 3/5] numa: reduce code duplication by adding helper numa_get_node_for_cpu()

In reply to Andrew Jones
Quoted 38 lines · On Fri, 1 Jul 2016 14:30:12 +0200 Andrew Jones <[email protected]> wrote:
Quoted 26 lines · Igor Mammedov

Replace repeated pattern

    for (i = 0; i < nb_numa_nodes; i++) {
        if (test_bit(idx, numa_info[i].node_cpu)) {
           ...
           break;

with a helper function to lookup numa node index for cpu.

---
 hw/arm/virt-acpi-build.c |  6 ++----
 hw/arm/virt.c            |  7 +++----
 hw/i386/acpi-build.c     |  7 ++-----
 hw/i386/pc.c             |  8 +++-----
 hw/ppc/spapr_cpu_core.c  |  6 ++----
 include/sysemu/numa.h    |  3 +++
 numa.c                   | 12 ++++++++++++
 7 files changed, 27 insertions(+), 22 deletions(-)
hw/arm/virt-acpi-build.c +0 -0
index 28fc59c..5923b3d 100644

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

Quoted 8 lines
hw/arm/virt-acpi-build.c +2 -2
@@ -426,11 +426,9 @@ build_srat(GArray *table_data, BIOSLinker
 *linker, VirtGuestInfo *guest_info) uint32_t *cpu_node =
 g_malloc0(guest_info->smp_cpus * sizeof(uint32_t)); 
     for (i = 0; i < guest_info->smp_cpus; i++) {
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
+        j = numa_get_node_for_cpu(i);
+        if (j < nb_numa_nodes) {
                 cpu_node[i] = j;

I think this, and all other occurrences, would read nicer like

Quoted 3 lines
 if (numa_enabled()) {
     cpu_node[i] = numa_get_node_for_cpu(i);

}

it would be nicer but it could be a guest visible change as in case of if cpu is not in numa_info[].node_cpu then old code won't do assignment, if done as suggested it will assign whatever value numa_get_node_for_cpu(i) returns.

Quoted 138 lines

We just need to also add

bool numa_enabled()

 {
    return nb_numa_nodes != 0;

}

Quoted 10 lines
hw/arm/virt-acpi-build.c +0 -2
-                break;
-            }
         }
     }
 
hw/arm/virt.c +0 -0
index c5c125e..b066f15 100644

hw/arm/virt.c static void fdt_add_cpu_nodes(const · line 414

Quoted 7 lines
hw/arm/virt.c +0 -3
@@ -411,10 +411,9 @@ static void fdt_add_cpu_nodes(const
 VirtBoardInfo *vbi) armcpu->mp_affinity);
         }
 
-        for (i = 0; i < nb_numa_nodes; i++) {
-            if (test_bit(cpu, numa_info[i].node_cpu)) {
-                qemu_fdt_setprop_cell(vbi->fdt, nodename,
 "numa-node-id", i);

We were missing the break here, which I had queued to send some day, now I don't need to :-)

Quoted 75 lines
hw/arm/virt.c +3 -1
-            }
+        i = numa_get_node_for_cpu(cpu);
+        if (i < nb_numa_nodes) {
+            qemu_fdt_setprop_cell(vbi->fdt, nodename,
 "numa-node-id", i); }
 
         g_free(nodename);
hw/i386/acpi-build.c +2 -5
index 5a594be..60be550 100644
@@ -2344,18 +2344,15 @@ build_srat(GArray *table_data, BIOSLinker
 *linker, MachineState *machine) srat->reserved1 = cpu_to_le32(1);
 
     for (i = 0; i < apic_ids->len; i++) {
-        int j;
+        int j = numa_get_node_for_cpu(i);
         int apic_id = apic_ids->cpus[i].arch_id;
 
         core = acpi_data_push(table_data, sizeof *core);
         core->type = ACPI_SRAT_PROCESSOR_APIC;
         core->length = sizeof(*core);
         core->local_apic_id = apic_id;
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
+        if (j < nb_numa_nodes) {
                 core->proximity_lo = j;
-                break;
-            }
         }
         memset(core->proximity_hi, 0, 3);
         core->local_sapic_eid = 0;
hw/i386/pc.c +0 -0
index 44a8f3b..fef34e7 100644
@@ -780,11 +780,9 @@ static FWCfgState
 *bochs_bios_init(AddressSpace *as, PCMachineState *pcms) for (i =

0; i < max_cpus; i++) { unsigned int apic_id =
x86_cpu_apic_id_from_index(i); assert(apic_id <
pcms->apic_id_limit);

hw/i386/pc.c +3 -5
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
-                numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
-                break;
-            }
+        j = numa_get_node_for_cpu(i);
+        if (j < nb_numa_nodes) {
+            numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
         }
     }
     for (i = 0; i < nb_numa_nodes; i++) {
hw/ppc/spapr_cpu_core.c +2 -4
index 3a5da09..030016c 100644
@@ -69,11 +69,9 @@ void spapr_cpu_init(sPAPRMachineState *spapr,
 PowerPCCPU *cpu, Error **errp) }
 
     /* Set NUMA node for the added CPUs  */
-    for (i = 0; i < nb_numa_nodes; i++) {
-        if (test_bit(cs->cpu_index, numa_info[i].node_cpu)) {
+    i = numa_get_node_for_cpu(cs->cpu_index);
+    if (i < nb_numa_nodes) {
             cs->numa_node = i;
-            break;
-        }
     }
 
     xics_cpu_setup(spapr->icp, cpu);
include/sysemu/numa.h +0 -0
index bb184c9..4da808a 100644
@@ -32,4 +32,7 @@ void numa_set_mem_node_id(ram_addr_t addr,
Quoted 5 lines

uint64_t size, uint32_t node); void numa_unset_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node); uint32_t numa_get_node(ram_addr_t addr, Error **errp); +/* on success returns node index in numa_info,
+ * on failure returns nb_numa_nodes */

Or zero when nb_numa_nodes == 0, which requires another condition to disambiguate it from node=0. You could return -1 for both failure to find the node and for when nb_numa_nodes == 0, but no users are checking for error right now, only for nb_numa_nodes == 0, which, as I said above, would look better with numa_enabled()

Quoted 21 lines
include/sysemu/numa.h +1 -0
+int numa_get_node_for_cpu(int idx);
 #endif
numa.c +11 -0
index 572712c..5790858 100644
@@ -548,3 +548,15 @@ MemdevList *qmp_query_memdev(Error **errp)
     object_child_foreach(obj, query_memdev, &list);
     return list;
 }
+
+int numa_get_node_for_cpu(int idx)
+{
+    int i;
+
+    for (i = 0; i < nb_numa_nodes; i++) {
+        if (test_bit(idx, numa_info[i].node_cpu)) {
+            break;
+        }
+    }
+    return i;
Quoted 8 lines
Quoted 5 lines
numa.c +1 -0
+}
Signature · 1 line
1.8.3.1

numa.c has one of these patterns too in numa_post_machine_init that could be replaced.

I didn't touch it intentionally as numa_post_machine_init is broken code when combined with sparse cpu_index and I plan to remove it in favor of explicit assignment (spapr does it, pc needs to be taught) or may be event redo sole user of CPUState:numa_node (HMP command info numa) and drop CPUState:numa_node field along with numa_post_machine_init()

but all that said it's topic for another not related patch.

Quoted 3 lines

Thanks,
drew

#8 lore raw

Re: [Qemu-devel] [PATCH v3 3/5] numa: reduce code duplication by adding helper numa_get_node_for_cpu()

In reply to Igor Mammedov
Quoted 11 lines · Igor Mammedov

Replace repeated pattern

    for (i = 0; i < nb_numa_nodes; i++) {
        if (test_bit(idx, numa_info[i].node_cpu)) {
           ...
           break;

with a helper function to lookup numa node index for cpu.

Nice, but please make it return a negative return code on error.

Quoted 142 lines
---
 hw/arm/virt-acpi-build.c |  6 ++----
 hw/arm/virt.c            |  7 +++----
 hw/i386/acpi-build.c     |  7 ++-----
 hw/i386/pc.c             |  8 +++-----
 hw/ppc/spapr_cpu_core.c  |  6 ++----
 include/sysemu/numa.h    |  3 +++
 numa.c                   | 12 ++++++++++++
 7 files changed, 27 insertions(+), 22 deletions(-)
hw/arm/virt-acpi-build.c +2 -4
index 28fc59c..5923b3d 100644
@@ -426,11 +426,9 @@ build_srat(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info)
     uint32_t *cpu_node = g_malloc0(guest_info->smp_cpus * sizeof(uint32_t));
 
     for (i = 0; i < guest_info->smp_cpus; i++) {
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
+        j = numa_get_node_for_cpu(i);
+        if (j < nb_numa_nodes) {
                 cpu_node[i] = j;
-                break;
-            }
         }
     }
 
hw/arm/virt.c +3 -4
index c5c125e..b066f15 100644
@@ -411,10 +411,9 @@ static void fdt_add_cpu_nodes(const VirtBoardInfo *vbi)
                                   armcpu->mp_affinity);
         }
 
-        for (i = 0; i < nb_numa_nodes; i++) {
-            if (test_bit(cpu, numa_info[i].node_cpu)) {
-                qemu_fdt_setprop_cell(vbi->fdt, nodename, "numa-node-id", i);
-            }
+        i = numa_get_node_for_cpu(cpu);
+        if (i < nb_numa_nodes) {
+            qemu_fdt_setprop_cell(vbi->fdt, nodename, "numa-node-id", i);
         }
 
         g_free(nodename);
hw/i386/acpi-build.c +2 -5
index 5a594be..60be550 100644
@@ -2344,18 +2344,15 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
     srat->reserved1 = cpu_to_le32(1);
 
     for (i = 0; i < apic_ids->len; i++) {
-        int j;
+        int j = numa_get_node_for_cpu(i);
         int apic_id = apic_ids->cpus[i].arch_id;
 
         core = acpi_data_push(table_data, sizeof *core);
         core->type = ACPI_SRAT_PROCESSOR_APIC;
         core->length = sizeof(*core);
         core->local_apic_id = apic_id;
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
+        if (j < nb_numa_nodes) {
                 core->proximity_lo = j;
-                break;
-            }
         }
         memset(core->proximity_hi, 0, 3);
         core->local_sapic_eid = 0;
hw/i386/pc.c +3 -5
index 44a8f3b..fef34e7 100644
@@ -780,11 +780,9 @@ static FWCfgState *bochs_bios_init(AddressSpace *as, PCMachineState *pcms)
     for (i = 0; i < max_cpus; i++) {
         unsigned int apic_id = x86_cpu_apic_id_from_index(i);
         assert(apic_id < pcms->apic_id_limit);
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
-                numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
-                break;
-            }
+        j = numa_get_node_for_cpu(i);
+        if (j < nb_numa_nodes) {
+            numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
         }
     }
     for (i = 0; i < nb_numa_nodes; i++) {
hw/ppc/spapr_cpu_core.c +2 -4
index 3a5da09..030016c 100644
@@ -69,11 +69,9 @@ void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
     }
 
     /* Set NUMA node for the added CPUs  */
-    for (i = 0; i < nb_numa_nodes; i++) {
-        if (test_bit(cs->cpu_index, numa_info[i].node_cpu)) {
+    i = numa_get_node_for_cpu(cs->cpu_index);
+    if (i < nb_numa_nodes) {
             cs->numa_node = i;
-            break;
-        }
     }
 
     xics_cpu_setup(spapr->icp, cpu);
include/sysemu/numa.h +3 -0
index bb184c9..4da808a 100644
@@ -32,4 +32,7 @@ void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node);
 void numa_unset_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node);
 uint32_t numa_get_node(ram_addr_t addr, Error **errp);
 
+/* on success returns node index in numa_info,
+ * on failure returns nb_numa_nodes */
+int numa_get_node_for_cpu(int idx);
 #endif
numa.c +12 -0
index 572712c..5790858 100644
@@ -548,3 +548,15 @@ MemdevList *qmp_query_memdev(Error **errp)
     object_child_foreach(obj, query_memdev, &list);
     return list;
 }
+
+int numa_get_node_for_cpu(int idx)
+{
+    int i;
+
+    for (i = 0; i < nb_numa_nodes; i++) {
+        if (test_bit(idx, numa_info[i].node_cpu)) {
+            break;
+        }
+    }
+    return i;
+}
Signature · 1 line
1.8.3.1
#11 lore raw

Re: [Qemu-devel] [PATCH v3 5/5] tests: acpi: extend cphp testcase with numa check

In reply to Igor Mammedov
Quoted 5 lines · Igor Mammedov

so it would be possible to verify _PXM generation in DSDT and SRAT tables.

It's still a pain to backport, pls make it a separate patch if you repost.

Quoted 67 lines

---
NOTE to maintainer:
SRAT table is included in patch as it doesn't have any chance for conflicts compared to often changing DSDT

following table blobs should be updated in git tree as part
of this commit after running ./tests/acpi-test-data/rebuild-expected-aml.sh

tests/acpi-test-data/q35/DSDT.cphp
tests/acpi-test-data/pc/DSDT.cphp

---
 tests/acpi-test-data/pc/SRAT.cphp  | Bin 0 -> 304 bytes
 tests/acpi-test-data/q35/SRAT.cphp | Bin 0 -> 304 bytes
 tests/bios-tables-test.c           |   6 ++++--
 3 files changed, 4 insertions(+), 2 deletions(-)
 create mode 100644 tests/acpi-test-data/pc/SRAT.cphp
 create mode 100644 tests/acpi-test-data/q35/SRAT.cphp
tests/acpi-test-data/pc/SRAT.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..ff2137642f488ec70b85207ed6c20e7351d61e98
GIT binary patch
tests/acpi-test-data/q35/SRAT.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..ff2137642f488ec70b85207ed6c20e7351d61e98
GIT binary patch
tests/bios-tables-test.c +4 -2
index de4019e..3796089 100644
@@ -809,7 +809,8 @@ static void test_acpi_piix4_tcg_cphp(void)
     data.machine = MACHINE_PC;
     data.variant = ".cphp";
     test_acpi_one("-machine accel=tcg"
-                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  " -smp 2,cores=3,sockets=2,maxcpus=6"
+                  " -numa node -numa node",
                   &data);
     free_test_data(&data);
 }
@@ -822,7 +823,8 @@ static void test_acpi_q35_tcg_cphp(void)
     data.machine = MACHINE_Q35;
     data.variant = ".cphp";
     test_acpi_one("-machine q35,accel=tcg"
-                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  " -smp 2,cores=3,sockets=2,maxcpus=6"
+                  " -numa node -numa node",
                   &data);
     free_test_data(&data);
 }
Signature · 1 line
1.8.3.1
#12 lore raw

Re: [Qemu-devel] [PATCH v3 5/5] tests: acpi: extend cphp testcase with numa check

Quoted 9 lines · On Mon, 4 Jul 2016 15:14:40 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov

so it would be possible to verify _PXM generation in DSDT and SRAT tables.

It's still a pain to backport, pls make it a separate patch if you repost.

Ok, I'll split it.

Quoted 69 lines
Quoted 69 lines

---
NOTE to maintainer:
SRAT table is included in patch as it doesn't have any chance for conflicts compared to often changing DSDT

following table blobs should be updated in git tree as part of this commit after
running ./tests/acpi-test-data/rebuild-expected-aml.sh

tests/acpi-test-data/q35/DSDT.cphp
tests/acpi-test-data/pc/DSDT.cphp

---
 tests/acpi-test-data/pc/SRAT.cphp  | Bin 0 -> 304 bytes
 tests/acpi-test-data/q35/SRAT.cphp | Bin 0 -> 304 bytes
 tests/bios-tables-test.c           |   6 ++++--
 3 files changed, 4 insertions(+), 2 deletions(-)
 create mode 100644 tests/acpi-test-data/pc/SRAT.cphp
 create mode 100644 tests/acpi-test-data/q35/SRAT.cphp
(quoted diff) +0 -0

b/tests/acpi-test-data/pc/SRAT.cphp new file mode 100644
index 0000000000000000000000000000000000000000..ff2137642f488ec70b85207ed6c20e7351d61e98 GIT binary patch literal 304 zcmWFzattwGWME)4bMklg2v%^42yhMtiUEZfKx_~V!f+sf!DmF1XF}yOvY_!<(fDl0 pd`1npO;83GTmZW|po75R12aq^syaB21u74tQT&BzFU&Ml8UVWm2>}2A

literal 0
HcmV?d00001

(quoted diff) +0 -0

b/tests/acpi-test-data/q35/SRAT.cphp new file mode 100644
index 0000000000000000000000000000000000000000..ff2137642f488ec70b85207ed6c20e7351d61e98 GIT binary patch literal 304 zcmWFzattwGWME)4bMklg2v%^42yhMtiUEZfKx_~V!f+sf!DmF1XF}yOvY_!<(fDl0 pd`1npO;83GTmZW|po75R12aq^syaB21u74tQT&BzFU&Ml8UVWm2>}2A

literal 0
HcmV?d00001

tests/bios-tables-test.c +4 -2
index de4019e..3796089 100644
@@ -809,7 +809,8 @@ static void test_acpi_piix4_tcg_cphp(void)
     data.machine = MACHINE_PC;
     data.variant = ".cphp";
     test_acpi_one("-machine accel=tcg"
-                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  " -smp 2,cores=3,sockets=2,maxcpus=6"
+                  " -numa node -numa node",
                   &data);
     free_test_data(&data);
 }
@@ -822,7 +823,8 @@ static void test_acpi_q35_tcg_cphp(void)
     data.machine = MACHINE_Q35;
     data.variant = ".cphp";
     test_acpi_one("-machine q35,accel=tcg"
-                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  " -smp 2,cores=3,sockets=2,maxcpus=6"
+                  " -numa node -numa node",
                   &data);
     free_test_data(&data);
 }
Signature · 1 line
1.8.3.1
#6 lore raw

Re: [Qemu-devel] [PATCH v3 3/5] numa: reduce code duplication by adding helper numa_get_node_for_cpu()

In reply to Igor Mammedov
Quoted 17 lines · Igor Mammedov
Quoted 15 lines · On Fri, 1 Jul 2016 14:30:12 +0200 Andrew Jones <[email protected]> wrote:

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

Quoted 11 lines · Igor Mammedov
hw/arm/virt-acpi-build.c +2 -2
@@ -426,11 +426,9 @@ build_srat(GArray *table_data, BIOSLinker
 *linker, VirtGuestInfo *guest_info) uint32_t *cpu_node =
 g_malloc0(guest_info->smp_cpus * sizeof(uint32_t)); 
     for (i = 0; i < guest_info->smp_cpus; i++) {
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
+        j = numa_get_node_for_cpu(i);
+        if (j < nb_numa_nodes) {
                 cpu_node[i] = j;

I think this, and all other occurrences, would read nicer like

Quoted 7 lines
Quoted 3 lines
 if (numa_enabled()) {
     cpu_node[i] = numa_get_node_for_cpu(i);

}

it would be nicer but it could be a guest visible change as in case of if cpu is not in numa_info[].node_cpu then old code won't do assignment, if done as suggested it will assign whatever value numa_get_node_for_cpu(i) returns.

I see. So how about creating

static inline bool numa_node_is_valid(int node)

 {
     return node >= 0 && node < nb_numa_nodes;  

}

and then using that for the condition, instead of the inequality.

It's not a huge improvement, so take it or leave it.

Thanks,
drew