Skip to contentSkip to conversation

numa: enable sparse node numbering on ppc

RFC PATCH Superseded Nishanth Aravamudan 2 participants 3 messages Jun 30, 2014 – Jul 1, 2014

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH v4 1/1 numa: enable sparse node numbering on ppc

Sparse node numbering occurs on powerpc in practice under PowerVM. In order to emulate the same NUMA topology under qemu, the assumption that NUMA nodes are linearly ordered has to be removed. qemu was recently modified to reject requests for sparse NUMA node numbering.

Leverage the present field in NodeInfo which indicates if a given nodeid was present on the command-line or not. Adjust the iteration of various NUMA loops to use the maximum known NUMA ID rather than the number of NUMA nodes.

numa.c::set_numa_nodes() has become a bit more convoluted for round-robin'ing the CPUs over known nodes when not specified by the user.

Note that the x86 code needs changes for both sparse node numbering and memoryless nodes, and the ppc code needs changes for memoryless nodes. ppc also requires node 0 to be present on the command-line (or else it fails with: "qemu: pSeries SLOF firmware requires >= 128M guest RMA (Real Mode Area memory)". Alexey has a series to address the latter.

Examples:

Before:
mlock=off -numa node,nodeid=3 -numa node,nodeid=0 -smp 4
qemu-system-ppc64-base: numa: Node ID missing: 2

After:
(qemu) info numa
2 nodes
node 0 cpus: 1 3
node 0 size: 2048 MB
node 3 cpus: 0 2
node 3 size: 2048 MB

available: 2 nodes (0,3)
node 0 cpus: 1 3
node 0 size: 2030 MB
node 0 free: 1934 MB
node 3 cpus: 0 2
node 3 size: 2045 MB
node 3 free: 1957 MB
node distances:
node 0 3

  0:  10  40
  3:  40  10

---
I understand that 2.1 is in freeze, so I'm not requesting this be applied, but would like feedback to have this ready to queue up for the next release.

v1 -> v2:
Modify set_numa_nodes loop for round-robin'ing CPUs.

v2 -> v3:
Updated changelog to indicate problem being solved. Updated memory_region_allocate_system_memory based upon feedback from

    Hu.

Updated set_numa_nodes loop again to be simpler based upon feedback
from Hu.
Fixed bug with a mix of nodes with nodeid specified and without, where
the same nodeid would be used by the explicit specification and the auto-numbering code.

v3 -> v4:
Rename nb_numa_nodes to num_numa_nodes to help catch usage. Rebased to master/origin as Eduardo's patches to support the Present
flag have gone upstream.
Disable sparse node numbering on i386, enable it on ppc.

hw/i386/pc.c +20 -8
index 2cf22b1..cdefafe 100644
@@ -698,23 +698,23 @@ static FWCfgState *bochs_bios_init(void)
      * of nodes, one word for each VCPU->node and one word for each node to
      * hold the amount of memory.
      */
-    numa_fw_cfg = g_new0(uint64_t, 1 + apic_id_limit + nb_numa_nodes);
-    numa_fw_cfg[0] = cpu_to_le64(nb_numa_nodes);
+    numa_fw_cfg = g_new0(uint64_t, 1 + apic_id_limit + num_numa_nodes);
+    numa_fw_cfg[0] = cpu_to_le64(num_numa_nodes);
     for (i = 0; i < max_cpus; i++) {
         unsigned int apic_id = x86_cpu_apic_id_from_index(i);
         assert(apic_id < apic_id_limit);
-        for (j = 0; j < nb_numa_nodes; j++) {
+        for (j = 0; j < num_numa_nodes; j++) {
             if (test_bit(i, numa_info[j].node_cpu)) {
                 numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
                 break;
             }
         }
     }
-    for (i = 0; i < nb_numa_nodes; i++) {
+    for (i = 0; i < num_numa_nodes; i++) {
         numa_fw_cfg[apic_id_limit + 1 + i] = cpu_to_le64(numa_info[i].node_mem);
     }
     fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, numa_fw_cfg,
-                     (1 + apic_id_limit + nb_numa_nodes) *
+                     (1 + apic_id_limit + num_numa_nodes) *
                      sizeof(*numa_fw_cfg));
 
     return fw_cfg;
@@ -1121,10 +1121,22 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     guest_info->ram_size = below_4g_mem_size + above_4g_mem_size;
     guest_info->apic_id_limit = pc_apic_id_limit(max_cpus);
     guest_info->apic_xrupt_override = kvm_allows_irq0_override();
-    guest_info->numa_nodes = nb_numa_nodes;
+    /* No support for sparse NUMA node IDs yet: */
+    for (i = max_numa_nodeid - 1; i >= 0; i--) {
+        /* Report large node IDs first, to make mistakes easier to spot */
+        if (!numa_info[i].present) {
+            error_report("numa: Node ID missing: %d", i);
+            exit(EXIT_FAILURE);
+        }
+    }
+
+    /* This must be always true if all nodes are present */
+    assert(num_numa_nodes == max_numa_nodeid);
+
+    guest_info->numa_nodes = num_numa_nodes;
     guest_info->node_mem = g_malloc0(guest_info->numa_nodes *
                                     sizeof *guest_info->node_mem);
-    for (i = 0; i < nb_numa_nodes; i++) {
+    for (i = 0; i < num_numa_nodes; i++) {
         guest_info->node_mem[i] = numa_info[i].node_mem;
     }
 
@@ -1134,7 +1146,7 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     for (i = 0; i < max_cpus; i++) {
         unsigned int apic_id = x86_cpu_apic_id_from_index(i);
         assert(apic_id < guest_info->apic_id_limit);
-        for (j = 0; j < nb_numa_nodes; j++) {
+        for (j = 0; j < num_numa_nodes; j++) {
             if (test_bit(i, numa_info[j].node_cpu)) {
                 guest_info->node_cpu[apic_id] = j;
                 break;
hw/ppc/spapr.c +8 -5
index a8ba916..9a247f8 100644
@@ -226,7 +226,7 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
             }
         }
 
-        if (nb_numa_nodes > 1) {
+        if (num_numa_nodes > 1) {
             ret = fdt_setprop(fdt, offset, "ibm,associativity", associativity,
                               sizeof(associativity));
             if (ret < 0) {
@@ -608,7 +608,7 @@ static int spapr_populate_memory(sPAPREnvironment *spapr, void *fdt)
     int i, off;
 
     /* memory node(s) */
-    if (nb_numa_nodes > 1 && numa_info[0].node_mem < ram_size) {
+    if (num_numa_nodes > 1 && numa_info[0].node_mem < ram_size) {
         node0_size = numa_info[0].node_mem;
     } else {
         node0_size = ram_size;
@@ -642,7 +642,10 @@ static int spapr_populate_memory(sPAPREnvironment *spapr, void *fdt)
 
     /* RAM: Node 1 and beyond */
     mem_start = node0_size;
-    for (i = 1; i < nb_numa_nodes; i++) {
+    for (i = 1; i < max_numa_nodeid; i++) {
+        if (!numa_info[i].present) {
+            continue;
+        }
         mem_reg_property[0] = cpu_to_be64(mem_start);
         if (mem_start >= ram_size) {
             node_size = 0;
@@ -792,7 +795,7 @@ static void spapr_reset_htab(sPAPREnvironment *spapr)
 
     /* Update the RMA size if necessary */
     if (spapr->vrma_adjust) {
-        hwaddr node0_size = (nb_numa_nodes > 1) ?
+        hwaddr node0_size = (num_numa_nodes > 1) ?
             numa_info[0].node_mem : ram_size;
         spapr->rma_size = kvmppc_rma_size(node0_size, spapr->htab_shift);
     }
@@ -1225,7 +1228,7 @@ static void ppc_spapr_init(MachineState *machine)
     MemoryRegion *sysmem = get_system_memory();
     MemoryRegion *ram = g_new(MemoryRegion, 1);
     hwaddr rma_alloc_size;
-    hwaddr node0_size = (nb_numa_nodes > 1) ? numa_info[0].node_mem : ram_size;
+    hwaddr node0_size = (num_numa_nodes > 1) ? numa_info[0].node_mem : ram_size;
     uint32_t initrd_base = 0;
     long kernel_size = 0, initrd_size = 0;
     long load_limit, rtas_limit, fw_size;
include/sysemu/sysemu.h +1 -1
index d8539fd..d17bdbe 100644
@@ -146,7 +146,7 @@ extern int mem_prealloc;
  */
 #define MAX_CPUMASK_BITS 255
 
-extern int nb_numa_nodes;   /* Number of NUMA nodes */
+extern int num_numa_nodes;  /* Number of NUMA nodes */
 extern int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
                              * For all nodes, nodeid < max_numa_nodeid
                              */
monitor.c +5 -2
index 5bc70a6..53955e4 100644
@@ -1948,8 +1948,11 @@ static void do_info_numa(Monitor *mon, const QDict *qdict)
     int i;
     CPUState *cpu;
 
-    monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
-    for (i = 0; i < nb_numa_nodes; i++) {
+    monitor_printf(mon, "%d nodes\n", num_numa_nodes);
+    for (i = 0; i < max_numa_nodeid; i++) {
+        if (!numa_info[i].present) {
+            continue;
+        }
         monitor_printf(mon, "node %d cpus:", i);
         CPU_FOREACH(cpu) {
             if (cpu->numa_node == i) {
numa.c +37 -35

145 lines not on this page · raw message

vl.c +2 -2
index 41ddcd2..5da4cc2 100644
@@ -195,7 +195,7 @@ struct FWBootEntry {
 static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
     QTAILQ_HEAD_INITIALIZER(fw_boot_order);
 
-int nb_numa_nodes;
+int num_numa_nodes;
 int max_numa_nodeid;
 NodeInfo numa_info[MAX_NODES];
 
@@ -2989,7 +2989,7 @@ int main(int argc, char **argv, char **envp)
         bitmap_zero(numa_info[i].node_cpu, MAX_CPUMASK_BITS);
     }
 
-    nb_numa_nodes = 0;
+    num_numa_nodes = 0;
     max_numa_nodeid = 0;
     nb_nics = 0;
 
#1 lore raw

On Mon, Jun 30, 2014 at 02:34:56PM -0700, Nishanth Aravamudan wrote:
[...]

numa.c error: · line 200

Quoted 4 lines
             }
numa.c +1 -0
+	    assert(numa_info[i].present);
             numa_info[i].node_mem = ram_size - usedmem;
         }

Tab here.

Quoted 1 line

[...]

numa.c void set_numa_nodes(void) · line 227

Quoted 4 lines
numa.c +4 -0
+            for (i = 0, j = 0; i < max_cpus; i++) {
+		do {
+                    j = (j + 1) % (max_numa_nodeid);
+		} while (!numa_info[j].present);

Ditto.

(Those can be detected using checkpatch.pl).

Other than that, the PC changes look good to me (I haven't reviewed the spapr.c changes). But I have an additional request: can you submit the nb_numa_nodes/num_numa_nodes rename as a separate patch, to make the other changes more visible and easier to review?

Signature · 1 line
Eduardo
#2 lore raw
Quoted 11 lines · Eduardo Habkost

On Mon, Jun 30, 2014 at 02:34:56PM -0700, Nishanth Aravamudan wrote:
[...]

numa.c error: · line 200

Quoted 4 lines
             }
numa.c +1 -0
+	    assert(numa_info[i].present);
             numa_info[i].node_mem = ram_size - usedmem;
         }

Tab here.

Quoted 1 line

[...]

Quoted 8 lines

numa.c void set_numa_nodes(void) · line 227

Quoted 4 lines
numa.c +4 -0
+            for (i = 0, j = 0; i < max_cpus; i++) {
+		do {
+                    j = (j + 1) % (max_numa_nodeid);
+		} while (!numa_info[j].present);

Ditto.

(Those can be detected using checkpatch.pl).

Grr, sorry, I had been using checkpatch, but rushed this one. My apologies!

Quoted 4 lines

Other than that, the PC changes look good to me (I haven't reviewed the spapr.c changes). But I have an additional request: can you submit the nb_numa_nodes/num_numa_nodes rename as a separate patch, to make the other changes more visible and easier to review?

Yep, that makes sense.

Thanks,
Nish