From nobody Thu May 2 00:04:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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=1554812973; cv=none; d=zoho.com; s=zohoarc; b=ABKPEu0W+I0erQiLdnUF1vwiGsG4LHvV1iNW70RX2jCKnid9v+B2e4yckwgxvX8ovlAnlIjpzuWb3JFX1dqs0S4V8szLXD8E1GTOV8lyE51Cxme3n1oysGA81qFmWfCP5skoDUrntOR8gaxwTsvyMKxZKS+tFVV24DKqMUnzpeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554812973; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=VwkzIm+GdP9ilB0XCdR4w1omZCih5X4z6ryAVHSZ/Wc=; b=WRbD5vHQqsmqJWNhQX4C1SYzN/8RT965x8ksMTFtLeVCshRVkIoOp3GT8EovNRS3xyLNLoPxXC4MrsZn/cAxNgWdUvsJfgeL7bl/DEJi28vk+i0dBxz2YHFbO8ggs8TxO5TkHDF3m6WAG++rez6HwSmCLx9p1EVovaDvF9ABbYw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.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 1554812973108484.6108500238954; Tue, 9 Apr 2019 05:29:33 -0700 (PDT) Received: from localhost ([127.0.0.1]:40320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDpsY-00032r-6R for importer@patchew.org; Tue, 09 Apr 2019 08:29:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDprU-0002ZX-6P for qemu-devel@nongnu.org; Tue, 09 Apr 2019 08:28:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDprT-00056Q-6F for qemu-devel@nongnu.org; Tue, 09 Apr 2019 08:28:24 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:33348) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hDprS-000562-Tv; Tue, 09 Apr 2019 08:28:23 -0400 Received: by mail-wr1-x42f.google.com with SMTP id q1so20682261wrp.0; Tue, 09 Apr 2019 05:28:22 -0700 (PDT) Received: from donizetti.lan ([2001:b07:6468:f312:1015:663:c7e9:4214]) by smtp.gmail.com with ESMTPSA id 84sm22940820wme.43.2019.04.09.05.28.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Apr 2019 05:28:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VwkzIm+GdP9ilB0XCdR4w1omZCih5X4z6ryAVHSZ/Wc=; b=gbDEBq8iHZktipbhTJfnx8NCrvWpNTAfwvoqhGoOdR4cSfz4z6Lebk0jOTl2o5K6s+ qcdxPe7RmWbMNfO8IXwm+gFWukEBAKuY3hSV4xmT4AWTC1fHUu1hjllyZ8LAN9g/UWs0 jQ868GYThnf7dJ3p/7UTaQmsNR7AWPHGLQT8D3FsgYbRzpZKs1yQaZBJWrKv0O8GhBIl DSUDyUKUdaGc+FktGTTLZyJWXgqwEWTCOP+SK3AzBgLC1N5hyRKn97wnircYU7Y/UqK9 kWTb9tSGfiFRlGO9FCIgJfBG7B74xeoU4B/knCLdHqzvXJ8IvoOHafJG/NzQe54KfNj4 /GXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=VwkzIm+GdP9ilB0XCdR4w1omZCih5X4z6ryAVHSZ/Wc=; b=p7Vc/p7T1JZVx8yw2SzKlEHSKtA29cmLfJpV1UA+H5xXC24POKsAXKeVhLLZfTKbtT F+aTqY2wz7a2iGix6Ee1PUEBr+IfIVX3VHU4c3HBXmcSuuUDYTUjk8E6Lf87FJMK/OuR TRxgT46nDFJmNBMtBL6Ue2O8VS+308M5RIgN8XKOU4lFISVKymNMZfK8Neeq70tqIgsD 0Alg9El9uGT96WpGpkDxbM/Wk8z6Trl0Gb3EnnU60nqCp+f21GN3bDXK9c7nPiijnCRI WJcI6JoAB5LfahlwvX9Gsr08JCO0amjpGpoKtsHLRRGJR6h1ArFlHocxDp74/WxK/EQG kBTg== X-Gm-Message-State: APjAAAW4ttbRjGt66gLRe7LwZ1SBsP3T6joYE9LPzp89aq6W7oCW3nUn GbIAEtUNvkGtxXjBQgfRUt01h/HY X-Google-Smtp-Source: APXvYqxmih+EN4wwtJseVJp4WPvddOGYlQE/jtJac9qwhqQx0zM6hCC6iKelAAJjdpSp3Flc6WdrFA== X-Received: by 2002:adf:f286:: with SMTP id k6mr19632230wro.137.1554812900848; Tue, 09 Apr 2019 05:28:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 9 Apr 2019 14:28:23 +0200 Message-Id: <20190409122823.12416-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42f Subject: [Qemu-devel] [PATCH v2 for-4.0?] aio-posix: ensure poll mode is left when aio_notify is called X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org, Sergio Lopez 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" With aio=3Dthread, adaptive polling makes latency worse rather than better, because it delays the execution of the ThreadPool's completion bottom half. event_notifier_poll() does run while polling, detecting that a bottom half was scheduled by a worker thread, but because ctx->notifier is explicitly ignored in run_poll_handlers_once(), scheduling the BH does not count as making progress and run_poll_handlers() keeps running. Fix this by recomputing the deadline after *timeout could have changed. With this change, ThreadPool still cannot participate in polling but at least it does not suffer from extra latency. Reported-by: Sergio Lopez Cc: Stefan Hajnoczi Cc: Kevin Wolf Cc: qemu-block@nongnu.org Signed-off-by: Paolo Bonzini Message-Id: <1553692145-86728-1-git-send-email-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini Reviewed-by: Sergio Lopez Reviewed-by: Stefan Hajnoczi --- v1->v2: use qemu_soonest_timeout to handle timeout =3D=3D -1 util/aio-posix.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index 6fbfa7924f..db11021287 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -519,6 +519,10 @@ static bool run_poll_handlers_once(AioContext *ctx, in= t64_t *timeout) if (!node->deleted && node->io_poll && aio_node_check(ctx, node->is_external) && node->io_poll(node->opaque)) { + /* + * Polling was successful, exit try_poll_mode immediately + * to adjust the next polling time. + */ *timeout =3D 0; if (node->opaque !=3D &ctx->notifier) { progress =3D true; @@ -558,8 +562,9 @@ static bool run_poll_handlers(AioContext *ctx, int64_t = max_ns, int64_t *timeout) do { progress =3D run_poll_handlers_once(ctx, timeout); elapsed_time =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start_ti= me; - } while (!progress && elapsed_time < max_ns - && !atomic_read(&ctx->poll_disable_cnt)); + max_ns =3D qemu_soonest_timeout(*timeout, max_ns); + assert(!(max_ns && progress)); + } while (elapsed_time < max_ns && !atomic_read(&ctx->poll_disable_cnt)= ); =20 /* If time has passed with no successful polling, adjust *timeout to * keep the same ending time. @@ -585,8 +590,7 @@ static bool run_poll_handlers(AioContext *ctx, int64_t = max_ns, int64_t *timeout) */ static bool try_poll_mode(AioContext *ctx, int64_t *timeout) { - /* See qemu_soonest_timeout() uint64_t hack */ - int64_t max_ns =3D MIN((uint64_t)*timeout, (uint64_t)ctx->poll_ns); + int64_t max_ns =3D qemu_soonest_timeout(*timeout, ctx->poll_ns); =20 if (max_ns && !atomic_read(&ctx->poll_disable_cnt)) { poll_set_started(ctx, true); --=20 2.21.0