From patchwork Tue Jul 6 18:03:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 1501440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=hHRyc03O; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GK9RJ5rzHz9shx for ; Wed, 7 Jul 2021 04:03:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231165AbhGFSGf (ORCPT ); Tue, 6 Jul 2021 14:06:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231149AbhGFSGe (ORCPT ); Tue, 6 Jul 2021 14:06:34 -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 0468FC061574 for ; Tue, 6 Jul 2021 11:03:56 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id y5-20020a37af050000b02903a9c3f8b89fso17255525qke.2 for ; Tue, 06 Jul 2021 11:03:55 -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=fF6j8POF8iWLCA43O7ZfDObsMW0wQoLTlF29knN9tKg=; b=hHRyc03OBksoyXSj89AptvKZOBbuf2SKJOosv8ggpviRQetpsOy+KEw+8j+vfumO/R 9MyNqJHkYMvOvVGWUMgdHCpgBK8yr9gBxRn4UVcr3rfKTjMb4NLHzQ8zy4nJK+33X166 IdV39ReiPwMxnsjweT1I9eTRG9RiFTP3OTUpm+5+Q+jN79OA6pkctVb+BHK+E+ACWbhM SknIzUxswsNUUgjGnMIyCEpKP52ldnNYlipLVdjS/2/lJUEu4yO8xkTZBa0bWMxSkY3K 49taI/LuZGDj+gSQqk4qUqq/oeoO29AW9cHM4IMIT/XmVniR6pBDv4hjVgl7jHG3aeQM 0Sug== 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=fF6j8POF8iWLCA43O7ZfDObsMW0wQoLTlF29knN9tKg=; b=iR9CCT2qymRRrm+wicWCB8rWgayvOFbwkHphsxU1FMnGm12MEx0kXSMbmVKvWIvog/ HrBNN/5/tWcYwZ+hTqV8RjP6KbCh3s7QoiYvgcgHNg5c4z4GxqE5d06piJYbDHb7wU9m mcQXkYn6nU4fze2B15rZr6cvSyFAc6B6DJxQl0YPFmcbZhDq3busaOsmkUFMLk67qaY2 b+Gx3gMbr3yMyEKIWOLUfcX+BxHKv7Q473qKlh8McL9Rz+19jCpuwBlGsW95SEWwQ9C/ 9M5GjL3xZepqO0y7C7B0Y3zbEDlzQxclrY0wFPCQDhDeru5Ju3tQVNFKUCuIy0H8OBvI B2pQ== X-Gm-Message-State: AOAM5319yJn1oO9T2zsaCGvU7sAcJ/YLq7ffFxnCX9JmXvfU1mOoHv7M vVk49nUcNodQSASWY29byw6UR14cMMK7B3fMGA== X-Google-Smtp-Source: ABdhPJzwzjtXd/x2FeBGe16SmcPRnxkwEm8GQ2lTaxo9PvBJj/UVzE1g3b2RBv7jkQA1GUzwRU8OgpCoFkuYFpF3nQ== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a05:6214:8ec:: with SMTP id dr12mr20074756qvb.12.1625594635091; Tue, 06 Jul 2021 11:03:55 -0700 (PDT) Date: Tue, 6 Jul 2021 18:03:47 +0000 In-Reply-To: <20210706180350.2838127-1-jingzhangos@google.com> Message-Id: <20210706180350.2838127-2-jingzhangos@google.com> Mime-Version: 1.0 References: <20210706180350.2838127-1-jingzhangos@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v1 1/4] 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-ppc@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 Reported-by: kernel test robot Reported-by: kernel test robot --- 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 | 16 ++++++++++++ include/uapi/linux/kvm.h | 11 +++++--- virt/kvm/binary_stats.c | 36 ++++++++++++++++++++++++++ 10 files changed, 98 insertions(+), 42 deletions(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index 1512a8007a78..cb44d8756fa7 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 1695f0ced5ba..7610d33d319b 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 8166ad113fb2..b94a80ad5b8d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -239,8 +239,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, @@ -280,8 +278,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..356af173114d 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, param) \ .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, \ + .hist_param = param -#define VM_GENERIC_STATS_DESC(stat, type, unit, base, exp) \ +#define VM_GENERIC_STATS_DESC(stat, type, unit, base, exp, sz, param) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp), \ + STATS_DESC_COMMON(type, unit, base, exp, sz, param), \ .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, param) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp), \ + STATS_DESC_COMMON(type, unit, base, exp, sz, param), \ .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, param) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp), \ + STATS_DESC_COMMON(type, unit, base, exp, sz, param), \ .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, param) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp), \ + STATS_DESC_COMMON(type, unit, base, exp, sz, param), \ .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, param) \ + SCOPE##_STATS_DESC(stat, type, unit, base, exp, sz, param) #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, param) \ + STATS_DESC(SCOPE, name, KVM_STATS_TYPE_LINEAR_HIST, \ + unit, base, exponent, sz, param) +#define STATS_DESC_LOG_HIST(SCOPE, name, unit, base, exponent, sz, param) \ + STATS_DESC(SCOPE, name, KVM_STATS_TYPE_LOG_HIST, \ + unit, base, exponent, sz, param) /* 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, bucket_size) \ + STATS_DESC_LINEAR_HIST(SCOPE, name, KVM_STATS_UNIT_SECONDS, \ + KVM_STATS_BASE_POW10, -9, sz, bucket_size) +/* 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, LOGHIST_BASE_2) #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..cc88cd676775 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -76,6 +76,22 @@ 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_SIZE_SMALL 8 +#define LOGHIST_SIZE_MEDIUM 16 +#define LOGHIST_SIZE_LARGE 32 +#define LOGHIST_SIZE_XLARGE 64 +#define LOGHIST_BASE_2 2 + struct kvm_vm_stat_generic { u64 remote_tlb_flush; }; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 68c9e6d8bbda..ff34a471d9ef 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1963,7 +1963,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) @@ -1987,7 +1989,10 @@ struct kvm_stats_header { * 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. + * @hist_param: A parameter value used for histogram stats. For linear + * histogram stats, it indicates the size of the bucket; + * For logarithmic histogram stats, it indicates the base + * of the logarithm. Only base of 2 is supported. * @name: The name string for the stats. Its size is indicated by the * &kvm_stats_header->name_size. */ @@ -1996,7 +2001,7 @@ struct kvm_stats_desc { __s16 exponent; __u16 size; __u32 offset; - __u32 unused; + __u32 hist_param; char name[]; }; diff --git a/virt/kvm/binary_stats.c b/virt/kvm/binary_stats.c index e609d428811a..6eead6979a7f 100644 --- a/virt/kvm/binary_stats.c +++ b/virt/kvm/binary_stats.c @@ -144,3 +144,39 @@ 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 = value / bucket_size; + + if (index >= size) + index = 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 = fls64(value); + + if (index >= size) + index = size - 1; + ++data[index]; +} From patchwork Tue Jul 6 18:03:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 1501442 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=JKuSvh3Q; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GK9RL1VPTz9t1r for ; Wed, 7 Jul 2021 04:03:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231178AbhGFSGg (ORCPT ); Tue, 6 Jul 2021 14:06:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231162AbhGFSGg (ORCPT ); Tue, 6 Jul 2021 14:06:36 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86CC2C061574 for ; Tue, 6 Jul 2021 11:03:57 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id 61-20020aed21430000b029024e7e455d67so11653808qtc.16 for ; Tue, 06 Jul 2021 11:03:57 -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=tuY40cRvRjb7LOqoOokdd2WJ/UxGgrW/aY+HZzkwyxg=; b=JKuSvh3Qc1mRz3g4jUBCdl2w09FhmvGwIfnYfp9xP+FtJqgtmVsQABLLq8SzosvZeG XQMAcz5oNR0Kvpm88UUF1Hv0nJAawGBAz44WgC1zlL8snKRmCDelTxJ6zXewwInLreho gRT23nzYjyFztpPSTgbNYqnLvTNG5JQa96PZie7dURMDxsp3f6KF70LiCr/rdeEJTf/p cR6PF87TowUIMfWwBUrRikvODGnpghvGqfDHeCoLqSRabTJk439L6LECYGzOkO5YjF/2 Ghqii2tje0ASDIf4jbGE/4HxZ1PzyPt7R8UNXAgZz8WcjJEgrEew3FerGZR5aYBWfLmH 2Uzw== 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=tuY40cRvRjb7LOqoOokdd2WJ/UxGgrW/aY+HZzkwyxg=; b=IDLh3nrJZU6SzTbu1D8GCbO23Jn63xIUFvOTxKT45kaWZblezKg/Kq8g6kXWgfRtVd 0gsIembBKz7Th+Ug5gHKahR1BbozwN7AkrDRQ99I0kJNj1NshFLahS3hrnx5qqKJyPuV 4Gj7Uq1Bi1XHXSXHlD3dfRXdYqVRKAWL5766oHgAsxiTLeSTVTY9MHNPNak9JcSAD7xY oIg38RH/KIzPW/RfkwOVbH3EgQurOWMa4KhbIP1hL3GNic44rRGdgGPkv6kuCZIcRXau LbGLCMdXCvzzvu/Gy55yfGkm2IRY/QMZ8wMVldy036RGT64m3yTM1N0hB6p41U2h1vIZ PUcA== X-Gm-Message-State: AOAM5329zTt3ePjDgjcgdh5g2v3Zwvz/tTZFx5eij3PCLBidxZT5LxFO 7AwHgPp1Rw1jmCmtM3ECdfMDzmBOwvrb+95X/g== X-Google-Smtp-Source: ABdhPJzESY6ESFJ2Ic1TWEY5cky+ur7M+9iz9D+Pqke5K3ovUn094YlKNjld75ok0TZ4vd3AePg6RNxzDS9NOtgRzw== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a0c:b38c:: with SMTP id t12mr19376471qve.44.1625594636671; Tue, 06 Jul 2021 11:03:56 -0700 (PDT) Date: Tue, 6 Jul 2021 18:03:48 +0000 In-Reply-To: <20210706180350.2838127-1-jingzhangos@google.com> Message-Id: <20210706180350.2838127-3-jingzhangos@google.com> Mime-Version: 1.0 References: <20210706180350.2838127-1-jingzhangos@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v1 2/4] 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-ppc@vger.kernel.org Add documentations for linear and logarithmic histogram statistics. Add binary stats capability text which is missing during merge of the binary stats patch. Signed-off-by: Jing Zhang --- Documentation/virt/kvm/api.rst | 36 +++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 3b6e3b1628b4..948d33c26704 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -5171,6 +5171,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) @@ -5178,11 +5181,13 @@ 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; @@ -5214,6 +5219,22 @@ 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 base of logarithm is + specified by the ``hist_param`` field. The range of the Nth bucket (1 < N < + ``size``) is [pow(``hist_param``, N-2), pow(``hist_param``, N-1)). The range + of the first bucket is [0, 1), while the range of the last bucket is + [pow(``hist_param``, ``size``-2), +INF). 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`` @@ -5246,9 +5267,10 @@ 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 ``hist_param`` field is used as a parameter for histogram statistics data. +For linear histogram statistics data, it indicates the size of a bucket. For +logarithmic histogram statistics data, it indicates the base of the logarithm. +Only base of 2 is supported fo logarithmic histogram. 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 @@ -7182,3 +7204,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_STATS_BINARY_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 Tue Jul 6 18:03:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 1501443 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=wN4RzJjI; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GK9RM57HRz9sj5 for ; Wed, 7 Jul 2021 04:03:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231185AbhGFSGi (ORCPT ); Tue, 6 Jul 2021 14:06:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231177AbhGFSGh (ORCPT ); Tue, 6 Jul 2021 14:06:37 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06D63C061574 for ; Tue, 6 Jul 2021 11:03:59 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id ke6-20020a0562143006b029028b8546bb01so13760246qvb.20 for ; Tue, 06 Jul 2021 11:03:58 -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=gxtUTPh5fwor/wpaYj5ONrHNzCoa+ClILdYbD39HBRk=; b=wN4RzJjIy66SQWY9ue61jGTFPH+UVIiQNgDal1a8vHwCpqS5QhIFL6/KOZw8s/mZ+4 nIU6410/kFLTkuDPLsCjIRSOR40hebTNN62avpmP1QsZmdFRMPABE9g4aXZMYpG7Mjir QmNC/Qq8YLPDvOTHbJipU9T/E90TerxsSsLReQS8h1T2V+xVpgnSYsDQezkUFEqqelpn 7F+rh5SfNFjCiU9Y7Z7Cx5Q+QClJR8YEtHcBI7iwOkA+YLG60ubwdMr83toSoTKlfqnV yFjNZ16Rco0U6CmIHwGUQrTJr8wmbJsf5d8ujQcMOsHDimLexKA8i4GqjDJ0RbRHDORw keFA== 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=gxtUTPh5fwor/wpaYj5ONrHNzCoa+ClILdYbD39HBRk=; b=o/6lDLMSKsl9ownhGG2xTbE+xSVnK3VokVqgC/UV15cgl3O6kVrR+3qTxN5by6VXS/ 3xHMpvZCRAoIISFi5yIC7y4vO5jLZJGz0WkcnoCugU8RBl8q+eS0t15taOeHxHaSF2a1 BaxkOU849s1OnX8Ccgs0u7Eb2d9Ai+Lmz66/e8pnvN444j10tu+prLI8cYgtUUzaentN VYtTxR8QgEODWHDl1GbcrplzTkfBLlGDNihzksB+g8XxOQxnoQGxRU0YcNPqLT2h+3V7 LByQOugBmoCFpwFsmW9+SLuU6b37BOYt3TuInyWYJWXgVevmMJ5G+hKHkopQTogokwUa +8Pg== X-Gm-Message-State: AOAM5315vDbcQckxvRSMSIst7fc+u0OsQQG3iGRGca8q961FS0EtF00x ouY69WTHfK5EouPIrChn2B08NHngmiUhfk5EZg== X-Google-Smtp-Source: ABdhPJzVXrdypAr1xE54GQA/Ctgc3cZntz0ffeuVpUUBIt4PA3RZaVP6zuES/rRdA1przzfP6bV3RnYDCO/yZR6vxw== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a05:6214:1042:: with SMTP id l2mr19298254qvr.53.1625594638130; Tue, 06 Jul 2021 11:03:58 -0700 (PDT) Date: Tue, 6 Jul 2021 18:03:49 +0000 In-Reply-To: <20210706180350.2838127-1-jingzhangos@google.com> Message-Id: <20210706180350.2838127-4-jingzhangos@google.com> Mime-Version: 1.0 References: <20210706180350.2838127-1-jingzhangos@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v1 3/4] KVM: selftests: Add checks for histogram stats parameters 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-ppc@vger.kernel.org The hist_param field should be zero for simple stats and 2 for logarithmic histogram. It shouldbe non-zero for linear histogram stats. Signed-off-by: Jing Zhang Reviewed-by: David Matlack --- .../selftests/kvm/kvm_binary_stats_test.c | 17 +++++++++++++++++ 1 file changed, 17 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..03c7842fcb26 100644 --- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c +++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c @@ -109,6 +109,23 @@ 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 hist_param field */ + switch (pdesc->flags & KVM_STATS_TYPE_MASK) { + case KVM_STATS_TYPE_LINEAR_HIST: + TEST_ASSERT(pdesc->hist_param, + "Bucket size of Linear Histogram stats (%s) is zero", + pdesc->name); + break; + case KVM_STATS_TYPE_LOG_HIST: + TEST_ASSERT(pdesc->hist_param == 2, + "Base of Log Histogram stats (%s) is not 2", + pdesc->name); + break; + default: + TEST_ASSERT(!pdesc->hist_param, + "Simple stats (%s) with hist_param of nonzero", + pdesc->name); + } size_data += pdesc->size * sizeof(*stats_data); } /* Check overlap */ From patchwork Tue Jul 6 18:03:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 1501444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=X1vH66OZ; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GK9RN6MsRz9shx for ; Wed, 7 Jul 2021 04:04:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231183AbhGFSGj (ORCPT ); Tue, 6 Jul 2021 14:06:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbhGFSGi (ORCPT ); Tue, 6 Jul 2021 14:06:38 -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 085BFC061574 for ; Tue, 6 Jul 2021 11:04:00 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id mm9-20020a17090b3589b029016e99e81994so2168114pjb.0 for ; Tue, 06 Jul 2021 11:04:00 -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=06jK6cC8nKrdCzhGRJ/lK6pEF1PxjezbNVT/NfdNI74=; b=X1vH66OZZ1yQeAmG92wEDD060uD5MSRcVJENlPg1Y7dLlFOdSPlQDIoxMXAGGN7DFt 4e1zAK/sXYwssb/f8k+NVEFCglpPjxFMNhp8LyDrYR36SvAe/4P4cvNGY1mhAtpOY1FU rOIq4fCPwGiCKgt3ovk/Bylet+U16yhHbakivwqLOCcRursdpR1tU37vkJK91COrTNhz t+uJToof5nszwFmGJ4J6hHJk0NJZ+Cgu1ZBTbi1H/bYOuQ7k8dLcc7X2RLYbALPTLUpd MjXZH4nlDa4vC8zHyDrCZkC30ITqTl+3hH9pR3VjKZZL9c8VMYrqDqSuCqWAZXnd2o7h GeWw== 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=06jK6cC8nKrdCzhGRJ/lK6pEF1PxjezbNVT/NfdNI74=; b=B7Gna3QEz/Pmrq0dI31LZyuhj+C1LzK7jObf8l+MsRT2+JRtnvvJ8uPstplFSf6n0Y 5LDuIeBw7u3ZtuwRqtHaK587OmfCa0APPGQwF7kwM1Y+zlhQRgjwynN73d9wCxRFLZQg rF39mvVnfN5U802G4c2ZzncGyyDUqzvqpGtQTu9TL3Cqw6poRV+zgDQjYvHQOqkXIJsN BFmStDwDP0+Qy2taoVqfURI263xDm25GCPqMsUe+F3LJNA1iGn44NZ5COS38k42URtJS YAf8FJ6aMHBI15Neo9VQ/vTEcNOULs7UatAUzqwt53FEo29xSDydRLFzLUf/GJi+vX1i H9IA== X-Gm-Message-State: AOAM532HMD3bxKv6HzVqayDxV2x95dr6Kta8i9wqGNvZxSg+8GTdV09R XytZi+jBGv8ddRXOjH7hWsy20r+Zgi2VZYaO0A== X-Google-Smtp-Source: ABdhPJxlrH+MEIDJb4FUshzYpX/hhS7/TQ4b5J9Uzd5ETCu0EzGjPmshJqQu1rG4FKSSEJPJ2y+nfmXv2Bvf9BVWSA== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:aa7:810b:0:b029:2fe:decd:c044 with SMTP id b11-20020aa7810b0000b02902fedecdc044mr21536341pfi.15.1625594639431; Tue, 06 Jul 2021 11:03:59 -0700 (PDT) Date: Tue, 6 Jul 2021 18:03:50 +0000 In-Reply-To: <20210706180350.2838127-1-jingzhangos@google.com> Message-Id: <20210706180350.2838127-5-jingzhangos@google.com> Mime-Version: 1.0 References: <20210706180350.2838127-1-jingzhangos@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v1 4/4] 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-ppc@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). 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 time spent before a successful polling. halt_poll_fail_hist: Distribution of time spent before a failed polling. halt_wait_hist: Distribution of time a VCPU has spent on waiting. 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 | 20 +++++++++++++++++--- arch/powerpc/kvm/booke.c | 1 - include/linux/kvm_host.h | 9 ++++++++- include/linux/kvm_types.h | 4 ++++ virt/kvm/kvm_main.c | 19 +++++++++++++++++++ 7 files changed, 48 insertions(+), 7 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..103f998cee75 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -4144,19 +4144,33 @@ 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); + kvm_stats_log_hist_update( + vc->runner->stat.generic.halt_wait_hist, + LOGHIST_SIZE_LARGE, + 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); + kvm_stats_log_hist_update( + vc->runner->stat.generic.halt_poll_fail_hist, + LOGHIST_SIZE_LARGE, 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); + kvm_stats_log_hist_update( + vc->runner->stat.generic.halt_poll_success_hist, + LOGHIST_SIZE_LARGE, + ktime_to_ns(cur) - ktime_to_ns(start_poll)); + } } /* Adjust poll time */ 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 356af173114d..268a0ccc9c5f 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1369,7 +1369,14 @@ 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_LOGHIST_TIME_NSEC(VCPU_GENERIC, halt_poll_success_hist, \ + LOGHIST_SIZE_LARGE), \ + STATS_DESC_LOGHIST_TIME_NSEC(VCPU_GENERIC, halt_poll_fail_hist, \ + LOGHIST_SIZE_LARGE), \ + STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_wait_ns), \ + STATS_DESC_LOGHIST_TIME_NSEC(VCPU_GENERIC, halt_wait_hist, \ + LOGHIST_SIZE_LARGE) extern struct dentry *kvm_debugfs_dir; diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h index cc88cd676775..7838a42932c8 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -103,6 +103,10 @@ struct kvm_vcpu_stat_generic { u64 halt_wakeup; u64 halt_poll_success_ns; u64 halt_poll_fail_ns; + u64 halt_poll_success_hist[LOGHIST_SIZE_LARGE]; + u64 halt_poll_fail_hist[LOGHIST_SIZE_LARGE]; + u64 halt_wait_ns; + u64 halt_wait_hist[LOGHIST_SIZE_LARGE]; }; #define KVM_STATS_NAME_SIZE 48 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 3dcc2abbfc60..840b5bece080 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3093,12 +3093,24 @@ 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; + + kvm_stats_log_hist_update( + vcpu->stat.generic.halt_poll_success_hist, + LOGHIST_SIZE_LARGE, + ktime_to_ns(ktime_get()) - + ktime_to_ns(start)); goto out; } poll_end = cur = ktime_get(); } while (kvm_vcpu_can_poll(cur, stop)); + + kvm_stats_log_hist_update( + vcpu->stat.generic.halt_poll_fail_hist, + LOGHIST_SIZE_LARGE, + ktime_to_ns(ktime_get()) - ktime_to_ns(start)); } + prepare_to_rcuwait(&vcpu->wait); for (;;) { set_current_state(TASK_INTERRUPTIBLE); @@ -3111,6 +3123,13 @@ 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); + kvm_stats_log_hist_update(vcpu->stat.generic.halt_wait_hist, + LOGHIST_SIZE_LARGE, + 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);