From: Anthony Liguori <anthony@codemonkey.ws>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, aliguori@linux.vnet.ibm.com,
stefanha@linux.vnet.ibm.com, sw@weilnetz.de
Subject: Re: [Qemu-devel] [PATCH 03/12] main-loop: use event notifiers
Date: Thu, 19 Jul 2012 14:04:58 -0500 [thread overview]
Message-ID: <87k3xz7esl.fsf@codemonkey.ws> (raw)
In-Reply-To: <1342435377-25897-4-git-send-email-pbonzini@redhat.com>
Paolo Bonzini <pbonzini@redhat.com> writes:
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Regards,
Anthony Liguori
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> Makefile.objs | 4 +--
> main-loop.c | 106 ++++++++-------------------------------------------------
> oslib-posix.c | 31 -----------------
> qemu-common.h | 1 -
> 4 files changed, 17 insertions(+), 125 deletions(-)
>
> diff --git a/Makefile.objs b/Makefile.objs
> index ecdfaf9..6ed1981 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -20,8 +20,8 @@ universal-obj-y += $(qom-obj-y)
> #######################################################################
> # oslib-obj-y is code depending on the OS (win32 vs posix)
> oslib-obj-y = osdep.o
> -oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
> -oslib-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
> +oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o event_notifier-win32.o
> +oslib-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o event_notifier-posix.o
>
> #######################################################################
> # coroutines
> diff --git a/main-loop.c b/main-loop.c
> index eb3b6e6..81f49b3 100644
> --- a/main-loop.c
> +++ b/main-loop.c
> @@ -26,75 +26,12 @@
> #include "qemu-timer.h"
> #include "slirp/slirp.h"
> #include "main-loop.h"
> +#include "event_notifier.h"
>
> #ifndef _WIN32
>
> #include "compatfd.h"
>
> -static int io_thread_fd = -1;
> -
> -void qemu_notify_event(void)
> -{
> - /* Write 8 bytes to be compatible with eventfd. */
> - static const uint64_t val = 1;
> - ssize_t ret;
> -
> - if (io_thread_fd == -1) {
> - return;
> - }
> - do {
> - ret = write(io_thread_fd, &val, sizeof(val));
> - } while (ret < 0 && errno == EINTR);
> -
> - /* EAGAIN is fine, a read must be pending. */
> - if (ret < 0 && errno != EAGAIN) {
> - fprintf(stderr, "qemu_notify_event: write() failed: %s\n",
> - strerror(errno));
> - exit(1);
> - }
> -}
> -
> -static void qemu_event_read(void *opaque)
> -{
> - int fd = (intptr_t)opaque;
> - ssize_t len;
> - char buffer[512];
> -
> - /* Drain the notify pipe. For eventfd, only 8 bytes will be read. */
> - do {
> - len = read(fd, buffer, sizeof(buffer));
> - } while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
> -}
> -
> -static int qemu_event_init(void)
> -{
> - int err;
> - int fds[2];
> -
> - err = qemu_eventfd(fds);
> - if (err == -1) {
> - return -errno;
> - }
> - err = fcntl_setfl(fds[0], O_NONBLOCK);
> - if (err < 0) {
> - goto fail;
> - }
> - err = fcntl_setfl(fds[1], O_NONBLOCK);
> - if (err < 0) {
> - goto fail;
> - }
> - qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL,
> - (void *)(intptr_t)fds[0]);
> -
> - io_thread_fd = fds[1];
> - return 0;
> -
> -fail:
> - close(fds[0]);
> - close(fds[1]);
> - return err;
> -}
> -
> /* If we have signalfd, we mask out the signals we want to handle and then
> * use signalfd to listen for them. We rely on whatever the current signal
> * handler is to dispatch the signals when we receive them.
> @@ -164,40 +101,22 @@ static int qemu_signal_init(void)
>
> #else /* _WIN32 */
>
> -static HANDLE qemu_event_handle = NULL;
> -
> -static void dummy_event_handler(void *opaque)
> -{
> -}
> -
> -static int qemu_event_init(void)
> +static int qemu_signal_init(void)
> {
> - qemu_event_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
> - if (!qemu_event_handle) {
> - fprintf(stderr, "Failed CreateEvent: %ld\n", GetLastError());
> - return -1;
> - }
> - qemu_add_wait_object(qemu_event_handle, dummy_event_handler, NULL);
> return 0;
> }
> +#endif
> +
> +static EventNotifier io_thread_notifier;
> +static int io_thread_initialized;
>
> void qemu_notify_event(void)
> {
> - if (!qemu_event_handle) {
> + if (!io_thread_initialized) {
> return;
> }
> - if (!SetEvent(qemu_event_handle)) {
> - fprintf(stderr, "qemu_notify_event: SetEvent failed: %ld\n",
> - GetLastError());
> - exit(1);
> - }
> -}
> -
> -static int qemu_signal_init(void)
> -{
> - return 0;
> + event_notifier_set(&io_thread_notifier);
> }
> -#endif
>
> int main_loop_init(void)
> {
> @@ -210,11 +129,15 @@ int main_loop_init(void)
> }
>
> /* Note eventfd must be drained before signalfd handlers run */
> - ret = qemu_event_init();
> + ret = event_notifier_init(&io_thread_notifier, 0);
> if (ret) {
> return ret;
> }
>
> + io_thread_initialized = true;
> + event_notifier_set_handler(&io_thread_notifier,
> + (EventNotifierHandler *)
> + event_notifier_test_and_clear);
> return 0;
> }
>
> @@ -400,7 +323,8 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
>
> void qemu_fd_register(int fd)
> {
> - WSAEventSelect(fd, qemu_event_handle, FD_READ | FD_ACCEPT | FD_CLOSE |
> + WSAEventSelect(fd, event_notifier_get_handle(&io_thread_notifier),
> + FD_READ | FD_ACCEPT | FD_CLOSE |
> FD_CONNECT | FD_WRITE | FD_OOB);
> }
>
> diff --git a/oslib-posix.c b/oslib-posix.c
> index 6b7ba64..2c6b044 100644
> --- a/oslib-posix.c
> +++ b/oslib-posix.c
> @@ -58,9 +58,6 @@ static int running_on_valgrind = -1;
> #ifdef CONFIG_LINUX
> #include <sys/syscall.h>
> #endif
> -#ifdef CONFIG_EVENTFD
> -#include <sys/eventfd.h>
> -#endif
>
> int qemu_get_thread_id(void)
> {
> @@ -180,34 +177,6 @@ int qemu_pipe(int pipefd[2])
> return ret;
> }
>
> -/*
> - * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set.
> - */
> -int qemu_eventfd(int fds[2])
> -{
> -#ifdef CONFIG_EVENTFD
> - int ret;
> -
> - ret = eventfd(0, 0);
> - if (ret >= 0) {
> - fds[0] = ret;
> - fds[1] = dup(ret);
> - if (fds[1] == -1) {
> - close(ret);
> - return -1;
> - }
> - qemu_set_cloexec(ret);
> - qemu_set_cloexec(fds[1]);
> - return 0;
> - }
> - if (errno != ENOSYS) {
> - return -1;
> - }
> -#endif
> -
> - return qemu_pipe(fds);
> -}
> -
> int qemu_utimens(const char *path, const struct timespec *times)
> {
> struct timeval tv[2], tv_now;
> diff --git a/qemu-common.h b/qemu-common.h
> index 9d9e603..036d254 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -195,7 +195,6 @@ ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags)
> QEMU_WARN_UNUSED_RESULT;
>
> #ifndef _WIN32
> -int qemu_eventfd(int pipefd[2]);
> int qemu_pipe(int pipefd[2]);
> #endif
>
> --
> 1.7.10.4
next prev parent reply other threads:[~2012-07-19 19:05 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-16 10:42 [Qemu-devel] [PATCH 00/12] Portable thread-pool/AIO, Win32 emulated AIO Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 01/12] event_notifier: enable it to use pipes Paolo Bonzini
2012-07-19 18:58 ` Anthony Liguori
2012-07-16 10:42 ` [Qemu-devel] [PATCH 02/12] event_notifier: add Win32 implementation Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 03/12] main-loop: use event notifiers Paolo Bonzini
2012-07-19 19:04 ` Anthony Liguori [this message]
2012-07-16 10:42 ` [Qemu-devel] [PATCH 04/12] aio: provide platform-independent API Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 05/12] aio: add Win32 implementation Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 06/12] linux-aio: use event notifiers Paolo Bonzini
2012-07-19 19:10 ` Anthony Liguori
2012-07-16 10:42 ` [Qemu-devel] [PATCH 07/12] qemu-thread: add QemuSemaphore Paolo Bonzini
2012-07-16 12:00 ` Jan Kiszka
2012-07-16 12:01 ` [Qemu-devel] [PATCH] qemu-thread: Introduce qemu_cond_timedwait for POSIX Jan Kiszka
2012-07-16 13:20 ` [Qemu-devel] [PATCH 07/12] qemu-thread: add QemuSemaphore Paolo Bonzini
2012-07-16 13:34 ` Jan Kiszka
2012-07-16 13:35 ` Paolo Bonzini
2012-07-16 13:53 ` Jan Kiszka
2012-07-16 14:03 ` Paolo Bonzini
2012-07-16 14:09 ` Jan Kiszka
2012-07-16 14:20 ` Paolo Bonzini
2012-07-24 16:55 ` Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 08/12] aio: add generic thread-pool facility Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 09/12] block: switch posix-aio-compat to threadpool Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 10/12] raw: merge posix-aio-compat.c into block/raw-posix.c Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 11/12] raw-posix: rename raw-posix-aio.h, hide unavailable prototypes Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 12/12] raw-win32: add emulated AIO support Paolo Bonzini
2012-07-23 16:35 ` Blue Swirl
2012-07-23 16:59 ` Paolo Bonzini
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=87k3xz7esl.fsf@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=aliguori@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
--cc=sw@weilnetz.de \
/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).