Message ID | 20240515093927.3453674-3-maobibo@loongson.cn (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | hw/loongarch: Refine numa memory map | expand |
在 2024/5/15 下午5:39, Bibo Mao 写道: > One LoongArch virt machine platform, there is limitation for memory > map information. The minimum memory size is 256M and minimum memory > size for numa node0 is 256M also. With qemu numa qtest, it is possible > that memory size of numa node0 is 128M. > > Limitations for minimum memory size for both total memory and numa > node0 is removed for fadt numa memory table creation. > > Signed-off-by: Bibo Mao <maobibo@loongson.cn> > --- Reviewed-by: Song Gao <gaosong@loongson.cn> Thanks. Song Gao > hw/loongarch/virt.c | 46 ++++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 43 insertions(+), 3 deletions(-) > > diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c > index f0640d2d80..c996305d87 100644 > --- a/hw/loongarch/virt.c > +++ b/hw/loongarch/virt.c > @@ -473,6 +473,48 @@ static void fdt_add_memory_node(MachineState *ms, > g_free(nodename); > } > > +static void fdt_add_memory_nodes(MachineState *ms) > +{ > + hwaddr base, size, ram_size, gap; > + int i, nb_numa_nodes, nodes; > + NodeInfo *numa_info; > + > + ram_size = ms->ram_size; > + base = VIRT_LOWMEM_BASE; > + gap = VIRT_LOWMEM_SIZE; > + nodes = nb_numa_nodes = ms->numa_state->num_nodes; > + numa_info = ms->numa_state->nodes; > + if (!nodes) { > + nodes = 1; > + } > + > + for (i = 0; i < nodes; i++) { > + if (nb_numa_nodes) { > + size = numa_info[i].node_mem; > + } else { > + size = ram_size; > + } > + > + /* > + * memory for the node splited into two part > + * lowram: [base, +gap) > + * highram: [VIRT_HIGHMEM_BASE, +(len - gap)) > + */ > + if (size >= gap) { > + fdt_add_memory_node(ms, base, gap, i); > + size -= gap; > + base = VIRT_HIGHMEM_BASE; > + gap = ram_size - VIRT_LOWMEM_SIZE; > + } > + > + if (size) { > + fdt_add_memory_node(ms, base, size, i); > + base += size; > + gap -= size; > + } > + } > +} > + > static void virt_build_smbios(LoongArchVirtMachineState *lvms) > { > MachineState *ms = MACHINE(lvms); > @@ -915,10 +957,10 @@ static void virt_init(MachineState *machine) > lacpu->phy_id = machine->possible_cpus->cpus[i].arch_id; > } > fdt_add_cpu_nodes(lvms); > + fdt_add_memory_nodes(machine); > > /* Node0 memory */ > memmap_add_entry(VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 1); > - fdt_add_memory_node(machine, VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 0); > memory_region_init_alias(&lvms->lowmem, NULL, "loongarch.node0.lowram", > machine->ram, offset, VIRT_LOWMEM_SIZE); > memory_region_add_subregion(address_space_mem, phyAddr, &lvms->lowmem); > @@ -932,7 +974,6 @@ static void virt_init(MachineState *machine) > } > phyAddr = VIRT_HIGHMEM_BASE; > memmap_add_entry(phyAddr, highram_size, 1); > - fdt_add_memory_node(machine, phyAddr, highram_size, 0); > memory_region_init_alias(&lvms->highmem, NULL, "loongarch.node0.highram", > machine->ram, offset, highram_size); > memory_region_add_subregion(address_space_mem, phyAddr, &lvms->highmem); > @@ -948,7 +989,6 @@ static void virt_init(MachineState *machine) > offset, numa_info[i].node_mem); > memory_region_add_subregion(address_space_mem, phyAddr, nodemem); > memmap_add_entry(phyAddr, numa_info[i].node_mem, 1); > - fdt_add_memory_node(machine, phyAddr, numa_info[i].node_mem, i); > offset += numa_info[i].node_mem; > phyAddr += numa_info[i].node_mem; > }
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index f0640d2d80..c996305d87 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -473,6 +473,48 @@ static void fdt_add_memory_node(MachineState *ms, g_free(nodename); } +static void fdt_add_memory_nodes(MachineState *ms) +{ + hwaddr base, size, ram_size, gap; + int i, nb_numa_nodes, nodes; + NodeInfo *numa_info; + + ram_size = ms->ram_size; + base = VIRT_LOWMEM_BASE; + gap = VIRT_LOWMEM_SIZE; + nodes = nb_numa_nodes = ms->numa_state->num_nodes; + numa_info = ms->numa_state->nodes; + if (!nodes) { + nodes = 1; + } + + for (i = 0; i < nodes; i++) { + if (nb_numa_nodes) { + size = numa_info[i].node_mem; + } else { + size = ram_size; + } + + /* + * memory for the node splited into two part + * lowram: [base, +gap) + * highram: [VIRT_HIGHMEM_BASE, +(len - gap)) + */ + if (size >= gap) { + fdt_add_memory_node(ms, base, gap, i); + size -= gap; + base = VIRT_HIGHMEM_BASE; + gap = ram_size - VIRT_LOWMEM_SIZE; + } + + if (size) { + fdt_add_memory_node(ms, base, size, i); + base += size; + gap -= size; + } + } +} + static void virt_build_smbios(LoongArchVirtMachineState *lvms) { MachineState *ms = MACHINE(lvms); @@ -915,10 +957,10 @@ static void virt_init(MachineState *machine) lacpu->phy_id = machine->possible_cpus->cpus[i].arch_id; } fdt_add_cpu_nodes(lvms); + fdt_add_memory_nodes(machine); /* Node0 memory */ memmap_add_entry(VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 1); - fdt_add_memory_node(machine, VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 0); memory_region_init_alias(&lvms->lowmem, NULL, "loongarch.node0.lowram", machine->ram, offset, VIRT_LOWMEM_SIZE); memory_region_add_subregion(address_space_mem, phyAddr, &lvms->lowmem); @@ -932,7 +974,6 @@ static void virt_init(MachineState *machine) } phyAddr = VIRT_HIGHMEM_BASE; memmap_add_entry(phyAddr, highram_size, 1); - fdt_add_memory_node(machine, phyAddr, highram_size, 0); memory_region_init_alias(&lvms->highmem, NULL, "loongarch.node0.highram", machine->ram, offset, highram_size); memory_region_add_subregion(address_space_mem, phyAddr, &lvms->highmem); @@ -948,7 +989,6 @@ static void virt_init(MachineState *machine) offset, numa_info[i].node_mem); memory_region_add_subregion(address_space_mem, phyAddr, nodemem); memmap_add_entry(phyAddr, numa_info[i].node_mem, 1); - fdt_add_memory_node(machine, phyAddr, numa_info[i].node_mem, i); offset += numa_info[i].node_mem; phyAddr += numa_info[i].node_mem; }
One LoongArch virt machine platform, there is limitation for memory map information. The minimum memory size is 256M and minimum memory size for numa node0 is 256M also. With qemu numa qtest, it is possible that memory size of numa node0 is 128M. Limitations for minimum memory size for both total memory and numa node0 is removed for fadt numa memory table creation. Signed-off-by: Bibo Mao <maobibo@loongson.cn> --- hw/loongarch/virt.c | 46 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-)