Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1996272pxj; Wed, 19 May 2021 20:10:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEKCcYhuVq2yTrdjKprZwhCtaadj9hVITHco4kYerZGFt22oLm22ESG8VbxoTJPGO3FoLy X-Received: by 2002:aa7:c349:: with SMTP id j9mr2495567edr.135.1621480254129; Wed, 19 May 2021 20:10:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621480254; cv=none; d=google.com; s=arc-20160816; b=ChH2g+JJXt/eL21UIwT7cslZ17Uc+hySw0Ct1Vxq2CJUIXQPpOWmTJ6HKQVy+j6nYn //gm6qRpYoARKr/Ws/oNjZ6DG/Nq8HlAWLXKK8RzMi/8RWGauPB67aVVFgdbEk6uMaA+ b/gEVRy4eNa3GEjlrTm3FzmjFp/cJY0LkI/hVIfk8fUdPiOal3QjcUHSVz4pGSe86aI3 kAHm9mIaGbyE79JjwO95YHexMFsupGif6DSrUZLC2ofrOfjwytAjIH81e+cV3tqP6LaZ v8iJpDHgMFdVj1mN2JvUgAPWbX1zHQmc7wmN6rDavb4T6cUNXhfEbk1NR4/ME923ShV1 Qx+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=Na1CWa0BMFc+cOGKtuK2YW6WlLnUfqio9iIU7E/006E=; b=fS1XU3BReMU33EfMQP2HYlada5sH5LbjS2ab7V8pvvxhRC3j+OuCXIlQmWO2GqA24/ cylUKPnkoZn+9LM0WLdXB2oZ7HFMWhm5TTE8r4h3pF/PO7sTYi4UuquZ/N7TKu+hgtsB soH1VAbZjjleoi0cicnIgvHA8l3jdpy5gXlPKlEDARb2iEwZUFAyJGj0kYRPngFP9zU6 V6GilFKcqDRW3qxmuFf8IK0pPzajEYEYje9R9CmRHLnUbb2+AKG8iHFH+iUgdHBwPQvh aWYLZnYZoYMF5YqJU/NTJujXSIZbm0LY9tzD128Oc/SjLPn6dr9MpZdgwLN9WQVRYeON 0Kbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eo8si1377107ejc.686.2021.05.19.20.10.29; Wed, 19 May 2021 20:10:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230146AbhETDHL (ORCPT + 99 others); Wed, 19 May 2021 23:07:11 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4759 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbhETDHL (ORCPT ); Wed, 19 May 2021 23:07:11 -0400 Received: from dggems704-chm.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Flvff052jzqV3M; Thu, 20 May 2021 11:02:18 +0800 (CST) Received: from dggpemm000003.china.huawei.com (7.185.36.128) by dggems704-chm.china.huawei.com (10.3.19.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 20 May 2021 11:05:33 +0800 Received: from DESKTOP-5IS4806.china.huawei.com (10.174.187.224) by dggpemm000003.china.huawei.com (7.185.36.128) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 20 May 2021 11:05:32 +0800 From: Keqian Zhu To: , , , , , Paolo Bonzini , "Jonathan Corbet" , Marc Zyngier CC: , , Subject: [PATCH] KVM: halt polling: Make the adjustment of polling time clearer Date: Thu, 20 May 2021 11:05:29 +0800 Message-ID: <20210520030529.22048-1-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.224] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm000003.china.huawei.com (7.185.36.128) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we have "block_ns > halt_poll_ns" and "block_ns < max_halt_poll_ns", then "halt_poll_ns < max_halt_poll_ns" is true, so we can drop this extra condition. We want to make sure halt_poll_ns is not zero before shrinking it. Put the condition in shrinking primitive can make code clearer. None functional change. Signed-off-by: Keqian Zhu --- Documentation/virt/kvm/halt-polling.rst | 21 ++++++++++----------- virt/kvm/kvm_main.c | 11 ++++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Documentation/virt/kvm/halt-polling.rst b/Documentation/virt/kvm/halt-polling.rst index 4922e4a15f18..d9f699395a7f 100644 --- a/Documentation/virt/kvm/halt-polling.rst +++ b/Documentation/virt/kvm/halt-polling.rst @@ -47,17 +47,16 @@ Thus this is a per vcpu (or vcore) value. During polling if a wakeup source is received within the halt polling interval, the interval is left unchanged. In the event that a wakeup source isn't received during the polling interval (and thus schedule is invoked) there are -two options, either the polling interval and total block time[0] were less than -the global max polling interval (see module params below), or the total block -time was greater than the global max polling interval. - -In the event that both the polling interval and total block time were less than -the global max polling interval then the polling interval can be increased in -the hope that next time during the longer polling interval the wake up source -will be received while the host is polling and the latency benefits will be -received. The polling interval is grown in the function grow_halt_poll_ns() and -is multiplied by the module parameters halt_poll_ns_grow and -halt_poll_ns_grow_start. +two options, either the total block time[0] were less than the global max +polling interval (see module params below), or the total block time was greater +than the global max polling interval. + +In the event that the total block time were less than the global max polling +interval then the polling interval can be increased in the hope that next time +during the longer polling interval the wake up source will be received while the +host is polling and the latency benefits will be received. The polling interval +is grown in the function grow_halt_poll_ns() and is multiplied by the module +parameters halt_poll_ns_grow and halt_poll_ns_grow_start. In the event that the total block time was greater than the global max polling interval then the host will never poll for long enough (limited by the global diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 6b4feb92dc79..13a9996c4ccb 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2906,6 +2906,9 @@ static void shrink_halt_poll_ns(struct kvm_vcpu *vcpu) unsigned int old, val, shrink; old = val = vcpu->halt_poll_ns; + if (!old) + return; + shrink = READ_ONCE(halt_poll_ns_shrink); if (shrink == 0) val = 0; @@ -3003,12 +3006,10 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) if (block_ns <= vcpu->halt_poll_ns) ; /* we had a long block, shrink polling */ - else if (vcpu->halt_poll_ns && - block_ns > vcpu->kvm->max_halt_poll_ns) + else if (block_ns > vcpu->kvm->max_halt_poll_ns) shrink_halt_poll_ns(vcpu); - /* we had a short halt and our poll time is too small */ - else if (vcpu->halt_poll_ns < vcpu->kvm->max_halt_poll_ns && - block_ns < vcpu->kvm->max_halt_poll_ns) + /* we had a short block, grow polling */ + else if (block_ns < vcpu->kvm->max_halt_poll_ns) grow_halt_poll_ns(vcpu); } else { vcpu->halt_poll_ns = 0; -- 2.19.1