From patchwork Mon Feb 18 13:06:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 10817983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ACBC51390 for ; Mon, 18 Feb 2019 13:10:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92A942AAAC for ; Mon, 18 Feb 2019 13:10:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 868652AA80; Mon, 18 Feb 2019 13:10:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0711C2AA5C for ; Mon, 18 Feb 2019 13:10:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730931AbfBRNKG (ORCPT ); Mon, 18 Feb 2019 08:10:06 -0500 Received: from foss.arm.com ([217.140.101.70]:58006 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729621AbfBRNKG (ORCPT ); Mon, 18 Feb 2019 08:10:06 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1F8F71993; Mon, 18 Feb 2019 05:10:06 -0800 (PST) Received: from ostrya.cambridge.arm.com (ostrya.cambridge.arm.com [10.1.197.2]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9979A3F720; Mon, 18 Feb 2019 05:09:59 -0800 (PST) From: Jean-Philippe Brucker To: kvm@vger.kernel.org Cc: will.deacon@arm.com, andre.przywara@arm.com Subject: [PATCH kvmtool 6/9] disk/aio: Fix AIO thread Date: Mon, 18 Feb 2019 13:06:59 +0000 Message-Id: <20190218130702.32575-7-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218130702.32575-1-jean-philippe.brucker@arm.com> References: <20190218130702.32575-1-jean-philippe.brucker@arm.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently when the kernel completes a batch of AIO requests and signals it via eventfd, we retrieve at most AIO_MAX events (256), and ignore the rest. Call io_getevents() again in case more events are pending. Signed-off-by: Jean-Philippe Brucker Reviewed-by: Andre Przywara --- disk/aio.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/disk/aio.c b/disk/aio.c index 007415c69..1fcf36857 100644 --- a/disk/aio.c +++ b/disk/aio.c @@ -66,20 +66,31 @@ ssize_t raw_image__write_async(struct disk_image *disk, u64 sector, offset, disk->evt, param); } -static void *disk_aio_thread(void *param) +static int disk_aio_get_events(struct disk_image *disk) { - struct disk_image *disk = param; struct io_event event[AIO_MAX]; struct timespec notime = {0}; int nr, i; + + do { + nr = io_getevents(disk->ctx, 1, ARRAY_SIZE(event), event, ¬ime); + for (i = 0; i < nr; i++) + disk->disk_req_cb(event[i].data, event[i].res); + } while (nr > 0); + + return 0; +} + +static void *disk_aio_thread(void *param) +{ + struct disk_image *disk = param; u64 dummy; kvm__set_thread_name("disk-image-io"); while (read(disk->evt, &dummy, sizeof(dummy)) > 0) { - nr = io_getevents(disk->ctx, 1, ARRAY_SIZE(event), event, ¬ime); - for (i = 0; i < nr; i++) - disk->disk_req_cb(event[i].data, event[i].res); + if (disk_aio_get_events(disk)) + break; } return NULL;