Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2917944pxb; Fri, 8 Oct 2021 19:14:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybq4LECEfauwdb7MA5vFRMWe2P42O7o2DOUlNkOk4aFjvCruvSjGgxYLOLQRR0PFhNRHPE X-Received: by 2002:a17:906:3148:: with SMTP id e8mr8839023eje.240.1633745699248; Fri, 08 Oct 2021 19:14:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633745699; cv=none; d=google.com; s=arc-20160816; b=OmOYVXrd2/lJlWjRELOIi0Iv5/1towQ1oLrvbGWguC/tvdvm3DiAklXc7Nj02oQFPQ fMuD4pOTJgNS7zzQLgfep9RZGiHMMpzcaJ+5KxeforH/lhjZ67K3xcCJ9cVm1QxDry73 wU1mHaK2Km3AexnbJiGgNfZUEEh8vfUH9JfAYumXWxdsZg0UcSk5f5u2FPduFupDX1AI LQSZBKREsF3GtFCUNlK4VzSzREWJ1QR6H/j94Ll8Xd1RloLqw0hcCYUP6p/f7cv0A3yM EuFgICkdk+7pj6q/35cSUc2NW2IM7IMXCdaC7ywqHAbNd1nTH7kbVvucan1Dpj8kFc75 XYDg== 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=duVCxds/Xk54aU09i5UIkyaIUq0yJMQJZI9wZA2YDlA=; b=P6uOjbzjsyLTjspVrgvjOh9voAA7s3QmH6yp0rL/M03KfLWuQqyZYBJwGGpdBk6+3d zIsIA1hl1PGQFO8CQO1e9A8YsK87hk4zT7/vo9g/eyK5dtYrHjht3VGyDG5IbwI3rr38 Xgpz3/Y5Ix0ofEy83ybWeC/s08CpztkxwNFerktHvqFccOkhmu2fwcsscdHPXzO7Be23 EFSZ51X7EyGtt7MBzMAXzpmT9dQqY28G02+U8rZ2O6guDDsI3WojFrYmsIvbp/7fbV3c oUGSfpx1FAsWGOcxe00G3Q80+Zlrw80dg2fDGu1ABsNnqQt61sfUw22H2tz6tcNDLY+e qMFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Wv/kcG4U"; 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 lx24si446158ejb.439.2021.10.08.19.14.35; Fri, 08 Oct 2021 19:14:59 -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="Wv/kcG4U"; 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 S244263AbhJICO6 (ORCPT + 99 others); Fri, 8 Oct 2021 22:14:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244222AbhJICOx (ORCPT ); Fri, 8 Oct 2021 22:14:53 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF1FFC061755 for ; Fri, 8 Oct 2021 19:12:57 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id b189-20020a3799c6000000b0045eb0c29072so9835518qke.12 for ; Fri, 08 Oct 2021 19:12:57 -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=duVCxds/Xk54aU09i5UIkyaIUq0yJMQJZI9wZA2YDlA=; b=Wv/kcG4ULQxV2PKupeA3o9viF1KOUTbF8+9gkKByWbWPMHCHTm+TZZg7F5whB1kJEv 00RE4Q8btFY4lrjbmtjP6hVSSAYJJdql8WRFW8k/FQZNMBqfykiFr2BiQA+wfe28C543 SWlusb4mpYdymW6ZMpaM7mrIbRvVwIrPb/jvum8yisSKEvO7UFeRbl7H6trZAhauAzQD a1bpHkCHoYH6NJt8GSDU7cMPxIgXQRKLxIkS2NtUm9+Lov6n2e8PGJQvej1YmfsKCffW TihOARLN4ummUTvbvoWa2j+nguD9Os55BuiemMJ8jed6VNGgNVOfE7xoH5rBJNb4aOyN lvIg== 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=duVCxds/Xk54aU09i5UIkyaIUq0yJMQJZI9wZA2YDlA=; b=nuFo4J4sF4mnOFXyzboy5e035fWE3mbBKYcjCSQ6Oh3/SpHk4CdW59wArKe8CiL9hG cb7R0vH4bon+mPzTu6qE/NgateNDog7V1FSlscXN2Ta4oMkGnMeUNQ218Zt2aJhk1D9e 5VpN+5rD0q+MDNNVRN6ULJwC9DX5RPESofhuYJpq7+Fnsi/DOVSGTens6j2uqk1sr+g+ cH+wHn+5HiklOw0RczX2F1W55esgxflpWIvd3UA2mrqPeijxoiaQ06BA/al4PRuhwRif 7pRc1B60p472I9ZUTY5a65bvVcDSOEXrKs4cj74mNW86bnh8Qw8W0msg/Qi5duQnvtdh KG6w== X-Gm-Message-State: AOAM531Jr04AOAND4UQ55rGaysNwBVgv5q+o/pFCDRi0K0OIuWAyVLQB 7700RGgw58BARr+1wXqK+etEoOxamcU= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:a05:622a:1055:: with SMTP id f21mr1892047qte.24.1633745576813; Fri, 08 Oct 2021 19:12:56 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 19:11:59 -0700 In-Reply-To: <20211009021236.4122790-1-seanjc@google.com> Message-Id: <20211009021236.4122790-7-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 06/43] KVM: Refactor and document halt-polling stats update helper 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 Add a comment to document that halt-polling is considered successful even if the polling loop itself didn't detect a wake event, i.e. if a wake event was detect in the final kvm_vcpu_check_block(). Invert the param to update helper so that the helper is a dumb function that is "told" whether or not polling was successful, as opposed to determining success based on blocking behavior. Opportunistically tweak the params to the update helper to reduce the line length for the call site so that it fits on a single line, and so that the prototype conforms to the more traditional kernel style. No functional change intended. Reviewed-by: David Matlack Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 6156719bcbbc..4dfcd736b274 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3201,13 +3201,15 @@ static int kvm_vcpu_check_block(struct kvm_vcpu *vcpu) return ret; } -static inline void -update_halt_poll_stats(struct kvm_vcpu *vcpu, u64 poll_ns, bool waited) +static inline void update_halt_poll_stats(struct kvm_vcpu *vcpu, ktime_t start, + ktime_t end, bool success) { - if (waited) - vcpu->stat.generic.halt_poll_fail_ns += poll_ns; - else + 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; } /* @@ -3277,9 +3279,13 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) kvm_arch_vcpu_unblocking(vcpu); block_ns = ktime_to_ns(cur) - ktime_to_ns(start); + /* + * Note, halt-polling is considered successful so long as the vCPU was + * never actually scheduled out, i.e. even if the wake event arrived + * after of the halt-polling loop itself, but before the full wait. + */ if (do_halt_poll) - update_halt_poll_stats( - vcpu, ktime_to_ns(ktime_sub(poll_end, start)), waited); + update_halt_poll_stats(vcpu, start, poll_end, !waited); if (halt_poll_allowed) { if (!vcpu_valid_wakeup(vcpu)) { -- 2.33.0.882.g93a45727a2-goog