[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v4 PATCH 41/49] multi-process/mig: Enable VMSD save in the Proxy ob
From: |
Jagannathan Raman |
Subject: |
[RFC v4 PATCH 41/49] multi-process/mig: Enable VMSD save in the Proxy object |
Date: |
Thu, 24 Oct 2019 05:09:22 -0400 |
Collect the VMSD from remote process on the source and save
it to the channel leading to the destination
Signed-off-by: Elena Ufimtseva <address@hidden>
Signed-off-by: John G Johnson <address@hidden>
Signed-off-by: Jagannathan Raman <address@hidden>
---
New patch in v4
hw/proxy/qemu-proxy.c | 132 ++++++++++++++++++++++++++++++++++++++++++
include/hw/proxy/qemu-proxy.h | 2 +
include/io/mpqemu-link.h | 1 +
3 files changed, 135 insertions(+)
diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 623a6c5..ce72e6a 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -52,6 +52,14 @@
#include "util/event_notifier-posix.c"
#include "hw/boards.h"
#include "include/qemu/log.h"
+#include "io/channel.h"
+#include "migration/qemu-file-types.h"
+#include "qapi/error.h"
+#include "io/channel-util.h"
+#include "migration/qemu-file-channel.h"
+#include "migration/qemu-file.h"
+#include "migration/migration.h"
+#include "migration/vmstate.h"
QEMUTimer *hb_timer;
static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
@@ -62,6 +70,9 @@ static void stop_heartbeat_timer(void);
static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx);
static void broadcast_msg(MPQemuMsg *msg, bool need_reply);
+#define PAGE_SIZE getpagesize()
+uint8_t *mig_data;
+
static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx)
{
/* TODO: Add proper handler. */
@@ -357,14 +368,135 @@ static void pci_proxy_dev_inst_init(Object *obj)
dev->mem_init = false;
}
+typedef struct {
+ QEMUFile *rem;
+ PCIProxyDev *dev;
+} proxy_mig_data;
+
+static void *proxy_mig_out(void *opaque)
+{
+ proxy_mig_data *data = opaque;
+ PCIProxyDev *dev = data->dev;
+ uint8_t byte;
+ uint64_t data_size = PAGE_SIZE;
+
+ mig_data = g_malloc(data_size);
+
+ while (true) {
+ byte = qemu_get_byte(data->rem);
+ mig_data[dev->migsize++] = byte;
+ if (dev->migsize == data_size) {
+ data_size += PAGE_SIZE;
+ mig_data = g_realloc(mig_data, data_size);
+ }
+ }
+
+ return NULL;
+}
+
+static int proxy_pre_save(void *opaque)
+{
+ PCIProxyDev *pdev = opaque;
+ proxy_mig_data *mig_data;
+ QEMUFile *f_remote;
+ MPQemuMsg msg = {0};
+ QemuThread thread;
+ Error *err = NULL;
+ QIOChannel *ioc;
+ uint64_t size;
+ int fd[2];
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
+ return -1;
+ }
+
+ ioc = qio_channel_new_fd(fd[0], &err);
+ if (err) {
+ error_report_err(err);
+ return -1;
+ }
+
+ qio_channel_set_name(QIO_CHANNEL(ioc), "PCIProxyDevice-mig");
+
+ f_remote = qemu_fopen_channel_input(ioc);
+
+ pdev->migsize = 0;
+
+ mig_data = g_malloc0(sizeof(proxy_mig_data));
+ mig_data->rem = f_remote;
+ mig_data->dev = pdev;
+
+ qemu_thread_create(&thread, "Proxy MIG_OUT", proxy_mig_out, mig_data,
+ QEMU_THREAD_DETACHED);
+
+ msg.cmd = START_MIG_OUT;
+ msg.bytestream = 0;
+ msg.num_fds = 2;
+ msg.fds[0] = fd[1];
+ msg.fds[1] = GET_REMOTE_WAIT;
+
+ mpqemu_msg_send(pdev->mpqemu_link, &msg, pdev->mpqemu_link->com);
+ size = wait_for_remote(msg.fds[1]);
+ PUT_REMOTE_WAIT(msg.fds[1]);
+
+ assert(size != ULLONG_MAX);
+
+ /*
+ * migsize is being update by a separate thread. Using volatile to
+ * instruct the compiler to fetch the value of this variable from
+ * memory during every read
+ */
+ while (*((volatile uint64_t *)&pdev->migsize) < size) {
+ }
+
+ qemu_thread_cancel(&thread);
+
+ qemu_fclose(f_remote);
+ close(fd[1]);
+
+ return 0;
+}
+
+static int proxy_post_save(void *opaque)
+{
+ MigrationState *ms = migrate_get_current();
+ PCIProxyDev *pdev = opaque;
+ uint64_t pos = 0;
+
+ while (pos < pdev->migsize) {
+ qemu_put_byte(ms->to_dst_file, mig_data[pos]);
+ pos++;
+ }
+
+ qemu_fflush(ms->to_dst_file);
+
+ return 0;
+}
+
+const VMStateDescription vmstate_pci_proxy_device = {
+ .name = "PCIProxyDevice",
+ .version_id = 2,
+ .minimum_version_id = 1,
+ .pre_save = proxy_pre_save,
+ .post_save = proxy_post_save,
+ .fields = (VMStateField[]) {
+ VMSTATE_PCI_DEVICE(parent_dev, PCIProxyDev),
+ VMSTATE_UINT64(migsize, PCIProxyDev),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
{
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+ DeviceClass *dc = DEVICE_CLASS(klass);
k->realize = pci_proxy_dev_realize;
k->exit = pci_dev_exit;
k->config_read = pci_proxy_read_config;
k->config_write = pci_proxy_write_config;
+
+ dc->vmsd = &vmstate_pci_proxy_device;
}
static const TypeInfo pci_proxy_dev_type_info = {
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index 17e07ac..b122e6d 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -89,6 +89,8 @@ struct PCIProxyDev {
void (*init_proxy) (PCIDevice *dev, char *command, bool need_spawn, Error
**errp);
ProxyMemoryRegion region[PCI_NUM_REGIONS];
+
+ uint64_t migsize;
};
typedef struct PCIProxyDevClass {
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 6fcc6f5..0ed7750 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -75,6 +75,7 @@ typedef enum {
PROXY_PING,
MMIO_RETURN,
DEVICE_RESET,
+ START_MIG_OUT,
MAX,
} mpqemu_cmd_t;
--
1.8.3.1
- [RFC v4 PATCH 30/49] multi-process: send heartbeat messages to remote, (continued)
- [RFC v4 PATCH 30/49] multi-process: send heartbeat messages to remote, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 31/49] multi-process: handle heartbeat messages in remote process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 32/49] multi-process: Use separate MMIO communication channel, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 34/49] multi-process/mon: choose HMP commands based on target, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 35/49] multi-process/mon: stub functions to enable QMP module for remote process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 36/49] multi-process/mon: enable QMP module support in the remote process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 38/49] multi-process/mon: Initialize QMP module for remote processes, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 37/49] multi-process/mon: Refactor monitor/chardev functions out of vl.c, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 39/49] multi-process: prevent duplicate memory initialization in remote, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 40/49] multi-process/mig: build migration module in the remote process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 41/49] multi-process/mig: Enable VMSD save in the Proxy object,
Jagannathan Raman <=
- [RFC v4 PATCH 42/49] multi-process/mig: Send VMSD of remote to the Proxy object, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 44/49] multi-process/mig: refactor runstate_check into common file, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 45/49] multi-process/mig: Synchronize runstate of remote process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 47/49] multi-process: Enable support for multiple devices in remote, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 08/49] multi-process: add functions to synchronize proxy and remote endpoints, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 07/49] multi-process: define mpqemu-link object, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 49/49] multi-process: add configure and usage information, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 48/49] multi-process: add the concept description to docs/devel/qemu-multiprocess, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 12/49] multi-process: remote process initialization, Jagannathan Raman, 2019/10/24