Message ID | 013cbc654f4f22a60659e580e98bd45925614866.1586165556.git.elena.ufimtseva@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Initial support for multi-process qemu | expand |
* elena.ufimtseva@oracle.com (elena.ufimtseva@oracle.com) wrote: > 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> > --- > include/io/mpqemu-link.h | 7 +++++++ > io/mpqemu-link.c | 41 ++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 48 insertions(+) > > diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h > index af401e640c..ef95599bca 100644 > --- a/include/io/mpqemu-link.h > +++ b/include/io/mpqemu-link.h > @@ -124,4 +124,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s, > void mpqemu_start_coms(MPQemuLinkState *s, MPQemuChannel* chan); > bool mpqemu_msg_valid(MPQemuMsg *msg); > > +#define GET_REMOTE_WAIT eventfd(0, EFD_CLOEXEC) > +#define PUT_REMOTE_WAIT(wait) close(wait) > +#define PROXY_LINK_WAIT_DONE 1 > + > +uint64_t wait_for_remote(int efd); > +void notify_proxy(int fd, uint64_t val); > + > #endif > diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c > index b7d3e53ae8..fa9b3a66b1 100644 > --- a/io/mpqemu-link.c > +++ b/io/mpqemu-link.c > @@ -10,6 +10,7 @@ > > #include "qemu/osdep.h" > #include "qemu-common.h" > +#include <poll.h> > > #include "qemu/module.h" > #include "io/mpqemu-link.h" > @@ -204,6 +205,46 @@ int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan) > 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; These don't seem to have changed since my review of v5 on the 4th March in which Jag said they would change to UINT64_MAX etc and there would be a big comment etc on the next function. Dave > +} > + > +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 mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout) > { > g_assert(timeout); > -- > 2.25.GIT > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index af401e640c..ef95599bca 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -124,4 +124,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s, void mpqemu_start_coms(MPQemuLinkState *s, MPQemuChannel* chan); bool mpqemu_msg_valid(MPQemuMsg *msg); +#define GET_REMOTE_WAIT eventfd(0, EFD_CLOEXEC) +#define PUT_REMOTE_WAIT(wait) close(wait) +#define PROXY_LINK_WAIT_DONE 1 + +uint64_t wait_for_remote(int efd); +void notify_proxy(int fd, uint64_t val); + #endif diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index b7d3e53ae8..fa9b3a66b1 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -10,6 +10,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include <poll.h> #include "qemu/module.h" #include "io/mpqemu-link.h" @@ -204,6 +205,46 @@ int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan) 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 mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout) { g_assert(timeout);