qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [multiprocess RFC PATCH 08/37] multi-process: add functions


From: elena . ufimtseva
Subject: [Qemu-devel] [multiprocess RFC PATCH 08/37] multi-process: add functions to synchronize proxy and remote endpoints
Date: Wed, 6 Mar 2019 23:21:15 -0800

From: Jagannathan Raman <address@hidden>

In some cases, for example MMIO read, QEMU has to wait for the remote to
complete a command before proceeding. An eventfd based mechanism is
added to synchronize QEMU & remote process.

Signed-off-by: John G Johnson <address@hidden>
Signed-off-by: Jagannathan Raman <address@hidden>
Signed-off-by: Elena Ufimtseva <address@hidden>
---
 include/io/proxy-link.h |  9 +++++++++
 io/proxy-link.c         | 26 ++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h
index ff602e4..a12c565 100644
--- a/include/io/proxy-link.h
+++ b/include/io/proxy-link.h
@@ -28,7 +28,9 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <glib.h>
+#include <unistd.h>
 #include <pthread.h>
+#include <sys/eventfd.h>
 
 #include "qemu/osdep.h"
 #include "qom/object.h"
@@ -124,11 +126,18 @@ struct ProxyLinkState {
     proxy_link_callback callback;
 };
 
+#define GET_REMOTE_WAIT eventfd(0, 0)
+#define PUT_REMOTE_WAIT(wait) close(wait)
+#define PROXY_LINK_WAIT_DONE 1
+
 ProxyLinkState *proxy_link_create(void);
 void proxy_link_finalize(ProxyLinkState *s);
 
 void proxy_proc_send(ProxyLinkState *s, ProcMsg *msg);
 int proxy_proc_recv(ProxyLinkState *s, ProcMsg *msg);
+uint64_t wait_for_remote(int efd);
+void notify_proxy(int fd, uint64_t val);
+
 void proxy_link_set_sock(ProxyLinkState *s, int fd);
 void proxy_link_set_callback(ProxyLinkState *s, proxy_link_callback callback);
 void start_handler(ProxyLinkState *s);
diff --git a/io/proxy-link.c b/io/proxy-link.c
index 9ea0ed7..9f6ae77 100644
--- a/io/proxy-link.c
+++ b/io/proxy-link.c
@@ -31,6 +31,7 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
+#include <limits.h>
 
 #include "qemu/module.h"
 #include "io/proxy-link.h"
@@ -210,6 +211,31 @@ int proxy_proc_recv(ProxyLinkState *s, ProcMsg *msg)
     return rc;
 }
 
+uint64_t wait_for_remote(int efd)
+{
+    uint64_t val;
+
+    if (read(efd, &val, sizeof(val)) == -1) {
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: %s\n",
+                      strerror(errno));
+        return ULLONG_MAX;
+    }
+
+    val = (val == ULLONG_MAX) ? val : (val - 1);
+
+    return val;
+}
+
+void notify_proxy(int efd, uint64_t val)
+{
+    val = (val == ULLONG_MAX) ? val : (val + 1);
+
+    if (write(efd, &val, sizeof(val)) == -1) {
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error notify_proxy: %s\n",
+                      strerror(errno));
+    }
+}
+
 static gboolean proxy_link_handler_prepare(GSource *gsrc, gint *timeout)
 {
     g_assert(timeout);
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]