From patchwork Thu May 20 03:05:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhukeqian X-Patchwork-Id: 12268809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D7D8C433ED for ; Thu, 20 May 2021 03:08:15 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D7606101D for ; Thu, 20 May 2021 03:08:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D7606101D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=wI8VpvYfE/8+NpDYFAK2UUF6pBLH0dZPa5ZDsBFEnXE=; b=N1dcmqDS4IPLJOgI+0rQ25PTzB V3ZIZZt3cC9fujBx/h2EX+xyQW2RBt9oDVTsT6N3mXnqvmGB/Up68JAUpaQk+kl3eIqk26m/vjfeB E4yqHLqpGxrOai4CXWxnnpq1zYBNX1wYMFOOfN3h+/rcPZYzocXdchTqFusxxkf9TiK5lpV18+wQ1 bXwZHGYihI3+viCsJij/4+fn/6qXoIK+JiICb7U+2RVWQAbMZ5vY1rEJAbesRsEYegrW22c7UPVVQ RFcqQJGrsh5GcDR4ts7gxUuo5Q5K3//5hMrvCCpKBkcsTbCtd/OscckOU46T0EdPvjzSyTaEkckD0 VdtrGO8w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ljZ0f-005j4s-4f; Thu, 20 May 2021 03:06:05 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljZ0b-005j4Z-9m for linux-arm-kernel@desiato.infradead.org; Thu, 20 May 2021 03:06:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:MIME-Version:Message-ID: Date:Subject:CC:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=Na1CWa0BMFc+cOGKtuK2YW6WlLnUfqio9iIU7E/006E=; b=w1WbJSxYc5BbwaI7ipB3zDmXzz AeGiE3QJDCFzkz/xiO1pSA/n9hlpxO5YqnkEPENdcdoov0DFhKkjxw1JmSbf7xQ/mtmczD46URYQe KEzylTwgnFKE+p3FLHFY3iWdQCnm1YNifwcrG155/G3HrkDzUF87FKsAIT/KqegLNRRZtNqiA9LVv yDTs+kvJ3CFdui8UZzIGBJX+HP3HSOPSjYz1PdlsBNmekU6kc5ZXFrJf/EZaYRnNFvcPIkpuovjDW sQnIMOk3ZVJP6Uqkda24Lxq0hQdvspeLPEHFZhkFlJRJbpBRTfHK3yMxdla21mba1t0Tp/8s4b2ka CWAd1ILA==; Received: from szxga04-in.huawei.com ([45.249.212.190]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljZ0W-00Fu2Q-RI for linux-arm-kernel@lists.infradead.org; Thu, 20 May 2021 03:05:58 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210519_200557_237071_9126FD1F X-CRM114-Status: GOOD ( 15.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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;