Support shared memory with broadcast interrupts using eventfd
RFC PATCH 2/2 Support shared memory with broadcast interrupts using eventfd
This patch supports shared memory between multiple VMs as well as point-to-point and broadcast interrupts via eventfds.
This is the third version of this patch. There is an increase in complexity due to supporting multiple VMs, eventfds and a shared memory server.
Instead of having one VM act as a server, the VMs now access a shared memory card server that runs on the host and passes the shared memory fd as well as the eventfds to each VM on startup. The server also manages updates to existing guests when a new guest connects and notification of when VMs disconnect.
The command-line parameter is now
-ivshmem <size in MB>,unix:<path>
where the first parameter is the size of shared memory to map into the device and the path is the unix domain socket of the shared memory card server.
When a VM connects to the server it receives a file descriptor for the shared memory and one eventfd for each running VM. Already running VMs then receive an update for the new VM's eventfd via a persistent connection to the server. The server only handles connections and updates, so it is not in the critical path.
Interrupts are triggered from a guest by ioctl. Magic numbers are defined in a enum for different interrupts. Currently, the driver supports a semaphore and wait event queue. Implementation is still light at this point in how
interrupts can be used and will continue to be fleshed out. The destination
of the VM is specified as an argument to the ioctl by global ID. VMs can determine their ID by ioctl. They can also get a bit vector of active global IDs. Broadcast interrupts are supported by sending the magic '255' as the destination ID.
With the added interrupts and broadcast, producer-consumer interaction and barriers between VMs are now possible. Using eventfds lowers overhead versus sockets.
There are lots of rough edges due to the added complexity. Feedback is much appreciated.
Cam
--- Makefile.target | 3 + hw/ivshmem.c | 591 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pc.c | 6 + hw/pc.h | 3 + qemu-options.hx | 12 ++ sysemu.h | 8 + vl.c | 14 ++ 7 files changed, 637 insertions(+), 0 deletions(-) create mode 100644 hw/ivshmem.c
Makefile.target +3 -0
@@ -603,6 +603,9 @@ obj-y += pcnet.o obj-y += rtl8139.o obj-y += e1000.o +# Inter-VM PCI shared memory +obj-y += ivshmem.o + # Generic watchdog support and some watchdog devices obj-y += wdt_ib700.o wdt_i6300esb.o
hw/ivshmem.c new file +591 -0
591 lines not on this page · raw message
hw/pc.c +6 -0
@@ -68,6 +68,8 @@ static PITState *pit;static IOAPICState *ioapic;static PCIDevice *i440fx_state; +extern int ivshmem_enabled; + typedef struct rom_reset_data { uint8_t *data; target_phys_addr_t addr;
@@ -1293,6 +1295,10 @@ static void pc_init1(ram_addr_t ram_size, } } +if (pci_enabled && ivshmem_enabled) { +pci_ivshmem_init (pci_bus); + } + rtc_state =rtc_init (0x70 , i8259[8 ],2000 );qemu_register_boot_set (pc_boot_set, rtc_state);
hw/pc.h +3 -0
@@ -183,6 +183,9 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd);void extboot_init (BlockDriverState *bs,int cmd); +/* ivshmem.c */ +int pci_ivshmem_init (PCIBus *bus); +int cpu_is_bsp (CPUState *env);#endif
qemu-options.hx +12 -0
@@ -1310,6 +1310,18 @@ The default device is @code{vc} in graphical mode and @code{stdio} in non graphical mode. ETEXI +DEF("ivshmem", HAS_ARG, QEMU_OPTION_ivshmem, \ + "-ivshmem size,unix:file connects to shared memory PCI card server \ + listening on unix domain socket 'path' of at least 'size' (in MB) and \ + exposes as a PCI device in the guest\n") +STEXI +@item -ivshmem @var{size},unix:@var{file} +Connects to a shared memory PCI server at UDS @var{file} that shares a POSIX +shared object of size @var{size} and creates a PCI device of the same size that +maps the shared object (received from the server) into the device for guests to +access. The servers also sends eventfds to the guest to support interrupts. +ETEXI + DEF("pidfile", HAS_ARG, QEMU_OPTION_pidfile, \ "-pidfile file write PID to 'file'\n") STEXI
sysemu.h +8 -0
@@ -240,6 +240,14 @@ extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES ]; +/* inter-VM shared memory devices */ + +#define MAX_IVSHMEM_DEVICES 1 + +extern CharDriverState * ivshmem_chardev; +void ivshmem_init (const char * optarg); +int ivshmem_get_size (void ); +#define TFR (expr) do { if ((expr) != -1) break; } while (errno == EINTR)#ifdef NEED_CPU_H
vl.c +14 -0
@@ -203,6 +203,7 @@ static int rtc_date_offset = -1; /* -1 means no change */int cirrus_vga_enabled =1 ;int std_vga_enabled =0 ;int vmsvga_enabled =0 ; +int ivshmem_enabled =0 ;int xenfb_enabled =0 ;#ifdef TARGET_SPARC int graphic_width =1024 ;
@@ -221,6 +222,8 @@ int no_quit = 0;CharDriverState *serial_hds[MAX_SERIAL_PORTS ];CharDriverState *parallel_hds[MAX_PARALLEL_PORTS ];CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES ]; +CharDriverState *ivshmem_chardev; +const char * ivshmem_device;#ifdef TARGET_I386 int win2k_install_hack =0 ;int rtc_td_hack =0 ;
@@ -4915,6 +4918,8 @@ int main(int argc, char **argv, char **envp) cyls = heads = secs =0 ; translation =BIOS_ATA_TRANSLATION_AUTO ; monitor_device ="vc:80Cx24C" ; + ivshmem_device =NULL ; + ivshmem_chardev =NULL ; serial_devices[0 ] ="vc:80Cx24C" ;for (i =1 ; i <MAX_SERIAL_PORTS ; i++)
@@ -5368,6 +5373,10 @@ int main(int argc, char **argv, char **envp) parallel_devices[parallel_device_index] = optarg; parallel_device_index++;break ; +case QEMU_OPTION_ivshmem: + ivshmem_device = optarg; + ivshmem_enabled =1 ; +break ;case QEMU_OPTION_loadvm: loadvm = optarg;break ;
@@ -5817,6 +5826,11 @@ int main(int argc, char **argv, char **envp)if (ram_size ==0 ) ram_size =DEFAULT_RAM_SIZE *1024 *1024 ; +if (ivshmem_enabled) { +ivshmem_init (ivshmem_device); + ram_size +=ivshmem_get_size (); + } +#ifdef CONFIG_KQEMU /* FIXME: This is a nasty hack because kqemu can't cope with dynamic guest ram allocation. It needs to go away. */
Signature · 1 line
1.6.0.6