Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2919594pxb; Fri, 8 Oct 2021 19:18:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTVjzFiLQL3yFUKHdCrWCM9IR0RvbcFt8un4MLPhpVerUUQfEUsoiIZtt7rOz8tf66YusU X-Received: by 2002:a17:906:f208:: with SMTP id gt8mr8152129ejb.522.1633745901245; Fri, 08 Oct 2021 19:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633745901; cv=none; d=google.com; s=arc-20160816; b=bSXBiorPtUcMSM5cm8hRwJqV0LRx1pb/j24HaCRM9zwc0ZPnoknVitaP1EvuY22fWN ufHseQUrjNVK2NsedpBOse1eNx2NNuofcMs/F/nUrBVTaCCpKDQG4gOEe5dVeW5DVIdh EQhEucrUsw6aG7f/XXgjDkXbs8+y5hUh/OHKpzFO3omomLSwoR2o01inJqVrYr9pKbx9 jdzMyvK3vxmyazbwOdl1U6T+TtWQ9OCde43Q1fYdsB68blPPglYEd7SJ6+XH6iAxq4sB +f/+bKgdZ3/fUCLrsmsxnwWapbuj+wzBSRJauqIkw5uULlmyAgEMg6K9Vv1usqf6O5wy 9euA== 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=v9oEyavsvbZNuuh7Q+PKViZhWtX7WRERjDZsEYQR4V4=; b=VQsBYivJaheaY4UAmtWQ2aldIekyjN/IYXvGhTenxLw/OuExD4DMIUJruClTpACd9p LU1rKdctwJXBWtetnvuipjSVVMpyNvNNiiQWqnmwVV/T6FX2/2R1sRdGMF0ahcytzD1J fLYy6NI2SbjyitqiO02XHYe4chHqeAl4KoucDwVtfC5ibSH0vGkTG1a69sQXKBggTd5P OdVVakK4SsHpTRY7KL75bL+H1OoHLBDR0CBE+rsZ10aqOwgBAyz4oUwwFE30V8S1Cq3w cT+2UXuFkhI1B+5c+gkXsalXqbXK8jJPMMUCSgh3cHo2NupguQcSC1zUqL1ESox/vsJ9 55FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SCbmKo34; 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 s7si1454109ejs.402.2021.10.08.19.17.58; Fri, 08 Oct 2021 19:18:21 -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=SCbmKo34; 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 S244452AbhJICPw (ORCPT + 99 others); Fri, 8 Oct 2021 22:15:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244341AbhJICPd (ORCPT ); Fri, 8 Oct 2021 22:15:33 -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 A63DAC06178C for ; Fri, 8 Oct 2021 19:13:19 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id j193-20020a2523ca000000b005b789d71d9aso14934817ybj.21 for ; Fri, 08 Oct 2021 19:13:19 -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=v9oEyavsvbZNuuh7Q+PKViZhWtX7WRERjDZsEYQR4V4=; b=SCbmKo34lA8oU3dDYTZHOvAjjDoLBR2GtJ37FhHZtdcyaf6gZ6bVC5uP3+oE2UTrpm SJ1/Of1dkXNWhoAvrrrc0TBpKSCl7QbMbUP05V4KS7XrfFN5yznrDd3S3rpM+VJAfNxW sgJsB3R3InfKb1YxSdio9cjUyN5vLtdRPSuiKEuzXF8FYwyexaMMd9+vSRILinVV6qSV xoprkuvodBmblmVDAvTCkF2/PUTZlIljlA8Ho6n+DzaVU4wysVfev3JmNpwSBGxwUiGy zAM+39D7BSF2N/tsIW4ULNBWFxHAGE3XzfEwYZiASKhZBF1Ybs3+4AJhw+TkNz0XHMRV DQvQ== 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=v9oEyavsvbZNuuh7Q+PKViZhWtX7WRERjDZsEYQR4V4=; b=zWzOqxRYx0m+rYH63TSuABTd4poIoYi3a9jz2Z8hSGDMB5Coyhjh0h/jNgaM8iweSp hyd6Ss23lisSmKZ1bps15yxXg8xOqtKyEoLAB7R/V0G/MWv+8Ai71qMjHNl8CmO3I3yk 1EkQImbSwyBAUNbznm2s/HZVBnvjfHYf8yJIQ7TGfxu7NtxiaIPKn1rn45YGUi5nro7K 2zaF4XQmP9tJVkR3U/+64i8A9bvW8FV/xLbzapip82kSnbHEU+5FytXdwcD8MK4Cdgwl Bzk89BRVBksE6ZzzOzvGAxl3LFhICOrag4thKn8grTgrNtQPtHqUqXMu687+rv4Ir1VC IJNw== X-Gm-Message-State: AOAM533RnARcDKvRqZE0MrdHxyOP9ZWB/PAb5K8rs7Wy+LIcUIiyCpoJ 1PAjOn7CRZDDtmV8aYT0sXVhHwlsMwE= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:e39b:6333:b001:cb]) (user=seanjc job=sendgmr) by 2002:a25:4cc3:: with SMTP id z186mr7298391yba.212.1633745598902; Fri, 08 Oct 2021 19:13:18 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 8 Oct 2021 19:12:08 -0700 In-Reply-To: <20211009021236.4122790-1-seanjc@google.com> Message-Id: <20211009021236.4122790-16-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 15/43] KVM: stats: Add stat to detect if vcpu is currently blocking 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 From: Jing Zhang Add a "blocking" stat that userspace can use to detect the case where a vCPU is not being run because of an vCPU/guest action, e.g. HLT or WFS on x86, WFI on arm64, etc... Current guest/host/halt stats don't show this well, e.g. if a guest halts for a long period of time then the vCPU could could appear pathologically blocked due to a host condition, when in reality the vCPU has been put into a not-runnable state by the guest. Originally-by: Cannon Matthews Suggested-by: Sean Christopherson Reviewed-by: David Matlack Signed-off-by: Jing Zhang [sean: renamed stat to "blocking", massaged changelog] Signed-off-by: Sean Christopherson --- include/linux/kvm_host.h | 3 ++- include/linux/kvm_types.h | 1 + virt/kvm/kvm_main.c | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 2d837e06eeec..bdaa0e70b060 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1462,7 +1462,8 @@ struct _kvm_stats_desc { STATS_DESC_LOGHIST_TIME_NSEC(VCPU_GENERIC, halt_poll_fail_hist, \ HALT_POLL_HIST_COUNT), \ STATS_DESC_LOGHIST_TIME_NSEC(VCPU_GENERIC, halt_wait_hist, \ - HALT_POLL_HIST_COUNT) + HALT_POLL_HIST_COUNT), \ + STATS_DESC_ICOUNTER(VCPU_GENERIC, blocking) extern struct dentry *kvm_debugfs_dir; diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h index 2237abb93ccd..c4f9257bf32d 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -94,6 +94,7 @@ struct kvm_vcpu_stat_generic { u64 halt_poll_success_hist[HALT_POLL_HIST_COUNT]; u64 halt_poll_fail_hist[HALT_POLL_HIST_COUNT]; u64 halt_wait_hist[HALT_POLL_HIST_COUNT]; + u64 blocking; }; #define KVM_STATS_NAME_SIZE 48 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 42894ff7c474..a36ccdc93a72 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3211,6 +3211,8 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu) struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu); bool waited = false; + vcpu->stat.generic.blocking = 1; + kvm_arch_vcpu_blocking(vcpu); prepare_to_rcuwait(wait); @@ -3227,6 +3229,8 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu) kvm_arch_vcpu_unblocking(vcpu); + vcpu->stat.generic.blocking = 0; + return waited; } -- 2.33.0.882.g93a45727a2-goog