From patchwork Mon Mar 6 19:01:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 13162201 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59649C64EC4 for ; Mon, 6 Mar 2023 19:02:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229823AbjCFTCY (ORCPT ); Mon, 6 Mar 2023 14:02:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229787AbjCFTCX (ORCPT ); Mon, 6 Mar 2023 14:02:23 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBA5820570 for ; Mon, 6 Mar 2023 11:02:01 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id cj27-20020a056a00299b00b005f1ef2e4e1aso5857453pfb.6 for ; Mon, 06 Mar 2023 11:02:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678129321; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aVeYFUAaozUOnFog0adFgmU2JgVVSGajkgl902L/1Rk=; b=ayF7i9DvZYu0FDkTEvY+lEZ1TzR7tFwo1A5yCyweiwEzFA0569mKnfCWbwfT1RuYoi aaoj0OLX7WH5Im9zuLmCg3rZNvdhl90C4a1BKpyW4x/Rubg7L9dVdsaZmtTnUT5cfTnk Nc1lmZ6fPheWE0NkKvZ9+Lp9C29mSi0spLczKUwC8b0qgfoe41IPITIS2c14lITxvnPM zhrb7ld7vwVaQdcKugb86XtsYk3weAUHE303Fxtk7OcLXuHXe96DFmN1WUOTaubuCtuP QQRVnUdGWrto44NaTGO0O7pKktt0pIZOJ+IqWSgMFAUkK80pJi/ziF6HAXcS1lPVrp2I luDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678129321; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aVeYFUAaozUOnFog0adFgmU2JgVVSGajkgl902L/1Rk=; b=JusPE2TlHGa+ZtTBZt6ZuYt5knbmV/oxwaEEp4aqhqlSuUV/hu2dVzqW6zwaH3H23g ez71FN1V5PXzxC+qWKH6dMt/UKL1bOfIZlp3B9lbYY0HpU4MFLEsCDI5B0l6JdwHO3x+ VZaMNNAKfsGY2sabo20blju6ixXPYr7ifoar3IArQcFCmNgJCFYZ8ugN0y7bzzK98L2a r96FLhScYCqqzuUmI86ClexeKEeO7QqhZyKHJFT7W+Wv7jxD/fdYH57KBL41QfZJSsYY Kb2jIJ1uFZAIYad+dIazydyRgaGd1DGuFWKIHtQWKuEY9U/ep5A6MI1THP2C1Bm3RYOk 9gRw== X-Gm-Message-State: AO0yUKVVmq5hVTQo4T8DBENFrX1NeqdEMJS+pw66Qa2gR3Hj4DXQcr0L oWMNHUDBvxpArzzpqUZOSQ6DvFzy9AqZDg== X-Google-Smtp-Source: AK7set8bkhEjkaxKFJOK+csmU8XUtWiWxWElSO+3ptgGRXr0eXqqwcSExjspxYfl4cT7fbWwfKjZyhdLvknmjw== X-Received: from dmatlack-n2d-128.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1309]) (user=dmatlack job=sendgmr) by 2002:a17:903:278d:b0:19c:1869:3558 with SMTP id jw13-20020a170903278d00b0019c18693558mr4672667plb.5.1678129321404; Mon, 06 Mar 2023 11:02:01 -0800 (PST) Date: Mon, 6 Mar 2023 11:01:53 -0800 In-Reply-To: <20230306190156.434452-1-dmatlack@google.com> Mime-Version: 1.0 References: <20230306190156.434452-1-dmatlack@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230306190156.434452-2-dmatlack@google.com> Subject: [PATCH v2 1/4] KVM: Refactor stats descriptor generation macros From: David Matlack To: Paolo Bonzini Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Huacai Chen , Aleksandar Markovic , Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Sean Christopherson , Michael Ellerman , Eric Farman , " =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= " , David Matlack , Sathvika Vasireddy , Nicholas Piggin , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Refactor the various KVM stats macros to reduce the amount of duplicate macro code. This change also improves readability by spelling out "CUMULATIVE", "INSTANT", and "PEAK" instead of the previous short-hands which were less clear ("COUNTER", "ICOUNTER", and "PCOUNTER"). No functional change intended. Suggested-by: Sean Christopherson Signed-off-by: David Matlack Acked-by: Anup Patel --- arch/arm64/kvm/guest.c | 14 +-- arch/mips/kvm/mips.c | 54 +++++------ arch/powerpc/kvm/book3s.c | 62 ++++++------ arch/powerpc/kvm/booke.c | 48 ++++----- arch/riscv/kvm/vcpu.c | 16 +-- arch/s390/kvm/kvm-s390.c | 198 +++++++++++++++++++------------------- arch/x86/kvm/x86.c | 94 +++++++++--------- include/linux/kvm_host.h | 95 ++++++------------ 8 files changed, 272 insertions(+), 309 deletions(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index 07444fa22888..890ed444c237 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -44,13 +44,13 @@ const struct kvm_stats_header kvm_vm_stats_header = { const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { KVM_GENERIC_VCPU_STATS(), - STATS_DESC_COUNTER(VCPU, hvc_exit_stat), - STATS_DESC_COUNTER(VCPU, wfe_exit_stat), - STATS_DESC_COUNTER(VCPU, wfi_exit_stat), - STATS_DESC_COUNTER(VCPU, mmio_exit_user), - STATS_DESC_COUNTER(VCPU, mmio_exit_kernel), - STATS_DESC_COUNTER(VCPU, signal_exits), - STATS_DESC_COUNTER(VCPU, exits) + KVM_STAT(VCPU, CUMULATIVE, NONE, hvc_exit_stat), + KVM_STAT(VCPU, CUMULATIVE, NONE, wfe_exit_stat), + KVM_STAT(VCPU, CUMULATIVE, NONE, wfi_exit_stat), + KVM_STAT(VCPU, CUMULATIVE, NONE, mmio_exit_user), + KVM_STAT(VCPU, CUMULATIVE, NONE, mmio_exit_kernel), + KVM_STAT(VCPU, CUMULATIVE, NONE, signal_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, exits) }; const struct kvm_stats_header kvm_vcpu_stats_header = { diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c index 36c8991b5d39..b7b2fa400bcf 100644 --- a/arch/mips/kvm/mips.c +++ b/arch/mips/kvm/mips.c @@ -53,34 +53,34 @@ const struct kvm_stats_header kvm_vm_stats_header = { const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { KVM_GENERIC_VCPU_STATS(), - STATS_DESC_COUNTER(VCPU, wait_exits), - STATS_DESC_COUNTER(VCPU, cache_exits), - STATS_DESC_COUNTER(VCPU, signal_exits), - STATS_DESC_COUNTER(VCPU, int_exits), - STATS_DESC_COUNTER(VCPU, cop_unusable_exits), - STATS_DESC_COUNTER(VCPU, tlbmod_exits), - STATS_DESC_COUNTER(VCPU, tlbmiss_ld_exits), - STATS_DESC_COUNTER(VCPU, tlbmiss_st_exits), - STATS_DESC_COUNTER(VCPU, addrerr_st_exits), - STATS_DESC_COUNTER(VCPU, addrerr_ld_exits), - STATS_DESC_COUNTER(VCPU, syscall_exits), - STATS_DESC_COUNTER(VCPU, resvd_inst_exits), - STATS_DESC_COUNTER(VCPU, break_inst_exits), - STATS_DESC_COUNTER(VCPU, trap_inst_exits), - STATS_DESC_COUNTER(VCPU, msa_fpe_exits), - STATS_DESC_COUNTER(VCPU, fpe_exits), - STATS_DESC_COUNTER(VCPU, msa_disabled_exits), - STATS_DESC_COUNTER(VCPU, flush_dcache_exits), - STATS_DESC_COUNTER(VCPU, vz_gpsi_exits), - STATS_DESC_COUNTER(VCPU, vz_gsfc_exits), - STATS_DESC_COUNTER(VCPU, vz_hc_exits), - STATS_DESC_COUNTER(VCPU, vz_grr_exits), - STATS_DESC_COUNTER(VCPU, vz_gva_exits), - STATS_DESC_COUNTER(VCPU, vz_ghfc_exits), - STATS_DESC_COUNTER(VCPU, vz_gpa_exits), - STATS_DESC_COUNTER(VCPU, vz_resvd_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, wait_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, cache_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, signal_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, int_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, cop_unusable_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, tlbmod_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, tlbmiss_ld_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, tlbmiss_st_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, addrerr_st_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, addrerr_ld_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, syscall_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, resvd_inst_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, break_inst_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, trap_inst_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, msa_fpe_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, fpe_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, msa_disabled_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, flush_dcache_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, vz_gpsi_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, vz_gsfc_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, vz_hc_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, vz_grr_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, vz_gva_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, vz_ghfc_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, vz_gpa_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, vz_resvd_exits), #ifdef CONFIG_CPU_LOONGSON64 - STATS_DESC_COUNTER(VCPU, vz_cpucfg_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, vz_cpucfg_exits), #endif }; diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index 57f4e7896d67..8a7a932961d5 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -40,8 +40,8 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { KVM_GENERIC_VM_STATS(), - STATS_DESC_ICOUNTER(VM, num_2M_pages), - STATS_DESC_ICOUNTER(VM, num_1G_pages) + KVM_STAT(VM, INSTANT, NONE, num_2M_pages), + KVM_STAT(VM, INSTANT, NONE, num_1G_pages) }; const struct kvm_stats_header kvm_vm_stats_header = { @@ -55,35 +55,35 @@ const struct kvm_stats_header kvm_vm_stats_header = { const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { KVM_GENERIC_VCPU_STATS(), - STATS_DESC_COUNTER(VCPU, sum_exits), - STATS_DESC_COUNTER(VCPU, mmio_exits), - STATS_DESC_COUNTER(VCPU, signal_exits), - STATS_DESC_COUNTER(VCPU, light_exits), - STATS_DESC_COUNTER(VCPU, itlb_real_miss_exits), - STATS_DESC_COUNTER(VCPU, itlb_virt_miss_exits), - STATS_DESC_COUNTER(VCPU, dtlb_real_miss_exits), - STATS_DESC_COUNTER(VCPU, dtlb_virt_miss_exits), - STATS_DESC_COUNTER(VCPU, syscall_exits), - STATS_DESC_COUNTER(VCPU, isi_exits), - STATS_DESC_COUNTER(VCPU, dsi_exits), - STATS_DESC_COUNTER(VCPU, emulated_inst_exits), - STATS_DESC_COUNTER(VCPU, dec_exits), - STATS_DESC_COUNTER(VCPU, ext_intr_exits), - STATS_DESC_COUNTER(VCPU, halt_successful_wait), - STATS_DESC_COUNTER(VCPU, dbell_exits), - STATS_DESC_COUNTER(VCPU, gdbell_exits), - STATS_DESC_COUNTER(VCPU, ld), - STATS_DESC_COUNTER(VCPU, st), - STATS_DESC_COUNTER(VCPU, pf_storage), - STATS_DESC_COUNTER(VCPU, pf_instruc), - STATS_DESC_COUNTER(VCPU, sp_storage), - STATS_DESC_COUNTER(VCPU, sp_instruc), - STATS_DESC_COUNTER(VCPU, queue_intr), - STATS_DESC_COUNTER(VCPU, ld_slow), - STATS_DESC_COUNTER(VCPU, st_slow), - STATS_DESC_COUNTER(VCPU, pthru_all), - STATS_DESC_COUNTER(VCPU, pthru_host), - STATS_DESC_COUNTER(VCPU, pthru_bad_aff) + KVM_STAT(VM, CUMULATIVE, NONE, sum_exits), + KVM_STAT(VM, CUMULATIVE, NONE, mmio_exits), + KVM_STAT(VM, CUMULATIVE, NONE, signal_exits), + KVM_STAT(VM, CUMULATIVE, NONE, light_exits), + KVM_STAT(VM, CUMULATIVE, NONE, itlb_real_miss_exits), + KVM_STAT(VM, CUMULATIVE, NONE, itlb_virt_miss_exits), + KVM_STAT(VM, CUMULATIVE, NONE, dtlb_real_miss_exits), + KVM_STAT(VM, CUMULATIVE, NONE, dtlb_virt_miss_exits), + KVM_STAT(VM, CUMULATIVE, NONE, syscall_exits), + KVM_STAT(VM, CUMULATIVE, NONE, isi_exits), + KVM_STAT(VM, CUMULATIVE, NONE, dsi_exits), + KVM_STAT(VM, CUMULATIVE, NONE, emulated_inst_exits), + KVM_STAT(VM, CUMULATIVE, NONE, dec_exits), + KVM_STAT(VM, CUMULATIVE, NONE, ext_intr_exits), + KVM_STAT(VM, CUMULATIVE, NONE, halt_successful_wait), + KVM_STAT(VM, CUMULATIVE, NONE, dbell_exits), + KVM_STAT(VM, CUMULATIVE, NONE, gdbell_exits), + KVM_STAT(VM, CUMULATIVE, NONE, ld), + KVM_STAT(VM, CUMULATIVE, NONE, st), + KVM_STAT(VM, CUMULATIVE, NONE, pf_storage), + KVM_STAT(VM, CUMULATIVE, NONE, pf_instruc), + KVM_STAT(VM, CUMULATIVE, NONE, sp_storage), + KVM_STAT(VM, CUMULATIVE, NONE, sp_instruc), + KVM_STAT(VM, CUMULATIVE, NONE, queue_intr), + KVM_STAT(VM, CUMULATIVE, NONE, ld_slow), + KVM_STAT(VM, CUMULATIVE, NONE, st_slow), + KVM_STAT(VM, CUMULATIVE, NONE, pthru_all), + KVM_STAT(VM, CUMULATIVE, NONE, pthru_host), + KVM_STAT(VM, CUMULATIVE, NONE, pthru_bad_aff) }; const struct kvm_stats_header kvm_vcpu_stats_header = { diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 01adffb24667..898bdd583289 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -38,8 +38,8 @@ unsigned long kvmppc_booke_handlers; const struct _kvm_stats_desc kvm_vm_stats_desc[] = { KVM_GENERIC_VM_STATS(), - STATS_DESC_ICOUNTER(VM, num_2M_pages), - STATS_DESC_ICOUNTER(VM, num_1G_pages) + KVM_STAT(VM, INSTANT, NONE, num_2M_pages), + KVM_STAT(VM, INSTANT, NONE, num_1G_pages) }; const struct kvm_stats_header kvm_vm_stats_header = { @@ -53,28 +53,28 @@ const struct kvm_stats_header kvm_vm_stats_header = { const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { KVM_GENERIC_VCPU_STATS(), - STATS_DESC_COUNTER(VCPU, sum_exits), - STATS_DESC_COUNTER(VCPU, mmio_exits), - STATS_DESC_COUNTER(VCPU, signal_exits), - STATS_DESC_COUNTER(VCPU, light_exits), - STATS_DESC_COUNTER(VCPU, itlb_real_miss_exits), - STATS_DESC_COUNTER(VCPU, itlb_virt_miss_exits), - STATS_DESC_COUNTER(VCPU, dtlb_real_miss_exits), - STATS_DESC_COUNTER(VCPU, dtlb_virt_miss_exits), - STATS_DESC_COUNTER(VCPU, syscall_exits), - STATS_DESC_COUNTER(VCPU, isi_exits), - STATS_DESC_COUNTER(VCPU, dsi_exits), - STATS_DESC_COUNTER(VCPU, emulated_inst_exits), - STATS_DESC_COUNTER(VCPU, dec_exits), - STATS_DESC_COUNTER(VCPU, ext_intr_exits), - STATS_DESC_COUNTER(VCPU, halt_successful_wait), - STATS_DESC_COUNTER(VCPU, dbell_exits), - STATS_DESC_COUNTER(VCPU, gdbell_exits), - STATS_DESC_COUNTER(VCPU, ld), - STATS_DESC_COUNTER(VCPU, st), - STATS_DESC_COUNTER(VCPU, pthru_all), - STATS_DESC_COUNTER(VCPU, pthru_host), - STATS_DESC_COUNTER(VCPU, pthru_bad_aff) + KVM_STAT(VCPU, CUMULATIVE, NONE, sum_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, mmio_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, signal_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, light_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, itlb_real_miss_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, itlb_virt_miss_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, dtlb_real_miss_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, dtlb_virt_miss_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, syscall_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, isi_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, dsi_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, emulated_inst_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, dec_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, ext_intr_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, halt_successful_wait), + KVM_STAT(VCPU, CUMULATIVE, NONE, dbell_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, gdbell_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, ld), + KVM_STAT(VCPU, CUMULATIVE, NONE, st), + KVM_STAT(VCPU, CUMULATIVE, NONE, pthru_all), + KVM_STAT(VCPU, CUMULATIVE, NONE, pthru_host), + KVM_STAT(VCPU, CUMULATIVE, NONE, pthru_bad_aff) }; const struct kvm_stats_header kvm_vcpu_stats_header = { diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 7d010b0be54e..57f57f6f5baf 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -25,14 +25,14 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { KVM_GENERIC_VCPU_STATS(), - STATS_DESC_COUNTER(VCPU, ecall_exit_stat), - STATS_DESC_COUNTER(VCPU, wfi_exit_stat), - STATS_DESC_COUNTER(VCPU, mmio_exit_user), - STATS_DESC_COUNTER(VCPU, mmio_exit_kernel), - STATS_DESC_COUNTER(VCPU, csr_exit_user), - STATS_DESC_COUNTER(VCPU, csr_exit_kernel), - STATS_DESC_COUNTER(VCPU, signal_exits), - STATS_DESC_COUNTER(VCPU, exits) + KVM_STAT(VCPU, CUMULATIVE, NONE, ecall_exit_stat), + KVM_STAT(VCPU, CUMULATIVE, NONE, wfi_exit_stat), + KVM_STAT(VCPU, CUMULATIVE, NONE, mmio_exit_user), + KVM_STAT(VCPU, CUMULATIVE, NONE, mmio_exit_kernel), + KVM_STAT(VCPU, CUMULATIVE, NONE, csr_exit_user), + KVM_STAT(VCPU, CUMULATIVE, NONE, csr_exit_kernel), + KVM_STAT(VCPU, CUMULATIVE, NONE, signal_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, exits) }; const struct kvm_stats_header kvm_vcpu_stats_header = { diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 39b36562c043..dfb3bc4d4b46 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -61,12 +61,12 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { KVM_GENERIC_VM_STATS(), - STATS_DESC_COUNTER(VM, inject_io), - STATS_DESC_COUNTER(VM, inject_float_mchk), - STATS_DESC_COUNTER(VM, inject_pfault_done), - STATS_DESC_COUNTER(VM, inject_service_signal), - STATS_DESC_COUNTER(VM, inject_virtio), - STATS_DESC_COUNTER(VM, aen_forward) + KVM_STAT(VM, CUMULATIVE, NONE, inject_io), + KVM_STAT(VM, CUMULATIVE, NONE, inject_float_mchk), + KVM_STAT(VM, CUMULATIVE, NONE, inject_pfault_done), + KVM_STAT(VM, CUMULATIVE, NONE, inject_service_signal), + KVM_STAT(VM, CUMULATIVE, NONE, inject_virtio), + KVM_STAT(VM, CUMULATIVE, NONE, aen_forward) }; const struct kvm_stats_header kvm_vm_stats_header = { @@ -80,99 +80,99 @@ const struct kvm_stats_header kvm_vm_stats_header = { const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { KVM_GENERIC_VCPU_STATS(), - STATS_DESC_COUNTER(VCPU, exit_userspace), - STATS_DESC_COUNTER(VCPU, exit_null), - STATS_DESC_COUNTER(VCPU, exit_external_request), - STATS_DESC_COUNTER(VCPU, exit_io_request), - STATS_DESC_COUNTER(VCPU, exit_external_interrupt), - STATS_DESC_COUNTER(VCPU, exit_stop_request), - STATS_DESC_COUNTER(VCPU, exit_validity), - STATS_DESC_COUNTER(VCPU, exit_instruction), - STATS_DESC_COUNTER(VCPU, exit_pei), - STATS_DESC_COUNTER(VCPU, halt_no_poll_steal), - STATS_DESC_COUNTER(VCPU, instruction_lctl), - STATS_DESC_COUNTER(VCPU, instruction_lctlg), - STATS_DESC_COUNTER(VCPU, instruction_stctl), - STATS_DESC_COUNTER(VCPU, instruction_stctg), - STATS_DESC_COUNTER(VCPU, exit_program_interruption), - STATS_DESC_COUNTER(VCPU, exit_instr_and_program), - STATS_DESC_COUNTER(VCPU, exit_operation_exception), - STATS_DESC_COUNTER(VCPU, deliver_ckc), - STATS_DESC_COUNTER(VCPU, deliver_cputm), - STATS_DESC_COUNTER(VCPU, deliver_external_call), - STATS_DESC_COUNTER(VCPU, deliver_emergency_signal), - STATS_DESC_COUNTER(VCPU, deliver_service_signal), - STATS_DESC_COUNTER(VCPU, deliver_virtio), - STATS_DESC_COUNTER(VCPU, deliver_stop_signal), - STATS_DESC_COUNTER(VCPU, deliver_prefix_signal), - STATS_DESC_COUNTER(VCPU, deliver_restart_signal), - STATS_DESC_COUNTER(VCPU, deliver_program), - STATS_DESC_COUNTER(VCPU, deliver_io), - STATS_DESC_COUNTER(VCPU, deliver_machine_check), - STATS_DESC_COUNTER(VCPU, exit_wait_state), - STATS_DESC_COUNTER(VCPU, inject_ckc), - STATS_DESC_COUNTER(VCPU, inject_cputm), - STATS_DESC_COUNTER(VCPU, inject_external_call), - STATS_DESC_COUNTER(VCPU, inject_emergency_signal), - STATS_DESC_COUNTER(VCPU, inject_mchk), - STATS_DESC_COUNTER(VCPU, inject_pfault_init), - STATS_DESC_COUNTER(VCPU, inject_program), - STATS_DESC_COUNTER(VCPU, inject_restart), - STATS_DESC_COUNTER(VCPU, inject_set_prefix), - STATS_DESC_COUNTER(VCPU, inject_stop_signal), - STATS_DESC_COUNTER(VCPU, instruction_epsw), - STATS_DESC_COUNTER(VCPU, instruction_gs), - STATS_DESC_COUNTER(VCPU, instruction_io_other), - STATS_DESC_COUNTER(VCPU, instruction_lpsw), - STATS_DESC_COUNTER(VCPU, instruction_lpswe), - STATS_DESC_COUNTER(VCPU, instruction_pfmf), - STATS_DESC_COUNTER(VCPU, instruction_ptff), - STATS_DESC_COUNTER(VCPU, instruction_sck), - STATS_DESC_COUNTER(VCPU, instruction_sckpf), - STATS_DESC_COUNTER(VCPU, instruction_stidp), - STATS_DESC_COUNTER(VCPU, instruction_spx), - STATS_DESC_COUNTER(VCPU, instruction_stpx), - STATS_DESC_COUNTER(VCPU, instruction_stap), - STATS_DESC_COUNTER(VCPU, instruction_iske), - STATS_DESC_COUNTER(VCPU, instruction_ri), - STATS_DESC_COUNTER(VCPU, instruction_rrbe), - STATS_DESC_COUNTER(VCPU, instruction_sske), - STATS_DESC_COUNTER(VCPU, instruction_ipte_interlock), - STATS_DESC_COUNTER(VCPU, instruction_stsi), - STATS_DESC_COUNTER(VCPU, instruction_stfl), - STATS_DESC_COUNTER(VCPU, instruction_tb), - STATS_DESC_COUNTER(VCPU, instruction_tpi), - STATS_DESC_COUNTER(VCPU, instruction_tprot), - STATS_DESC_COUNTER(VCPU, instruction_tsch), - STATS_DESC_COUNTER(VCPU, instruction_sie), - STATS_DESC_COUNTER(VCPU, instruction_essa), - STATS_DESC_COUNTER(VCPU, instruction_sthyi), - STATS_DESC_COUNTER(VCPU, instruction_sigp_sense), - STATS_DESC_COUNTER(VCPU, instruction_sigp_sense_running), - STATS_DESC_COUNTER(VCPU, instruction_sigp_external_call), - STATS_DESC_COUNTER(VCPU, instruction_sigp_emergency), - STATS_DESC_COUNTER(VCPU, instruction_sigp_cond_emergency), - STATS_DESC_COUNTER(VCPU, instruction_sigp_start), - STATS_DESC_COUNTER(VCPU, instruction_sigp_stop), - STATS_DESC_COUNTER(VCPU, instruction_sigp_stop_store_status), - STATS_DESC_COUNTER(VCPU, instruction_sigp_store_status), - STATS_DESC_COUNTER(VCPU, instruction_sigp_store_adtl_status), - STATS_DESC_COUNTER(VCPU, instruction_sigp_arch), - STATS_DESC_COUNTER(VCPU, instruction_sigp_prefix), - STATS_DESC_COUNTER(VCPU, instruction_sigp_restart), - STATS_DESC_COUNTER(VCPU, instruction_sigp_init_cpu_reset), - STATS_DESC_COUNTER(VCPU, instruction_sigp_cpu_reset), - STATS_DESC_COUNTER(VCPU, instruction_sigp_unknown), - STATS_DESC_COUNTER(VCPU, instruction_diagnose_10), - STATS_DESC_COUNTER(VCPU, instruction_diagnose_44), - STATS_DESC_COUNTER(VCPU, instruction_diagnose_9c), - STATS_DESC_COUNTER(VCPU, diag_9c_ignored), - STATS_DESC_COUNTER(VCPU, diag_9c_forward), - STATS_DESC_COUNTER(VCPU, instruction_diagnose_258), - STATS_DESC_COUNTER(VCPU, instruction_diagnose_308), - STATS_DESC_COUNTER(VCPU, instruction_diagnose_500), - STATS_DESC_COUNTER(VCPU, instruction_diagnose_other), - STATS_DESC_COUNTER(VCPU, pfault_sync) + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_userspace), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_null), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_external_request), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_io_request), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_external_interrupt), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_stop_request), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_validity), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_instruction), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_pei), + KVM_STAT(VCPU, CUMULATIVE, NONE, halt_no_poll_steal), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_lctl), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_lctlg), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_stctl), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_stctg), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_program_interruption), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_instr_and_program), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_operation_exception), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_ckc), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_cputm), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_external_call), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_emergency_signal), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_service_signal), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_virtio), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_stop_signal), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_prefix_signal), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_restart_signal), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_program), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_io), + KVM_STAT(VCPU, CUMULATIVE, NONE, deliver_machine_check), + KVM_STAT(VCPU, CUMULATIVE, NONE, exit_wait_state), + KVM_STAT(VCPU, CUMULATIVE, NONE, inject_ckc), + KVM_STAT(VCPU, CUMULATIVE, NONE, inject_cputm), + KVM_STAT(VCPU, CUMULATIVE, NONE, inject_external_call), + KVM_STAT(VCPU, CUMULATIVE, NONE, inject_emergency_signal), + KVM_STAT(VCPU, CUMULATIVE, NONE, inject_mchk), + KVM_STAT(VCPU, CUMULATIVE, NONE, inject_pfault_init), + KVM_STAT(VCPU, CUMULATIVE, NONE, inject_program), + KVM_STAT(VCPU, CUMULATIVE, NONE, inject_restart), + KVM_STAT(VCPU, CUMULATIVE, NONE, inject_set_prefix), + KVM_STAT(VCPU, CUMULATIVE, NONE, inject_stop_signal), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_epsw), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_gs), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_io_other), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_lpsw), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_lpswe), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_pfmf), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_ptff), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sck), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sckpf), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_stidp), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_spx), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_stpx), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_stap), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_iske), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_ri), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_rrbe), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sske), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_ipte_interlock), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_stsi), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_stfl), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_tb), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_tpi), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_tprot), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_tsch), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sie), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_essa), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sthyi), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_sense), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_sense_running), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_external_call), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_emergency), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_cond_emergency), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_start), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_stop), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_stop_store_status), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_store_status), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_store_adtl_status), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_arch), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_prefix), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_restart), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_init_cpu_reset), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_cpu_reset), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_sigp_unknown), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_diagnose_10), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_diagnose_44), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_diagnose_9c), + KVM_STAT(VCPU, CUMULATIVE, NONE, diag_9c_ignored), + KVM_STAT(VCPU, CUMULATIVE, NONE, diag_9c_forward), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_diagnose_258), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_diagnose_308), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_diagnose_500), + KVM_STAT(VCPU, CUMULATIVE, NONE, instruction_diagnose_other), + KVM_STAT(VCPU, CUMULATIVE, NONE, pfault_sync) }; const struct kvm_stats_header kvm_vcpu_stats_header = { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f706621c35b8..072f5ba83170 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -233,19 +233,19 @@ EXPORT_SYMBOL_GPL(host_xss); const struct _kvm_stats_desc kvm_vm_stats_desc[] = { KVM_GENERIC_VM_STATS(), - STATS_DESC_COUNTER(VM, mmu_shadow_zapped), - STATS_DESC_COUNTER(VM, mmu_pte_write), - STATS_DESC_COUNTER(VM, mmu_pde_zapped), - STATS_DESC_COUNTER(VM, mmu_flooded), - STATS_DESC_COUNTER(VM, mmu_recycled), - STATS_DESC_COUNTER(VM, mmu_cache_miss), - STATS_DESC_ICOUNTER(VM, mmu_unsync), - STATS_DESC_ICOUNTER(VM, pages_4k), - STATS_DESC_ICOUNTER(VM, pages_2m), - STATS_DESC_ICOUNTER(VM, pages_1g), - STATS_DESC_ICOUNTER(VM, nx_lpage_splits), - STATS_DESC_PCOUNTER(VM, max_mmu_rmap_size), - STATS_DESC_PCOUNTER(VM, max_mmu_page_hash_collisions) + KVM_STAT(VM, CUMULATIVE, NONE, mmu_shadow_zapped), + KVM_STAT(VM, CUMULATIVE, NONE, mmu_pte_write), + KVM_STAT(VM, CUMULATIVE, NONE, mmu_pde_zapped), + KVM_STAT(VM, CUMULATIVE, NONE, mmu_flooded), + KVM_STAT(VM, CUMULATIVE, NONE, mmu_recycled), + KVM_STAT(VM, CUMULATIVE, NONE, mmu_cache_miss), + KVM_STAT(VM, INSTANT, NONE, mmu_unsync), + KVM_STAT(VM, INSTANT, NONE, pages_4k), + KVM_STAT(VM, INSTANT, NONE, pages_2m), + KVM_STAT(VM, INSTANT, NONE, pages_1g), + KVM_STAT(VM, INSTANT, NONE, nx_lpage_splits), + KVM_STAT(VM, PEAK, NONE, max_mmu_rmap_size), + KVM_STAT(VM, PEAK, NONE, max_mmu_page_hash_collisions) }; const struct kvm_stats_header kvm_vm_stats_header = { @@ -259,40 +259,40 @@ const struct kvm_stats_header kvm_vm_stats_header = { const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { KVM_GENERIC_VCPU_STATS(), - STATS_DESC_COUNTER(VCPU, pf_taken), - STATS_DESC_COUNTER(VCPU, pf_fixed), - STATS_DESC_COUNTER(VCPU, pf_emulate), - STATS_DESC_COUNTER(VCPU, pf_spurious), - STATS_DESC_COUNTER(VCPU, pf_fast), - STATS_DESC_COUNTER(VCPU, pf_mmio_spte_created), - STATS_DESC_COUNTER(VCPU, pf_guest), - STATS_DESC_COUNTER(VCPU, tlb_flush), - STATS_DESC_COUNTER(VCPU, invlpg), - STATS_DESC_COUNTER(VCPU, exits), - STATS_DESC_COUNTER(VCPU, io_exits), - STATS_DESC_COUNTER(VCPU, mmio_exits), - STATS_DESC_COUNTER(VCPU, signal_exits), - STATS_DESC_COUNTER(VCPU, irq_window_exits), - STATS_DESC_COUNTER(VCPU, nmi_window_exits), - STATS_DESC_COUNTER(VCPU, l1d_flush), - STATS_DESC_COUNTER(VCPU, halt_exits), - STATS_DESC_COUNTER(VCPU, request_irq_exits), - STATS_DESC_COUNTER(VCPU, irq_exits), - STATS_DESC_COUNTER(VCPU, host_state_reload), - STATS_DESC_COUNTER(VCPU, fpu_reload), - STATS_DESC_COUNTER(VCPU, insn_emulation), - STATS_DESC_COUNTER(VCPU, insn_emulation_fail), - STATS_DESC_COUNTER(VCPU, hypercalls), - STATS_DESC_COUNTER(VCPU, irq_injections), - STATS_DESC_COUNTER(VCPU, nmi_injections), - STATS_DESC_COUNTER(VCPU, req_event), - STATS_DESC_COUNTER(VCPU, nested_run), - STATS_DESC_COUNTER(VCPU, directed_yield_attempted), - STATS_DESC_COUNTER(VCPU, directed_yield_successful), - STATS_DESC_COUNTER(VCPU, preemption_reported), - STATS_DESC_COUNTER(VCPU, preemption_other), - STATS_DESC_IBOOLEAN(VCPU, guest_mode), - STATS_DESC_COUNTER(VCPU, notify_window_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, pf_taken), + KVM_STAT(VCPU, CUMULATIVE, NONE, pf_fixed), + KVM_STAT(VCPU, CUMULATIVE, NONE, pf_emulate), + KVM_STAT(VCPU, CUMULATIVE, NONE, pf_spurious), + KVM_STAT(VCPU, CUMULATIVE, NONE, pf_fast), + KVM_STAT(VCPU, CUMULATIVE, NONE, pf_mmio_spte_created), + KVM_STAT(VCPU, CUMULATIVE, NONE, pf_guest), + KVM_STAT(VCPU, CUMULATIVE, NONE, tlb_flush), + KVM_STAT(VCPU, CUMULATIVE, NONE, invlpg), + KVM_STAT(VCPU, CUMULATIVE, NONE, exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, io_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, mmio_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, signal_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, irq_window_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, nmi_window_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, l1d_flush), + KVM_STAT(VCPU, CUMULATIVE, NONE, halt_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, request_irq_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, irq_exits), + KVM_STAT(VCPU, CUMULATIVE, NONE, host_state_reload), + KVM_STAT(VCPU, CUMULATIVE, NONE, fpu_reload), + KVM_STAT(VCPU, CUMULATIVE, NONE, insn_emulation), + KVM_STAT(VCPU, CUMULATIVE, NONE, insn_emulation_fail), + KVM_STAT(VCPU, CUMULATIVE, NONE, hypercalls), + KVM_STAT(VCPU, CUMULATIVE, NONE, irq_injections), + KVM_STAT(VCPU, CUMULATIVE, NONE, nmi_injections), + KVM_STAT(VCPU, CUMULATIVE, NONE, req_event), + KVM_STAT(VCPU, CUMULATIVE, NONE, nested_run), + KVM_STAT(VCPU, CUMULATIVE, NONE, directed_yield_attempted), + KVM_STAT(VCPU, CUMULATIVE, NONE, directed_yield_successful), + KVM_STAT(VCPU, CUMULATIVE, NONE, preemption_reported), + KVM_STAT(VCPU, CUMULATIVE, NONE, preemption_other), + KVM_STAT(VCPU, INSTANT, BOOLEAN, guest_mode), + KVM_STAT(VCPU, CUMULATIVE, NONE, notify_window_exits), }; const struct kvm_stats_header kvm_vcpu_stats_header = { diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 8ada23756b0e..02b1151c2753 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1785,80 +1785,43 @@ struct _kvm_stats_desc { }, \ .name = #stat, \ } + /* SCOPE: VM, VM_GENERIC, VCPU, VCPU_GENERIC */ #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, 1, 0) -#define STATS_DESC_INSTANT(SCOPE, name, 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, 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) \ - STATS_DESC_CUMULATIVE(SCOPE, name, KVM_STATS_UNIT_NONE, \ - KVM_STATS_BASE_POW10, 0) -/* Instantaneous counter, read only */ -#define STATS_DESC_ICOUNTER(SCOPE, name) \ - STATS_DESC_INSTANT(SCOPE, name, KVM_STATS_UNIT_NONE, \ - KVM_STATS_BASE_POW10, 0) -/* Peak counter, read/write */ -#define STATS_DESC_PCOUNTER(SCOPE, name) \ - STATS_DESC_PEAK(SCOPE, name, KVM_STATS_UNIT_NONE, \ - KVM_STATS_BASE_POW10, 0) - -/* Instantaneous boolean value, read only */ -#define STATS_DESC_IBOOLEAN(SCOPE, name) \ - STATS_DESC_INSTANT(SCOPE, name, KVM_STATS_UNIT_BOOLEAN, \ - KVM_STATS_BASE_POW10, 0) -/* Peak (sticky) boolean value, read/write */ -#define STATS_DESC_PBOOLEAN(SCOPE, name) \ - STATS_DESC_PEAK(SCOPE, name, KVM_STATS_UNIT_BOOLEAN, \ - KVM_STATS_BASE_POW10, 0) - -/* Cumulative time in nanosecond */ -#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_STAT(SCOPE, TYPE, UNIT, _stat) \ + STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_##TYPE, \ + KVM_STATS_UNIT_##UNIT, KVM_STATS_BASE_POW10, 0, 1, 0) + +#define KVM_STAT_NSEC(SCOPE, _stat) \ + STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_CUMULATIVE, \ + KVM_STATS_UNIT_SECONDS, KVM_STATS_BASE_POW10, -9, 1, 0) + +#define KVM_HIST_NSEC(SCOPE, TYPE, _stat, _size, _bucket_size) \ + STATS_DESC(VCPU_GENERIC, _stat, KVM_STATS_TYPE_##TYPE##_HIST, \ + KVM_STATS_UNIT_SECONDS, KVM_STATS_BASE_POW10, -9, \ + _size, _bucket_size) #define KVM_GENERIC_VM_STATS() \ - STATS_DESC_COUNTER(VM_GENERIC, remote_tlb_flush), \ - STATS_DESC_COUNTER(VM_GENERIC, remote_tlb_flush_requests) + KVM_STAT(VM_GENERIC, CUMULATIVE, NONE, remote_tlb_flush), \ + KVM_STAT(VM_GENERIC, CUMULATIVE, NONE, remote_tlb_flush_requests) + +#define KVM_HALT_POLL_HIST(_stat) \ + KVM_HIST_NSEC(VCPU_GENERIC, LOG, _stat, HALT_POLL_HIST_COUNT, 0) #define KVM_GENERIC_VCPU_STATS() \ - STATS_DESC_COUNTER(VCPU_GENERIC, halt_successful_poll), \ - STATS_DESC_COUNTER(VCPU_GENERIC, halt_attempted_poll), \ - 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_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), \ - STATS_DESC_IBOOLEAN(VCPU_GENERIC, blocking) + KVM_STAT(VCPU_GENERIC, CUMULATIVE, NONE, halt_successful_poll), \ + KVM_STAT(VCPU_GENERIC, CUMULATIVE, NONE, halt_attempted_poll), \ + KVM_STAT(VCPU_GENERIC, CUMULATIVE, NONE, halt_poll_invalid), \ + KVM_STAT(VCPU_GENERIC, CUMULATIVE, NONE, halt_wakeup), \ + KVM_STAT_NSEC(VCPU_GENERIC, halt_poll_success_ns), \ + KVM_STAT_NSEC(VCPU_GENERIC, halt_poll_fail_ns), \ + KVM_STAT_NSEC(VCPU_GENERIC, halt_wait_ns), \ + KVM_HALT_POLL_HIST(halt_poll_success_hist), \ + KVM_HALT_POLL_HIST(halt_poll_fail_hist), \ + KVM_HALT_POLL_HIST(halt_wait_hist), \ + KVM_STAT(VCPU_GENERIC, INSTANT, BOOLEAN, blocking) extern struct dentry *kvm_debugfs_dir; From patchwork Mon Mar 6 19:01:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 13162200 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16844C61DA4 for ; Mon, 6 Mar 2023 19:02:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229890AbjCFTCZ (ORCPT ); Mon, 6 Mar 2023 14:02:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229813AbjCFTCY (ORCPT ); Mon, 6 Mar 2023 14:02:24 -0500 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 D9E8232CFF for ; Mon, 6 Mar 2023 11:02:03 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 66-20020a250245000000b00a53c1100d72so11493654ybc.0 for ; Mon, 06 Mar 2023 11:02:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678129323; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YtNaR+Rua5pfZ3i1GgJ4+hfSm+WXWk7IiLK4Wtb8+uM=; b=A42BX/LP2I7Yrldf83rjJjVVWP9EY7MIToR2w3fKfHNuwlJilnDlJG9Ga110/MBKfg bANY0GGZpHkSiBa5gtT3zYMm3kqQ6eoCd9XQbU1Nw97OaGmCCVTg5gCJq6SSBEjZs5D2 WXuRcS2VBsFJxrimrp+JQlNpq+OFmS1Ohh71sBzmcc1MXrTW549F5OJ3aZCaRVfQfJrL Xl5df+WIcc/z0GU55ilZ3Am2ARcrEJpAjke5BrZTBJ9d+m4fByyPMgXYOtOtNovF1gQu M0K+F9OgIzJN5j3FpXghI6sTRl0hwMpb0KkZDbWtWBZRE7ORKqG1rS1sA7NOJROAsX6B zrWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678129323; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YtNaR+Rua5pfZ3i1GgJ4+hfSm+WXWk7IiLK4Wtb8+uM=; b=PPQbflXTX2iq03nQdmp6+fcsGK/aCtI6YhC7YdqwQhzzAPVzp/a/4tkjZ8vTB/YVku Nj6BqLE8TB8niXD9nWjVrvHHWHeq3t+acyqyxpIvq/IMUONgvjzPeBFd5+pFoZUjKKbs IYE7Gl5ehzaomT4tgHrPAvWJcssgjsqgaTNNSR2w5WCvN5G8tdWrRiOyT9wUXdSbUGWt NWyzTRvBo6tD3/ppbYmrFU7Z5ZVxLT4+KsbWPPw57IwGyzwjBpicEnEzsGlitjxKlSTr Zr2ahBBmbUiZWLmHbml4Pyf82oZPlUQtJBHGksppNv9pISLP2StIi88rp5WMfHVtqQo/ FInA== X-Gm-Message-State: AO0yUKX/WJCCwjsawKP5XADqhsiCRvkBf72JVVDbju6MLGMz06Mfl0XK nUk1X4ZOAood1IyFloCHOxVCQkIV1LCo5w== X-Google-Smtp-Source: AK7set90Igml/rc2W0Ya1hk1eHjjJqlvHrIGVSaZmJTzp6vbZseA2XP1DWQDVsfl/YAYC2c0ne8CFj1tJ7LMiQ== X-Received: from dmatlack-n2d-128.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1309]) (user=dmatlack job=sendgmr) by 2002:a81:ad0d:0:b0:52e:b635:5496 with SMTP id l13-20020a81ad0d000000b0052eb6355496mr7126400ywh.2.1678129323101; Mon, 06 Mar 2023 11:02:03 -0800 (PST) Date: Mon, 6 Mar 2023 11:01:54 -0800 In-Reply-To: <20230306190156.434452-1-dmatlack@google.com> Mime-Version: 1.0 References: <20230306190156.434452-1-dmatlack@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230306190156.434452-3-dmatlack@google.com> Subject: [PATCH v2 2/4] KVM: Refactor designated initializer macros for struct _kvm_stats_desc From: David Matlack To: Paolo Bonzini Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Huacai Chen , Aleksandar Markovic , Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Sean Christopherson , Michael Ellerman , Eric Farman , " =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= " , David Matlack , Sathvika Vasireddy , Nicholas Piggin , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Refactor the macros that generate struct _kvm_stats_desc designated initializers to cut down on duplication. No functional change intended. Signed-off-by: David Matlack --- include/linux/kvm_host.h | 75 +++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 02b1151c2753..6673ae757c4e 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1744,47 +1744,42 @@ struct _kvm_stats_desc { char name[KVM_STATS_NAME_SIZE]; }; -#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 = sz, \ - .bucket_size = bsz - -#define VM_GENERIC_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ +/* Generates a designated initializer list for a struct _kvm_stats_desc. */ +#define _KVM_STATS_DESC(_struct, _field, _name, _type, _unit, _base, \ + _exponent, _size, _bucket_size) \ +{ \ { \ - { \ - 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, sz, bsz) \ - { \ - { \ - 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, sz, bsz) \ - { \ - { \ - 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, sz, bsz) \ - { \ - { \ - STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ - .offset = offsetof(struct kvm_vcpu_stat, stat) \ - }, \ - .name = #stat, \ - } + .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 = _exponent, \ + .size = _size, \ + .bucket_size = _bucket_size, \ + .offset = offsetof(_struct, _field), \ + }, \ + .name = _name, \ +} + +#define VM_GENERIC_STATS_DESC(_stat, _type, _unit, _base, _exponent, _size, \ + _bucket_size) \ + _KVM_STATS_DESC(struct kvm_vm_stat, generic._stat, #_stat, _type, \ + _unit, _base, _exponent, _size, _bucket_size) + +#define VCPU_GENERIC_STATS_DESC(_stat, _type, _unit, _base, _exponent, _size, \ + _bucket_size) \ + _KVM_STATS_DESC(struct kvm_vcpu_stat, generic._stat, #_stat, _type, \ + _unit, _base, _exponent, _size, _bucket_size) + +#define VM_STATS_DESC(_stat, _type, _unit, _base, _exponent, _size, \ + _bucket_size) \ + _KVM_STATS_DESC(struct kvm_vm_stat, _stat, #_stat, _type, _unit, \ + _base, _exponent, _size, _bucket_size) + +#define VCPU_STATS_DESC(_stat, _type, _unit, _base, _exponent, _size, \ + _bucket_size) \ + _KVM_STATS_DESC(struct kvm_vcpu_stat, _stat, #_stat, _type, _unit, \ + _base, _exponent, _size, _bucket_size) /* SCOPE: VM, VM_GENERIC, VCPU, VCPU_GENERIC */ #define STATS_DESC(SCOPE, stat, type, unit, base, exp, sz, bsz) \ From patchwork Mon Mar 6 19:01:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 13162203 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A05AC6FD1C for ; Mon, 6 Mar 2023 19:02:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229927AbjCFTC0 (ORCPT ); Mon, 6 Mar 2023 14:02:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229787AbjCFTCZ (ORCPT ); Mon, 6 Mar 2023 14:02:25 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E0C642BF3 for ; Mon, 6 Mar 2023 11:02:05 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id d7-20020a25adc7000000b00953ffdfbe1aso11658491ybe.23 for ; Mon, 06 Mar 2023 11:02:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678129324; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XCoFR/ZEz+o/3af75F9xOrPS2psj7bAuPaV+hSWOgQo=; b=UtpACFkTBCbOuRJEDO4GIV5VZyNtvBXfzND3oU3x+MTJtqKf4RC+aJ4iEUgKvk/Gbv QwvfJnU9JToxEfS+WRcwSwlVT4IlfuPHxbDlaSiueIsWANa2Ta9bs7g2Xb/SoaztXvbW AcZzwTzgMy8MObXk877NToyNHzCNVG6tPs8bD3L2lDLtP1vJbpQNVe/QUw4MOneGcben A12+mWFZoMCKAD0Z64Pf8fB/rO0lgxgHvfoLNCDEimxkEwLixX3fA9CtbPgaW1lHLH/k mZfeAEacPOyAvkjV/89Ze4YmYA+t2BabNvI12wvTJZnOvTvidyImSKerp51EgZ1O07yo W1MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678129324; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XCoFR/ZEz+o/3af75F9xOrPS2psj7bAuPaV+hSWOgQo=; b=15zjmzGdYXY+lk1NI8XXGBmQr8yPwbm6fjITb0dRl5loyFVal/Y09ePddM+Me39Pro qRzkeZwxiyTb9ZwsT3hhyI/I4p7lY2R/IV0BTb/22gaH2e5TIfEusW2IIfa89S10TT5e DQ7RTq00BQ+xapXLv5pjn+2VUINZxrt9AmOn4Ch8XZPZY3bEF1QmCY7uUZRxXSHS0k8G jyYPH6vF/2SSqP8FIlyvxTBmrizJ+iiRbVA++FUc8ixnEkjnsj1WuVB1rz/N6AQll3gy dMVcWcvO4XonpYOmesVoYlQ557xez1o4ejMbqLw1O8PCd4mn+SKB/UfPSeq4uHVSK2+E H1/Q== X-Gm-Message-State: AO0yUKVvxSFZFbrpTQoZQ8HilHRHhzZRqV+NqcmTV+cAQOXEMEpRpQER G9PVn9kPiVsVkJCTRATnKK/K5nlYMoh4+A== X-Google-Smtp-Source: AK7set//cZ5G8Yg9tzyC35+cBUfG5YD+QOMFZSqm+c6ivqgffhDJvoZQbaLGDxeXrS7rdZX3Y2pHJ1bn0bJjqg== X-Received: from dmatlack-n2d-128.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1309]) (user=dmatlack job=sendgmr) by 2002:a81:ac4b:0:b0:533:9ffb:cb12 with SMTP id z11-20020a81ac4b000000b005339ffbcb12mr7643877ywj.10.1678129324575; Mon, 06 Mar 2023 11:02:04 -0800 (PST) Date: Mon, 6 Mar 2023 11:01:55 -0800 In-Reply-To: <20230306190156.434452-1-dmatlack@google.com> Mime-Version: 1.0 References: <20230306190156.434452-1-dmatlack@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230306190156.434452-4-dmatlack@google.com> Subject: [PATCH v2 3/4] KVM: Allow custom names for KVM_STAT() From: David Matlack To: Paolo Bonzini Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Huacai Chen , Aleksandar Markovic , Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Sean Christopherson , Michael Ellerman , Eric Farman , " =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= " , David Matlack , Sathvika Vasireddy , Nicholas Piggin , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, Jing Zhang Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Allow custom names to be specified for stats built on KVM_STAT() via a new inner macro __KVM_STAT(). e.g. KVM_STAT(VM, CUMULATIVE, NONE, foo), __KVM_STAT(VM, CUMULATIVE, NONE, bar, "custom_name"), ... Custom name support enables decoupling the userspace-visible stat names from their internal representation in C. This can allow future commits to refactor the various stats structs without impacting userspace tools that read KVM stats. This also allows stats to be stored in data structures such as arrays, without needing unions to access specific stats. For example, the union for pages_{4k,2m,1g} is no longer necessary. At Google, we have several other out-of-tree stats that would benefit from this support. No functional change intended. Link: https://lore.kernel.org/all/20211019000459.3163029-1-jingzhangos@google.com/ Suggested-by: Jing Zhang Signed-off-by: David Matlack --- include/linux/kvm_host.h | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 6673ae757c4e..fa026e8997b2 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1761,40 +1761,43 @@ struct _kvm_stats_desc { .name = _name, \ } -#define VM_GENERIC_STATS_DESC(_stat, _type, _unit, _base, _exponent, _size, \ - _bucket_size) \ - _KVM_STATS_DESC(struct kvm_vm_stat, generic._stat, #_stat, _type, \ +#define VM_GENERIC_STATS_DESC(_stat, _name, _type, _unit, _base, _exponent, \ + _size, _bucket_size) \ + _KVM_STATS_DESC(struct kvm_vm_stat, generic._stat, _name, _type, \ _unit, _base, _exponent, _size, _bucket_size) -#define VCPU_GENERIC_STATS_DESC(_stat, _type, _unit, _base, _exponent, _size, \ - _bucket_size) \ - _KVM_STATS_DESC(struct kvm_vcpu_stat, generic._stat, #_stat, _type, \ +#define VCPU_GENERIC_STATS_DESC(_stat, _name, _type, _unit, _base, _exponent, \ + _size, _bucket_size) \ + _KVM_STATS_DESC(struct kvm_vcpu_stat, generic._stat, _name, _type, \ _unit, _base, _exponent, _size, _bucket_size) -#define VM_STATS_DESC(_stat, _type, _unit, _base, _exponent, _size, \ +#define VM_STATS_DESC(_stat, _name, _type, _unit, _base, _exponent, _size, \ _bucket_size) \ - _KVM_STATS_DESC(struct kvm_vm_stat, _stat, #_stat, _type, _unit, \ + _KVM_STATS_DESC(struct kvm_vm_stat, _stat, _name, _type, _unit, \ _base, _exponent, _size, _bucket_size) -#define VCPU_STATS_DESC(_stat, _type, _unit, _base, _exponent, _size, \ +#define VCPU_STATS_DESC(_stat, _name, _type, _unit, _base, _exponent, _size, \ _bucket_size) \ - _KVM_STATS_DESC(struct kvm_vcpu_stat, _stat, #_stat, _type, _unit, \ + _KVM_STATS_DESC(struct kvm_vcpu_stat, _stat, _name, _type, _unit, \ _base, _exponent, _size, _bucket_size) /* SCOPE: VM, VM_GENERIC, VCPU, VCPU_GENERIC */ -#define STATS_DESC(SCOPE, stat, type, unit, base, exp, sz, bsz) \ - SCOPE##_STATS_DESC(stat, type, unit, base, exp, sz, bsz) +#define STATS_DESC(SCOPE, stat, name, type, unit, base, exp, sz, bsz) \ + SCOPE##_STATS_DESC(stat, name, type, unit, base, exp, sz, bsz) -#define KVM_STAT(SCOPE, TYPE, UNIT, _stat) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_##TYPE, \ +#define __KVM_STAT(SCOPE, TYPE, UNIT, _stat, _name) \ + STATS_DESC(SCOPE, _stat, _name, KVM_STATS_TYPE_##TYPE, \ KVM_STATS_UNIT_##UNIT, KVM_STATS_BASE_POW10, 0, 1, 0) +#define KVM_STAT(SCOPE, TYPE, UNIT, _stat) \ + __KVM_STAT(SCOPE, TYPE, UNIT, _stat, #_stat) + #define KVM_STAT_NSEC(SCOPE, _stat) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_CUMULATIVE, \ + STATS_DESC(SCOPE, _stat, #_stat, KVM_STATS_TYPE_CUMULATIVE, \ KVM_STATS_UNIT_SECONDS, KVM_STATS_BASE_POW10, -9, 1, 0) #define KVM_HIST_NSEC(SCOPE, TYPE, _stat, _size, _bucket_size) \ - STATS_DESC(VCPU_GENERIC, _stat, KVM_STATS_TYPE_##TYPE##_HIST, \ + STATS_DESC(VCPU_GENERIC, _stat, #_stat, KVM_STATS_TYPE_##TYPE##_HIST, \ KVM_STATS_UNIT_SECONDS, KVM_STATS_BASE_POW10, -9, \ _size, _bucket_size) From patchwork Mon Mar 6 19:01:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 13162202 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA14CC6FD1D for ; Mon, 6 Mar 2023 19:02:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229975AbjCFTC1 (ORCPT ); Mon, 6 Mar 2023 14:02:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229907AbjCFTC0 (ORCPT ); Mon, 6 Mar 2023 14:02:26 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D03031BEF for ; Mon, 6 Mar 2023 11:02:06 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-536e8d6d9ceso112060627b3.12 for ; Mon, 06 Mar 2023 11:02:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678129326; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Hy1Buh0DyhAQ1dsWc1I6Y0GrKiZLM4ytS70wq/2qiU0=; b=Letr5LRp7bS0YmkVINmE83RF8//+0ihwPomgSJZC4+dkD9sFUFEL35AQoxcfPpIbXW Y1mVJA34aQ9Fn9+jBPkAovdeUPbAGsum3MVzw575zB3u4rfwK4ZVePdw3VSiVo2j9C9v 3XnoKl7fEhlmtkQ5DdG9/UhFj+tyVjNmSih/iYAuSQ6xwOtYmbjOYgHRAkzFRXa92dze ZQvrRjBbIKvFglVzBDH4EAw30eROHuzuIjsYKsJXNnWsAQHIog+eYwButoAe0B9OxSD2 pOTz7b2aOyFjFOUOaTEw5+7DJRfnksutj0fbq9nxtjgFb7SGFFpwHZTOmxj6KpssL5px NozA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678129326; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Hy1Buh0DyhAQ1dsWc1I6Y0GrKiZLM4ytS70wq/2qiU0=; b=y3U1q+I+ZR+DjCAO1NI/LDpshiNaT9fAoN1OipCb6FckujzlxwVXF37pTxITRveoIT u2gT5WPt9LicVVJh4dtp8Lz/4D+r/xGpzX/D2uDB4wnQUCp9udXTxhAgcd2WBhXmQhNH wmpC4EBLdVuRGI+hfLYC42IO5iFdabagJB9LIg3U8QiHDglMsXzJJnY/bgHRqsigXSyf 3/O9KACoduKO0qpg8eraOmLuVTlCSDNr9wouKteWPxq9guFwRtc8dnh4Y1lB3aEgDMRT gucndyQlpwELLQGI7x29aRqbL3cw2hw/5/KdFOFDOqWJG3RF9AQFPe3OU2OBSxrJ/ohY tlyA== X-Gm-Message-State: AO0yUKXWKhNYYKIVe9p/tFqHzpA0fZ4QWn4QHd/y4aBiUXyy2cfQyzlu m0NE3ypd4lHQCEwwOR74dmru/D0iP3ikfA== X-Google-Smtp-Source: AK7set9e2oV5ajrE5TnGPzkyECRcuaio2KGOJRsM0L6WhO9k90cawVld9W/AAFXa4Ih5X3b9O+P88E69HqyVhg== X-Received: from dmatlack-n2d-128.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1309]) (user=dmatlack job=sendgmr) by 2002:a81:b667:0:b0:534:d71f:14e6 with SMTP id h39-20020a81b667000000b00534d71f14e6mr7365447ywk.9.1678129326079; Mon, 06 Mar 2023 11:02:06 -0800 (PST) Date: Mon, 6 Mar 2023 11:01:56 -0800 In-Reply-To: <20230306190156.434452-1-dmatlack@google.com> Mime-Version: 1.0 References: <20230306190156.434452-1-dmatlack@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230306190156.434452-5-dmatlack@google.com> Subject: [PATCH v2 4/4] KVM: x86: Drop union for pages_{4k,2m,1g} stats From: David Matlack To: Paolo Bonzini Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Huacai Chen , Aleksandar Markovic , Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Sean Christopherson , Michael Ellerman , Eric Farman , " =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= " , David Matlack , Sathvika Vasireddy , Nicholas Piggin , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Drop the union for the pages_{4k,2m,1g} stats. The union is no longer necessary now that KVM supports choosing a custom name for stats. Eliminating the union also would allow future commits to more easily move pages[] into common code, e.g. if KVM ever gains support for a common page table code. An alternative would be to drop pages[] and have kvm_update_page_stats() update pages_{4k,2m,1g} directly. But that's not a good direction to go in since other architectures use other page sizes. No functional change intended. Link: https://lore.kernel.org/kvm/20221208193857.4090582-1-dmatlack@google.com/ Signed-off-by: David Matlack --- arch/x86/include/asm/kvm_host.h | 9 +-------- arch/x86/kvm/x86.c | 6 +++--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 808c292ad3f4..a59e41355ef4 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1473,14 +1473,7 @@ struct kvm_vm_stat { u64 mmu_recycled; u64 mmu_cache_miss; u64 mmu_unsync; - union { - struct { - atomic64_t pages_4k; - atomic64_t pages_2m; - atomic64_t pages_1g; - }; - atomic64_t pages[KVM_NR_PAGE_SIZES]; - }; + atomic64_t pages[KVM_NR_PAGE_SIZES]; u64 nx_lpage_splits; u64 max_mmu_page_hash_collisions; u64 max_mmu_rmap_size; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 072f5ba83170..101ad6b7e7b6 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -240,9 +240,9 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { KVM_STAT(VM, CUMULATIVE, NONE, mmu_recycled), KVM_STAT(VM, CUMULATIVE, NONE, mmu_cache_miss), KVM_STAT(VM, INSTANT, NONE, mmu_unsync), - KVM_STAT(VM, INSTANT, NONE, pages_4k), - KVM_STAT(VM, INSTANT, NONE, pages_2m), - KVM_STAT(VM, INSTANT, NONE, pages_1g), + __KVM_STAT(VM, INSTANT, NONE, pages[PG_LEVEL_4K - 1], "pages_4k"), + __KVM_STAT(VM, INSTANT, NONE, pages[PG_LEVEL_2M - 1], "pages_2m"), + __KVM_STAT(VM, INSTANT, NONE, pages[PG_LEVEL_1G - 1], "pages_1g"), KVM_STAT(VM, INSTANT, NONE, nx_lpage_splits), KVM_STAT(VM, PEAK, NONE, max_mmu_rmap_size), KVM_STAT(VM, PEAK, NONE, max_mmu_page_hash_collisions)