[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH REPOST v3 04/80] machine: introduce convenience MachineState::ram
From: |
Igor Mammedov |
Subject: |
[PATCH REPOST v3 04/80] machine: introduce convenience MachineState::ram |
Date: |
Thu, 23 Jan 2020 12:37:29 +0100 |
the new field will be used by boards to get access to main
RAM memory region and will help to save boiler plate in
boards which often introduce a field or variable just for
this purpose.
Memory region will be equivalent to what currently used
memory_region_allocate_system_memory() is returning apart
from that it will come from hostmem backend.
Followup patches will incrementally switch boards to using
RAM from MachineState::ram.
Patch takes care of non-NUMA case and follow up patch will
initialize MachineState::ram for NUMA case.
Signed-off-by: Igor Mammedov <address@hidden>
---
CC: address@hidden
CC: address@hidden
---
include/hw/boards.h | 9 ++++++++-
hw/core/machine.c | 21 +++++++++++++++++++++
hw/core/numa.c | 14 +-------------
3 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 2a4e804..351479d 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -73,7 +73,12 @@ void machine_set_cpu_numa_node(MachineState *machine,
Error **errp);
void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char
*type);
-
+/*
+ * Checks that backend isn't used, preps it for exclusive usage and
+ * returns migratable MemoryRegion provided by backend.
+ */
+MemoryRegion *machine_consume_memdev(MachineState *machine,
+ HostMemoryBackend *backend);
/**
* CPUArchId:
@@ -292,6 +297,8 @@ struct MachineState {
bool enable_graphics;
char *memory_encryption;
HostMemoryBackend *ram_memdev;
+ /* convenience alias to ram_memdev memory region or numa container */
+ MemoryRegion *ram;
DeviceMemoryState *device_memory;
ram_addr_t ram_size;
diff --git a/hw/core/machine.c b/hw/core/machine.c
index bf30183..81791a0 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -26,6 +26,7 @@
#include "sysemu/qtest.h"
#include "hw/pci/pci.h"
#include "hw/mem/nvdimm.h"
+#include "migration/vmstate.h"
GlobalProperty hw_compat_4_2[] = {
{ "virtio-blk-device", "x-enable-wce-if-config-wce", "off" },
@@ -1041,10 +1042,30 @@ static void machine_numa_finish_cpu_init(MachineState
*machine)
g_string_free(s, true);
}
+MemoryRegion *machine_consume_memdev(MachineState *machine,
+ HostMemoryBackend *backend)
+{
+ MemoryRegion *ret = host_memory_backend_get_memory(backend);
+
+ if (memory_region_is_mapped(ret)) {
+ char *path = object_get_canonical_path_component(OBJECT(backend));
+ error_report("memory backend %s can't be used multiple times.", path);
+ g_free(path);
+ exit(EXIT_FAILURE);
+ }
+ host_memory_backend_set_mapped(backend, true);
+ vmstate_register_ram_global(ret);
+ return ret;
+}
+
void machine_run_board_init(MachineState *machine)
{
MachineClass *machine_class = MACHINE_GET_CLASS(machine);
+ if (machine->ram_memdev) {
+ machine->ram = machine_consume_memdev(machine, machine->ram_memdev);
+ }
+
if (machine->numa_state) {
numa_complete_configuration(machine);
if (machine->numa_state->num_nodes) {
diff --git a/hw/core/numa.c b/hw/core/numa.c
index 840e685..8264336 100644
--- a/hw/core/numa.c
+++ b/hw/core/numa.c
@@ -817,20 +817,8 @@ void memory_region_allocate_system_memory(MemoryRegion
*mr, Object *owner,
if (!backend) {
continue;
}
- MemoryRegion *seg = host_memory_backend_get_memory(backend);
-
- if (memory_region_is_mapped(seg)) {
- char *path = object_get_canonical_path_component(OBJECT(backend));
- error_report("memory backend %s is used multiple times. Each "
- "-numa option must use a different memdev value.",
- path);
- g_free(path);
- exit(1);
- }
-
- host_memory_backend_set_mapped(backend, true);
+ MemoryRegion *seg = machine_consume_memdev(ms, backend);
memory_region_add_subregion(mr, addr, seg);
- vmstate_register_ram_global(seg);
addr += size;
}
}
--
2.7.4
- [PATCH REPOST v3 00/80] refactor main RAM allocation to use hostmem backend, Igor Mammedov, 2020/01/23
- [PATCH REPOST v3 02/80] machine: introduce memory-backend property, Igor Mammedov, 2020/01/23
- [PATCH REPOST v3 01/80] numa: remove deprecated -mem-path fallback to anonymous RAM, Igor Mammedov, 2020/01/23
- [PATCH REPOST v3 03/80] machine: alias -mem-path and -mem-prealloc into memory-foo backend, Igor Mammedov, 2020/01/23
- [PATCH REPOST v3 04/80] machine: introduce convenience MachineState::ram,
Igor Mammedov <=
- [PATCH REPOST v3 05/80] initialize MachineState::ram in NUMA case, Igor Mammedov, 2020/01/23
- [PATCH REPOST v3 06/80] alpha:dp264: use memdev for RAM, Igor Mammedov, 2020/01/23
- [PATCH REPOST v3 10/80] arm/cubieboard: use memdev for RAM, Igor Mammedov, 2020/01/23
- [PATCH REPOST v3 07/80] arm/aspeed: actually check RAM size, Igor Mammedov, 2020/01/23
- [PATCH REPOST v3 09/80] arm/collie: use memdev for RAM, Igor Mammedov, 2020/01/23
- [PATCH REPOST v3 08/80] arm/aspeed: use memdev for RAM, Igor Mammedov, 2020/01/23