From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mark McLoughlin Subject: [PATCH 4/6] kvm: qemu: aggregate reads from eventfd Date: Thu, 30 Oct 2008 17:51:51 +0000 Message-ID: <1225389113-28332-5-git-send-email-markmc@redhat.com> References: <> <1225389113-28332-1-git-send-email-markmc@redhat.com> <1225389113-28332-2-git-send-email-markmc@redhat.com> <1225389113-28332-3-git-send-email-markmc@redhat.com> <1225389113-28332-4-git-send-email-markmc@redhat.com> Cc: kvm@vger.kernel.org, Mark McLoughlin To: Avi Kivity Return-path: Received: from mail12.svc.cra.dublin.eircom.net ([159.134.118.28]:40177 "HELO mail12.svc.cra.dublin.eircom.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1754592AbYJ3RxX (ORCPT ); Thu, 30 Oct 2008 13:53:23 -0400 In-Reply-To: <1225389113-28332-4-git-send-email-markmc@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Keep reading from eventfd until it's empty and aggregate the results. Only really important when we're emulating eventfd using a pipe as in that case we may have multiple "1" values queued up, potentially leading to the pipe buffer filling up and the write side blocking. Signed-off-by: Mark McLoughlin --- qemu/compatfd.c | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-) diff --git a/qemu/compatfd.c b/qemu/compatfd.c index 7e3e7f7..2da6dd6 100644 --- a/qemu/compatfd.c +++ b/qemu/compatfd.c @@ -153,7 +153,7 @@ int qemu_eventfd_write(int eventfd, uint64_t value) return offset == 8 ? 0 : -1; } -uint64_t qemu_eventfd_read(int eventfd) +static uint64_t qemu_eventfd_read_one(int eventfd) { char buffer[8]; size_t offset = 0; @@ -177,3 +177,22 @@ uint64_t qemu_eventfd_read(int eventfd) return value; } + +uint64_t qemu_eventfd_read(int eventfd) +{ + uint64_t ret; + fd_set fds; + struct timeval tv; + + FD_ZERO(&fds); + FD_SET(eventfd, &fds); + + tv.tv_sec = tv.tv_usec = 0; + + ret = 0; + do { + ret += qemu_eventfd_read_one(eventfd); + } while (select(eventfd + 1, &fds, NULL, NULL, &tv) > 0); + + return ret; +} -- 1.5.4.3