[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v4 PATCH 30/49] multi-process: send heartbeat messages to remote
From: |
Jagannathan Raman |
Subject: |
[RFC v4 PATCH 30/49] multi-process: send heartbeat messages to remote |
Date: |
Thu, 24 Oct 2019 05:09:11 -0400 |
From: Elena Ufimtseva <address@hidden>
In order to detect remote processes which are hung, the
proxy periodically sends heartbeat messages to confirm if
the remote process is alive
Signed-off-by: Jagannathan Raman <address@hidden>
Signed-off-by: John G Johnson <address@hidden>
Signed-off-by: Elena Ufimtseva <address@hidden>
---
hw/proxy/qemu-proxy.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++
include/io/mpqemu-link.h | 1 +
2 files changed, 102 insertions(+)
diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index fc1c731..691b991 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -53,14 +53,96 @@
#include "hw/boards.h"
#include "include/qemu/log.h"
+QEMUTimer *hb_timer;
static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
static void setup_irqfd(PCIProxyDev *dev);
+static void pci_dev_exit(PCIDevice *dev);
+static void start_heartbeat_timer(void);
+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);
+
+static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx)
+{
+ /* TODO: Add proper handler. */
+ printf("Child (pid %d) is dead? Signal is %d, Exit code is %d.\n",
+ siginfo->si_pid, siginfo->si_signo, siginfo->si_code);
+}
+
+static void broadcast_msg(MPQemuMsg *msg, bool need_reply)
+{
+ PCIProxyDev *entry;
+ unsigned int pid;
+ int wait;
+
+ QLIST_FOREACH(entry, &proxy_dev_list.devices, next) {
+ if (need_reply) {
+ wait = eventfd(0, EFD_NONBLOCK);
+ msg->num_fds = 1;
+ msg->fds[0] = wait;
+ }
+
+ mpqemu_msg_send(entry->mpqemu_link, msg, entry->mpqemu_link->com);
+ if (need_reply) {
+ pid = (uint32_t)wait_for_remote(wait);
+ close(wait);
+ /* TODO: Add proper handling. */
+ if (pid) {
+ need_reply = 0;
+ }
+ }
+ }
+}
+
+#define NOP_INTERVAL 1000000
+
+static void remote_ping(void *opaque)
+{
+ MPQemuMsg msg;
+
+ memset(&msg, 0, sizeof(MPQemuMsg));
+
+ msg.num_fds = 0;
+ msg.cmd = PROXY_PING;
+ msg.bytestream = 0;
+ msg.size = 0;
+
+ broadcast_msg(&msg, true);
+ timer_mod(hb_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL);
+
+}
+
+void start_heartbeat_timer(void)
+{
+ hb_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
+ remote_ping,
+ &proxy_dev_list);
+ timer_mod(hb_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL);
+
+}
+
+static void stop_heartbeat_timer(void)
+{
+ timer_del(hb_timer);
+ timer_free(hb_timer);
+}
+
+static void set_sigchld_handler(void)
+{
+ struct sigaction sa_sigterm;
+ memset(&sa_sigterm, 0, sizeof(sa_sigterm));
+ sa_sigterm.sa_sigaction = childsig_handler;
+ sa_sigterm.sa_flags = SA_SIGINFO | SA_NOCLDWAIT | SA_NOCLDSTOP;
+ sigaction(SIGCHLD, &sa_sigterm, NULL);
+}
static void proxy_ready(PCIDevice *dev)
{
PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
setup_irqfd(pdev);
+ set_sigchld_handler();
+ start_heartbeat_timer();
}
static void set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd)
@@ -259,6 +341,7 @@ static void pci_proxy_dev_class_init(ObjectClass *klass,
void *data)
PCIDeviceClass *k = PCI_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;
}
@@ -397,6 +480,24 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error
**errp)
dev->proxy_ready = proxy_ready;
}
+static void pci_dev_exit(PCIDevice *pdev)
+{
+ PCIProxyDev *entry, *sentry;
+ PCIProxyDev *dev = PCI_PROXY_DEV(pdev);
+
+ stop_heartbeat_timer();
+
+ QLIST_FOREACH_SAFE(entry, &proxy_dev_list.devices, next, sentry) {
+ if (entry->remote_pid == dev->remote_pid) {
+ QLIST_REMOVE(entry, next);
+ }
+ }
+
+ if (!QLIST_EMPTY(&proxy_dev_list.devices)) {
+ start_heartbeat_timer();
+ }
+}
+
static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
bool write, hwaddr addr, uint64_t *val,
unsigned size, bool memory)
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 3145b0e..16a913b 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -72,6 +72,7 @@ typedef enum {
DRIVE_OPTS,
DEVICE_ADD,
DEVICE_DEL,
+ PROXY_PING,
MAX,
} mpqemu_cmd_t;
--
1.8.3.1
- [RFC v4 PATCH 19/49] multi-process: configure remote side devices, (continued)
- [RFC v4 PATCH 19/49] multi-process: configure remote side devices, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 18/49] multi-process: create IOHUB object to handle irq, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 20/49] multi-process: add qdev_proxy_add to create proxy devices, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 21/49] multi-process: remote: add setup_devices and setup_drive msg processing, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 22/49] multi-process: remote: use fd for socket from parent process, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 23/49] multi-process: remote: add create_done condition, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 24/49] multi-process: add processing of remote drive and device command line, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 26/49] multi-process: refractor vl.c code to re-use in remote, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 27/49] multi-process: add remote option, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 28/49] multi-process: add remote options parser, Jagannathan Raman, 2019/10/24
- [RFC v4 PATCH 30/49] multi-process: send heartbeat messages to remote,
Jagannathan Raman <=
- [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, 2019/10/24