From patchwork Wed Jul 14 22:30:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 12377995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC8DDC47E48 for ; Wed, 14 Jul 2021 22:30:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE654613C9 for ; Wed, 14 Jul 2021 22:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230441AbhGNWdc (ORCPT ); Wed, 14 Jul 2021 18:33:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbhGNWdb (ORCPT ); Wed, 14 Jul 2021 18:33:31 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED853C061760 for ; Wed, 14 Jul 2021 15:30:38 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id j17-20020a63cf110000b0290226eb0c27acso2710288pgg.23 for ; Wed, 14 Jul 2021 15:30:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=oy+6fSOgVvelfBYqm9I93gxvw6Do50+x0vRkEpIyCfY=; b=tz16AEtKfG2EUdC15bPbUk+WUL8riHoR54VGvb+lkRLbJSzwSKPUphDFP2c8XJB2oD tRYeCifFwWDoNGRPbOXzhhikKdnEbrV+GSotLdSVMUToZ9YZRkeyBxMJ2fGBXQVSsO/K CES1+CuKoDT1pf7ZHWoVYbxUSeqhJo64Pp0QRbSgnD1IltKWfSHsYw/I46T2ge7j91fu wTffFeqfZi+q0Ejvj6N6HCQObQkcXDAYGTcT77s3U+QmKH9wk9M5r4wUFq7pXrjDGmFq nh1G3rMYh80gn1phbAK8odckwhq3QmEjs9AZA9nzXcUwXS0di14/5auHXCNJ1ZJeheAY yOWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=oy+6fSOgVvelfBYqm9I93gxvw6Do50+x0vRkEpIyCfY=; b=jn0e6un98cVrMFqMuk+oPr9gEIlnyKxUFp8a8wspttWmzn3E1S9f7rjs4Uf1V3CYPG j7w9oxdbZLQADEzokGXQN0vDgYzC6rAYBoUaRwU8BtqjUF/4kse7Z80+slWPfYrkXKA+ e1vBXjmUh/V/2M+42cC0sqn1eiWT8D+0Lq3sChLOP18tqRTPdFkypGO64XeybcScTdgh Zz0uUHpmOUHadxQcJ6juM6FaDZnTXnZfvYOOO4803yNuRHd6U48Qm8t1ioVr64IhVUH2 52SUJjwy3MPfmFelFtVDKG0Np/COG6cvaPYUhCgPxNyzoNfhIZNzs4Lr46G6Q6sz3fyf saLA== X-Gm-Message-State: AOAM5304Ag9rJEKxXZC7xyFLoHE2Ro/IULb0tPoB9179tr1iO41wv7Uv XclVwiQfYuXuWqyAJ7+3vV4He/tOstkJ6JIB+tzi2HMMcCjAaytlhfkefZnzSb8Fli0aIGC6HtO A8Bd0ry3MKhRcNcUb5bpkQUqv8vFHbTDRL2d1GWiTF9kXcP3BRyL6qAcdsGDz7kBOmONWyMQ= X-Google-Smtp-Source: ABdhPJyiuRd2/a1tYiN3eAIKGn0ap+o/F3PZnCFaTGnmlVbtxFslorqTMKuMd+q3l23RLWc4YyKMa8KF4idDns/yFQ== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a17:902:b288:b029:12b:533e:5ea0 with SMTP id u8-20020a170902b288b029012b533e5ea0mr209491plr.44.1626301838387; Wed, 14 Jul 2021 15:30:38 -0700 (PDT) Date: Wed, 14 Jul 2021 22:30:28 +0000 In-Reply-To: <20210714223033.742261-1-jingzhangos@google.com> Message-Id: <20210714223033.742261-2-jingzhangos@google.com> Mime-Version: 1.0 References: <20210714223033.742261-1-jingzhangos@google.com> X-Mailer: git-send-email 2.32.0.402.g57bb445576-goog Subject: [PATCH v2 1/6] KVM: stats: Add capability description for KVM binary stats From: Jing Zhang To: KVM , KVMPPC , Paolo Bonzini , Sean Christopherson , Jim Mattson , Peter Shier , Oliver Upton , David Rientjes , David Matlack Cc: Jing Zhang Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The binary stats capability description was lost during merge of the binary stats patch. Fixes: fdc09ddd4064 ("KVM: stats: Add documentation for binary statistics interface") Signed-off-by: Jing Zhang --- Documentation/virt/kvm/api.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index b9ddce5638f5..889b19a58b33 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -7241,3 +7241,11 @@ The argument to KVM_ENABLE_CAP is also a bitmask, and must be a subset of the result of KVM_CHECK_EXTENSION. KVM will forward to userspace the hypercalls whose corresponding bit is in the argument, and return ENOSYS for the others. + +8.35 KVM_CAP_BINARY_STATS_FD +---------------------------- + +:Architectures: all + +This capability indicates the feature that userspace can get a file descriptor +for every VM and VCPU to read statistics data in binary format. From patchwork Wed Jul 14 22:30:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 12377997 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C67DEC12002 for ; Wed, 14 Jul 2021 22:30:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B000E613C9 for ; Wed, 14 Jul 2021 22:30:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbhGNWde (ORCPT ); Wed, 14 Jul 2021 18:33:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233967AbhGNWdd (ORCPT ); Wed, 14 Jul 2021 18:33:33 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99B68C061760 for ; Wed, 14 Jul 2021 15:30:40 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id l21-20020a056a0016d5b0290319e1ac27b1so2727634pfc.12 for ; Wed, 14 Jul 2021 15:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=cQrvGwwPS02wSpYxaKEKB1xeCe3Pf6yhrdDBd5BAS+M=; b=HOUsBolUL7C0/Jr6UlSR2TqjedJlpQ3FY0r8zm9nNAsEJ94XgboBoRcmnst3IDXeOl X/X5dvTBSJVFH7NZxOwcyI+el+0d3kaHUiaZCfwVYwB12dON9AlHZ0av9JVzc5ybJJ41 Wf94pkxEHbkqAIG4ye+/QOqRX4Fvfaw8YnblgMIDSYGYRDAOjgU0X3Kcd53mIVMorToC ukdmIYATi3z4PMee4bJK9v8+Oxe0Xp55cs6PfubPUudxdgqvN9NJa1eMGwOoV6VXfNRy 3SbuhoEXhF5cT+cv8DR8vCdPlI7sEK6XstpphqEItNqmMmcjqfEmbGx8MEe+F9SJd9BV emDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=cQrvGwwPS02wSpYxaKEKB1xeCe3Pf6yhrdDBd5BAS+M=; b=Qp1Y30GCItLBXzGvF2fY6xdTk9hhvL01bDybZtnDZfGIZfMQ5RWLvCHX9U9c/8UUYQ IW67++dU3JKGDrrVw+LNnygp1QxymsYNCPWPaIytwr/Jq7an3Rcvw97Zxj/je2o9iaNV w8SNmTfX3x11SUdjhf3+XNOv9MR/VYGl9pDl46vt1RBNyvmWZqtoJ2vY/aGhEedO5SO8 M6Q05IaHDWTQhK9atS3zycNxTf+DzwtuKXiz6I/ZD7KV8aNzovH83d5a+mjhLMkFINQe 6siBpMdB1P6H0dluHhsD7f64uXmAhhXi7HE71gC3VrQdwKxpScUJrL4bmPaK0vHpqi7l xG5g== X-Gm-Message-State: AOAM533D/smRN5V8zdM/uDSoXnDpJf2POyEJOjTDt7h6/9Ti7QKYcEOX xry87LAHwmrOjq2ofZwS2KAt/JzImhgWPR3EiCGPNaD9RHhT8aHuIkN0yDMjFQS9suoO/fU4zpN juoc7XElgZFjAbSkoI1txCx5fEUSOosjl8/oRp0L4vlj76+5J7muFBtJNscMAKXIf5SqsaY8= X-Google-Smtp-Source: ABdhPJxTENLZidlXhfS4Lx3MoS6T4avx/cMc9HuxryU9eVD66KKDLf/p9bUMrMnvRc0ezhURwHLyXaDxuj1NQBdCTg== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a17:902:d90b:b029:11b:f58c:f3d6 with SMTP id c11-20020a170902d90bb029011bf58cf3d6mr341789plz.42.1626301840050; Wed, 14 Jul 2021 15:30:40 -0700 (PDT) Date: Wed, 14 Jul 2021 22:30:29 +0000 In-Reply-To: <20210714223033.742261-1-jingzhangos@google.com> Message-Id: <20210714223033.742261-3-jingzhangos@google.com> Mime-Version: 1.0 References: <20210714223033.742261-1-jingzhangos@google.com> X-Mailer: git-send-email 2.32.0.402.g57bb445576-goog Subject: [PATCH v2 2/6] KVM: stats: Support linear and logarithmic histogram statistics From: Jing Zhang To: KVM , KVMPPC , Paolo Bonzini , Sean Christopherson , Jim Mattson , Peter Shier , Oliver Upton , David Rientjes , David Matlack Cc: Jing Zhang Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add new types of KVM stats, linear and logarithmic histogram. Histogram are very useful for observing the value distribution of time or size related stats. Signed-off-by: Jing Zhang --- arch/arm64/kvm/guest.c | 4 --- arch/mips/kvm/mips.c | 4 --- arch/powerpc/kvm/book3s.c | 4 --- arch/powerpc/kvm/booke.c | 4 --- arch/s390/kvm/kvm-s390.c | 4 --- arch/x86/kvm/x86.c | 4 --- include/linux/kvm_host.h | 53 ++++++++++++++++++++++++++++----------- include/linux/kvm_types.h | 15 +++++++++++ include/uapi/linux/kvm.h | 11 +++++--- virt/kvm/binary_stats.c | 32 +++++++++++++++++++++++ 10 files changed, 92 insertions(+), 43 deletions(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index 1dfb83578277..5188184d25d0 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -31,8 +31,6 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { KVM_GENERIC_VM_STATS() }; -static_assert(ARRAY_SIZE(kvm_vm_stats_desc) == - sizeof(struct kvm_vm_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vm_stats_header = { .name_size = KVM_STATS_NAME_SIZE, @@ -52,8 +50,6 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { STATS_DESC_COUNTER(VCPU, mmio_exit_kernel), STATS_DESC_COUNTER(VCPU, exits) }; -static_assert(ARRAY_SIZE(kvm_vcpu_stats_desc) == - sizeof(struct kvm_vcpu_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vcpu_stats_header = { .name_size = KVM_STATS_NAME_SIZE, diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c index af9dd029a4e1..75c6f264c626 100644 --- a/arch/mips/kvm/mips.c +++ b/arch/mips/kvm/mips.c @@ -41,8 +41,6 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { KVM_GENERIC_VM_STATS() }; -static_assert(ARRAY_SIZE(kvm_vm_stats_desc) == - sizeof(struct kvm_vm_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vm_stats_header = { .name_size = KVM_STATS_NAME_SIZE, @@ -85,8 +83,6 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { STATS_DESC_COUNTER(VCPU, vz_cpucfg_exits), #endif }; -static_assert(ARRAY_SIZE(kvm_vcpu_stats_desc) == - sizeof(struct kvm_vcpu_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vcpu_stats_header = { .name_size = KVM_STATS_NAME_SIZE, diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index 79833f78d1da..5cc6e90095b0 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -43,8 +43,6 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { STATS_DESC_ICOUNTER(VM, num_2M_pages), STATS_DESC_ICOUNTER(VM, num_1G_pages) }; -static_assert(ARRAY_SIZE(kvm_vm_stats_desc) == - sizeof(struct kvm_vm_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vm_stats_header = { .name_size = KVM_STATS_NAME_SIZE, @@ -88,8 +86,6 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { STATS_DESC_COUNTER(VCPU, pthru_host), STATS_DESC_COUNTER(VCPU, pthru_bad_aff) }; -static_assert(ARRAY_SIZE(kvm_vcpu_stats_desc) == - sizeof(struct kvm_vcpu_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vcpu_stats_header = { .name_size = KVM_STATS_NAME_SIZE, diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 551b30d84aee..5ed6c235e059 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -41,8 +41,6 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { STATS_DESC_ICOUNTER(VM, num_2M_pages), STATS_DESC_ICOUNTER(VM, num_1G_pages) }; -static_assert(ARRAY_SIZE(kvm_vm_stats_desc) == - sizeof(struct kvm_vm_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vm_stats_header = { .name_size = KVM_STATS_NAME_SIZE, @@ -79,8 +77,6 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { STATS_DESC_COUNTER(VCPU, pthru_host), STATS_DESC_COUNTER(VCPU, pthru_bad_aff) }; -static_assert(ARRAY_SIZE(kvm_vcpu_stats_desc) == - sizeof(struct kvm_vcpu_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vcpu_stats_header = { .name_size = KVM_STATS_NAME_SIZE, diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index f9fb1e1d960d..c7f2b1124740 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -66,8 +66,6 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { STATS_DESC_COUNTER(VM, inject_service_signal), STATS_DESC_COUNTER(VM, inject_virtio) }; -static_assert(ARRAY_SIZE(kvm_vm_stats_desc) == - sizeof(struct kvm_vm_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vm_stats_header = { .name_size = KVM_STATS_NAME_SIZE, @@ -174,8 +172,6 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { STATS_DESC_COUNTER(VCPU, diagnose_other), STATS_DESC_COUNTER(VCPU, pfault_sync) }; -static_assert(ARRAY_SIZE(kvm_vcpu_stats_desc) == - sizeof(struct kvm_vcpu_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vcpu_stats_header = { .name_size = KVM_STATS_NAME_SIZE, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d715ae9f9108..e1b00597b84f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -236,8 +236,6 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { STATS_DESC_ICOUNTER(VM, nx_lpage_splits), STATS_DESC_PCOUNTER(VM, max_mmu_page_hash_collisions) }; -static_assert(ARRAY_SIZE(kvm_vm_stats_desc) == - sizeof(struct kvm_vm_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vm_stats_header = { .name_size = KVM_STATS_NAME_SIZE, @@ -277,8 +275,6 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { STATS_DESC_COUNTER(VCPU, directed_yield_successful), STATS_DESC_ICOUNTER(VCPU, guest_mode) }; -static_assert(ARRAY_SIZE(kvm_vcpu_stats_desc) == - sizeof(struct kvm_vcpu_stat) / sizeof(u64)); const struct kvm_stats_header kvm_vcpu_stats_header = { .name_size = KVM_STATS_NAME_SIZE, diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index ae7735b490b4..c44cf5029e30 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1273,56 +1273,66 @@ struct _kvm_stats_desc { char name[KVM_STATS_NAME_SIZE]; }; -#define STATS_DESC_COMMON(type, unit, base, exp) \ +#define STATS_DESC_COMMON(type, unit, base, exp, sz, bsz) \ .flags = type | unit | base | \ BUILD_BUG_ON_ZERO(type & ~KVM_STATS_TYPE_MASK) | \ BUILD_BUG_ON_ZERO(unit & ~KVM_STATS_UNIT_MASK) | \ BUILD_BUG_ON_ZERO(base & ~KVM_STATS_BASE_MASK), \ .exponent = exp, \ - .size = 1 + .size = sz, \ + .bucket_size = bsz -#define VM_GENERIC_STATS_DESC(stat, type, unit, base, exp) \ +#define VM_GENERIC_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp), \ + STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ .offset = offsetof(struct kvm_vm_stat, generic.stat) \ }, \ .name = #stat, \ } -#define VCPU_GENERIC_STATS_DESC(stat, type, unit, base, exp) \ +#define VCPU_GENERIC_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp), \ + STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ .offset = offsetof(struct kvm_vcpu_stat, generic.stat) \ }, \ .name = #stat, \ } -#define VM_STATS_DESC(stat, type, unit, base, exp) \ +#define VM_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp), \ + STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ .offset = offsetof(struct kvm_vm_stat, stat) \ }, \ .name = #stat, \ } -#define VCPU_STATS_DESC(stat, type, unit, base, exp) \ +#define VCPU_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp), \ + STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ .offset = offsetof(struct kvm_vcpu_stat, stat) \ }, \ .name = #stat, \ } /* SCOPE: VM, VM_GENERIC, VCPU, VCPU_GENERIC */ -#define STATS_DESC(SCOPE, stat, type, unit, base, exp) \ - SCOPE##_STATS_DESC(stat, type, unit, base, exp) +#define STATS_DESC(SCOPE, stat, type, unit, base, exp, sz, bsz) \ + SCOPE##_STATS_DESC(stat, type, unit, base, exp, sz, bsz) #define STATS_DESC_CUMULATIVE(SCOPE, name, unit, base, exponent) \ - STATS_DESC(SCOPE, name, KVM_STATS_TYPE_CUMULATIVE, unit, base, exponent) + STATS_DESC(SCOPE, name, KVM_STATS_TYPE_CUMULATIVE, \ + unit, base, exponent, 1, 0) #define STATS_DESC_INSTANT(SCOPE, name, unit, base, exponent) \ - STATS_DESC(SCOPE, name, KVM_STATS_TYPE_INSTANT, unit, base, exponent) + STATS_DESC(SCOPE, name, KVM_STATS_TYPE_INSTANT, \ + unit, base, exponent, 1, 0) #define STATS_DESC_PEAK(SCOPE, name, unit, base, exponent) \ - STATS_DESC(SCOPE, name, KVM_STATS_TYPE_PEAK, unit, base, exponent) + STATS_DESC(SCOPE, name, KVM_STATS_TYPE_PEAK, \ + unit, base, exponent, 1, 0) +#define STATS_DESC_LINEAR_HIST(SCOPE, name, unit, base, exponent, sz, bsz) \ + STATS_DESC(SCOPE, name, KVM_STATS_TYPE_LINEAR_HIST, \ + unit, base, exponent, sz, bsz) +#define STATS_DESC_LOG_HIST(SCOPE, name, unit, base, exponent, sz) \ + STATS_DESC(SCOPE, name, KVM_STATS_TYPE_LOG_HIST, \ + unit, base, exponent, sz, 0) /* Cumulative counter, read/write */ #define STATS_DESC_COUNTER(SCOPE, name) \ @@ -1341,6 +1351,14 @@ struct _kvm_stats_desc { #define STATS_DESC_TIME_NSEC(SCOPE, name) \ STATS_DESC_CUMULATIVE(SCOPE, name, KVM_STATS_UNIT_SECONDS, \ KVM_STATS_BASE_POW10, -9) +/* Linear histogram for time in nanosecond */ +#define STATS_DESC_LINHIST_TIME_NSEC(SCOPE, name, sz, bsz) \ + STATS_DESC_LINEAR_HIST(SCOPE, name, KVM_STATS_UNIT_SECONDS, \ + KVM_STATS_BASE_POW10, -9, sz, bsz) +/* Logarithmic histogram for time in nanosecond */ +#define STATS_DESC_LOGHIST_TIME_NSEC(SCOPE, name, sz) \ + STATS_DESC_LOG_HIST(SCOPE, name, KVM_STATS_UNIT_SECONDS, \ + KVM_STATS_BASE_POW10, -9, sz) #define KVM_GENERIC_VM_STATS() \ STATS_DESC_COUNTER(VM_GENERIC, remote_tlb_flush) @@ -1354,10 +1372,15 @@ struct _kvm_stats_desc { STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_poll_fail_ns) extern struct dentry *kvm_debugfs_dir; + ssize_t kvm_stats_read(char *id, const struct kvm_stats_header *header, const struct _kvm_stats_desc *desc, void *stats, size_t size_stats, char __user *user_buffer, size_t size, loff_t *offset); +void kvm_stats_linear_hist_update(u64 *data, size_t size, + u64 value, size_t bucket_size); +void kvm_stats_log_hist_update(u64 *data, size_t size, u64 value); + extern const struct kvm_stats_header kvm_vm_stats_header; extern const struct _kvm_stats_desc kvm_vm_stats_desc[]; extern const struct kvm_stats_header kvm_vcpu_stats_header; diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h index ed6a985c5680..723f8a77a8ea 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -76,6 +76,21 @@ struct kvm_mmu_memory_cache { }; #endif +/* Constants used for histogram stats */ +#define LINHIST_SIZE_SMALL 10 +#define LINHIST_SIZE_MEDIUM 20 +#define LINHIST_SIZE_LARGE 50 +#define LINHIST_SIZE_XLARGE 100 +#define LINHIST_BUCKET_SIZE_SMALL 10 +#define LINHIST_BUCKET_SIZE_MEDIUM 100 +#define LINHIST_BUCKET_SIZE_LARGE 1000 +#define LINHIST_BUCKET_SIZE_XLARGE 10000 + +#define LOGHIST_BUCKET_COUNT_SMALL 8 +#define LOGHIST_BUCKET_COUNT_MEDIUM 16 +#define LOGHIST_BUCKET_COUNT_LARGE 32 +#define LOGHIST_BUCKET_COUNT_XLARGE 64 + struct kvm_vm_stat_generic { u64 remote_tlb_flush; }; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index d9e4aabcb31a..a067410ebea5 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1965,7 +1965,9 @@ struct kvm_stats_header { #define KVM_STATS_TYPE_CUMULATIVE (0x0 << KVM_STATS_TYPE_SHIFT) #define KVM_STATS_TYPE_INSTANT (0x1 << KVM_STATS_TYPE_SHIFT) #define KVM_STATS_TYPE_PEAK (0x2 << KVM_STATS_TYPE_SHIFT) -#define KVM_STATS_TYPE_MAX KVM_STATS_TYPE_PEAK +#define KVM_STATS_TYPE_LINEAR_HIST (0x3 << KVM_STATS_TYPE_SHIFT) +#define KVM_STATS_TYPE_LOG_HIST (0x4 << KVM_STATS_TYPE_SHIFT) +#define KVM_STATS_TYPE_MAX KVM_STATS_TYPE_LOG_HIST #define KVM_STATS_UNIT_SHIFT 4 #define KVM_STATS_UNIT_MASK (0xF << KVM_STATS_UNIT_SHIFT) @@ -1988,8 +1990,9 @@ struct kvm_stats_header { * @size: The number of data items for this stats. * Every data item is of type __u64. * @offset: The offset of the stats to the start of stat structure in - * struture kvm or kvm_vcpu. - * @unused: Unused field for future usage. Always 0 for now. + * structure kvm or kvm_vcpu. + * @bucket_size: A parameter value used for histogram stats. It is only used + * for linear histogram stats, specifying the size of the bucket; * @name: The name string for the stats. Its size is indicated by the * &kvm_stats_header->name_size. */ @@ -1998,7 +2001,7 @@ struct kvm_stats_desc { __s16 exponent; __u16 size; __u32 offset; - __u32 unused; + __u32 bucket_size; char name[]; }; diff --git a/virt/kvm/binary_stats.c b/virt/kvm/binary_stats.c index e609d428811a..c134383f43a8 100644 --- a/virt/kvm/binary_stats.c +++ b/virt/kvm/binary_stats.c @@ -144,3 +144,35 @@ ssize_t kvm_stats_read(char *id, const struct kvm_stats_header *header, *offset = pos; return len; } + +/** + * kvm_stats_linear_hist_update() - Update bucket value for linear histogram + * statistics data. + * + * @data: start address of the stats data + * @size: the number of bucket of the stats data + * @value: the new value used to update the linear histogram's bucket + * @bucket_size: the size (width) of a bucket + */ +void kvm_stats_linear_hist_update(u64 *data, size_t size, + u64 value, size_t bucket_size) +{ + size_t index = min((size_t)div64_u64(value, bucket_size), size - 1); + + ++data[index]; +} + +/** + * kvm_stats_log_hist_update() - Update bucket value for logarithmic histogram + * statistics data. + * + * @data: start address of the stats data + * @size: the number of bucket of the stats data + * @value: the new value used to update the logarithmic histogram's bucket + */ +void kvm_stats_log_hist_update(u64 *data, size_t size, u64 value) +{ + size_t index = min((size_t)fls64(value), size - 1); + + ++data[index]; +} From patchwork Wed Jul 14 22:30:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 12377999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AACBC47E48 for ; Wed, 14 Jul 2021 22:30:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1E37610A7 for ; Wed, 14 Jul 2021 22:30:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235198AbhGNWdf (ORCPT ); Wed, 14 Jul 2021 18:33:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233967AbhGNWdf (ORCPT ); Wed, 14 Jul 2021 18:33:35 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C775C061760 for ; Wed, 14 Jul 2021 15:30:42 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id k3-20020a6568c30000b029022887377adeso2712483pgt.15 for ; Wed, 14 Jul 2021 15:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=8XizaOLNigUNpC9Dwn5fRe5kCM6P7X2OH+X0AAfHNv0=; b=lIHJIUEhYgsfIVcuXOj2x2gJyZJ5gPcUGG1iXf69ABeEA1PwhadTIpxNzqSuICnqG6 AlJ01r7cEHXvgt3w4CCcFSAA4W4jBRUOX+zbi/mkdGTz+VHTZLDNBGk0rNS6dKefPpRY Umt211MalkIkAKFSTjMTnlKgXWmkuAZdzijWpKYPZwdW7A/CLpFoRT1PdkV/aZreLVvf d66Qy7seRwzxghkXBrfvvDhKAcMCC5umCmmlJVdMLpweQHtUrkGmBVeqQFRdBRQuBeN5 w9Jbf/+ulDFMUq3dlgoBqIC36NA0Wb00jZb2QBUuas/9nU6M+HUn2fqxBaX/ta9LHUug Su7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=8XizaOLNigUNpC9Dwn5fRe5kCM6P7X2OH+X0AAfHNv0=; b=lta9c5eCxYt6rlCuYCDS+s5dYwxIchGyMmha+aJTeQBJ4Ti1TiZozMWGs87cO9ScXn UFntCPNNrmgIxOZDdUQ+jlDYUz/Zcu+PhPfSzdvpwkzQg/Bkju2FzohrpiNVrIN+n7r9 aq32QCDuWkIdi2a9hP78BZtT9txERKb9Hq5hQWkgoXW+L3NiKLFGUFGmeeWW9Upy0oFi 65vyGyYbm9QVZ/A+EqHBGzhswGaDMA8beCU1moNVDiKSFLTphWLQD5nrdnRcT7lWbalG r1xm/RPZTLPDOjrdaQfx0asGvf5CULD7ZgGrAaUficpJtYEYsQ/aTqpid0XpENrwb5hA A1ow== X-Gm-Message-State: AOAM532XEZ8hzQIL4E5Syu3OlbAYFA4HQN+8oVqAAI2tFB7RCiAe9VAr AuhK4Pe5Ph+zzMTasPksu7l3t2qj8B7c4E5gWrLHLBXLk1TWrtUotCEGsg2i//EN6SVMDX3uKo3 xaPrdZ+FhiC04zlj+nTToCv+FzRdWYDoWgC+xKRBgHZbZ3lcJYTsgCgE7q7hGOxo4rAgG5ZM= X-Google-Smtp-Source: ABdhPJxkquTJrpafWNjf+vRDCUU2OXKY+VTtAtXkQF0Rw1LqYiv4dAYfxoh+IGLNHgt3T363WDQU3Bo7uW5JxHS0TA== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a17:902:778f:b029:128:b3e1:15f8 with SMTP id o15-20020a170902778fb0290128b3e115f8mr248466pll.14.1626301841672; Wed, 14 Jul 2021 15:30:41 -0700 (PDT) Date: Wed, 14 Jul 2021 22:30:30 +0000 In-Reply-To: <20210714223033.742261-1-jingzhangos@google.com> Message-Id: <20210714223033.742261-4-jingzhangos@google.com> Mime-Version: 1.0 References: <20210714223033.742261-1-jingzhangos@google.com> X-Mailer: git-send-email 2.32.0.402.g57bb445576-goog Subject: [PATCH v2 3/6] KVM: stats: Update doc for histogram statistics From: Jing Zhang To: KVM , KVMPPC , Paolo Bonzini , Sean Christopherson , Jim Mattson , Peter Shier , Oliver Upton , David Rientjes , David Matlack Cc: Jing Zhang Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add documentations for linear and logarithmic histogram statistics. Signed-off-by: Jing Zhang --- Documentation/virt/kvm/api.rst | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 889b19a58b33..bcd3b77fa4e8 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -5207,6 +5207,9 @@ by a string of size ``name_size``. #define KVM_STATS_TYPE_CUMULATIVE (0x0 << KVM_STATS_TYPE_SHIFT) #define KVM_STATS_TYPE_INSTANT (0x1 << KVM_STATS_TYPE_SHIFT) #define KVM_STATS_TYPE_PEAK (0x2 << KVM_STATS_TYPE_SHIFT) + #define KVM_STATS_TYPE_LINEAR_HIST (0x3 << KVM_STATS_TYPE_SHIFT) + #define KVM_STATS_TYPE_LOG_HIST (0x4 << KVM_STATS_TYPE_SHIFT) + #define KVM_STATS_TYPE_MAX KVM_STATS_TYPE_LOG_HIST #define KVM_STATS_UNIT_SHIFT 4 #define KVM_STATS_UNIT_MASK (0xF << KVM_STATS_UNIT_SHIFT) @@ -5214,18 +5217,20 @@ by a string of size ``name_size``. #define KVM_STATS_UNIT_BYTES (0x1 << KVM_STATS_UNIT_SHIFT) #define KVM_STATS_UNIT_SECONDS (0x2 << KVM_STATS_UNIT_SHIFT) #define KVM_STATS_UNIT_CYCLES (0x3 << KVM_STATS_UNIT_SHIFT) + #define KVM_STATS_UNIT_MAX KVM_STATS_UNIT_CYCLES #define KVM_STATS_BASE_SHIFT 8 #define KVM_STATS_BASE_MASK (0xF << KVM_STATS_BASE_SHIFT) #define KVM_STATS_BASE_POW10 (0x0 << KVM_STATS_BASE_SHIFT) #define KVM_STATS_BASE_POW2 (0x1 << KVM_STATS_BASE_SHIFT) + #define KVM_STATS_BASE_MAX KVM_STATS_BASE_POW2 struct kvm_stats_desc { __u32 flags; __s16 exponent; __u16 size; __u32 offset; - __u32 unused; + __u32 bucket_size; char name[]; }; @@ -5250,6 +5255,21 @@ Bits 0-3 of ``flags`` encode the type: represents a peak value for a measurement, for example the maximum number of items in a hash table bucket, the longest time waited and so on. The corresponding ``size`` field for this type is always 1. + * ``KVM_STATS_TYPE_LINEAR_HIST`` + The statistics data is in the form of linear histogram. The number of + buckets is specified by the ``size`` field. The size of buckets is specified + by the ``hist_param`` field. The range of the Nth bucket (1 <= N < ``size``) + is [``hist_param``*(N-1), ``hist_param``*N), while the range of the last + bucket is [``hist_param``*(``size``-1), +INF). (+INF means positive infinity + value.) The bucket value indicates how many times the statistics data is in + the bucket's range. + * ``KVM_STATS_TYPE_LOG_HIST`` + The statistics data is in the form of logarithmic histogram. The number of + buckets is specified by the ``size`` field. The range of the first bucket is + [0, 1), while the range of the last bucket is [pow(2, ``size``-2), +INF). + Otherwise, The Nth bucket (1 < N < ``size``) covers + [pow(2, N-2), pow(2, N-1)). The bucket value indicates how many times the + statistics data is in the bucket's range. Bits 4-7 of ``flags`` encode the unit: * ``KVM_STATS_UNIT_NONE`` @@ -5282,9 +5302,9 @@ unsigned 64bit data. The ``offset`` field is the offset from the start of Data Block to the start of the corresponding statistics data. -The ``unused`` field is reserved for future support for other types of -statistics data, like log/linear histogram. Its value is always 0 for the types -defined above. +The ``bucket_size`` field is used as a parameter for histogram statistics data. +It is only used by linear histogram statistics data, specifying the size of a +bucket. The ``name`` field is the name string of the statistics data. The name string starts at the end of ``struct kvm_stats_desc``. The maximum length including From patchwork Wed Jul 14 22:30:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 12378001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 733D1C12002 for ; Wed, 14 Jul 2021 22:30:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A0CA610A7 for ; Wed, 14 Jul 2021 22:30:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235338AbhGNWdh (ORCPT ); Wed, 14 Jul 2021 18:33:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235538AbhGNWdh (ORCPT ); Wed, 14 Jul 2021 18:33:37 -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 E0804C061760 for ; Wed, 14 Jul 2021 15:30:43 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id h1-20020a255f410000b02905585436b530so4748627ybm.21 for ; Wed, 14 Jul 2021 15:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=NLo2orw2GrujjOHbkY0DlGp9/FL5YLDeLP3ALI1aHhM=; b=G4hul3bnSLj9qvJAnOnLCK17khPm4foRgCTwXc4l4zgP2yieKnyScK2wI5PUMF8BUf Snj5M4N6oJjq9eyI8P9uKkPkxJme8112xSa899olrd4QJvobjBJafq4SaSvBM2RDogHq UfHY3z7ZaMgX/v3Pj0LyiRD1snrf53wFsnQDJUFc3KgWeJgKptjQz+U03NtkpBKr3++C M+UL3cUjkPqz+GRugB9zn67UJ9rqprl+atvKWF+00wbAxNvoF8UzEwbkG1M4scrD4KFZ hi6Sz4U7qmUvCWLh0c/SONN25bNkbYLC3tX3zjhXi7VMM7tyeUpi6Z/mtuAL77EKdGfi mxag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=NLo2orw2GrujjOHbkY0DlGp9/FL5YLDeLP3ALI1aHhM=; b=PlFAAw9SmHZXAJ/48A5sFfN/onDAY5cYVninxL7a2If+3kFREnu0SoChU1nsQTi+2Q 9Bm2VoYEWnwADgMKYrkltyP17u1DE4N4ATnici8Oqqa1FepS0GwjX1yidWi1sorDh2IU TYKbTI5XPZc4P15Zh9kefbMFf97AzcJMmACKC7ms7tVAS4cbpv43rHiwQF81jEzLYdVq zY+mX4ekiZra6rIvY+NaXGD3bcaQ7S4/ChoBZuIJZ3wWJ3zpJ7iM0yykfcz4E2BPrEE/ NQvbodJXPwRvqTXq5LLvVG3KpmU3zbAf7SaE0Xs+UL37wE3D+JClrQs0TjC1QTG2ORNY tELQ== X-Gm-Message-State: AOAM532pZksMZ+uiHKrhY7jVscL9s6nqbQrfV8xavYx2wY+oawxboQfB Rm+YnctLNhh6PP6binhwZasfvrARqT4ybLFFLKQRTIcVpFzmGlk9biuQNADVhiM7rc+nN61wdTS rpl5Ni3e0ftKIMvrVkaZEDC+U/tcePGegyAbecsNFJTnuJU8R+Yi+yqp+VkexDoNkC+nonLM= X-Google-Smtp-Source: ABdhPJwRpOHjHJzu/zQxNv/BIxT6+OmPYhVERu/lrtpL/BGir7IgLCbLCtnY47LxeFknQwTnK7DC7FRXYtPykbGkxA== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a25:d912:: with SMTP id q18mr323595ybg.294.1626301843001; Wed, 14 Jul 2021 15:30:43 -0700 (PDT) Date: Wed, 14 Jul 2021 22:30:31 +0000 In-Reply-To: <20210714223033.742261-1-jingzhangos@google.com> Message-Id: <20210714223033.742261-5-jingzhangos@google.com> Mime-Version: 1.0 References: <20210714223033.742261-1-jingzhangos@google.com> X-Mailer: git-send-email 2.32.0.402.g57bb445576-goog Subject: [PATCH v2 4/6] KVM: selftests: Add checks for histogram stats bucket_size field From: Jing Zhang To: KVM , KVMPPC , Paolo Bonzini , Sean Christopherson , Jim Mattson , Peter Shier , Oliver Upton , David Rientjes , David Matlack Cc: Jing Zhang Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The bucket_size field should be non-zero for linear histogram stats and should be zero for other stats types. Reviewed-by: David Matlack Signed-off-by: Jing Zhang --- tools/testing/selftests/kvm/kvm_binary_stats_test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/kvm/kvm_binary_stats_test.c b/tools/testing/selftests/kvm/kvm_binary_stats_test.c index 5906bbc08483..17f65d514915 100644 --- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c +++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c @@ -109,6 +109,18 @@ static void stats_test(int stats_fd) /* Check size field, which should not be zero */ TEST_ASSERT(pdesc->size, "KVM descriptor(%s) with size of 0", pdesc->name); + /* Check bucket_size field */ + switch (pdesc->flags & KVM_STATS_TYPE_MASK) { + case KVM_STATS_TYPE_LINEAR_HIST: + TEST_ASSERT(pdesc->bucket_size, + "Bucket size of Linear Histogram stats (%s) is zero", + pdesc->name); + break; + default: + TEST_ASSERT(!pdesc->bucket_size, + "Bucket size of stats (%s) is not zero", + pdesc->name); + } size_data += pdesc->size * sizeof(*stats_data); } /* Check overlap */ From patchwork Wed Jul 14 22:30:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 12378003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C360C1B08C for ; Wed, 14 Jul 2021 22:30:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3985D613C2 for ; Wed, 14 Jul 2021 22:30:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236046AbhGNWdi (ORCPT ); Wed, 14 Jul 2021 18:33:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235956AbhGNWdi (ORCPT ); Wed, 14 Jul 2021 18:33:38 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3088DC061762 for ; Wed, 14 Jul 2021 15:30:45 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id j17-20020a63cf110000b0290226eb0c27acso2710486pgg.23 for ; Wed, 14 Jul 2021 15:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=vSk4PrTqRRwcqhupjszeaAACsXVyJ0E1vQTmnoEDT1w=; b=ewrhIlPFa7nrn5V7dkW6IIEzVDGj+CzxYfs/Je0/eP+pa6iH5ggLirvMmIThx/X3Jl pdiWX+3Kwonpd382EatujQFMrqRGzmYYFFZo+u94+cF9mnjNvQ6Ghzxu7uioCAoSObXI 4UKjuoAOXXCak+m9paGlIlvK1NAgK5h5KBSQQ3tggjVzUaMeBcRExWlUGRG7A9ZyzXC/ Pw2SzuCNp2FZSVGln71+EpT5sr5QAoFcXOEvkBDN/q+AAM77+UG1ec8iBtfKiPClnoie plcJ9JI1/4K00efaBOy1BwrSqVO8u0SpfoIZZOvg6TFUtxZi05el3G9T24jV8jp+HzxX Di6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=vSk4PrTqRRwcqhupjszeaAACsXVyJ0E1vQTmnoEDT1w=; b=kh5HpYpKAX81vOizu7NQBRQcyQZI1coQ3lXpuH3Ei+EWpdIT9z14fZAKzp/YZfFjVZ 5YUI+lwcfMNlajG5yxWjvExnJ/f0uLsBUdnoDXluSZgg6W39DhJ2xVC4uq1Fv4+Y4xzJ Pq0K1EnZmdmbcnsGyXKDRLUgIcw1R6b3OlomvhuQhqWIrijEHLWy7YcqIQpXqQjWk7NA ue+0hXfjgQw6Bhk00S2sxrGqCl8IDb2b8Yxek2Tw5rA+QqwqUKWe4M4r9iVXbB068uD3 R3rmTzvmab4uHpaSMLrmcdGOEU9OACYCR/Aqd+lIE6cxpfl/ZVDxTd0Kb6PoxKM5d1MF XIIw== X-Gm-Message-State: AOAM5317Swx5Y8XR8RGLwAA6h6LPu5F+lNEMqlCPyWfAaNZ94J/5SrQk OJN5tvgzup43h9TU+SUjUPSwnIxkxYOhGLBL/KaxeCwyOi6/wH82CTz4jjUiI+oK8tUDdS+vCVg pyP9Y2edqL1umUR5va41y90TRKm4YLu7F/buwxr8Y3uNsaIyK8Fkq7TCP/q/4yJddRg134OA= X-Google-Smtp-Source: ABdhPJxEhuKOS6Ebn1mxgOK9o0hXweHka2Z2LedyMocOIVXPmOcbzOpVgdLsXnbKFXfaKJZA1AV30jvgl0Aowrm3qQ== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a17:90a:1951:: with SMTP id 17mr5993821pjh.49.1626301844600; Wed, 14 Jul 2021 15:30:44 -0700 (PDT) Date: Wed, 14 Jul 2021 22:30:32 +0000 In-Reply-To: <20210714223033.742261-1-jingzhangos@google.com> Message-Id: <20210714223033.742261-6-jingzhangos@google.com> Mime-Version: 1.0 References: <20210714223033.742261-1-jingzhangos@google.com> X-Mailer: git-send-email 2.32.0.402.g57bb445576-goog Subject: [PATCH v2 5/6] KVM: stats: Add halt_wait_ns stats for all architectures From: Jing Zhang To: KVM , KVMPPC , Paolo Bonzini , Sean Christopherson , Jim Mattson , Peter Shier , Oliver Upton , David Rientjes , David Matlack Cc: Jing Zhang Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add simple stats halt_wait_ns to record the time a VCPU has spent on waiting for all architectures (not just powerpc). Signed-off-by: Jing Zhang --- arch/powerpc/include/asm/kvm_host.h | 1 - arch/powerpc/kvm/book3s.c | 1 - arch/powerpc/kvm/book3s_hv.c | 2 +- arch/powerpc/kvm/booke.c | 1 - include/linux/kvm_host.h | 3 ++- include/linux/kvm_types.h | 1 + virt/kvm/kvm_main.c | 4 ++++ 7 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 9f52f282b1aa..4931d03e5799 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -103,7 +103,6 @@ struct kvm_vcpu_stat { u64 emulated_inst_exits; u64 dec_exits; u64 ext_intr_exits; - u64 halt_wait_ns; u64 halt_successful_wait; u64 dbell_exits; u64 gdbell_exits; diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index 5cc6e90095b0..b785f6772391 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -69,7 +69,6 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { STATS_DESC_COUNTER(VCPU, emulated_inst_exits), STATS_DESC_COUNTER(VCPU, dec_exits), STATS_DESC_COUNTER(VCPU, ext_intr_exits), - STATS_DESC_TIME_NSEC(VCPU, halt_wait_ns), STATS_DESC_COUNTER(VCPU, halt_successful_wait), STATS_DESC_COUNTER(VCPU, dbell_exits), STATS_DESC_COUNTER(VCPU, gdbell_exits), diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index cd544a46183e..92698a5e54fd 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -4144,7 +4144,7 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) /* Attribute wait time */ if (do_sleep) { - vc->runner->stat.halt_wait_ns += + vc->runner->stat.generic.halt_wait_ns += ktime_to_ns(cur) - ktime_to_ns(start_wait); /* Attribute failed poll time */ if (vc->halt_poll_ns) diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 5ed6c235e059..977801c83aff 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -67,7 +67,6 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { STATS_DESC_COUNTER(VCPU, emulated_inst_exits), STATS_DESC_COUNTER(VCPU, dec_exits), STATS_DESC_COUNTER(VCPU, ext_intr_exits), - STATS_DESC_TIME_NSEC(VCPU, halt_wait_ns), STATS_DESC_COUNTER(VCPU, halt_successful_wait), STATS_DESC_COUNTER(VCPU, dbell_exits), STATS_DESC_COUNTER(VCPU, gdbell_exits), diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index c44cf5029e30..2414f3c7e6f7 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1369,7 +1369,8 @@ struct _kvm_stats_desc { STATS_DESC_COUNTER(VCPU_GENERIC, halt_poll_invalid), \ STATS_DESC_COUNTER(VCPU_GENERIC, halt_wakeup), \ STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_poll_success_ns), \ - STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_poll_fail_ns) + STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_poll_fail_ns), \ + STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_wait_ns) extern struct dentry *kvm_debugfs_dir; diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h index 723f8a77a8ea..d70f8f475da1 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -102,6 +102,7 @@ struct kvm_vcpu_stat_generic { u64 halt_wakeup; u64 halt_poll_success_ns; u64 halt_poll_fail_ns; + u64 halt_wait_ns; }; #define KVM_STATS_NAME_SIZE 48 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 6980dabe9df5..88bf17e7bf51 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3126,6 +3126,10 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) } finish_rcuwait(&vcpu->wait); cur = ktime_get(); + if (waited) { + vcpu->stat.generic.halt_wait_ns += + ktime_to_ns(cur) - ktime_to_ns(poll_end); + } out: kvm_arch_vcpu_unblocking(vcpu); block_ns = ktime_to_ns(cur) - ktime_to_ns(start); From patchwork Wed Jul 14 22:30:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 12378005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39C49C12002 for ; Wed, 14 Jul 2021 22:30:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20FD8610A7 for ; Wed, 14 Jul 2021 22:30:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236178AbhGNWdk (ORCPT ); Wed, 14 Jul 2021 18:33:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235809AbhGNWdj (ORCPT ); Wed, 14 Jul 2021 18:33:39 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C16E1C061760 for ; Wed, 14 Jul 2021 15:30:46 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id 4-20020a17090a1a44b029016e8392f557so4506437pjl.5 for ; Wed, 14 Jul 2021 15:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1SH2eHkvIHR7S+ZT3V2gNG/O07x0E5G53MVHIgpgwPY=; b=kt8Nh8lJ1edTeWYkzpihgo7GN4J/AtheIhIARrjOgNZVxctPLfA1eYOZq0zFkpBhEN evUmhJnKGCaQHX6sjoya8K8Pyh43kCukNJKfglTHmJ2AevoZNbxHJ0FZwzCppNLHUOYl o1wEb4lTIHS+iQKt+7e9w3F0gI/RqsZtYk8FX0AHvTEP8gnl+7q4VDZunYUF+2jTTWyC 0Bo7DeecCyGxcZ14RBCvPuAwiIIfmjTzvrIu6U1STqUcgTvZiUpQP5YJk8OjseyLQwmC sl6imIed3IIPCUZXXVn0G1wWSCUu27HOUXGTKAHd3P9ZyMHD2B2d6Vbk+tQFSRGp9/JO 76WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1SH2eHkvIHR7S+ZT3V2gNG/O07x0E5G53MVHIgpgwPY=; b=PmA2JvJdh4bEOe/GF2NSPnH6SY3g/RswFlIDtYRABfC/R45NqbaarY5O/CoxlXPfNk ULmiAy4jxYtPvEIdr17IFq0GVJYp/yLz5GkA8iMxFPR8nXj8YR+k1fBcLWWg5jdFTOEJ 3QWJyxBiHi+hMynCd5OPDlrgxvZHuBLGphlLpPxMH5tEk/hj2vMhMhR9iLB+1n8IPLnT GOY23YMbHGvp9pec5tGAoop27vTjMMpLBsZBONsW7F6DDIERQo2ZaYKPCU2Fjf7ZT/zQ Un5I8pXpod/biaWDnIMcndp+u7RZmGezcvRB4ybW1H2Cnx6E5aQAdsuYqo/xbHAW+Clh pjEQ== X-Gm-Message-State: AOAM533s42y0a7yX4W/4xMvz5Y2UbyD0ERPI/IRVa5VNaEzwLPPhxphu BnHEGMxHzgzb5prsTtvEZ+UbRtNC0fdaoluVP9IHsZpcZbP7c/zGVAVjFvWY2BzpxuzTdqKWkRO EqrqwQQ5GWE3Ec8JiB+TmDtegMD/XIdZVjO9vG4Jn31dcpYayNPCeXGlkkBjSkaSIUs93RMI= X-Google-Smtp-Source: ABdhPJwz1IbPrreEDAIH+90UbrfitjSmpVp5MLZrVzwQp95bjjWThrfUyEw+d5hYgGBByjMlivLWjGsX4ZPYuqKp1g== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a17:902:9895:b029:128:cdfb:f389 with SMTP id s21-20020a1709029895b0290128cdfbf389mr184973plp.45.1626301846186; Wed, 14 Jul 2021 15:30:46 -0700 (PDT) Date: Wed, 14 Jul 2021 22:30:33 +0000 In-Reply-To: <20210714223033.742261-1-jingzhangos@google.com> Message-Id: <20210714223033.742261-7-jingzhangos@google.com> Mime-Version: 1.0 References: <20210714223033.742261-1-jingzhangos@google.com> X-Mailer: git-send-email 2.32.0.402.g57bb445576-goog Subject: [PATCH v2 6/6] KVM: stats: Add halt polling related histogram stats From: Jing Zhang To: KVM , KVMPPC , Paolo Bonzini , Sean Christopherson , Jim Mattson , Peter Shier , Oliver Upton , David Rientjes , David Matlack Cc: Jing Zhang Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add three log histogram stats to record the distribution of time spent on successful polling, failed polling and VCPU wait. halt_poll_success_hist: Distribution of spent time for a successful poll. halt_poll_fail_hist: Distribution of spent time for a failed poll. halt_wait_hist: Distribution of time a VCPU has spent on waiting. Signed-off-by: Jing Zhang --- arch/powerpc/kvm/book3s_hv.c | 16 ++++++++++++++-- include/linux/kvm_host.h | 13 ++++++++++++- include/linux/kvm_types.h | 5 +++++ virt/kvm/kvm_main.c | 12 ++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 92698a5e54fd..c75a5f46d31d 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -4146,17 +4146,29 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) if (do_sleep) { vc->runner->stat.generic.halt_wait_ns += ktime_to_ns(cur) - ktime_to_ns(start_wait); + halt_poll_hist_update( + vc->runner->stat.generic.halt_wait_hist, + ktime_to_ns(cur) - ktime_to_ns(start_wait)); /* Attribute failed poll time */ - if (vc->halt_poll_ns) + if (vc->halt_poll_ns) { vc->runner->stat.generic.halt_poll_fail_ns += ktime_to_ns(start_wait) - ktime_to_ns(start_poll); + halt_poll_hist_update( + vc->runner->stat.generic.halt_poll_fail_hist, + ktime_to_ns(start_wait) - + ktime_to_ns(start_poll)); + } } else { /* Attribute successful poll time */ - if (vc->halt_poll_ns) + if (vc->halt_poll_ns) { vc->runner->stat.generic.halt_poll_success_ns += ktime_to_ns(cur) - ktime_to_ns(start_poll); + halt_poll_hist_update( + vc->runner->stat.generic.halt_poll_success_hist, + ktime_to_ns(cur) - ktime_to_ns(start_poll)); + } } /* Adjust poll time */ diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 2414f3c7e6f7..e0db0216e627 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1370,7 +1370,13 @@ struct _kvm_stats_desc { STATS_DESC_COUNTER(VCPU_GENERIC, halt_wakeup), \ STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_poll_success_ns), \ STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_poll_fail_ns), \ - STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_wait_ns) + STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_wait_ns), \ + STATS_DESC_LOGHIST_TIME_NSEC(VCPU_GENERIC, halt_poll_success_hist, \ + HALT_POLL_HIST_COUNT), \ + 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) extern struct dentry *kvm_debugfs_dir; @@ -1387,6 +1393,11 @@ extern const struct _kvm_stats_desc kvm_vm_stats_desc[]; extern const struct kvm_stats_header kvm_vcpu_stats_header; extern const struct _kvm_stats_desc kvm_vcpu_stats_desc[]; +static inline void halt_poll_hist_update(u64 *hist, u64 value) +{ + kvm_stats_log_hist_update(hist, HALT_POLL_HIST_COUNT, value); +} + #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) static inline int mmu_notifier_retry(struct kvm *kvm, unsigned long mmu_seq) { diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h index d70f8f475da1..e073cfcabf8c 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -91,6 +91,8 @@ struct kvm_mmu_memory_cache { #define LOGHIST_BUCKET_COUNT_LARGE 32 #define LOGHIST_BUCKET_COUNT_XLARGE 64 +#define HALT_POLL_HIST_COUNT LOGHIST_BUCKET_COUNT_LARGE + struct kvm_vm_stat_generic { u64 remote_tlb_flush; }; @@ -103,6 +105,9 @@ struct kvm_vcpu_stat_generic { u64 halt_poll_success_ns; u64 halt_poll_fail_ns; u64 halt_wait_ns; + 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]; }; #define KVM_STATS_NAME_SIZE 48 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 88bf17e7bf51..5fcdffd7d66a 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3108,12 +3108,22 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) ++vcpu->stat.generic.halt_successful_poll; if (!vcpu_valid_wakeup(vcpu)) ++vcpu->stat.generic.halt_poll_invalid; + + halt_poll_hist_update( + vcpu->stat.generic.halt_poll_success_hist, + ktime_to_ns(ktime_get()) - + ktime_to_ns(start)); goto out; } poll_end = cur = ktime_get(); } while (kvm_vcpu_can_poll(cur, stop)); + + halt_poll_hist_update( + vcpu->stat.generic.halt_poll_fail_hist, + ktime_to_ns(ktime_get()) - ktime_to_ns(start)); } + prepare_to_rcuwait(&vcpu->wait); for (;;) { set_current_state(TASK_INTERRUPTIBLE); @@ -3129,6 +3139,8 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) if (waited) { vcpu->stat.generic.halt_wait_ns += ktime_to_ns(cur) - ktime_to_ns(poll_end); + halt_poll_hist_update(vcpu->stat.generic.halt_wait_hist, + ktime_to_ns(cur) - ktime_to_ns(poll_end)); } out: kvm_arch_vcpu_unblocking(vcpu);