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 08/35] multi-process: add functions to synchronize proxy and remote endpoints
Date: Mon, 17 Jun 2019 11:15:29 -0700 [thread overview]
Message-ID: <20190617181529.29468-1-elena.ufimtseva@oracle.com> (raw)
From: Jagannathan Raman <jag.raman@oracle.com>
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 <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
Changes in v2:
- Added timeout to communication channel.
---
include/io/proxy-link.h | 9 +++++++++
io/proxy-link.c | 42 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h
index fb266ca2a8..2f1584e87d 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 75e0bb5e27..9bda646f39 100644
--- a/io/proxy-link.c
+++ b/io/proxy-link.c
@@ -31,6 +31,8 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
+#include <limits.h>
+#include <poll.h>
#include "qemu/module.h"
#include "io/proxy-link.h"
@@ -210,6 +212,46 @@ int proxy_proc_recv(ProxyLinkState *s, ProcMsg *msg)
return rc;
}
+uint64_t wait_for_remote(int efd)
+{
+ struct pollfd pfd = { .fd = efd, .events = POLLIN };
+ uint64_t val;
+ int ret;
+
+ ret = poll(&pfd, 1, 1000);
+
+ switch (ret) {
+ case 0:
+ qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: Timed out\n");
+ /* TODO: Kick-off error recovery */
+ return ULLONG_MAX;
+ case -1:
+ qemu_log_mask(LOG_REMOTE_DEBUG, "Poll error wait_for_remote: %s\n",
+ strerror(errno));
+ return ULLONG_MAX;
+ default:
+ 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);
--
2.17.1
reply other threads:[~2019-06-17 18:23 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=20190617181529.29468-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).