From patchwork Wed May 26 14:09:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 53635 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 09893B7D19 for ; Thu, 27 May 2010 01:27:18 +1000 (EST) Received: from localhost ([127.0.0.1]:51176 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OHIVm-0004LQ-OZ for incoming@patchwork.ozlabs.org; Wed, 26 May 2010 11:27:14 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:subject:date :message-id:x-mailer:in-reply-to:references; bh=TvtqFYtfRXrthUAGT5Ml5GOtGX5Tb2uL8L8ckZV1tjI=; b=rEL5sCnsnRJbrc69GdA6vfNjjuRC2rzisuzzhGCBJc1PEWmEbkwC3/p/sWc9+MC5vT zNVBTym2YFayyKNqZZgzo/C5//hv9GzZIjDuvjhRXyTtGEtEXtl71jTSgkHwnX6F4Zzt BuF+oiY+QEYinlmnJkTIqQ82/0E1Q4EHULxJw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; b=R4yU9dtknTEZKw1EkHQSHnSXBrnqGvlMjB4POEjfEbpPasW5fOmEEsC6QCphECZUVy tLb+WnbgaGdpZoHa4dWxQKdzcGij/3OqfVdSRyxWjAYK8CFfVHvzwQ0e3ovab2EapG+y 5qJ+TNGHqBHeAJUhlPvysuazFU/F/upuYUdCY= Received: by 10.227.141.200 with SMTP id n8mr8544965wbu.200.1274883003134; Wed, 26 May 2010 07:10:03 -0700 (PDT) Received: from localhost.localdomain (nat-pool-brq-t.redhat.com [209.132.186.34]) by mx.google.com with ESMTPS id u32sm318964wbc.11.2010.05.26.07.10.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 26 May 2010 07:10:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 26 May 2010 16:09:38 +0200 Message-Id: <1274882978-9875-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1274882978-9875-1-git-send-email-pbonzini@redhat.com> References: <1274882978-9875-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 8/8] change ioevent to use event notifiers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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)