From patchwork Fri Oct 26 14:05:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 194504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5AE342C008C for ; Sat, 27 Oct 2012 02:09:24 +1100 (EST) Received: from localhost ([::1]:34712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRkcZ-00089i-Me for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2012 10:10:47 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRkbi-0006cN-Gp for qemu-devel@nongnu.org; Fri, 26 Oct 2012 10:09:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TRkbc-0005fL-Er for qemu-devel@nongnu.org; Fri, 26 Oct 2012 10:09:54 -0400 Received: from mail-bk0-f45.google.com ([209.85.214.45]:61615) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRkbc-0005Sp-8Z for qemu-devel@nongnu.org; Fri, 26 Oct 2012 10:09:48 -0400 Received: by mail-bk0-f45.google.com with SMTP id jf3so1090170bkc.4 for ; Fri, 26 Oct 2012 07:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=2HTNJYe5ztIph8fB13BdXMLb5ZLvJU1tp0uIaQCPYOw=; b=t30IBSYwgN6EBTGxZ2FAg8yxrt84DkplMlK0lyQfG0TfxWK4ifT7NdTtZCkIdTpQ+P xE4YtHb0Lpc0jOnvCpQqgLr41wIz2/AVDCEgmE2Ex8ggCFE6VQcpP0i5wjfmi0enIJrU jIzcIXv1lsiYIiLiA1iduct6qX4Z+AVYYLkT7rBBvOWfMJhXlNGxPXBOptevtM9OtBbv ZmUDvnOI69r7av/AYQ4sFQvfsER3mmQPONfMCGQwT9VFOYxK89/3cxFFNuP80CFteYSV wZGsLrZMb++qA7RUfaD0I6hsnamxsy6pt2f51z+RzP29wYSLl1yGHSIhSJbERyJrAEsn GrAg== Received: by 10.205.128.148 with SMTP id he20mr7032478bkc.99.1351260587901; Fri, 26 Oct 2012 07:09:47 -0700 (PDT) Received: from yakj.usersys.redhat.com (nat-pool-mxp-t.redhat.com. [209.132.186.18]) by mx.google.com with ESMTPS id s20sm1082468bkw.15.2012.10.26.07.09.46 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 26 Oct 2012 07:09:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2012 16:05:45 +0200 Message-Id: <1351260355-19802-16-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1351260355-19802-1-git-send-email-pbonzini@redhat.com> References: <1351260355-19802-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.45 Cc: aliguori@us.ibm.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 15/25] main-loop: use aio_notify for qemu_notify_event X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Reviewed-by: Anthony Liguori Signed-off-by: Paolo Bonzini --- main-loop.c | 110 ++++++------------------------------------------------------ 1 file modificato, 10 inserzioni(+), 100 rimozioni(-) diff --git a/main-loop.c b/main-loop.c index 209f699..978050a 100644 --- a/main-loop.c +++ b/main-loop.c @@ -32,70 +32,6 @@ #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. @@ -165,35 +101,6 @@ 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) -{ - 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; -} - -void qemu_notify_event(void) -{ - if (!qemu_event_handle) { - 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; @@ -202,6 +109,14 @@ static int qemu_signal_init(void) static AioContext *qemu_aio_context; +void qemu_notify_event(void) +{ + if (!qemu_aio_context) { + return; + } + aio_notify(qemu_aio_context); +} + int main_loop_init(void) { int ret; @@ -213,12 +128,6 @@ int main_loop_init(void) return ret; } - /* Note eventfd must be drained before signalfd handlers run */ - ret = qemu_event_init(); - if (ret) { - return ret; - } - qemu_aio_context = aio_context_new(); src = aio_get_g_source(qemu_aio_context); g_source_attach(src, NULL); @@ -408,7 +317,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(&qemu_aio_context->notifier), + FD_READ | FD_ACCEPT | FD_CLOSE | FD_CONNECT | FD_WRITE | FD_OOB); }