[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 07/86] initialize MachineState::ram in NUMA case
From: |
Igor Mammedov |
Subject: |
[PATCH 07/86] initialize MachineState::ram in NUMA case |
Date: |
Tue, 31 Dec 2019 14:02:51 +0100 |
In case of NUMA there are 2 cases to consider:
1. '-numa node,memdev', the only one that will be available
for 5.0 and newer machine types.
In this case reuse current behavior, with only difference
memdevs are put into MachineState::ram container +
a temporary glue to keep memory_region_allocate_system_memory()
working until all boards converted.
2. fake NUMA ("-numa node mem" and default RAM splitting)
the later has been deprecated and will be removed but the former
is going to stay available for compat reasons for 4.2 and
older machine types (libvirt was heavy user of this)
it takes allocate_system_memory_nonnuma() path, like non-NUMA
case and falls under conversion to memdev. So extend non-NUMA
MachineState::ram initialization introduced in previous patch
to take care of fake NUMA case.
Signed-off-by: Igor Mammedov <address@hidden>
---
include/sysemu/numa.h | 1 +
hw/core/numa.c | 43 ++++++++++++++++++++++++++++++-------------
vl.c | 7 ++++---
3 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h
index ae9c41d..21f6a5a 100644
--- a/include/sysemu/numa.h
+++ b/include/sysemu/numa.h
@@ -49,5 +49,6 @@ void numa_default_auto_assign_ram(MachineClass *mc, NodeInfo
*nodes,
int nb_nodes, ram_addr_t size);
void numa_cpu_pre_plug(const struct CPUArchId *slot, DeviceState *dev,
Error **errp);
+bool numa_uses_legacy_mem(void);
#endif
diff --git a/hw/core/numa.c b/hw/core/numa.c
index ee655b0..a752866 100644
--- a/hw/core/numa.c
+++ b/hw/core/numa.c
@@ -51,6 +51,11 @@ QemuOptsList qemu_numa_opts = {
};
static int have_memdevs;
+bool numa_uses_legacy_mem(void)
+{
+ return !have_memdevs;
+}
+
static int have_mem;
static int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
* For all nodes, nodeid < max_numa_nodeid
@@ -355,6 +360,23 @@ void numa_default_auto_assign_ram(MachineClass *mc,
NodeInfo *nodes,
nodes[i].node_mem = size - usedmem;
}
+static void numa_init_memdev_container(MachineState *ms, MemoryRegion *ram)
+{
+ int i;
+ uint64_t addr = 0;
+
+ for (i = 0; i < ms->numa_state->num_nodes; i++) {
+ uint64_t size = ms->numa_state->nodes[i].node_mem;
+ HostMemoryBackend *backend = ms->numa_state->nodes[i].node_memdev;
+ if (!backend) {
+ continue;
+ }
+ MemoryRegion *seg = machine_consume_memdev(ms, backend);
+ memory_region_add_subregion(ram, addr, seg);
+ addr += size;
+ }
+}
+
void numa_complete_configuration(MachineState *ms)
{
int i;
@@ -437,6 +459,12 @@ void numa_complete_configuration(MachineState *ms)
exit(1);
}
+ if (!numa_uses_legacy_mem() && mc->default_ram_id) {
+ ms->ram = g_new(MemoryRegion, 1);
+ memory_region_init(ms->ram, OBJECT(ms), mc->default_ram_id,
+ ram_size);
+ numa_init_memdev_container(ms, ms->ram);
+ }
/* QEMU needs at least all unique node pair distances to build
* the whole NUMA distance table. QEMU treats the distance table
* as symmetric by default, i.e. distance A->B == distance B->A.
@@ -503,27 +531,16 @@ void memory_region_allocate_system_memory(MemoryRegion
*mr, Object *owner,
const char *name,
uint64_t ram_size)
{
- uint64_t addr = 0;
- int i;
MachineState *ms = MACHINE(qdev_get_machine());
if (ms->numa_state == NULL ||
- ms->numa_state->num_nodes == 0 || !have_memdevs) {
+ ms->numa_state->num_nodes == 0 || numa_uses_legacy_mem()) {
allocate_system_memory_nonnuma(mr, owner, name, ram_size);
return;
}
memory_region_init(mr, owner, name, ram_size);
- for (i = 0; i < ms->numa_state->num_nodes; i++) {
- uint64_t size = ms->numa_state->nodes[i].node_mem;
- HostMemoryBackend *backend = ms->numa_state->nodes[i].node_memdev;
- if (!backend) {
- continue;
- }
- MemoryRegion *seg = machine_consume_memdev(ms, backend);
- memory_region_add_subregion(mr, addr, seg);
- addr += size;
- }
+ numa_init_memdev_container(ms, mr);
}
static void numa_stat_memory_devices(NumaNodeMem node_mem[])
diff --git a/vl.c b/vl.c
index 579ae44..b89e76c 100644
--- a/vl.c
+++ b/vl.c
@@ -4294,9 +4294,10 @@ int main(int argc, char **argv, char **envp)
}
parse_numa_opts(current_machine);
- if (!current_machine->ram_memdev &&
- machine_class->default_ram_size &&
- machine_class->default_ram_id) {
+ if (numa_uses_legacy_mem() &&
+ machine_class->default_ram_size &&
+ machine_class->default_ram_id &&
+ !current_machine->ram_memdev) {
create_default_memdev(current_machine, mem_path, mem_prealloc);
}
/* do monitor/qmp handling at preconfig state if requested */
--
2.7.4
- [PATCH 00/86] refactor main RAM allocation to use hostmem backend, Igor Mammedov, 2019/12/31
- [PATCH 02/86] numa: properly check if numa is supported, Igor Mammedov, 2019/12/31
- [PATCH 03/86] numa: remove deprecated -mem-path fallback to anonymous RAM, Igor Mammedov, 2019/12/31
- [PATCH 04/86] machine: introduce ram-memdev property, Igor Mammedov, 2019/12/31
- [PATCH 01/86] numa: remove not needed check, Igor Mammedov, 2019/12/31
- [PATCH 05/86] machine: alias -mem-path and -mem-prealloc into memory-foo backend, Igor Mammedov, 2019/12/31
- [PATCH 06/86] machine: introduce convenience MachineState::ram, Igor Mammedov, 2019/12/31
- [PATCH 07/86] initialize MachineState::ram in NUMA case,
Igor Mammedov <=
- [PATCH 11/86] hw:aspeed: drop warning and bogus ram_size fixup, Igor Mammedov, 2019/12/31
- [PATCH 08/86] alpha:dp264: use memdev for RAM, Igor Mammedov, 2019/12/31
- [PATCH 09/86] arm:aspeed: convert valid RAM sizes to data, Igor Mammedov, 2019/12/31
- [PATCH 10/86] arm:aspeed: actually check RAM size, Igor Mammedov, 2019/12/31
- [PATCH 12/86] arm:aspeed: use memdev for RAM, Igor Mammedov, 2019/12/31
- [PATCH 15/86] arm:digic_boards: use memdev for RAM, Igor Mammedov, 2019/12/31
- [PATCH 16/86] arm:highbank: use memdev for RAM, Igor Mammedov, 2019/12/31
- [PATCH 18/86] arm:imx25_pdk: use memdev for RAM, Igor Mammedov, 2019/12/31
- [PATCH 22/86] arm:mcimx6ul-evk: use memdev for RAM, Igor Mammedov, 2019/12/31