From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:48342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8a9z-0001Bj-Cf for qemu-devel@nongnu.org; Tue, 27 Sep 2011 12:05:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R8a9n-00066e-RM for qemu-devel@nongnu.org; Tue, 27 Sep 2011 12:05:31 -0400 Received: from mail-vx0-f173.google.com ([209.85.220.173]:35177) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8a9n-00066U-Nw for qemu-devel@nongnu.org; Tue, 27 Sep 2011 12:05:19 -0400 Received: by vcbfl10 with SMTP id fl10so4513991vcb.4 for ; Tue, 27 Sep 2011 09:05:18 -0700 (PDT) Message-ID: <4E81F43B.1040708@codemonkey.ws> Date: Tue, 27 Sep 2011 11:05:15 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1317133583-25212-1-git-send-email-avi@redhat.com> <4E81EB8A.3070202@siemens.com> In-Reply-To: <4E81EB8A.3070202@siemens.com> Content-Type: multipart/mixed; boundary="------------000004060601070306020002" Subject: Re: [Qemu-devel] [PATCH] event_notifier: move to top-level directory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jan Kiszka Cc: Kevin Wolf , Stefan Hajnoczi , Avi Kivity , qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------000004060601070306020002 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 09/27/2011 10:28 AM, Jan Kiszka wrote: > On 2011-09-27 17:17, Stefan Hajnoczi wrote: >> On Tue, Sep 27, 2011 at 3:26 PM, Avi Kivity wrote: >>> Has no business in hw/. >>> >>> Signed-off-by: Avi Kivity >>> --- >>> hw/event_notifier.c => event_notifier.c | 1 - >>> hw/event_notifier.h => event_notifier.h | 0 >>> 2 files changed, 0 insertions(+), 1 deletions(-) >>> rename hw/event_notifier.c => event_notifier.c (98%) >>> rename hw/event_notifier.h => event_notifier.h (100%) >> >> Yay. Now perhaps we can kill qemu_eventfd(), whose users are >> typically poking around with write(2) and read(2) when really they >> could use the high-level event_notifier.h API. > > EventNotifiers will have to be superseded by something more generic > first. It's not fully covering the use cases of cpus.c and > posix-aio-compat.c. Actually, for posix-aio, we can just switch to using g_idle_add(). g_idle_add() uses g_source_attach which is thread safe. g_idle_add() gives you a thread safe mechanism to defer a piece of work to the main loop which is really what we want here. This can actually be made to work with sync I/O emulation too by having another GMainLoop in the sync I/O loop although I thought I recalled a patch series to remove that stuff. Kevin/Stefan, what's the plans for sync I/O emulation? See untested patch below. Regards, Anthony Liguori > > Jan > --------------000004060601070306020002 Content-Type: text/x-patch; name="0001-posix-aio-compat-use-g_idle_add.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-posix-aio-compat-use-g_idle_add.patch" >>From cf036a192f09ea76d89648b83ec84a4226d14172 Mon Sep 17 00:00:00 2001 From: Anthony Liguori Date: Tue, 27 Sep 2011 11:01:51 -0500 Subject: [PATCH] posix-aio-compat: use g_idle_add() Signed-off-by: Anthony Liguori --- posix-aio-compat.c | 51 +++++++-------------------------------------------- 1 files changed, 7 insertions(+), 44 deletions(-) diff --git a/posix-aio-compat.c b/posix-aio-compat.c index d3c1174..1f746be 100644 --- a/posix-aio-compat.c +++ b/posix-aio-compat.c @@ -52,7 +52,6 @@ struct qemu_paiocb { }; typedef struct PosixAioState { - int rfd, wfd; struct qemu_paiocb *first_aio; } PosixAioState; @@ -466,7 +465,7 @@ static int qemu_paio_error(struct qemu_paiocb *aiocb) return ret; } -static int posix_aio_process_queue(void *opaque) +static gboolean posix_aio_process_queue(void *opaque) { PosixAioState *s = opaque; struct qemu_paiocb *acb, **pacb; @@ -477,8 +476,9 @@ static int posix_aio_process_queue(void *opaque) pacb = &s->first_aio; for(;;) { acb = *pacb; - if (!acb) - return result; + if (!acb) { + goto out; + } ret = qemu_paio_error(acb); if (ret == ECANCELED) { @@ -513,27 +513,8 @@ static int posix_aio_process_queue(void *opaque) } } - return result; -} - -static void posix_aio_read(void *opaque) -{ - PosixAioState *s = opaque; - ssize_t len; - - /* read all bytes from signal pipe */ - for (;;) { - char bytes[16]; - - len = read(s->rfd, bytes, sizeof(bytes)); - if (len == -1 && errno == EINTR) - continue; /* try again */ - if (len == sizeof(bytes)) - continue; /* more to read */ - break; - } - - posix_aio_process_queue(s); +out: + return FALSE; } static int posix_aio_flush(void *opaque) @@ -546,12 +527,7 @@ static PosixAioState *posix_aio_state; static void posix_aio_notify_event(void) { - char byte = 0; - ssize_t ret; - - ret = write(posix_aio_state->wfd, &byte, sizeof(byte)); - if (ret < 0 && errno != EAGAIN) - die("write()"); + g_idle_add(posix_aio_process_queue, posix_aio_state); } static void paio_remove(struct qemu_paiocb *acb) @@ -665,19 +641,6 @@ int paio_init(void) s = g_malloc(sizeof(PosixAioState)); s->first_aio = NULL; - if (qemu_pipe(fds) == -1) { - fprintf(stderr, "failed to create pipe\n"); - return -1; - } - - s->rfd = fds[0]; - s->wfd = fds[1]; - - fcntl(s->rfd, F_SETFL, O_NONBLOCK); - fcntl(s->wfd, F_SETFL, O_NONBLOCK); - - qemu_aio_set_fd_handler(s->rfd, posix_aio_read, NULL, posix_aio_flush, - posix_aio_process_queue, s); ret = pthread_attr_init(&attr); if (ret) -- 1.7.4.1 --------------000004060601070306020002--