From nobody Wed Apr 16 03:53:26 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=1583930537; cv=none; d=zohomail.com; s=zohoarc; b=eN6zeYmOsT47anO77fhc9AvcXOTqWn+ABpmKHKRTPL+RDnVHnPKrPJ4gE1LcMf19AQp433k2XUHGCU46NGxuVxh3Ag+XpTib04RMZXtLFyQvidS/3ft22XTGkIZPytcQZPJOM0H0JM3F+PA3n6Pt6KOPZZ4ZZ6x88tRqWIdzIXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583930537; 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=U3Jtfg1TTB2Ah/JG3MKEAc1vIUmTSjTGAWT/B4X6ezQ=; b=d0U8jZl2nDLpHPSXuDjZ+fosm63R/GDRtSAOeAWEt1v3S2Ty9E/0VFdGtPO96pNGxaGQ6l7a6LZXNEFCXJCaBx5XXyRl9mHQiaZdD80ezc3/khcVa7Sbu7GiJ3VldvIOlO4gjAKndg1lT5jEhBSW0uGewroVIeliNJ8M0KRqIBU= 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 1583930537079480.51776485815765; Wed, 11 Mar 2020 05:42:17 -0700 (PDT) Received: from localhost ([::1]:51136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0gh-0008IP-OK for importer@patchew.org; Wed, 11 Mar 2020 08:42:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46900) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0fh-0006eq-Ob for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:41:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC0fg-0000FL-JH for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:41:13 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:47850 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jC0fg-0000FB-GF for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:41:12 -0400 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-315-88HbSqWPNM-RqxCCeowwTQ-1; Wed, 11 Mar 2020 08:41:05 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8D7431084431; Wed, 11 Mar 2020 12:41:04 +0000 (UTC) Received: from localhost (unknown [10.36.118.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id 648C338E; Wed, 11 Mar 2020 12:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583930472; 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=U3Jtfg1TTB2Ah/JG3MKEAc1vIUmTSjTGAWT/B4X6ezQ=; b=Fa4Q/Navdq7WxyOFWvYv6wMoqzPEOuyvWKWuG/XBe0xRyXleRwJDP4XbgUxWrr6trt65oh Jb+pSEDP/U2pDOtQwD5OcikkwlICqrm9/70MxE7MIDlCCUpdnoEmm2R6xmtuE0HPWWHs/r wx0C2RHPK90M438GeryEEpB2Xg8AjSA= X-MC-Unique: 88HbSqWPNM-RqxCCeowwTQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PULL 3/9] aio-posix: completely stop polling when disabled Date: Wed, 11 Mar 2020 12:40:39 +0000 Message-Id: <20200311124045.277969-4-stefanha@redhat.com> In-Reply-To: <20200311124045.277969-1-stefanha@redhat.com> References: <20200311124045.277969-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.120 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 , Peter Maydell , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf 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 Link: https://lore.kernel.org/r/20200305170806.1313245-2-stefanha@redhat.com Message-Id: <20200305170806.1313245-2-stefanha@redhat.com> --- 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 b339aab12c..65964a2597 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