Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp883364pxb; Wed, 27 Oct 2021 14:25:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvUgrpVmBk/UghfR0I6KsHdFCGOgDGd9AY/VsjNTexeHdvbTWH5rT6N0HQU+/3YLLE5K+E X-Received: by 2002:a17:907:9727:: with SMTP id jg39mr47496ejc.271.1635369924189; Wed, 27 Oct 2021 14:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635369924; cv=none; d=google.com; s=arc-20160816; b=ZmJQpRs4fSeGaScpoSXKsPBHMRU+tOZFBkzP8z9pXLZPgeuzWsyd4p39kPhUKfXLZ6 SK2+xG4zHp5q7EM3EyiQmoxXTqHm417k+CMSa2NHFqItmtLd3HbgwN0J3McPKstDeIGW X842HdfQzF2egndDPFKenADF4F4yqTz8dH22kL6FfsWrqN/7dAP2u/Hcpt1uAbPhSUGe l+eCnvHCKep12IEpGUsTG+hGaXX2ccmkjlw9Z1TlA9uvhHnw5vfKHzAkJJqCRjO2nTqp uNt1RBRf2YS5vOayj1DYLwIHyMBwcDeGbHnX3ki6uyk3M7V42uXA3XAHC22wVPmlBcgk npmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=6755i8Ev1p/V649+fKWbCguz7hafsCtx6KF7gf1uorY=; b=j82QxxyGGg8XNMt4BfTv6aiij7R2LWu3jQidCDNPdX45OT8UPizpU9eyi5ugy6b9wz tcomrHUdnb4IlR9mW2QQy8nYOXgBIqSE7xtmKTeNjSeq0g9JNTI4O4dEG8JOMcQv3boq HC9A0Ql5HPEve3CY98psJBahNTOZOV7rp0Yt/c/zchKlKE/BVfuUIKRtuR+Wo3fiyiHo rIZlzSuubuoBczfys8mga++odc2yNp7l/7qJKqcaiXJMQM8H1CXobmr+InBPywbNvtGq 7RMdILfspjBYnbWQtLn60s+LrYj1CO4bJk3J5SnhoQBjAyIicrRNXSD10gs/LC2+Gk0b vEnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="OC9P+2/g"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hz6si1585347ejc.700.2021.10.27.14.25.00; Wed, 27 Oct 2021 14:25:24 -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=@redhat.com header.s=mimecast20190719 header.b="OC9P+2/g"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241643AbhJ0Lci (ORCPT + 97 others); Wed, 27 Oct 2021 07:32:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40862 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241629AbhJ0Lch (ORCPT ); Wed, 27 Oct 2021 07:32:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635334211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6755i8Ev1p/V649+fKWbCguz7hafsCtx6KF7gf1uorY=; b=OC9P+2/g/e5/3V5cb30fNIrI+24s9VTvRyfG0iOhrXeR/Wk22EhWWLxr8K22ZDhPp15qBc iupJlRMjKgn5qPqLgf+m+PmLZqWweet5oePR0nkrptOZdII72MCzgavfKVX/LbMcOxk2gm CFGFQayK+1XXM8F0EyrupXnNwTa/0sk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-97-SCV0Ypy_PSae9_O3yFoh6Q-1; Wed, 27 Oct 2021 07:30:07 -0400 X-MC-Unique: SCV0Ypy_PSae9_O3yFoh6Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B14A3100C66D; Wed, 27 Oct 2021 11:30:03 +0000 (UTC) Received: from starship (unknown [10.40.194.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id A291C101E591; Wed, 27 Oct 2021 11:29:47 +0000 (UTC) Message-ID: <62231cec8a62db6bf2baba24cc55e0ec2515d0b1.camel@redhat.com> Subject: Re: [PATCH v2 07/43] KVM: Reconcile discrepancies in halt-polling stats From: Maxim Levitsky To: Sean Christopherson , 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 , 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 Date: Wed, 27 Oct 2021 14:29:46 +0300 In-Reply-To: <20211009021236.4122790-8-seanjc@google.com> References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-8-seanjc@google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2021-10-08 at 19:12 -0700, Sean Christopherson wrote: > 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)); > } > > Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky