QEMU shared-memory backend
v2 cover QEMU shared-memory backend
A new memory backend, the shared memory backend, based on the file memory backend.
This new backend allows a master QEMU instance to share a part of his main memory whith a slave QEMU instance. It is then possible to load a firmware on this memory and trigger the slave boot using a SDM signal.
Such new backend enables, on a master side, to allocate the whole memory as shareable (e.g. /dev/shm, or hugetlbfs).
On the slave side it enables the startup of QEMU without any main memory allocated. Then the slave goes in a waiting state, the same used in the case of an incoming migration, and the file descriptor of the shared memory is sent by the master over a socket.
The waiting state ends when the master sends to the slave a signal with size and offset to mmap and use as memory as payload.
You can test those patches using modules and test application available on https://git.virtualopensystems.com/dev/qemu-het-tools.
- SDM Platform module on branch sdm_test_mod_v1
- Test application on branch sdm_test_app
- Slave files on branch demo_slaves_sdm
QEMU code is avalaible here https://git.virtualopensystems.com/dev/qemu on branch rfc_v2.
Run QEMU master instance:
./qemu-system-arm -nographic \
-kernel zImage \
-M virt -m 1G \
-initrd busybox.cpio \
-object multi-socket-backend,id=sock,path=sock,listen \
-object memory-backend-shared,id=mem,size=1G,mem-path=/dev/hugepages,socket=sock,master \
-object sdm-signal-shboot,id=boot,shm=mem \
-object sdm-communication-socket,id=scomm,socket=sock \
-device virtio-sdm-device,comm=scomm,master,num-slaves=1,len-signals=1,signals[0]=boot \
-append "mem=512M memmap=512M$0x60000000" \
-numa node,memdev=mem -m 1GRun QEMU slave instance:
./qemu-system-arm -nographic \
-kernel zImage \
-M virt -m 1G \
-initrd busybox.cpio \
-object multi-socket-backend,id=sock,path=sock \
-object memory-backend-shared,id=mem,size=512M,socket=sock \
-object sdm-signal-shboot,id=boot,shm=mem \
-object sdm-communication-socket,id=scomm,socket=sock \
-device sdm-platform,comm=scomm,len-signals=1,signals[0]="boot" \
-incoming "shared:mem" \
-numa node,memdev=mem -m 512MOn the master, load the SDM module (insmod sdm_test_mod_v1) and trigger the boot with the following command:
./sdm-test -b 0 1 zImage slave.dtb
zImage and slave.dtb are available on branch demo_slaves_sdm.
This patch serie is a follow-up to "[RFC PATCH 0/8] Towards an Heterogeneous QEMU":
https://lists.gnu.org/archive/html/qemu-devel/2015-10/msg00171.html
This patch serie depends on:
- [RFC v2 0/6] SDM Interface
- [RFC v2 1/1] backend: multi-client-socket
This work has been sponsored by Huawei Technologies Duesseldorf GmbH.
Baptiste Reynal (3):
backend: shared memory backend
migration: add shared migration type
hw/misc: sdm signal shboot
Christian Pinto (3):
qemu: slave machine flag
hw/arm: boot
qemu: numa
backends/Makefile.objs | 2 +- backends/hostmem-shared.c | 198 ++++++++++++++++++++++++++++++++++++ hw/arm/boot.c | 13 +++ hw/core/machine.c | 27 +++++ hw/misc/Makefile.objs | 1 + hw/misc/sdm-signal-shboot.c | 62 +++++++++++ include/hw/boards.h | 2 + include/hw/misc/sdm-signal-shboot.h | 38 +++++++ include/migration/migration.h | 2 + include/sysemu/hostmem-shared.h | 66 ++++++++++++ migration/Makefile.objs | 2 +- migration/migration.c | 2 + migration/shared.c | 33 ++++++ numa.c | 17 +++- qemu-options.hx | 5 +- util/qemu-config.c | 5 + 16 files changed, 471 insertions(+), 4 deletions(-) create mode 100644 backends/hostmem-shared.c create mode 100644 hw/misc/sdm-signal-shboot.c create mode 100644 include/hw/misc/sdm-signal-shboot.h create mode 100644 include/sysemu/hostmem-shared.h create mode 100644 migration/shared.c
Signature · 1 line
2.7.3
RFC v2 1/6 backend: shared memory backend
This patch introduces a shared memory backend, allowing to share memory between a master and many slaves.
The memory is implemented using hugetlbfs, and relies on the multi-socket backend to share informations (size and offset for the slaves).
Instantiation on the master:
-object memory-backend-shared,id=<id>,size=<memory_sizeK,M,G>,
chardev=<multi-socket_id>,master=on
Instantiation on the slave:
-object memory-backend-shared,id=<id>,size=<slave_memory_sizeK,M,G>,
chardev=<multi-socket_id>,master=off
Memory size on the slave can be smaller than on master. The master will send to the slave the size and the offset of the memory segment it can allocate in the total shared memory.
--- backends/Makefile.objs | 2 +- backends/hostmem-shared.c | 192 ++++++++++++++++++++++++++++++++++++++++ include/sysemu/hostmem-shared.h | 66 ++++++++++++++ 3 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 backends/hostmem-shared.c create mode 100644 include/sysemu/hostmem-shared.h
backends/Makefile.objs +1 -1
@@ -8,6 +8,6 @@ baum.o-cflags := $(SDL_CFLAGS) common-obj-$(CONFIG_TPM) += tpm.o common-obj-y += hostmem.o hostmem-ram.o -common-obj-$(CONFIG_LINUX) += hostmem-file.o +common-obj-$(CONFIG_LINUX) += hostmem-file.o hostmem-shared.o common-obj-y += multi-socket.o
backends/hostmem-shared.c new file +192 -0
192 lines not on this page · raw message
include/sysemu/hostmem-shared.h new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.7.3
RFC v2 2/6 migration: add shared migration type
In reply to Baptiste ReynalA QEMU instance can now wait for the instantiation of the memory by the master while shared-memory backend is used.
Use:
-incoming "shared:<shared-memory_id>"
--- backends/hostmem-shared.c | 6 ++++++ include/migration/migration.h | 2 ++ migration/Makefile.objs | 2 +- migration/migration.c | 2 ++ migration/shared.c | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 migration/shared.c
backends/hostmem-shared.c +6 -0
@@ -11,6 +11,7 @@*/ #include "sysemu/hostmem-shared.h" +#include "migration/vmstate.h" static void shm_map (HostMemoryBackendShared *shm,size_t size,off_t offset) {
@@ -96,6 +97,11 @@ shared_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) set_shared_memory, shm); } } + + shm->levent =g_new (EventNotifier,1 ); +event_notifier_init (shm->levent,0 ); + + shm->event =event_notifier_get_fd (shm->levent); } static void
include/migration/migration.h +2 -0
@@ -114,6 +114,8 @@ void migrate_fd_connect(MigrationState *s);int migrate_fd_close (MigrationState *s); +void shared_start_incoming_migration (const char *name,Error **errp); +void add_migration_state_change_notifier (Notifier *notify);void remove_migration_state_change_notifier (Notifier *notify);bool migration_in_setup (MigrationState *);
migration/Makefile.objs +1 -1
@@ -7,4 +7,4 @@ common-obj-$(CONFIG_RDMA) += rdma.o common-obj-$(CONFIG_POSIX) += exec.o unix.o fd.o common-obj-y += block.o - +common-obj-y += shared.o
migration/migration.c +2 -0
@@ -249,6 +249,8 @@ void qemu_start_incoming_migration(const char *uri, Error **errp)deferred_incoming_migration (errp); }else if (strstart (uri,"tcp:" , &p)) {tcp_start_incoming_migration (p, errp); + }else if (strstart (uri,"shared:" , &p)) { +shared_start_incoming_migration (p, errp); #ifdef CONFIG_RDMA }else if (strstart (uri,"rdma:" , &p)) {rdma_start_incoming_migration (p, errp);
migration/shared.c new file +33 -0
@@ -0,0 +1,33 @@ +#include "qemu-common.h" +#include "qemu/main-loop.h" +#include "qemu/sockets.h" +#include "migration/migration.h" +#include "monitor/monitor.h" +#include "migration/qemu-file.h" +#include "block/block.h" +#include "sysemu/hostmem-shared.h" + +static void shared_accept_incoming_migration (void *opaque) +{ +QEMUFile *f = opaque; +printf ("Start !\n" ); + +qemu_set_fd_handler (qemu_get_fd (f),NULL ,NULL ,NULL ); +vm_start (); +} + +void shared_start_incoming_migration (const char *id,Error **errp) +{ +HostMemoryBackendShared *shm = (HostMemoryBackendShared *) +object_resolve_path_type (id,TYPE_MEMORY_BACKEND_SHARED ,NULL ); +QEMUFile *f; + +if (shm ==NULL ) { +printf ("Error: Cannot find shared memory %s\n" , id); +exit (-1 ); + } + + f =qemu_fdopen (shm->event,"rb" ); + +qemu_set_fd_handler (shm->event, shared_accept_incoming_migration,NULL , f); +}
Signature · 1 line
2.7.3
RFC v2 3/6 hw/misc: sdm signal shboot
In reply to Baptiste ReynalThis patch introduces a new signal for SDM device, which triggers the boot of a machine using a shared memory.
--- hw/misc/Makefile.objs | 1 + hw/misc/sdm-signal-shboot.c | 62 +++++++++++++++++++++++++++++++++++++ include/hw/misc/sdm-signal-shboot.h | 38 +++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 hw/misc/sdm-signal-shboot.c create mode 100644 include/hw/misc/sdm-signal-shboot.h
hw/misc/Makefile.objs +1 -0
@@ -27,6 +27,7 @@ obj-$(CONFIG_SDM) += sdm-signal.o obj-$(CONFIG_SDM) += sdm-platform.o obj-$(CONFIG_SDM) += sdm-communication-local.o obj-$(CONFIG_SDM) += sdm-communication-socket.o +obj-$(CONFIG_SDM) += sdm-signal-shboot.o obj-$(CONFIG_REALVIEW) += arm_sysctl.o obj-$(CONFIG_NSERIES) += cbus.o
hw/misc/sdm-signal-shboot.c new file +62 -0
62 lines not on this page · raw message
include/hw/misc/sdm-signal-shboot.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* SDM Signal Shared Boot +* +* Copyright (C) 2016 - Virtual Open Systems +* +* Author: Baptiste Reynal <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* This signal triggers the boot of a shared memory backend. It is intended to +* find the size in PAYLOAD_REG0 and the offset in PAYLOAD_REG1. +*/ +#ifndef HW_SDM_SIGNAL_SHBOOT_H +#define HW_SDM_SIGNAL_SHBOOT_H + +#include "hw/misc/sdm-signal.h" +#include "sysemu/hostmem-shared.h" + +#define TYPE_SDM_SIGNAL_SHBOOT "sdm-signal-shboot" +#define SDM_SIGNAL_SHBOOT (obj) \ + OBJECT_CHECK(SDMSignalShBoot, (obj), TYPE_SDM_SIGNAL) + +typedef struct SDMSignalShBoot SDMSignalShBoot ; + +/** +* +* @SDMSignalShBoot +* +* @parent: opaque parent object container +*/ +struct SDMSignalShBoot { +/* private */ +SDMSignal parent; + +HostMemoryBackendShared *shm; +}; +#endif
Signature · 1 line
2.7.3
RFC v2 4/6 qemu: slave machine flag
In reply to Baptiste ReynalFrom: Christian Pinto <[email protected]>
This patch adds a new machine flag, to configure qemu as a slave instance.
Usage
-machine -slave=[on|off] (default=off)
--- hw/core/machine.c | 27 +++++++++++++++++++++++++++ include/hw/boards.h | 2 ++ qemu-options.hx | 5 ++++- util/qemu-config.c | 5 +++++ 4 files changed, 38 insertions(+), 1 deletion(-)
hw/core/machine.c +27 -0
@@ -283,6 +283,20 @@ static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)return ms->suppress_vmdesc; } +static bool machine_get_slave (Object *obj,Error **errp) +{ +MachineState *ms =MACHINE (obj); + +return ms->slave; +} + +static void machine_set_slave (Object *obj,bool value,Error **errp) +{ +MachineState *ms =MACHINE (obj); + + ms->slave = value; +} +static int error_on_sysbus_device (SysBusDevice *sbdev,void *opaque) { error_report("Option '-device %s' cannot be handled by this machine",
@@ -335,6 +349,7 @@ static void machine_initfn(Object *obj) ms->kvm_shadow_mem =-1 ; ms->dump_guest_core = true; ms->mem_merge = true; + ms->slave = false;object_property_add_str (obj,"accel" , machine_get_accel, machine_set_accel,NULL );
@@ -437,6 +452,13 @@ static void machine_initfn(Object *obj)object_property_set_description (obj,"suppress-vmdesc" ,"Set on to disable self-describing migration" ,NULL ); +object_property_add_bool (obj,"slave" , + machine_get_slave, + machine_set_slave, +NULL ); +object_property_set_description (obj,"slave" , +"Enables a slave (remote) machine instance" , +NULL );/* Register notifier when init is done for sysbus sanity checks */ ms->sysbus_notifier.notify = machine_init_notify;
@@ -497,6 +519,11 @@ bool machine_mem_merge(MachineState *machine)return machine->mem_merge; } +bool machine_slave (MachineState *machine) +{ +return machine->slave; +} +static const TypeInfo machine_info = { .name =TYPE_MACHINE , .parent =TYPE_OBJECT ,
include/hw/boards.h +2 -0
@@ -40,6 +40,7 @@ int machine_kvm_shadow_mem(MachineState *machine);int machine_phandle_start (MachineState *machine);bool machine_dump_guest_core (MachineState *machine);bool machine_mem_merge (MachineState *machine); +bool machine_slave (MachineState *machine);/** * MachineClass:
@@ -120,6 +121,7 @@ struct MachineState {char *firmware;bool iommu;bool suppress_vmdesc; +bool slave;ram_addr_t ram_size;ram_addr_t maxram_size;
qemu-options.hx +4 -1
@@ -41,7 +41,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n" - " suppress-vmdesc=on|off disables self-describing migration (default=off)\n", + " suppress-vmdesc=on|off disables self-describing migration (default=off)\n" + " slave=on|off enables a slave (remote) machine instance (default=off)", QEMU_ARCH_ALL) STEXI @item -machine [type=]@var{name}[,prop=@var{value}[,...]]
@@ -80,6 +81,8 @@ execution of AES cryptographic functions. The default is on. Enables or disables DEA key wrapping support on s390-ccw hosts. This feature controls whether DEA wrapping keys will be created to allow execution of DEA cryptographic functions. The default is on. +@item slave=on|off +Enables a slave (remote) machine instance @end table ETEXI
util/qemu-config.c +5 -0
@@ -219,6 +219,11 @@ static QemuOptsList machine_opts = { .name = "suppress-vmdesc", .type = QEMU_OPT_BOOL, .help = "Set on to disable self-describing migration", + },{ + .name = "slave", + .type = QEMU_OPT_BOOL, + .help = "Indicates the machine is a slave instance " + "(e.g. remoteproc)", }, {/* End of list */ } }
Signature · 1 line
2.7.3
RFC v2 5/6 hw/arm: boot
In reply to Baptiste ReynalFrom: Christian Pinto <[email protected]>
This patch modifies the boot process of an ARM machine in otrder to check whether if it is a slave, by checking the slave machine flag.
When the slave flag is on, no kernel, dtb or initrd are loaded into memory. The boot address of each core is set to the start address of the RAM, that depends on the machine model executed.
--- hw/arm/boot.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/arm/boot.c +13 -0
@@ -590,6 +590,19 @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)/* Load the kernel. */ if (!info->kernel_filename || info->firmware_loaded) { +if (!info->kernel_filename &&machine_slave (current_machine)) { +/* If a machine is booted as a slave instance there is no need to +* provide the DTB blob or kernel image, that will instead +* be copied into memory later by a master instance. +* The boot address is set to be at the beginning of the RAM. +*/ + info->entry = info->loader_start; +CPU_FOREACH (cs) { +ARM_CPU (cs)->env.boot_info = info; + } +return ; + } +if (have_dtb (info)) {/* If we have a device tree blob, but no kernel to supply it to (or * the kernel is supposed to be loaded by the bootloader), copy the
Signature · 1 line
2.7.3
RFC v2 6/6 qemu: numa
In reply to Baptiste ReynalFrom: Christian Pinto <[email protected]>
This patch modifies the behavior of memory_region_allocate_system_memory, when the new shared memory backend is used from a slave qemu instance.
In such case there is not yet a valid pointer for the memory region pointed by the backend (it will be innitilized later when received from the master.) and vmstate_register would fail.
The patch skips the call to vmstate_register in case of slave shared memory backend, that will be performed later after the actual memory pointer is available.
--- numa.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
numa.c +16 -1
@@ -33,6 +33,7 @@#include "qapi/dealloc-visitor.h" #include "hw/boards.h" #include "sysemu/hostmem.h" +#include "sysemu/hostmem-shared.h" #include "qmp-commands.h" #include "hw/mem/pc-dimm.h" #include "qemu/option.h"
@@ -442,6 +443,7 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner, {uint64_t addr =0 ;int i; +bool vmstate_register = true;if (nb_numa_nodes ==0 || !have_memdevs) {allocate_system_memory_nonnuma (mr, owner, name, ram_size);
@@ -453,9 +455,18 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,Error *local_err =NULL ;uint64_t size = numa_info[i].node_mem;HostMemoryBackend *backend = numa_info[i].node_memdev; +if (!backend) {continue ; } + +if (IS_MEMORY_BACKEND_SHARED (backend)) { +HostMemoryBackendShared *shm =MEMORY_BACKEND_SHARED (backend); +if (!shm->master) { + vmstate_register = false; + } + } +MemoryRegion *seg =host_memory_backend_get_memory (backend, &local_err);if (local_err) {error_report_err (local_err);
@@ -471,7 +482,11 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner, }memory_region_add_subregion (mr, addr, seg); -vmstate_register_ram_global (seg); + +if (vmstate_register) { +vmstate_register_ram_global (seg); + } + addr += size; } }
Signature · 1 line
2.7.3
Copying Paolo, author of memory-backend-file.
Quoted 7 lines · Baptiste Reynal
A new memory backend, the shared memory backend, based on the file memory backend.
This new backend allows a master QEMU instance to share a part of his main memory whith a slave QEMU instance. It is then possible to load a firmware on this memory and trigger the slave boot using a SDM signal.
Can you explain why that's useful in a bit more detail?
Quoted 2 lines
Such new backend enables, on a master side, to allocate the whole memory as shareable (e.g.
/dev/shm, or hugetlbfs).
memory-backend-file can do that already. What exactly does memory-backend-shared add to it?
Quoted 88 lines
On the slave side it enables the startup of QEMU without any main memory allocated. Then the slave goes in a waiting state, the same used in the case of an incoming migration, and the file descriptor of the shared memory is sent by the master over a socket.
The waiting state ends when the master sends to the slave a signal with size and offset to mmap and use as memory as payload.You can test those patches using modules and test application available on https://git.virtualopensystems.com/dev/qemu-het-tools.
- SDM Platform module on branchsdm_test_mod_v1
- Test application on branchsdm_test_app
- Slave files on branchdemo_slaves_sdmQEMU code is avalaible here https://git.virtualopensystems.com/dev/qemu on branch
rfc_v2.Run QEMU master instance:
./qemu-system-arm -nographic \ -kernel zImage \ -M virt -m 1G \ -initrd busybox.cpio \ -object multi-socket-backend,id=sock,path=sock,listen \ -object memory-backend-shared,id=mem,size=1G,mem-path=/dev/hugepages,socket=sock,master \ -object sdm-signal-shboot,id=boot,shm=mem \ -object sdm-communication-socket,id=scomm,socket=sock \ -device virtio-sdm-device,comm=scomm,master,num-slaves=1,len-signals=1,signals[0]=boot \ -append "mem=512M memmap=512M$0x60000000" \ -numa node,memdev=mem -m 1GRun QEMU slave instance:
./qemu-system-arm -nographic \ -kernel zImage \ -M virt -m 1G \ -initrd busybox.cpio \ -object multi-socket-backend,id=sock,path=sock \ -object memory-backend-shared,id=mem,size=512M,socket=sock \ -object sdm-signal-shboot,id=boot,shm=mem \ -object sdm-communication-socket,id=scomm,socket=sock \ -device sdm-platform,comm=scomm,len-signals=1,signals[0]="boot" \ -incoming "shared:mem" \ -numa node,memdev=mem -m 512MOn the master, load the SDM module (insmod
sdm_test_mod_v1) and trigger the boot with the following command:
./sdm-test -b 0 1 zImage slave.dtbzImage and slave.dtb are available on branch
demo_slaves_sdm.This patch serie is a follow-up to "[RFC PATCH 0/8] Towards an Heterogeneous QEMU":
https://lists.gnu.org/archive/html/qemu-devel/2015-10/msg00171.htmlThis patch serie depends on:
- [RFC v2 0/6] SDM Interface
- [RFC v2 1/1] backend: multi-client-socketThis work has been sponsored by Huawei Technologies Duesseldorf GmbH.
Baptiste Reynal (3):
backend: shared memory backend
migration: add shared migration type
hw/misc: sdm signal shbootChristian Pinto (3):
qemu: slave machine flag
hw/arm: boot
qemu: numabackends/Makefile.objs | 2 +- backends/hostmem-shared.c | 198 ++++++++++++++++++++++++++++++++++++ hw/arm/boot.c | 13 +++ hw/core/machine.c | 27 +++++ hw/misc/Makefile.objs | 1 + hw/misc/sdm-signal-shboot.c | 62 +++++++++++ include/hw/boards.h | 2 + include/hw/misc/sdm-signal-shboot.h | 38 +++++++ include/migration/migration.h | 2 + include/sysemu/hostmem-shared.h | 66 ++++++++++++ migration/Makefile.objs | 2 +- migration/migration.c | 2 + migration/shared.c | 33 ++++++ numa.c | 17 +++- qemu-options.hx | 5 +- util/qemu-config.c | 5 + 16 files changed, 471 insertions(+), 4 deletions(-) create mode 100644 backends/hostmem-shared.c create mode 100644 hw/misc/sdm-signal-shboot.c create mode 100644 include/hw/misc/sdm-signal-shboot.h create mode 100644 include/sysemu/hostmem-shared.h create mode 100644 migration/shared.c
Quoted 8 lines · Markus Armbruster
Copying Paolo, author of memory-backend-file.
Quoted 3 lines · Baptiste Reynal
A new memory backend, the shared memory backend, based on the file memory backend.
Quoted 7 lines
Quoted 4 lines
This new backend allows a master QEMU instance to share a part of his main memory whith a slave QEMU instance. It is then possible to load a firmware on this memory and trigger the slave boot using a SDM signal.
Can you explain why that's useful in a bit more detail?
The purpose of such memory backend is to enable the modeling of asymmetric multiprocessing (AMP) configurations. An example is a multi-core ARM CPU working alongside with two Cortex-M micro controllers.
On such configurations many CPU (modeled by many QEMU instances) share the same memory bus. This patch series allows multiple QEMU instances to share the same file-backed memory bus.
Quoted 6 lines
Quoted 3 lines
Such new backend enables, on a master side, to allocate the whole memory as shareable (e.g.
/dev/shm, or hugetlbfs).memory-backend-file can do that already. What exactly does memory-backend-shared add to it?
This memory-backend-shared allows multiple QEMU instances to share the same memory backend. A slave instance will have access only to a subset of the whole AMP system memory, by mapping just one part of the file as its memory. This can be considered as an MMU configured by the master processor to restrict slave memory accesses to only a subset of the whole system memory.
For the purpose of AMP modeling, a QEMU instance can be put in waiting mode (by using QEMU migration) until a master QEMU triggers its boot. It allows the master to fill the slave memory with its firmware before boot, in order to be compliant with the remoteproc framework (power on, load firmware, power off).
Quoted 90 lines
Quoted 90 lines
On the slave side it enables the startup of QEMU without any main memory allocated. Then the slave goes in a waiting state, the same used in the case of an incoming migration, and the file descriptor of the shared memory is sent by the master over a socket.
The waiting state ends when the master sends to the slave a signal with size and offset to mmap and use as memory as payload.You can test those patches using modules and test application available on https://git.virtualopensystems.com/dev/qemu-het-tools.
- SDM Platform module on branchsdm_test_mod_v1
- Test application on branchsdm_test_app
- Slave files on branchdemo_slaves_sdmQEMU code is avalaible here https://git.virtualopensystems.com/dev/qemu on branch
rfc_v2.Run QEMU master instance:
./qemu-system-arm -nographic \ -kernel zImage \ -M virt -m 1G \ -initrd busybox.cpio \ -object multi-socket-backend,id=sock,path=sock,listen \ -object memory-backend-shared,id=mem,size=1G,mem-path=/dev/hugepages,socket=sock,master \ -object sdm-signal-shboot,id=boot,shm=mem \ -object sdm-communication-socket,id=scomm,socket=sock \ -device virtio-sdm-device,comm=scomm,master,num-slaves=1,len-signals=1,signals[0]=boot \ -append "mem=512M memmap=512M$0x60000000" \ -numa node,memdev=mem -m 1GRun QEMU slave instance:
./qemu-system-arm -nographic \ -kernel zImage \ -M virt -m 1G \ -initrd busybox.cpio \ -object multi-socket-backend,id=sock,path=sock \ -object memory-backend-shared,id=mem,size=512M,socket=sock \ -object sdm-signal-shboot,id=boot,shm=mem \ -object sdm-communication-socket,id=scomm,socket=sock \ -device sdm-platform,comm=scomm,len-signals=1,signals[0]="boot" \ -incoming "shared:mem" \ -numa node,memdev=mem -m 512MOn the master, load the SDM module (insmod
sdm_test_mod_v1) and trigger the boot with the following command:
./sdm-test -b 0 1 zImage slave.dtbzImage and slave.dtb are available on branch
demo_slaves_sdm.This patch serie is a follow-up to "[RFC PATCH 0/8] Towards an Heterogeneous QEMU":
https://lists.gnu.org/archive/html/qemu-devel/2015-10/msg00171.htmlThis patch serie depends on:
- [RFC v2 0/6] SDM Interface
- [RFC v2 1/1] backend: multi-client-socketThis work has been sponsored by Huawei Technologies Duesseldorf GmbH.
Baptiste Reynal (3):
backend: shared memory backend
migration: add shared migration type
hw/misc: sdm signal shbootChristian Pinto (3):
qemu: slave machine flag
hw/arm: boot
qemu: numabackends/Makefile.objs | 2 +- backends/hostmem-shared.c | 198 ++++++++++++++++++++++++++++++++++++ hw/arm/boot.c | 13 +++ hw/core/machine.c | 27 +++++ hw/misc/Makefile.objs | 1 + hw/misc/sdm-signal-shboot.c | 62 +++++++++++ include/hw/boards.h | 2 + include/hw/misc/sdm-signal-shboot.h | 38 +++++++ include/migration/migration.h | 2 + include/sysemu/hostmem-shared.h | 66 ++++++++++++ migration/Makefile.objs | 2 +- migration/migration.c | 2 + migration/shared.c | 33 ++++++ numa.c | 17 +++- qemu-options.hx | 5 +- util/qemu-config.c | 5 + 16 files changed, 471 insertions(+), 4 deletions(-) create mode 100644 backends/hostmem-shared.c create mode 100644 hw/misc/sdm-signal-shboot.c create mode 100644 include/hw/misc/sdm-signal-shboot.h create mode 100644 include/sysemu/hostmem-shared.h create mode 100644 migration/shared.c
Quoted 17 lines · Baptiste Reynal
Quoted 8 lines · Markus Armbruster
Copying Paolo, author of memory-backend-file.
Quoted 3 lines · Baptiste Reynal
A new memory backend, the shared memory backend, based on the file memory backend.
Quoted 7 lines
Quoted 4 lines
This new backend allows a master QEMU instance to share a part of his main memory whith a slave QEMU instance. It is then possible to load a firmware on this memory and trigger the slave boot using a SDM signal.
Can you explain why that's useful in a bit more detail?
Quoted 8 lines
The purpose of such memory backend is to enable the modeling of asymmetric multiprocessing (AMP) configurations. An example is a multi-core ARM CPU working alongside with two Cortex-M micro controllers.
On such configurations many CPU (modeled by many QEMU instances) share the same memory bus. This patch series allows multiple QEMU instances to share the same file-backed memory bus.
All right, this is for implementing (heterogenous) multi-core via multiple QEMU instances. The alternative would be making one QEMU instance support more different CPUs. Which one is the more promising approach I can't say.
Quoted 12 lines
Quoted 5 lines
Quoted 2 lines
Such new backend enables, on a master side, to allocate the whole memory as shareable (e.g.
/dev/shm, or hugetlbfs).memory-backend-file can do that already. What exactly does memory-backend-shared add to it?
This memory-backend-shared allows multiple QEMU instances to share the same memory backend. A slave instance will have access only to a subset of the whole AMP system memory, by mapping just one part of the file as its memory. This can be considered as an MMU configured by the master processor to restrict slave memory accesses to only a subset of the whole system memory.
Quoted 4 lines
For the purpose of AMP modeling, a QEMU instance can be put in waiting mode (by using QEMU migration) until a master QEMU triggers its boot. It allows the master to fill the slave memory with its firmware before boot, in order to be compliant with the remoteproc framework (power on, load firmware, power off).
If I understand you correctly, you need two things: multiple QEMU instances sharing (some) memory, and a signalling mechanism between them.
memory-backend-file provides the former, but by itself can't provide the latter.
Is this roughly correct?
Quoted 24 lines · Markus Armbruster
Quoted 22 lines · Baptiste Reynal
Quoted 8 lines · Markus Armbruster
Copying Paolo, author of memory-backend-file.
Quoted 3 lines · Baptiste Reynal
A new memory backend, the shared memory backend, based on the file memory backend.
Quoted 7 lines
Quoted 4 lines
This new backend allows a master QEMU instance to share a part of his main memory whith a slave QEMU instance. It is then possible to load a firmware on this memory and trigger the slave boot using a SDM signal.
Can you explain why that's useful in a bit more detail?
The purpose of such memory backend is to enable the modeling of asymmetric multiprocessing (AMP) configurations. An example is a multi-core ARM CPU working alongside with two Cortex-M micro controllers.
Quoted 8 lines
Quoted 3 lines
On such configurations many CPU (modeled by many QEMU instances) share the same memory bus. This patch series allows multiple QEMU instances to share the same file-backed memory bus.
All right, this is for implementing (heterogenous) multi-core via multiple QEMU instances. The alternative would be making one QEMU instance support more different CPUs. Which one is the more promising approach I can't say.
We decided to implement it using multiple QEMU instances in order to reduce the impact on QEMU code.
Quoted 18 lines
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
Such new backend enables, on a master side, to allocate the whole memory as shareable (e.g.
/dev/shm, or hugetlbfs).memory-backend-file can do that already. What exactly does memory-backend-shared add to it?
This memory-backend-shared allows multiple QEMU instances to share the same memory backend. A slave instance will have access only to a subset of the whole AMP system memory, by mapping just one part of the file as its memory. This can be considered as an MMU configured by the master processor to restrict slave memory accesses to only a subset of the whole system memory.
Quoted 4 lines
For the purpose of AMP modeling, a QEMU instance can be put in waiting mode (by using QEMU migration) until a master QEMU triggers its boot. It allows the master to fill the slave memory with its firmware before boot, in order to be compliant with the remoteproc framework (power on, load firmware, power off).
Quoted 8 lines
If I understand you correctly, you need two things: multiple QEMU instances sharing (some) memory, and a signalling mechanism between them.
memory-backend-file provides the former, but by itself can't provide the latter.
Is this roughly correct?
Exactly. The signaling mechanism is handled by the SDM device, presented here:
https://www.mail-archive.com/[email protected]/msg361316.html
Quoted 29 lines · Baptiste Reynal
Quoted 28 lines · Markus Armbruster
Quoted 25 lines · Baptiste Reynal
Quoted 8 lines · Markus Armbruster
Copying Paolo, author of memory-backend-file.
Quoted 3 lines · Baptiste Reynal
A new memory backend, the shared memory backend, based on the file memory backend.
Quoted 7 lines
Quoted 4 lines
This new backend allows a master QEMU instance to share a part of his main memory whith a slave QEMU instance. It is then possible to load a firmware on this memory and trigger the slave boot using a SDM signal.
Can you explain why that's useful in a bit more detail?
The purpose of such memory backend is to enable the modeling of asymmetric multiprocessing (AMP) configurations. An example is a multi-core ARM CPU working alongside with two Cortex-M micro controllers.
On such configurations many CPU (modeled by many QEMU instances) share the same memory bus. This patch series allows multiple QEMU instances to share the same file-backed memory bus.
Quoted 7 lines
Quoted 4 lines
All right, this is for implementing (heterogenous) multi-core via multiple QEMU instances. The alternative would be making one QEMU instance support more different CPUs. Which one is the more promising approach I can't say.
We decided to implement it using multiple QEMU instances in order to reduce the impact on QEMU code.
Understood.
Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
Quoted 5 lines
Quoted 2 lines
Such new backend enables, on a master side, to allocate the whole memory as shareable (e.g.
/dev/shm, or hugetlbfs).memory-backend-file can do that already. What exactly does memory-backend-shared add to it?
This memory-backend-shared allows multiple QEMU instances to share the same memory backend. A slave instance will have access only to a subset of the whole AMP system memory, by mapping just one part of the file as its memory. This can be considered as an MMU configured by the master processor to restrict slave memory accesses to only a subset of the whole system memory.
Quoted 4 lines
For the purpose of AMP modeling, a QEMU instance can be put in waiting mode (by using QEMU migration) until a master QEMU triggers its boot. It allows the master to fill the slave memory with its firmware before boot, in order to be compliant with the remoteproc framework (power on, load firmware, power off).
If I understand you correctly, you need two things: multiple QEMU instances sharing (some) memory, and a signalling mechanism between them.
Quoted 8 lines
Quoted 4 lines
memory-backend-file provides the former, but by itself can't provide the latter.
Is this roughly correct?
Exactly. The signaling mechanism is handled by the SDM device, presented here:
https://www.mail-archive.com/[email protected]/msg361316.html
Got it, thanks.
I think your commit message needs to explain why memory-backend-file,share doesn't suffice for your use case (assuming it doesn't). You elaborated on your use case in reply to my question (quoted above), but 1. you didn't quite answer my question why memory-backend-file won't do, and 2. it should really be in git.
Quoted 10 lines · Baptiste Reynal
A new memory backend, the shared memory backend, based on the file memory backend.
This new backend allows a master QEMU instance to share a part of his main memory whith a slave QEMU instance. It is then possible to load a firmware on this memory and trigger the slave boot using a SDM signal.
Such new backend enables, on a master side, to allocate the whole memory as shareable (e.g.
/dev/shm, or hugetlbfs).
How is this different from qemu -mem-path which can be used for hugetlbfs?
Quoted 10 lines · Stefan Hajnoczi
Quoted 8 lines · Baptiste Reynal
A new memory backend, the shared memory backend, based on the file memory backend.
This new backend allows a master QEMU instance to share a part of his main memory whith a slave QEMU instance. It is then possible to load a firmware on this memory and trigger the slave boot using a SDM signal.
Quoted 5 lines
Quoted 2 lines
Such new backend enables, on a master side, to allocate the whole memory as shareable (e.g.
/dev/shm, or hugetlbfs).How is this different from qemu -mem-path which can be used for hugetlbfs?
A new mechanism is integrated here. This shared memory allows the slave to map dynamically only a subregion of the master memory, when with mempath the entire memory is shared.
A use-case can be the use of remoteproc framework on Linux. Remoteproc carveout a memory region and load the slave firmware to this region, then send the size and offset to the slave before boot. The slave memory region is unknown before master execution, it cannot be set in QEMU command line.
Quoted 17 lines · Baptiste Reynal
Quoted 10 lines · Stefan Hajnoczi
Quoted 8 lines · Baptiste Reynal
A new memory backend, the shared memory backend, based on the file memory backend.
This new backend allows a master QEMU instance to share a part of his main memory whith a slave QEMU instance. It is then possible to load a firmware on this memory and trigger the slave boot using a SDM signal.
Quoted 5 lines
Quoted 2 lines
Such new backend enables, on a master side, to allocate the whole memory as shareable (e.g.
/dev/shm, or hugetlbfs).How is this different from qemu -mem-path which can be used for hugetlbfs?
Quoted 8 lines
A new mechanism is integrated here. This shared memory allows the slave to map dynamically only a subregion of the master memory, when with mempath the entire memory is shared.
A use-case can be the use of remoteproc framework on Linux. Remoteproc carveout a memory region and load the slave firmware to this region, then send the size and offset to the slave before boot. The slave memory region is unknown before master execution, it cannot be set in QEMU command line.
Igor: Do you know what level of control QEMU already has for individual DIMMs backed by hugetlbfs? Is it possible to have just a specific physical memory range on hugetlbfs by defining individual DIMMs on the command-line?
Quoted 27 lines · On Wed, 6 Apr 2016 09:57:57 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 17 lines · Baptiste Reynal
Quoted 10 lines · Stefan Hajnoczi
Quoted 8 lines · Baptiste Reynal
A new memory backend, the shared memory backend, based on the file memory backend.
This new backend allows a master QEMU instance to share a part of his main memory whith a slave QEMU instance. It is then possible to load a firmware on this memory and trigger the slave boot using a SDM signal.
Quoted 5 lines
Quoted 2 lines
Such new backend enables, on a master side, to allocate the whole memory as shareable (e.g.
/dev/shm, or hugetlbfs).How is this different from qemu -mem-path which can be used for hugetlbfs?
Quoted 8 lines
A new mechanism is integrated here. This shared memory allows the slave to map dynamically only a subregion of the master memory, when with mempath the entire memory is shared.
A use-case can be the use of remoteproc framework on Linux. Remoteproc carveout a memory region and load the slave firmware to this region, then send the size and offset to the slave before boot. The slave memory region is unknown before master execution, it cannot be set in QEMU command line.
Quoted 4 lines
Igor: Do you know what level of control QEMU already has for individual DIMMs backed by hugetlbfs? Is it possible to have just a specific physical memory range on hugetlbfs by defining individual DIMMs on the command-line?
it should be possible by using memory-backend-file object with "mem-path" property pointing to hugetlbfs and property "share" should help to make it shared.
Also one could use backend for initial memory as well via
-numa xxx,memdev=foo
option
Quoted 34 lines · Igor Mammedov
Quoted 27 lines · On Wed, 6 Apr 2016 09:57:57 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 17 lines · Baptiste Reynal
Quoted 10 lines · Stefan Hajnoczi
Quoted 8 lines · Baptiste Reynal
A new memory backend, the shared memory backend, based on the file memory backend.
This new backend allows a master QEMU instance to share a part of his main memory whith a slave QEMU instance. It is then possible to load a firmware on this memory and trigger the slave boot using a SDM signal.
Quoted 5 lines
Quoted 2 lines
Such new backend enables, on a master side, to allocate the whole memory as shareable (e.g.
/dev/shm, or hugetlbfs).How is this different from qemu -mem-path which can be used for hugetlbfs?
Quoted 8 lines
A new mechanism is integrated here. This shared memory allows the slave to map dynamically only a subregion of the master memory, when with mempath the entire memory is shared.
A use-case can be the use of remoteproc framework on Linux. Remoteproc carveout a memory region and load the slave firmware to this region, then send the size and offset to the slave before boot. The slave memory region is unknown before master execution, it cannot be set in QEMU command line.Quoted 4 lines
Igor: Do you know what level of control QEMU already has for individual DIMMs backed by hugetlbfs? Is it possible to have just a specific physical memory range on hugetlbfs by defining individual DIMMs on the command-line?
Quoted 7 lines
it should be possible by using memory-backend-file object with "mem-path" property pointing to hugetlbfs and property "share" should help to make it shared.
Also one could use backend for initial memory as well via
-numa xxx,memdev=foo
option
Thanks for the help.
Quoted 1 line
From my understanding the solution will be each slave backed by a
different hugetlbfs file shared with the master. This solution seems acceptable. The dynamic aspect is lost but it is not mandatory. In some AMP implementation (i.e OMAP remoteproc) the entire memory is shared and the memory protection is assured by an IOMMU, the lack of IOMMU in this project forces us to have some static configuration at some point.
The next version will then focus on the incoming state with a boot signal.