From nobody Fri Nov 14 00:46:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583428422; cv=none; d=zohomail.com; s=zohoarc; b=E01EcPbPewEdVd5A4xVYjVpc0ZYiVzPkCKEg6Zt6NJuWvl8VT3xVa/0LsbptuJVu+xhVxb0cMXHN93MTsDPXbQp07eTGQCqS+q4eaNo+snZXj8ImZVkpNpJwMdjdnKeI6V6cj/RWFh4wmc+NwdmQ1YH+Ie9KBFON8r+qZbT61CQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583428422; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Wn5pfHyFieRx4tcNdpGnIlXvgQvmLlf3D2iVohA8EFI=; b=SwLivVlIUsQQdHql0ABTEEByRNmWxG0Zrs90PbS512gX7A7XJLgtimIP/TwGDoD9XFqOKuGsdEDfDi2v082/ig5TkQolS9yAoI2+goUoJeX9wrtuuEqlK7hvZ69sax0azIOhf5VAYuRqgk9SazB97q5OThnskrgKSTAOj+1qxro= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583428422920187.48226386259967; Thu, 5 Mar 2020 09:13:42 -0800 (PST) Received: from localhost ([::1]:53726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9u45-000865-M7 for importer@patchew.org; Thu, 05 Mar 2020 12:13:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37927) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9tyu-0008C5-By for qemu-devel@nongnu.org; Thu, 05 Mar 2020 12:08:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j9tys-0003Bg-R1 for qemu-devel@nongnu.org; Thu, 05 Mar 2020 12:08:20 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:42895 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j9tys-0003BN-N5 for qemu-devel@nongnu.org; Thu, 05 Mar 2020 12:08:18 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-311-5PhE3C4cMSisDjniv1SNpQ-1; Thu, 05 Mar 2020 12:08:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 97426107ACC4; Thu, 5 Mar 2020 17:08:15 +0000 (UTC) Received: from localhost (ovpn-117-104.ams2.redhat.com [10.36.117.104]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE0E31001902; Thu, 5 Mar 2020 17:08:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583428098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wn5pfHyFieRx4tcNdpGnIlXvgQvmLlf3D2iVohA8EFI=; b=e8gQPL688ETZKbBq434LoXUdr8SrUoQjH4GHDth+Gt5fFkxxZoVIElnmLhi38+VQFFdwQ/ meQw2c+He30YMTiZxZd+n0PS1zpRNRWgeWPIMrBYtIpHllBTaNsQ2HzRNYYGe/LoNwRt5w FEzPpQENUpHKGeh7OousFnhBIpVfyMY= X-MC-Unique: 5PhE3C4cMSisDjniv1SNpQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 1/7] aio-posix: completely stop polling when disabled Date: Thu, 5 Mar 2020 17:08:00 +0000 Message-Id: <20200305170806.1313245-2-stefanha@redhat.com> In-Reply-To: <20200305170806.1313245-1-stefanha@redhat.com> References: <20200305170806.1313245-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" One iteration of polling is always performed even when polling is disabled. This is done because: 1. Userspace polling is cheaper than making a syscall. We might get lucky. 2. We must poll once more after polling has stopped in case an event occurred while stopping polling. However, there are downsides: 1. Polling becomes a bottleneck when the number of event sources is very high. It's more efficient to monitor fds in that case. 2. A high-frequency polling event source can starve non-polling event sources because ppoll(2)/epoll(7) is never invoked. This patch removes the forced polling iteration so that poll_ns=3D0 really means no polling. IOPS increases from 10k to 60k when the guest has 100 virtio-blk-pci,num-queues=3D32 devices and 1 virtio-blk-pci,num-queues=3D1 device because the large number of event sources being polled slows down the event loop. Signed-off-by: Stefan Hajnoczi --- util/aio-posix.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index 9e1befc0c0..029f146455 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -361,12 +361,13 @@ void aio_set_event_notifier_poll(AioContext *ctx, (IOHandler *)io_poll_end); } =20 -static void poll_set_started(AioContext *ctx, bool started) +static bool poll_set_started(AioContext *ctx, bool started) { AioHandler *node; + bool progress =3D false; =20 if (started =3D=3D ctx->poll_started) { - return; + return false; } =20 ctx->poll_started =3D started; @@ -388,8 +389,15 @@ static void poll_set_started(AioContext *ctx, bool sta= rted) if (fn) { fn(node->opaque); } + + /* Poll one last time in case ->io_poll_end() raced with the event= */ + if (!started) { + progress =3D node->io_poll(node->opaque) || progress; + } } qemu_lockcnt_dec(&ctx->list_lock); + + return progress; } =20 =20 @@ -670,12 +678,12 @@ static bool try_poll_mode(AioContext *ctx, int64_t *t= imeout) } } =20 - poll_set_started(ctx, false); + if (poll_set_started(ctx, false)) { + *timeout =3D 0; + return true; + } =20 - /* Even if we don't run busy polling, try polling once in case it can = make - * progress and the caller will be able to avoid ppoll(2)/epoll_wait(2= ). - */ - return run_poll_handlers_once(ctx, timeout); + return false; } =20 bool aio_poll(AioContext *ctx, bool blocking) --=20 2.24.1