Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2182696pxb; Fri, 24 Sep 2021 23:43:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSKoZO8Y2kCosQcvQDyHxsFvw61/04Q68rGYz6ODRuc8UXHNQ6SjAHxIhFVZ98FZpUAdut X-Received: by 2002:a02:5444:: with SMTP id t65mr12943440jaa.42.1632552194419; Fri, 24 Sep 2021 23:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632552194; cv=none; d=google.com; s=arc-20160816; b=agQcVNt6XZ4qtu/uqAs5JKQCTltLhmhP6UN7lZIQ4XkZu4ngnGPuD0IQUulaJDGRxP P3eC51hq50O1GouFyqmtZeMbuCypbhNY3Di+kCbk9GCpDDnYObXBcAL4w0AgybPdlFv7 gsipRJXScfqJAnmMeOsXEDgy34/aJSHbqSZSAgFdJ7684jj7Y/Wtj6SKtf3hepmJaJnO RjkbchcpkMIB4yrQ2Vsu10FmIAWrBATI1NmOaeIYy5+Q9xPEOGjgQMVizjKkf62+eI6/ V3VanPb9Ekj3BRIA4oyP3FWmelfVsLQFpguL0TXZpEUPZQzX/FZ6sx4BoxZJycO9nSQ+ bpyg== 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=FC6lH+ozNX1rSn/Zvey/qYq1p870FyZo4a/L9N/Tnnw=; b=jC9P5+BpEII3Xi2zVsyAdJgdvotm1bnBF1yGXd5KqHFMTwVBUvrluxPMXO8vtSVLBX pB2dZs2cis/gVNPlXqgA/TN/qJrrP3Flux0kDAM32BuTvjaCyvxqoAVkNFPZN9FA0A6p XdSQ2U+IL7/V4kXzUf9+UnuC0T/P8nnXEoQkUp9MTAq18i0JsIwVJp0HPi45YK4mbpJT 1ZR+ee45WiNkEgThVUHiCaCndyTlX9+OJxdKFQJeYEtxyMHAq6SzXxM88+xRAoSYQPJ5 dIgeOch+zTYhHLsuRdu5wY7tyNAOSn6hfRyJzPDvevi0LUSEVrMvpNV16eaMKrEY6QQR 7BrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=H1jaweJg; 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 z16si4343866ill.147.2021.09.24.23.43.03; Fri, 24 Sep 2021 23:43:14 -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=H1jaweJg; 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 S1346529AbhIYA5V (ORCPT + 99 others); Fri, 24 Sep 2021 20:57:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346178AbhIYA5O (ORCPT ); Fri, 24 Sep 2021 20:57:14 -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 39CADC061571 for ; Fri, 24 Sep 2021 17:55:40 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id b9-20020a5b07890000b0290558245b7eabso5784590ybq.10 for ; Fri, 24 Sep 2021 17:55:40 -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=FC6lH+ozNX1rSn/Zvey/qYq1p870FyZo4a/L9N/Tnnw=; b=H1jaweJg22GIvKz5wgIWDSWv9jBnold6xO8+Vir58J3vlW5yvGMJeY+RWUfUakOq0R orXdIRa207F1tk4zi8vuNL8CHfSf+xkMzWW/nJggJB4dETOCDuAFmo/uxwSrXfHa281o qUP6uOeam12R8fIodx3kiS3/hgxxDJx4AhPCjd3rZUC9XrvKS1+XNmDeTDwaJ19xQqhV cyard+R6ZMOtQO+e0PqanrPIokG2Of63+8xBF7DfYrbPWcKhcpKGH/k2SRB/D5Z/gfcU kBugNJHQN0/5+P2fD4RJGRBJy0JvWbzcwyoR231nRb6G1W76P8apmJbzeaDCVzireilR R6gQ== 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=FC6lH+ozNX1rSn/Zvey/qYq1p870FyZo4a/L9N/Tnnw=; b=J3P+i298HTGF7Ccbvl47kZVZlIj0QOmEM3w1j8tWsKwrfjtNMWtx2rTK6rHHat0Ea3 yE+vHnXvFa7MagVnNkPdUMh4R9pj9ifxSDqrkTUmepiQ1tKw+L6cUgy+Ub68gyApQCzu IiKNGoPvhy38iG+J8NYuP2DFquwHbtparf951GURTlKrq7yuzXgqtaPcXORXIzDdcRBj 7P8S+PgGs86tc7L4eDRUvWWyfL3HZq1ZPwezIKtEUIcYywXhluU1GRayuFwYpGBX7t8q Yhhqj2jJNTwaSVZ3YoV6pgbTCraykMjukLDNQKGXMZ7oecBg7sQquDcUJZAz9ccim7Zm b9TQ== X-Gm-Message-State: AOAM5329RB8htBmCvwTxK0MBnlyPfMgm7h5tDvMdBm43NMBv597JcnZg UCTy4xEB+OzNUj1GPfrI9dylCs/oTL0= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:4c72:89be:dba3:2bcb]) (user=seanjc job=sendgmr) by 2002:a25:d747:: with SMTP id o68mr16209002ybg.488.1632531339489; Fri, 24 Sep 2021 17:55:39 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 24 Sep 2021 17:55:18 -0700 In-Reply-To: <20210925005528.1145584-1-seanjc@google.com> Message-Id: <20210925005528.1145584-5-seanjc@google.com> Mime-Version: 1.0 References: <20210925005528.1145584-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [PATCH 04/14] KVM: Reconcile discrepancies in halt-polling stats From: Sean Christopherson To: Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Christian Borntraeger , Janosch Frank , Paolo Bonzini Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , 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, linux-kernel@vger.kernel.org, David Matlack , 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. 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 12fe91a0a4c8..2ba22b68af3b 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3202,12 +3202,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); + } } /* @@ -3227,30 +3238,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.685.g46640cef36-goog