From: elena.ufimtseva@oracle.com
To: qemu-devel@nongnu.org
Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com,
jag.raman@oracle.com, konrad.wilk@oracle.com,
berrange@redhat.com, ross.lagerwall@citrix.com,
liran.alon@oracle.com, stefanha@redhat.com,
kanth.ghatraju@oracle.com
Subject: [Qemu-devel] [RFC PATCH v2 29/35] multi-process: add heartbeat timer and signal handler
Date: Mon, 17 Jun 2019 11:16:50 -0700 [thread overview]
Message-ID: <20190617181650.30461-1-elena.ufimtseva@oracle.com> (raw)
From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Add a signal handler for launched remote processes and set up
the heartbit timer for remote processes.
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
hw/proxy/qemu-proxy.c | 101 ++++++++++++++++++++++++++++++++++++++++
include/io/proxy-link.h | 1 +
2 files changed, 102 insertions(+)
diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 1666cc546e..4ee7521987 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -60,14 +60,96 @@
*/
int kvm_vm_ioctl(KVMState *s, int type, ...);
+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(ProcMsg *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(ProcMsg *msg, bool need_reply)
+{
+ PCIProxyDev *entry;
+ unsigned int pid;
+ int wait;
+
+ QLIST_FOREACH(entry, &proxy_dev_list.devices, next) {
+ if (need_reply) {
+ wait = GET_REMOTE_WAIT;
+ msg->num_fds = 1;
+ msg->fds[0] = wait;
+ }
+
+ proxy_proc_send(entry->proxy_link, msg);
+ if (need_reply) {
+ pid = (uint32_t)wait_for_remote(wait);
+ PUT_REMOTE_WAIT(wait);
+ /* TODO: Add proper handling. */
+ if (pid) {
+ need_reply = 0;
+ }
+ }
+ }
+}
+
+#define NOP_INTERVAL 1000000
+
+static void remote_ping(void *opaque)
+{
+ ProcMsg msg;
+
+ memset(&msg, 0, sizeof(ProcMsg));
+
+ 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)
@@ -228,6 +310,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;
}
@@ -357,6 +440,24 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
}
+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(ProxyLinkState *proxy_link, MemoryRegion *mr,
bool write, hwaddr addr, uint64_t *val,
unsigned size, bool memory)
diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h
index 38bd80535a..2ba3e614f0 100644
--- a/include/io/proxy-link.h
+++ b/include/io/proxy-link.h
@@ -76,6 +76,7 @@ typedef enum {
DRIVE_OPTS,
DEVICE_ADD,
DEVICE_DEL,
+ PROXY_PING,
MAX,
} proc_cmd_t;
--
2.17.1
reply other threads:[~2019-06-17 18:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190617181650.30461-1-elena.ufimtseva@oracle.com \
--to=elena.ufimtseva@oracle.com \
--cc=berrange@redhat.com \
--cc=jag.raman@oracle.com \
--cc=john.g.johnson@oracle.com \
--cc=kanth.ghatraju@oracle.com \
--cc=konrad.wilk@oracle.com \
--cc=liran.alon@oracle.com \
--cc=qemu-devel@nongnu.org \
--cc=ross.lagerwall@citrix.com \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).