From nobody Sun May 5 08:17:20 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553692251296646.1630028318166; Wed, 27 Mar 2019 06:10:51 -0700 (PDT) Received: from localhost ([127.0.0.1]:47613 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h98KN-0004Xw-Rn for importer@patchew.org; Wed, 27 Mar 2019 09:10:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h98Iu-0003kj-Nb for qemu-devel@nongnu.org; Wed, 27 Mar 2019 09:09:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h98It-00076B-JA for qemu-devel@nongnu.org; Wed, 27 Mar 2019 09:09:16 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:40091) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h98Iq-000729-F4; Wed, 27 Mar 2019 09:09:13 -0400 Received: by mail-wm1-x32d.google.com with SMTP id z24so13507230wmi.5; Wed, 27 Mar 2019 06:09:09 -0700 (PDT) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id k9sm26388852wru.55.2019.03.27.06.09.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Mar 2019 06:09:07 -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; bh=fKkcLqgke4QYpTrw/NrAwO3wr02Kk+a29q1K/qCh+WA=; b=o7qsw4tX81gOk01JjcEOx+xi/T/DoLDrVCJ0gFncSagXve+laq0OWt9K/5Se2GpD7K IwCSYrc5LGBnbsXR+ZZywpe9OOkQ3TEsi/C6q4Ofhi/HDWuqvPv3QEwrG7XScwjVVGFf 4Vk6oRwe2Fg4lzevIRsY4EJRhrFCfhaCLkHYqXLXxPPfUVGahrOWqhJd9clwEuyPRhGp pEZ3g10ad6ZcgjiaTzBhJEP/wDqv9a6MoEtZ3/3cLyRUW3jl1rGHetEW3XndBWyOacqh QFYhsOS7btvhMayOQUpAnRWlIrPyv2me/dNFrYVldfEMwdxlJBKxb1iV3O3GvnlTznH2 1mCw== 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; bh=fKkcLqgke4QYpTrw/NrAwO3wr02Kk+a29q1K/qCh+WA=; b=NoTkGjZeGWLlfkJ4So7FED/CK3LIrN3S+A4aSeAt/WGZaQk0ciJYHmtnHAgR7YHsH2 4aUwixUMcrjodeg+v368TbsI1afcpndxj3du5oqoAVA5u6XbomnL019joBg21UsxqQ3d 7WlA8ZWlels2LvO4hykyvkAzkBTGB6OTpyi6dceFwasGDZKMeApm4SHc+LHdAtqtj+fc 36drr5xNsRF0Jt9GyiH+t2pweo+G0rGiRoB6UxrziSvXLQCxA087ylyP1Ee5NGUHuGN4 25jScB3Nf2+jPJ5n00MlU2aHFJhke81zHHX3g6w7+j82ZEmjKwzxqq4HlZbNWcaUBhza ZzZw== X-Gm-Message-State: APjAAAULDvz9BX6y0JMdD64njeEOjux1bVl7aQLdge2doFuNM5fMua// 0fR/A0mLL0Xi9kh24GRE6g6JvMB4 X-Google-Smtp-Source: APXvYqwW8C4rdljId0pHfJ4hrh+/EjqRmFPJ7TPKnnNIQmXkkeKyLWRnOkruxzBTjFUtAiYJzi29Kg== X-Received: by 2002:a7b:c4d5:: with SMTP id g21mr11361009wmk.133.1553692147786; Wed, 27 Mar 2019 06:09:07 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 27 Mar 2019 14:09:05 +0100 Message-Id: <1553692145-86728-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32d Subject: [Qemu-devel] [PATCH 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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 --- util/aio-posix.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index 6fbfa79..b166cda 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 MIN(*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. --=20 1.8.3.1