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: 13162216 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7C42C61DA4 for ; Mon, 6 Mar 2023 19:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=usTjmY8dy+Zkehyc2I7+7Xuijo9ZO1s7VeTAKculIpc=; b=2ZIc1SdN6b/Z3NSgz8gzKNupNP t+Ok9ej/U+YeB/Vl0XYOfVqiPoU5QKT6vc6cMwgwW4JZyYX2vjTQoZi/QeKyzO+jJnNks5+uz7dkv QcRih45ECosDsnLQTzUSoeu4Q8Zo9FegZKreosvhoqHVj3bHVRtszDrmNKuJLDkb2GGXwAI3dGUW+ F4CW2GJ/8NzuUw03+EmnzFVYtC7tfoS+L3XMNtjF4PpuTe2y5J4A/WCJV3tETe2Nvwaaj2/TGn5T+ ghk84ms7Wy9Zt0AWKOcsPDveJhd+o/WWgjtcj7HLXRhz2Z2ASGoxA2ak90egzm7REOgCz7QhvPb// 12VEdWNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZG6V-00ERkY-TF; Mon, 06 Mar 2023 19:02:36 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZG61-00ERWU-RD for linux-arm-kernel@lists.infradead.org; Mon, 06 Mar 2023 19:02:10 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id w5-20020a253005000000b00aedd4305ff2so10903414ybw.13 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=swh+msB9CI+vvHu0rWhxm0Zfw7Qp6FOSwMy4HNo5ssRC/AKnos3yHlZbaLsqOrMqIo cij3L1UyVWzcku+PpO1h3pWjy05Yj4eeCwBm1nQU5P0NUHvwnOhaxDWTs4OqIOArXxgM QoTwovYxrKsGxZQZojXV+MxLTtvIA7Rzy457FEKqeWiXpj+rJg2VtokdqbSIK+E0iv1j Sj/bTQqUCa2Nk0x9sE32yQcDPy5AslWvk3nhuKWpX60z5pSnxibkScz4/oLMFBVTp1CY wsGzF1xKRqnp1s2RCQJawMeVd1fr2vdV4I1brxF3lX1ePa7itzRgavtiLT+SobN8ATTL ltCg== X-Gm-Message-State: AO0yUKWRLYmtwPukdj1D1aDX+yCOkSuB+VcIVdqEdOXhGr1Dm9uSao00 IuWQoO0aE7FTuSMl6M4GTdN9R1PVaZdvgQ== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230306_110205_947577_814E79ED X-CRM114-Status: GOOD ( 11.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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)