From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkmx-00023D-Gm for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:23:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFkmr-00059J-2x for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:23:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21707) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkmq-000595-R6 for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:23:33 -0400 Message-ID: <4F7D80B0.5070008@redhat.com> Date: Thu, 05 Apr 2012 13:23:28 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <14c3f383cbeedf4bf67a920a8fb6f6ced85d5be2.1333623555.git.jan.kiszka@siemens.com> In-Reply-To: <14c3f383cbeedf4bf67a920a8fb6f6ced85d5be2.1333623555.git.jan.kiszka@siemens.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 05/10] Introduce QemuEvent abstraction List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jan Kiszka Cc: Kevin Wolf , Anthony Liguori , qemu-devel@nongnu.org, "Michael S. Tsirkin" Il 05/04/2012 12:59, Jan Kiszka ha scritto: > Provide generic services for binary events. Blocking wait would be > feasible but is not included yet as there are no users. > > diff --git a/qemu-event-posix.c b/qemu-event-posix.c > new file mode 100644 > index 0000000..6138168 > --- /dev/null > +++ b/qemu-event-posix.c > @@ -0,0 +1,110 @@ > +/* > + * Posix implementations of event signaling service > + * > + * Copyright Red Hat, Inc. 2012 > + * Copyright Siemens AG 2012 > + * > + * Author: > + * Paolo Bonzini > + * Jan Kiszka > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or later. > + * See the COPYING file in the top-level directory. > + * > + */ > +#include "qemu-thread.h" > +#include "qemu-common.h" > +#include "main-loop.h" > + > +#ifdef CONFIG_EVENTFD > +#include > +#endif > + > +void qemu_event_init(QemuEvent *event, bool signaled) > +{ > + int fds[2]; > + int ret; > + > +#ifdef CONFIG_EVENTFD > + ret = eventfd(signaled, EFD_NONBLOCK | EFD_CLOEXEC); > + if (ret >= 0) { > + event->rfd = ret; > + event->wfd = dup(ret); > + if (event->wfd < 0) { > + qemu_error_exit(errno, __func__); > + } > + qemu_set_cloexec(event->wfd); > + return; > + } > + if (errno != ENOSYS) { > + qemu_error_exit(errno, __func__); > + } > + /* fall back to pipe-based support */ > +#endif > + > + ret = qemu_pipe(fds); > + if (ret < 0) { > + qemu_error_exit(errno, __func__); > + } > + event->rfd = fds[0]; > + event->wfd = fds[1]; > + if (signaled) { > + qemu_event_signal(event); > + } > +} > + > +void qemu_event_destroy(QemuEvent *event) > +{ > + close(event->rfd); > + close(event->wfd); > +} > + > +int qemu_event_get_signal_fd(QemuEvent *event) > +{ > + return event->wfd; > +} How would you use it? Since qemu_event_signal ignores EAGAIN, polling for writeability of the fd is useless. This is really little more than search-and-replace from what gets out of event-notifier.c after my patches, and the commit message does not explain the differences in the two APIs. Having separate commits as I had would make the steps obvious. Is it really worthwhile to do this and introduce the need for patches 9+10 (plus IIRC conflicts in qemu-kvm)? (In fact, qemu_event_get_poll_fd is a layering violation too. In a perfect world, aio.c would simply get a list of EventNotifiers and no other types of fd). Paolo