From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=45310 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OHHN5-0003KX-Uh for qemu-devel@nongnu.org; Wed, 26 May 2010 10:14:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OHHJ5-00049s-Ka for qemu-devel@nongnu.org; Wed, 26 May 2010 10:10:08 -0400 Received: from mail-ww0-f45.google.com ([74.125.82.45]:39026) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHHJ5-00044Y-F4 for qemu-devel@nongnu.org; Wed, 26 May 2010 10:10:03 -0400 Received: by mail-ww0-f45.google.com with SMTP id 39so860125wwb.4 for ; Wed, 26 May 2010 07:10:03 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 26 May 2010 16:09:38 +0200 Message-Id: <1274882978-9875-9-git-send-email-pbonzini@redhat.com> In-Reply-To: <1274882978-9875-1-git-send-email-pbonzini@redhat.com> References: <1274882978-9875-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 8/8] change ioevent to use event notifiers List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Signed-off-by: Paolo Bonzini --- cpus.c | 95 +++++----------------------------------------------------------- 1 files changed, 9 insertions(+), 86 deletions(-) diff --git a/cpus.c b/cpus.c index 8341f6c..7a1dd06 100644 --- a/cpus.c +++ b/cpus.c @@ -26,6 +26,7 @@ #include "config-host.h" #include "monitor.h" +#include "event_notifier.h" #include "sysemu.h" #include "gdbstub.h" #include "dma.h" @@ -141,97 +142,19 @@ static int tcg_has_work(void) return 0; } -#ifndef _WIN32 -static int io_thread_fd = -1; - -static void qemu_event_increment(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_event_increment: write() filed: %s\n", - strerror(errno)); - exit (1); - } -} - -static void qemu_event_read(void *opaque) -{ - int fd = (unsigned long)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 EventNotifier io_thread_notifier; static int qemu_event_init(void) { int err; - int fds[2]; - - err = qemu_eventfd(fds); - if (err == -1) - return -errno; + err = event_notifier_init(&io_thread_notifier, 0); + if (err == 0) + event_notifier_set_handler(&io_thread_notifier, + (EventNotifierHandler *) + event_notifier_test_and_clear); - 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 *)(unsigned long)fds[0]); - - io_thread_fd = fds[1]; - return 0; - -fail: - close(fds[0]); - close(fds[1]); return err; } -#else -HANDLE qemu_event_handle; - -static void dummy_event_handler(void *opaque) -{ -} - -static int qemu_event_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; -} - -static void qemu_event_increment(void) -{ - if (!SetEvent(qemu_event_handle)) { - fprintf(stderr, "qemu_event_increment: SetEvent failed: %ld\n", - GetLastError()); - exit (1); - } -} -#endif #ifndef CONFIG_IOTHREAD int qemu_init_main_loop(void) @@ -281,7 +203,7 @@ void qemu_notify_event(void) { CPUState *env = cpu_single_env; - qemu_event_increment (); + event_notifier_set(&io_thread_notifier); if (env) { cpu_exit(env); } @@ -709,7 +631,7 @@ void qemu_init_vcpu(void *_env) void qemu_notify_event(void) { - qemu_event_increment(); + event_notifier_set(&io_thread_notifier); } static void qemu_system_vmstop_request(int reason) -- 1.6.6.1