From patchwork Wed Feb 10 23:23:46 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 45073 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 AC6DCB7CB8 for ; Thu, 11 Feb 2010 10:32:39 +1100 (EST) Received: from localhost ([127.0.0.1]:34392 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfM2u-0000zr-Ip for incoming@patchwork.ozlabs.org; Wed, 10 Feb 2010 18:32:36 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NfLy7-0006hu-Dt for qemu-devel@nongnu.org; Wed, 10 Feb 2010 18:27:39 -0500 Received: from [199.232.76.173] (port=58723 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfLy7-0006hj-18 for qemu-devel@nongnu.org; Wed, 10 Feb 2010 18:27:39 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NfLy5-0004Ds-Qj for qemu-devel@nongnu.org; Wed, 10 Feb 2010 18:27:38 -0500 Received: from mail-fx0-f223.google.com ([209.85.220.223]:40352) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NfLy5-0004Dm-GJ for qemu-devel@nongnu.org; Wed, 10 Feb 2010 18:27:37 -0500 Received: by fxm23 with SMTP id 23so605565fxm.2 for ; Wed, 10 Feb 2010 15:27:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:cc:subject :date:message-id:x-mailer; bh=hiBM9vUueIu8WHLc8MJrM7NsoreXhnXncPjghnZC6Zc=; b=O4d0ZjgooT9iKEl6TvjL7cHM21zQQ/A6muHKD4MQS7vsKdbo9adKC1SmKF3Co5bTok alccB7f/RnVXIz4jDsbGGUGg/e8GbOGwNkJCmF5uyF/nnpZIyNVCYJJT4Z7bMlCyIRdu XiIxoTJHFJDnO8D4sD15vMQhjupTAQxCw+uk0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer; b=wDkDRhgH1YP4MOi7vv1LiHBbF3zdv4yNv2QLmVAa5CioSRT82gDdsIbDYwDH+74lF4 +oS1MK6lPYgVjQBqKmMl4MgMJbERnMCdnrI7eNKr+I/Jtqh1nITCGNTRXXGAErT5soy3 fuHavF2nLVZaZxDtAoOE1/x/XHfzySSzm78Zc= Received: by 10.223.2.194 with SMTP id 2mr1022883fak.30.1265844232779; Wed, 10 Feb 2010 15:23:52 -0800 (PST) Received: from localhost.localdomain ([85.93.118.17]) by mx.google.com with ESMTPS id p17sm551885fka.35.2010.02.10.15.23.49 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 10 Feb 2010 15:23:52 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 11 Feb 2010 00:23:46 +0100 Message-Id: <1265844226-29613-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.6.6 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH] [uq/master] 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 Signed-off-by: Paolo Bonzini --- 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;