From patchwork Sat Sep 25 00:55:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12517179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EADF0C433F5 for ; Sat, 25 Sep 2021 01:02:37 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A96CF61029 for ; Sat, 25 Sep 2021 01:02:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A96CF61029 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References :Mime-Version:Message-Id:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VZzJW3IUovlL/u53eAQ6EJ5tlJ5TqM6rhuOT6Z25noM=; b=uH7P42EVDsJ0Ic 43swFxUtSdKK4Na6FTm687A7JgjYWDrSv7fxUcy6rm0m3NFjSXl/e0m+haU7ihCnT9Tj38AuLEcmQ AjROrC+tcKvBncb8QBxwYAkkrIykRak/1SoUNlzVyXUlM5edKYVI56BhjOKhmQm6wyAofjvo619bV bmgtZISyGX1BFOn4xQqvtAxvi7uYU3lki1qgGJmeTB7jySKuyfW/XkUpSb9T+swquyx5Fs+wiZeTQ 0d6vDauMj6k20gc1CeMvnxYm6RN0qOyFSYg4MXEN7j4ElE8OwhrpO1OrcUNa3QZPXXnWWfbrVzkUh Jg6mPLJjlJutg0j7Scvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTw32-00Frq3-EW; Sat, 25 Sep 2021 01:00:13 +0000 Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTvyu-00Fq0A-Jh for linux-arm-kernel@lists.infradead.org; Sat, 25 Sep 2021 00:55:57 +0000 Received: by mail-qv1-xf49.google.com with SMTP id h18-20020ad446f2000000b0037a7b48ba05so42478888qvw.19 for ; Fri, 24 Sep 2021 17:55:55 -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=6T7U4FXDkZ4wSGR8PtdmKZv58jArlrzHMsBoVgMor+w=; b=KgOQHaJyXdK+GWQ+2KMuSUf8InFqvhIUK/RxDy04xLvESXB6G2X9Jrj1x+kNBAkBne PhOPZCYyVTUtZk6I8w8hOOLbiyX3n5M/2piepUvMuIeJBbfMZODdPBqWRJwDQLPaSQaV ewfzmZaiB/oD/jH9DEY0fO4j1eb1EJD3/BuOYOmy3Z3p8tliNWZ3jgZE0pCoLAqL2Vps m5RIhb9I1VErm10gqjjLk+L9EXIdeOdjyBhSzqXoCpxEKT+r+HDGPmZylA5xz8VPnVSN xkjZ3BURokP4QeF2PBXLrqVKvIiL/oQGDt7iU9yMu62sr1RqEYFvj68QISSAxPBFN6sX XnfQ== 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=6T7U4FXDkZ4wSGR8PtdmKZv58jArlrzHMsBoVgMor+w=; b=ylhaKztWHiWM39Q3CGwV16wCLYHyrffQafR8gcitOVCbU/VQt8BYcUtuzwJQscV/na w7pbPovj0sIB3pVqtL2MxVTzmEHSR5vFzZZ1amBQ3EQ95hl4RdcpD8FHUj7Q5mawzueL s83d6zOiJxZS19MReaOeX5tJH92GAIG/KJ/xgCjZvapgw3U/LsxhK02E1BAmKgOLByGA L0YVXdBP9CDJBWI+xHrlb2ifRp3IzDOto4XXrRmtgoEqo/xtdJgv0ULkDRjRHdxBL7QQ HzvhgyCZsxAOjUEU66ADLeLgs6jW7y5A8xh46sTGbeGw4FqRKiQS4LAsc528UoMUhstu NKCg== X-Gm-Message-State: AOAM53245M34AJmtfK2pwzLWUJXifCKjXkTvRa+4wk2rXfIYk1IgQvZB 98eeT4Uk52QJKbtK4+m8KEcOwyWkdyE= X-Google-Smtp-Source: ABdhPJxLb+obVS+gVpjC5G0ly7yv0fDwQXsQOvFcbn5XQYMMnEu8TwQl4KzgaC2kLIcfTeYpbPGVyglE2HA= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:4c72:89be:dba3:2bcb]) (user=seanjc job=sendgmr) by 2002:ad4:446f:: with SMTP id s15mr13334020qvt.3.1632531354888; Fri, 24 Sep 2021 17:55:54 -0700 (PDT) Date: Fri, 24 Sep 2021 17:55:25 -0700 In-Reply-To: <20210925005528.1145584-1-seanjc@google.com> Message-Id: <20210925005528.1145584-12-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 11/14] KVM: stats: Add stat to detect if vcpu is currently blocking 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210924_175556_678158_1C53CC49 X-CRM114-Status: GOOD ( 13.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 a 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 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 Signed-off-by: Jing Zhang [sean: renamed stat to "blocking", massaged changelog] Signed-off-by: Sean Christopherson Reviewed-by: David Matlack --- include/linux/kvm_host.h | 3 ++- include/linux/kvm_types.h | 1 + virt/kvm/kvm_main.c | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 655c2b24db2d..9bb1972e396a 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1453,7 +1453,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 fe34457530c2..2980d2b88559 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3208,6 +3208,7 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu) { bool waited = false; + vcpu->stat.generic.blocking = 1; kvm_arch_vcpu_blocking(vcpu); prepare_to_rcuwait(&vcpu->wait); @@ -3223,6 +3224,7 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu) finish_rcuwait(&vcpu->wait); kvm_arch_vcpu_unblocking(vcpu); + vcpu->stat.generic.blocking = 0; return waited; }