From patchwork Mon Feb 22 21:26:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 46018 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 97379B7CE2 for ; Tue, 23 Feb 2010 08:47:33 +1100 (EST) Received: from localhost ([127.0.0.1]:47284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Njg4l-0003qM-9p for incoming@patchwork.ozlabs.org; Mon, 22 Feb 2010 16:44:23 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Njfov-0006wq-Ef for qemu-devel@nongnu.org; Mon, 22 Feb 2010 16:28:01 -0500 Received: from [199.232.76.173] (port=56409 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Njfov-0006wd-0f for qemu-devel@nongnu.org; Mon, 22 Feb 2010 16:28:01 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Njfol-00036J-Hv for qemu-devel@nongnu.org; Mon, 22 Feb 2010 16:28:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59397) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Njfok-00035z-Jh for qemu-devel@nongnu.org; Mon, 22 Feb 2010 16:27:51 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1MLRlxn021628 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 22 Feb 2010 16:27:47 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1MLRkqc020843; Mon, 22 Feb 2010 16:27:46 -0500 Received: from amt.cnet (vpn-11-163.rdu.redhat.com [10.11.11.163]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o1MLRiRS016390; Mon, 22 Feb 2010 16:27:45 -0500 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 70E0F68A6D4; Mon, 22 Feb 2010 18:27:01 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o1MLQw7i000782; Mon, 22 Feb 2010 18:26:58 -0300 From: Marcelo Tosatti To: Anthony Liguori Date: Mon, 22 Feb 2010 18:26:43 -0300 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Paolo Bonzini , qemu-devel@nongnu.org, kvm@vger.kernel.org, Avi Kivity Subject: [Qemu-devel] [PATCH 1/8] use eventfd for iothread 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 From: Paolo Bonzini Signed-off-by: Paolo Bonzini Signed-off-by: Avi Kivity --- osdep.c | 32 ++++++++++++++++++++++++++++++++ qemu-common.h | 1 + vl.c | 9 +++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/osdep.c b/osdep.c index 9059f01..9e4b17b 100644 --- a/osdep.c +++ b/osdep.c @@ -37,6 +37,10 @@ #include #endif +#ifdef CONFIG_EVENTFD +#include +#endif + #ifdef _WIN32 #include #elif defined(CONFIG_BSD) @@ -281,6 +285,34 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count) #ifndef _WIN32 /* + * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set. + */ +int qemu_eventfd(int fds[2]) +{ + int ret; + +#ifdef CONFIG_EVENTFD + ret = eventfd(0, 0); + if (ret >= 0) { + fds[0] = ret; + qemu_set_cloexec(ret); + if ((fds[1] = dup(ret)) == -1) { + close(ret); + return -1; + } + qemu_set_cloexec(fds[1]); + return 0; + } + + if (errno != ENOSYS) { + return -1; + } +#endif + + return qemu_pipe(fds); +} + +/* * Creates a pipe with FD_CLOEXEC set on both file descriptors */ int qemu_pipe(int pipefd[2]) diff --git a/qemu-common.h b/qemu-common.h index b09f717..c941006 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -170,6 +170,7 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count) void qemu_set_cloexec(int fd); #ifndef _WIN32 +int qemu_eventfd(int pipefd[2]); int qemu_pipe(int pipefd[2]); #endif diff --git a/vl.c b/vl.c index 98918ac..1957018 100644 --- a/vl.c +++ b/vl.c @@ -3211,14 +3211,15 @@ static int io_thread_fd = -1; static void qemu_event_increment(void) { - static const char byte = 0; + /* Write 8 bytes to be compatible with eventfd. */ + static uint64_t val = 1; ssize_t ret; if (io_thread_fd == -1) return; do { - ret = write(io_thread_fd, &byte, sizeof(byte)); + ret = write(io_thread_fd, &val, sizeof(val)); } while (ret < 0 && errno == EINTR); /* EAGAIN is fine, a read must be pending. */ @@ -3235,7 +3236,7 @@ static void qemu_event_read(void *opaque) ssize_t len; char buffer[512]; - /* Drain the notify pipe */ + /* 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)); @@ -3246,7 +3247,7 @@ static int qemu_event_init(void) int err; int fds[2]; - err = qemu_pipe(fds); + err = qemu_eventfd(fds); if (err == -1) return -errno;