Message ID | 20240515093927.3453674-5-maobibo@loongson.cn |
---|---|
State | New |
Headers | show |
Series | hw/loongarch: Refine numa memory map | expand |
在 2024/5/15 下午5:39, Bibo Mao 写道: > For system dram memory region, it is not necessary to use numa node > information. There is only low memory region and high memory region. > > Remove numa node information for ddr memory region here, it can reduce > memory region number on LoongArch virt machine. > > Signed-off-by: Bibo Mao <maobibo@loongson.cn> > --- > hw/loongarch/virt.c | 55 +++++++++++++++------------------------------ > 1 file changed, 18 insertions(+), 37 deletions(-) > > diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c > index b67d691fa5..ac980aec8e 100644 > --- a/hw/loongarch/virt.c > +++ b/hw/loongarch/virt.c > @@ -972,14 +972,10 @@ static void virt_init(MachineState *machine) > { > LoongArchCPU *lacpu; > const char *cpu_model = machine->cpu_type; > - ram_addr_t offset = 0; > - ram_addr_t ram_size = machine->ram_size; > - uint64_t highram_size = 0, phyAddr = 0; > MemoryRegion *address_space_mem = get_system_memory(); > LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(machine); > - int nb_numa_nodes = machine->numa_state->num_nodes; > - NodeInfo *numa_info = machine->numa_state->nodes; > int i; > + hwaddr base, size, ram_size = machine->ram_size; > const CPUArchIdList *possible_cpus; > MachineClass *mc = MACHINE_GET_CLASS(machine); > CPUState *cpu; > @@ -1017,40 +1013,27 @@ static void virt_init(MachineState *machine) > fw_cfg_add_memory(machine); > > /* Node0 memory */ > - 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); > - > - offset += VIRT_LOWMEM_SIZE; > - if (nb_numa_nodes > 0) { > - assert(numa_info[0].node_mem > VIRT_LOWMEM_SIZE); > - highram_size = numa_info[0].node_mem - VIRT_LOWMEM_SIZE; > - } else { > - highram_size = ram_size - VIRT_LOWMEM_SIZE; > - } > - phyAddr = VIRT_HIGHMEM_BASE; > - 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); > - > - /* Node1 - Nodemax memory */ > - offset += highram_size; > - phyAddr += highram_size; > - > - for (i = 1; i < nb_numa_nodes; i++) { > - MemoryRegion *nodemem = g_new(MemoryRegion, 1); > - g_autofree char *ramName = g_strdup_printf("loongarch.node%d.ram", i); > - memory_region_init_alias(nodemem, NULL, ramName, machine->ram, > - offset, numa_info[i].node_mem); > - memory_region_add_subregion(address_space_mem, phyAddr, nodemem); > - offset += numa_info[i].node_mem; > - phyAddr += numa_info[i].node_mem; > + size = ram_size; > + base = VIRT_LOWMEM_BASE; > + if (size > VIRT_LOWMEM_SIZE) { > + size = VIRT_LOWMEM_SIZE; > } > > + memory_region_init_alias(&lvms->lowmem, NULL, "loongarch.lowram", > + machine->ram, base, size); > + memory_region_add_subregion(address_space_mem, base, &lvms->lowmem); > + base += size; > + if (ram_size - size) { > + base = VIRT_HIGHMEM_BASE; > + memory_region_init_alias(&lvms->highmem, NULL, "loongarch.highram", > + machine->ram, VIRT_LOWMEM_BASE + size, ram_size - size); > + memory_region_add_subregion(address_space_mem, base, &lvms->highmem); > + base += ram_size - size; > + } an extra space before '}' Reviewed-by: Song Gao <gaosong@loongson.cn> Thanks. Song Gao > + > /* initialize device memory address space */ > if (machine->ram_size < machine->maxram_size) { > ram_addr_t device_mem_size = machine->maxram_size - machine->ram_size; > - hwaddr device_mem_base; > > if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { > error_report("unsupported amount of memory slots: %"PRIu64, > @@ -1064,9 +1047,7 @@ static void virt_init(MachineState *machine) > "%d bytes", TARGET_PAGE_SIZE); > exit(EXIT_FAILURE); > } > - /* device memory base is the top of high memory address. */ > - device_mem_base = ROUND_UP(VIRT_HIGHMEM_BASE + highram_size, 1 * GiB); > - machine_memory_devices_init(machine, device_mem_base, device_mem_size); > + machine_memory_devices_init(machine, base, device_mem_size); > } > > /* load the BIOS image. */
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index b67d691fa5..ac980aec8e 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -972,14 +972,10 @@ static void virt_init(MachineState *machine) { LoongArchCPU *lacpu; const char *cpu_model = machine->cpu_type; - ram_addr_t offset = 0; - ram_addr_t ram_size = machine->ram_size; - uint64_t highram_size = 0, phyAddr = 0; MemoryRegion *address_space_mem = get_system_memory(); LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(machine); - int nb_numa_nodes = machine->numa_state->num_nodes; - NodeInfo *numa_info = machine->numa_state->nodes; int i; + hwaddr base, size, ram_size = machine->ram_size; const CPUArchIdList *possible_cpus; MachineClass *mc = MACHINE_GET_CLASS(machine); CPUState *cpu; @@ -1017,40 +1013,27 @@ static void virt_init(MachineState *machine) fw_cfg_add_memory(machine); /* Node0 memory */ - 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); - - offset += VIRT_LOWMEM_SIZE; - if (nb_numa_nodes > 0) { - assert(numa_info[0].node_mem > VIRT_LOWMEM_SIZE); - highram_size = numa_info[0].node_mem - VIRT_LOWMEM_SIZE; - } else { - highram_size = ram_size - VIRT_LOWMEM_SIZE; - } - phyAddr = VIRT_HIGHMEM_BASE; - 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); - - /* Node1 - Nodemax memory */ - offset += highram_size; - phyAddr += highram_size; - - for (i = 1; i < nb_numa_nodes; i++) { - MemoryRegion *nodemem = g_new(MemoryRegion, 1); - g_autofree char *ramName = g_strdup_printf("loongarch.node%d.ram", i); - memory_region_init_alias(nodemem, NULL, ramName, machine->ram, - offset, numa_info[i].node_mem); - memory_region_add_subregion(address_space_mem, phyAddr, nodemem); - offset += numa_info[i].node_mem; - phyAddr += numa_info[i].node_mem; + size = ram_size; + base = VIRT_LOWMEM_BASE; + if (size > VIRT_LOWMEM_SIZE) { + size = VIRT_LOWMEM_SIZE; } + memory_region_init_alias(&lvms->lowmem, NULL, "loongarch.lowram", + machine->ram, base, size); + memory_region_add_subregion(address_space_mem, base, &lvms->lowmem); + base += size; + if (ram_size - size) { + base = VIRT_HIGHMEM_BASE; + memory_region_init_alias(&lvms->highmem, NULL, "loongarch.highram", + machine->ram, VIRT_LOWMEM_BASE + size, ram_size - size); + memory_region_add_subregion(address_space_mem, base, &lvms->highmem); + base += ram_size - size; + } + /* initialize device memory address space */ if (machine->ram_size < machine->maxram_size) { ram_addr_t device_mem_size = machine->maxram_size - machine->ram_size; - hwaddr device_mem_base; if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { error_report("unsupported amount of memory slots: %"PRIu64, @@ -1064,9 +1047,7 @@ static void virt_init(MachineState *machine) "%d bytes", TARGET_PAGE_SIZE); exit(EXIT_FAILURE); } - /* device memory base is the top of high memory address. */ - device_mem_base = ROUND_UP(VIRT_HIGHMEM_BASE + highram_size, 1 * GiB); - machine_memory_devices_init(machine, device_mem_base, device_mem_size); + machine_memory_devices_init(machine, base, device_mem_size); } /* load the BIOS image. */
For system dram memory region, it is not necessary to use numa node information. There is only low memory region and high memory region. Remove numa node information for ddr memory region here, it can reduce memory region number on LoongArch virt machine. Signed-off-by: Bibo Mao <maobibo@loongson.cn> --- hw/loongarch/virt.c | 55 +++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 37 deletions(-)