Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2918636pxb; Fri, 8 Oct 2021 19:16:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwlskU9QxxxgyS9JGWtxO5MUBG+hvZ6AWK+BlrHDyYsu7iB6EMJ/FkbasDRizM6IfUa1hp X-Received: by 2002:a50:d9c9:: with SMTP id x9mr20361268edj.179.1633745789366; Fri, 08 Oct 2021 19:16:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633745789; cv=none; d=google.com; s=arc-20160816; b=E2OqkYEOjuU981ddN8XRZgskR7O50NmXLTVlRM93kRPx5V3XjbRTXz5GfwchDC+6ie xZS1VT2mwxLYV/dEHtH1oJlMCzYqqyB5lfG/z974flnZz4OBqvQ3MZL7vmgoI4YOOzBm Q2Fsf5hh8gC2ZVGgWxohSINHmeDDU4vLTjDmyojzyoh4rEJakYW59YH14p7NDhdN3j8N jHm7Inv6O/KFvN1UEyGd7+441fOCX/m3nHM3x1GsW/TMyQJscZrh6K5l2BibbpGC/4sd ZbBgB06GcUSlOzUqsD60dcqDHNKbPdmFBwCnBNybpl/R9gSQikabnqJb1nsb7xLk2KMx GgCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=iENfBAERukntPY2X5QGQTh9qzr8Td2a/eMmZN0gkPVI=; b=oRBisel/8NerlmDa/KWMstg/Wf0JQ/MHQrxlAfnnlcuT41aZu6EImN+tkTfAaWcK7f jIMAf/m5SQRVc40uMonhGdiRedafuxXWETNFEk9RSWqgYzTBaDPc3d6mfVbnUJA8LOn6 kL+LO2BkgD7tNlhjQlp9tgUG/lfXfQn7JFuJe1/uYm675htEmPeKewy3ratRh87lEo2Z lNQAm0+ItGb7tDdrjmYxafOiQUrEQQ+Qv+OaxwGm6Jic9FmO/FbsYftnieu6qsdoPJdG bvlqOj77PG1yzbb/FAMZmKfMzCT1H6PLTjTjfhypQbaS68sfGNYkv93qYvuxFSOwyz57 UVxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DzCx6d3m; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hs6si3217032ejc.12.2021.10.08.19.16.04; Fri, 08 Oct 2021 19:16:29 -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; dkim=pass header.i=@google.com header.s=20210112 header.b=DzCx6d3m; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244543AbhJICP4 (ORCPT + 99 others); Fri, 8 Oct 2021 22:15:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244222AbhJICPf (ORCPT ); Fri, 8 Oct 2021 22:15:35 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0515CC061797 for ; Fri, 8 Oct 2021 19:13:22 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id f8-20020a2585480000b02905937897e3daso15198405ybn.2 for ; Fri, 08 Oct 2021 19:13:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=iENfBAERukntPY2X5QGQTh9qzr8Td2a/eMmZN0gkPVI=; b=DzCx6d3mDseqABvdcGbaVVyn1eWP9DyM0ptlZC0Av6M11xsmwM4hDygp2I9SRsOTlD CaLslZ/5tpgFn7ZGK8Q+oAp/z+7Kry0ksTb1JHhzjTahq7Wh+o5eGwzQrJzYlowAOZ48 VNCB+jXgqhl1lAdIBlzi52PfjMMWOIp8/GrzMp+AjpBgmC/UstMbkG/AsaR/Zi/J2Jar o4OtrA3m//aakuHjWV9VK3H1BLYWwyP3onVfEMCmc4KxgicKakfGDgJSztgcePWQk2I1 bTHWhpYvVB73G/ZnG29ntm8kUxVEF6vAxFCPnskmCGo64vtpSvX8eFpV4pMmLiFClOgf jaMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=iENfBAERukntPY2X5QGQTh9qzr8Td2a/eMmZN0gkPVI=; b=cdwBLH6Yyv/N6nNzBOG9yNKAtHjuuRAjXyi5vCMqRC4wz8ErDbPP2UwoWnNSXwTyd5 Cr7e3ZqONDS8/evO+/17HQ3LoSsOtl7eyIBIwSAx70gRiujpBQwX+ZDPzPP7BJpLgQ1s tRAhhk/BXAdpAuxWGOuMMY+PbNJDSacWyE1/IAPJgkLvnT/0LytBohYssl+wDiohhd2x Qb/jefsUCFFZzfLsnA+KkXqSsB69QdYlPB8q20x89301KCFVdJOGKUmfMf6O9ki8muTT Iz8FB2DzE68lE4+S6ewgXobiel/jCY0V33+I3bLLEoXQ4UaYS3cdZSrpNlWxny0PMyms k9Zg== X-Gm-Message-State: AOAM533O34oIsj8x+AE0xhyo0jdB1eKYxoRg1TrvGZYC/Z3gBlLqjDjD AuNJ87P0QMUb9ne9JSpJXdlIpURHZqk= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:a25:bb93:: with SMTP id y19mr7661688ybg.266.1633745601224; Fri, 08 Oct 2021 19:13:21 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 19:12:09 -0700 In-Reply-To: <20211009021236.4122790-1-seanjc@google.com> Message-Id: <20211009021236.4122790-17-seanjc@google.com> Mime-Version: 1.0 References: <20211009021236.4122790-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v2 16/43] KVM: Don't redo ktime_get() when calculating halt-polling stop/deadline From: Sean Christopherson To: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Paolo Bonzini Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , Oliver Upton , Jing Zhang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Calculate the halt-polling "stop" time using "cur" instead of redoing ktime_get(). In the happy case where hardware correctly predicts do_halt_poll, "cur" is only a few cycles old. And if the branch is mispredicted, arguably that extra latency should count toward the halt-polling time. In all likelihood, the numbers involved are in the noise and either approach is perfectly ok. Reviewed-by: David Matlack Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index a36ccdc93a72..481e8178b43d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3272,7 +3272,7 @@ void kvm_vcpu_halt(struct kvm_vcpu *vcpu) start = cur = poll_end = ktime_get(); if (do_halt_poll) { - ktime_t stop = ktime_add_ns(ktime_get(), vcpu->halt_poll_ns); + ktime_t stop = ktime_add_ns(cur, vcpu->halt_poll_ns); do { /* -- 2.33.0.882.g93a45727a2-goog