mirror of https://github.com/xemu-project/xemu.git
machine: introduce convenience MachineState::ram
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 <imammedo@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20200219160953.13771-5-imammedo@redhat.com>
This commit is contained in:
parent
900c0ba373
commit
82b911aaff
|
@ -26,6 +26,7 @@
|
||||||
#include "sysemu/qtest.h"
|
#include "sysemu/qtest.h"
|
||||||
#include "hw/pci/pci.h"
|
#include "hw/pci/pci.h"
|
||||||
#include "hw/mem/nvdimm.h"
|
#include "hw/mem/nvdimm.h"
|
||||||
|
#include "migration/vmstate.h"
|
||||||
|
|
||||||
GlobalProperty hw_compat_4_2[] = {
|
GlobalProperty hw_compat_4_2[] = {
|
||||||
{ "virtio-blk-device", "x-enable-wce-if-config-wce", "off" },
|
{ "virtio-blk-device", "x-enable-wce-if-config-wce", "off" },
|
||||||
|
@ -1059,10 +1060,33 @@ static void machine_numa_finish_cpu_init(MachineState *machine)
|
||||||
g_string_free(s, true);
|
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)
|
void machine_run_board_init(MachineState *machine)
|
||||||
{
|
{
|
||||||
MachineClass *machine_class = MACHINE_GET_CLASS(machine);
|
MachineClass *machine_class = MACHINE_GET_CLASS(machine);
|
||||||
|
|
||||||
|
if (machine->ram_memdev_id) {
|
||||||
|
Object *o;
|
||||||
|
o = object_resolve_path_type(machine->ram_memdev_id,
|
||||||
|
TYPE_MEMORY_BACKEND, NULL);
|
||||||
|
machine->ram = machine_consume_memdev(machine, MEMORY_BACKEND(o));
|
||||||
|
}
|
||||||
|
|
||||||
if (machine->numa_state) {
|
if (machine->numa_state) {
|
||||||
numa_complete_configuration(machine);
|
numa_complete_configuration(machine);
|
||||||
if (machine->numa_state->num_nodes) {
|
if (machine->numa_state->num_nodes) {
|
||||||
|
|
|
@ -817,20 +817,8 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
|
||||||
if (!backend) {
|
if (!backend) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
MemoryRegion *seg = host_memory_backend_get_memory(backend);
|
MemoryRegion *seg = machine_consume_memdev(ms, 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);
|
|
||||||
memory_region_add_subregion(mr, addr, seg);
|
memory_region_add_subregion(mr, addr, seg);
|
||||||
vmstate_register_ram_global(seg);
|
|
||||||
addr += size;
|
addr += size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,12 @@ void machine_set_cpu_numa_node(MachineState *machine,
|
||||||
Error **errp);
|
Error **errp);
|
||||||
|
|
||||||
void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type);
|
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:
|
* CPUArchId:
|
||||||
|
@ -295,6 +300,11 @@ struct MachineState {
|
||||||
bool enable_graphics;
|
bool enable_graphics;
|
||||||
char *memory_encryption;
|
char *memory_encryption;
|
||||||
char *ram_memdev_id;
|
char *ram_memdev_id;
|
||||||
|
/*
|
||||||
|
* convenience alias to ram_memdev_id backend memory region
|
||||||
|
* or to numa container memory region
|
||||||
|
*/
|
||||||
|
MemoryRegion *ram;
|
||||||
DeviceMemoryState *device_memory;
|
DeviceMemoryState *device_memory;
|
||||||
|
|
||||||
ram_addr_t ram_size;
|
ram_addr_t ram_size;
|
||||||
|
|
Loading…
Reference in New Issue