Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2918068pxb; Fri, 8 Oct 2021 19:15:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymhzDgrl2z50E3g3bqTjpXOLT0trBk3Wm++Nm0AjEnUMr0p9UUIDJ3VQR7alfoCB2362fE X-Received: by 2002:a50:bb67:: with SMTP id y94mr19696373ede.308.1633745713476; Fri, 08 Oct 2021 19:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633745713; cv=none; d=google.com; s=arc-20160816; b=HdsPW77pxvgBpJzbWWgrysXftUIP0BCwQmQ4zYQPZZw+oC+noo1cTmNZQwbgo8nH7P HLlQ4+ri3PwBbqReioGG7XDZWrfyaDPfBSpXzn4ghzMDuDHKg0G/TX+Xk616ZFWFiJoX cxghdKOanL6ryuVC8mxeVAiA8Wn9Ve25BitLnx3kB5liS2IuX1yPahQndXjv7iLdrsWq vd9RC70QdBW1RnK2zSDZymj6gOvD7n/9xcwAFOYpVQeHzi4oVU4nskFErYGOXgR1gtAH 5qLjCcighYxQ7ZMNDxxizyqh2CwD7kbFoiSWydBlVtLJjeb1xs8zpUT766UR4ihIHZbJ lv3g== 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=C+i8NrMil/B/zUdg/nLE/M0TZQFBBWIIBWMi/JAr4uc=; b=CQbbEME+Edvinvqv4txwVRP1uxGY8vmtcGVBjJiv6dkwo1cYaTWi5CY1WCrKa/PCbX a+ke/6GMPd+UKrZ6W2cO3IJSEQxyj6biNf0FBUtP6hX87cRtSdNcwuxpCRcwe0rW2mKR XEDkzCwRDo4J2bDZ2pz8RNW8MyA56fzCz+T6OC5VPHhRGPzQLKnlsAbCOyEeHSX7mZOv +FyZ+jJz/kBqqopELVj1VTIN/PbMvtePucVRM9Cia9ZCQD+pmZEQRh17UhJEZ+a38ge9 kRwccMxDdQy2xRxhPBAxARI83jZyyQ6XdRuJ4jmJUYTscwI6q8ixABf2ieB/g9VTMnCO W4Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=je+n3lLm; 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 w11si1647043edc.191.2021.10.08.19.14.50; Fri, 08 Oct 2021 19:15:13 -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=je+n3lLm; 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 S244245AbhJICPA (ORCPT + 99 others); Fri, 8 Oct 2021 22:15:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244257AbhJICO4 (ORCPT ); Fri, 8 Oct 2021 22:14:56 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44F66C061762 for ; Fri, 8 Oct 2021 19:13:00 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id x16-20020a25b910000000b005b6b7f2f91cso15202312ybj.1 for ; Fri, 08 Oct 2021 19:13:00 -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=C+i8NrMil/B/zUdg/nLE/M0TZQFBBWIIBWMi/JAr4uc=; b=je+n3lLm4A0uVSi9vpvS/05S8oYMXrlHSB6veYJTbVDTpbNd4p8mCzawy0O3YfBv0U VkYS1gQyXD+Vhv2MKKEDypDIAmAUZV7+XoKV2GNHaTVHTXEEief1nVbXKyPAlhbnV2Iq AgDv18LthCBgw3zhOl5b0oeHGLTEvaCSkl5+xlvQQtEny0Ld/9Zg4+QFyGyrsCI8av18 DmcjgY9VieQy4PNiTx9Rjpoa5+HAuInKE44ebmh0tt4Cev6vzGuTfdj3Hb7+Xq+pKABX ReTheEfMC8DB/Mq2Zd65wAAdUEOkI6Nw5jw5fMSe0n/pdwq1ppMu0LuEVStnZqxTNlvJ ADqw== 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=C+i8NrMil/B/zUdg/nLE/M0TZQFBBWIIBWMi/JAr4uc=; b=nsP6FGsCvyQjYcn2E5CoEfB1reORNCmGwp8erD4P6F0+qKdIOzFxA5+qbTB1PJQxK9 RHQgTBX/MJEoV7GWZFcC+TGY/St8Hv+O8MK57dMZBqu3MZMvITvxcoZxj/vAnMYm57iy 5dissLdJpIE19ZP3cPS2Z4vXabHmeD2R340FUyiL66th87SuPWsh36uBCdW87iC4Pznt nI3fLJQne1Vo/2a3A/y45zkzr2VXZvfC1eGpXU55+AA5rtsLk2VlOrb/4IoRcsDGTywY bC6nhkTgx3qmekTXhMO2/AU27vj0+/HB12LygprsEFa3wMEgiElfrG9gfdCuqG8Vb8WE 7CGQ== X-Gm-Message-State: AOAM531VTRPPDCKURXdXZZFFy5hzCy3FXmFZG8z/A75+ySmEAWjYKsmq YwIBenTRr5+6UBdHsXoTqrSa3q/MXtk= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:a05:6902:1105:: with SMTP id o5mr7903925ybu.518.1633745579491; Fri, 08 Oct 2021 19:12:59 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 19:12:00 -0700 In-Reply-To: <20211009021236.4122790-1-seanjc@google.com> Message-Id: <20211009021236.4122790-8-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 07/43] KVM: Reconcile discrepancies in halt-polling stats 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 Move the halt-polling "success" and histogram stats update into the dedicated helper to fix a discrepancy where the success/fail "time" stats consider polling successful so long as the wait is avoided, but the main "success" and histogram stats consider polling successful if and only if a wake event was detected by the halt-polling loop. Move halt_attempted_poll to the helper as well so that all the stats are updated in a single location. While it's a bit odd to update the stat well after the fact, practically speaking there's no meaningful advantage to updating before polling. Note, there is a functional change in addition to the success vs. fail change. The histogram updates previously called ktime_get() instead of using "cur". But that change is desirable as it means all the stats are now updated with the same polling time, and avoids the extra ktime_get(), which isn't expensive but isn't free either. Reviewed-by: David Matlack Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 4dfcd736b274..1292c7876d3f 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3204,12 +3204,23 @@ static int kvm_vcpu_check_block(struct kvm_vcpu *vcpu) static inline void update_halt_poll_stats(struct kvm_vcpu *vcpu, ktime_t start, ktime_t end, bool success) { + struct kvm_vcpu_stat_generic *stats = &vcpu->stat.generic; u64 poll_ns = ktime_to_ns(ktime_sub(end, start)); - if (success) - vcpu->stat.generic.halt_poll_success_ns += poll_ns; - else - vcpu->stat.generic.halt_poll_fail_ns += poll_ns; + ++vcpu->stat.generic.halt_attempted_poll; + + if (success) { + ++vcpu->stat.generic.halt_successful_poll; + + if (!vcpu_valid_wakeup(vcpu)) + ++vcpu->stat.generic.halt_poll_invalid; + + stats->halt_poll_success_ns += poll_ns; + KVM_STATS_LOG_HIST_UPDATE(stats->halt_poll_success_hist, poll_ns); + } else { + stats->halt_poll_fail_ns += poll_ns; + KVM_STATS_LOG_HIST_UPDATE(stats->halt_poll_fail_hist, poll_ns); + } } /* @@ -3230,30 +3241,16 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) if (do_halt_poll) { ktime_t stop = ktime_add_ns(ktime_get(), vcpu->halt_poll_ns); - ++vcpu->stat.generic.halt_attempted_poll; do { /* * This sets KVM_REQ_UNHALT if an interrupt * arrives. */ - if (kvm_vcpu_check_block(vcpu) < 0) { - ++vcpu->stat.generic.halt_successful_poll; - if (!vcpu_valid_wakeup(vcpu)) - ++vcpu->stat.generic.halt_poll_invalid; - - KVM_STATS_LOG_HIST_UPDATE( - vcpu->stat.generic.halt_poll_success_hist, - ktime_to_ns(ktime_get()) - - ktime_to_ns(start)); + if (kvm_vcpu_check_block(vcpu) < 0) goto out; - } cpu_relax(); poll_end = cur = ktime_get(); } while (kvm_vcpu_can_poll(cur, stop)); - - KVM_STATS_LOG_HIST_UPDATE( - vcpu->stat.generic.halt_poll_fail_hist, - ktime_to_ns(ktime_get()) - ktime_to_ns(start)); } -- 2.33.0.882.g93a45727a2-goog