KVM: Refactor KVM stats macros to allow custom names
cover KVM: Refactor KVM stats macros to allow custom names
This series refactors the KVM stats macros to allow specifying custom names, e.g.
STATS_DESC_COUNTER(VM, foo),
__STATS_DESC_COUNTER(VM, bar, "custom_name"),
Custom name makes it possible to decouple 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. Case in point, the last patch in this series removes the pages_{4k,2m,1g} union, which is a useful cleanup to prepare for the Common MMU [1].
And for full transparency, another motivation for this series it that at Google we have several out-of-tree stats that use arrays. Custom name support is something we added internally and it reduces our technical debt to get the support merged upstream.
David Matlack (5):
KVM: Consistently use "stat" name in stats macros
KVM: Spell out parameter names in stats macros
KVM: Fix indentation in stats macros
KVM: Allow custom names for stats
KVM: x86: Drop union for pages_{4k,2m,1g} stats
arch/x86/include/asm/kvm_host.h | 9 +- arch/x86/kvm/x86.c | 6 +- include/linux/kvm_host.h | 170 +++++++++++++++++++------------- 3 files changed, 107 insertions(+), 78 deletions(-)
base-commit: de60733246ff4545a0483140c1f21426b8d7cb7f
prerequisite-patch-id: 42a76ce7cec240776c21f674e99e893a3a6bee58
Signature · 1 line
2.39.0.246.g2a6d74b583-goog
PATCH 1/5 KVM: Consistently use "stat" name in stats macros
Consistently use "stat" instead of a mix of "stat" and "name" in the various KVM stats macros. This improves the readability, and also enables a future commit to add a separate "name" parameter.
No functional change intended.
--- include/linux/kvm_host.h | 52 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 26 deletions(-)
include/linux/kvm_host.h +26 -26
@@ -1789,55 +1789,55 @@ struct _kvm_stats_desc {#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, \ +#define STATS_DESC_CUMULATIVE (SCOPE , stat, unit, base, exponent) \ + STATS_DESC(SCOPE, stat, 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, \ +#define STATS_DESC_INSTANT (SCOPE , stat, unit, base, exponent) \ + STATS_DESC(SCOPE, stat, 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, \ +#define STATS_DESC_PEAK (SCOPE , stat, unit, base, exponent) \ + STATS_DESC(SCOPE, stat, 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, \ +#define STATS_DESC_LINEAR_HIST (SCOPE , stat, unit, base, exponent, sz, bsz) \ + STATS_DESC(SCOPE, stat, 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, \ +#define STATS_DESC_LOG_HIST (SCOPE , stat, unit, base, exponent, sz) \ + STATS_DESC(SCOPE, stat, 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, \ +#define STATS_DESC_COUNTER (SCOPE , stat) \ + STATS_DESC_CUMULATIVE(SCOPE, stat, 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, \ +#define STATS_DESC_ICOUNTER (SCOPE , stat) \ + STATS_DESC_INSTANT(SCOPE, stat, 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, \ +#define STATS_DESC_PCOUNTER (SCOPE , stat) \ + STATS_DESC_PEAK(SCOPE, stat, 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, \ +#define STATS_DESC_IBOOLEAN (SCOPE , stat) \ + STATS_DESC_INSTANT(SCOPE, stat, 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, \ +#define STATS_DESC_PBOOLEAN (SCOPE , stat) \ + STATS_DESC_PEAK(SCOPE, stat, 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, \ +#define STATS_DESC_TIME_NSEC (SCOPE , stat) \ + STATS_DESC_CUMULATIVE(SCOPE, stat, 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, \ +#define STATS_DESC_LINHIST_TIME_NSEC (SCOPE , stat, sz, bsz) \ + STATS_DESC_LINEAR_HIST(SCOPE, stat, 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, \ +#define STATS_DESC_LOGHIST_TIME_NSEC (SCOPE , stat, sz) \ + STATS_DESC_LOG_HIST(SCOPE, stat, KVM_STATS_UNIT_SECONDS, \ KVM_STATS_BASE_POW10, -9, sz)#define KVM_GENERIC_VM_STATS () \
Signature · 1 line
2.39.0.246.g2a6d74b583-goog
PATCH 2/5 KVM: Spell out parameter names in stats macros
In reply to David MatlackSpell out the parameter names in the various KVM stats macros. This increases readability (e.g. _bucket_size vs. bsz).
Opportunistically add an underscore to all the macro parameter names for consistency. Since these macros generate designated initializers, the underscores are important to avoid clashing with field names.
No functional change intended.
--- include/linux/kvm_host.h | 134 +++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 61 deletions(-)
include/linux/kvm_host.h +73 -61
@@ -1744,101 +1744,113 @@ 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) \ +#define STATS_DESC_COMMON (_type, _unit, _base, _exponent, _size, _bucket_size) \ + .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 + +#define VM_GENERIC_STATS_DESC (_stat, _type, _unit, _base, _exponent, _size, \ + _bucket_size) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ - .offset = offsetof(struct kvm_vm_stat, generic.stat) \ + STATS_DESC_COMMON(_type, _unit, _base, _exponent, \ + _size, _bucket_size), \ + .offset = offsetof(struct kvm_vm_stat, generic._stat) \ }, \ - .name = #stat, \ + .name = #_stat, \ } -#define VCPU_GENERIC_STATS_DESC (stat, type, unit, base, exp, sz, bsz) \ +#define VCPU_GENERIC_STATS_DESC (_stat, _type, _unit, _base, _exponent, _size, \ + _bucket_size) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ - .offset = offsetof(struct kvm_vcpu_stat, generic.stat) \ + STATS_DESC_COMMON(_type, _unit, _base, _exponent, \ + _size, _bucket_size), \ + .offset = \ + offsetof(struct kvm_vcpu_stat, generic._stat) \ }, \ - .name = #stat, \ + .name = #_stat, \ } -#define VM_STATS_DESC (stat, type, unit, base, exp, sz, bsz) \ +#define VM_STATS_DESC (_stat, _type, _unit, _base, _exponent, _size, \ + _bucket_size) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ - .offset = offsetof(struct kvm_vm_stat, stat) \ + STATS_DESC_COMMON(_type, _unit, _base, _exponent, \ + _size, _bucket_size), \ + .offset = offsetof(struct kvm_vm_stat, _stat) \ }, \ - .name = #stat, \ + .name = #_stat, \ } -#define VCPU_STATS_DESC (stat, type, unit, base, exp, sz, bsz) \ +#define VCPU_STATS_DESC (_stat, _type, _unit, _base, _exponent, _size, \ + _bucket_size) \ { \ { \ - STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ - .offset = offsetof(struct kvm_vcpu_stat, stat) \ + STATS_DESC_COMMON(_type, _unit, _base, _exponent, \ + _size, _bucket_size), \ + .offset = offsetof(struct kvm_vcpu_stat, _stat) \ }, \ - .name = #stat, \ + .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 , stat, unit, base, exponent) \ - STATS_DESC(SCOPE, stat, KVM_STATS_TYPE_CUMULATIVE, \ - unit, base, exponent, 1, 0) -#define STATS_DESC_INSTANT (SCOPE , stat, unit, base, exponent) \ - STATS_DESC(SCOPE, stat, KVM_STATS_TYPE_INSTANT, \ - unit, base, exponent, 1, 0) -#define STATS_DESC_PEAK (SCOPE , stat, unit, base, exponent) \ - STATS_DESC(SCOPE, stat, KVM_STATS_TYPE_PEAK, \ - unit, base, exponent, 1, 0) -#define STATS_DESC_LINEAR_HIST (SCOPE , stat, unit, base, exponent, sz, bsz) \ - STATS_DESC(SCOPE, stat, KVM_STATS_TYPE_LINEAR_HIST, \ - unit, base, exponent, sz, bsz) -#define STATS_DESC_LOG_HIST (SCOPE , stat, unit, base, exponent, sz) \ - STATS_DESC(SCOPE, stat, KVM_STATS_TYPE_LOG_HIST, \ - unit, base, exponent, sz, 0) +#define STATS_DESC (SCOPE , _stat, _type, _unit, _base, _exponent, _size, \ + _bucket_size) \ + SCOPE##_STATS_DESC(_stat, _type, _unit, _base, _exponent, _size, \ + _bucket_size) + +#define STATS_DESC_CUMULATIVE (SCOPE , _stat, _unit, _base, exponent) \ + STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_CUMULATIVE, \ + _unit, _base, exponent, 1, 0) +#define STATS_DESC_INSTANT (SCOPE , _stat, _unit, _base, exponent) \ + STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_INSTANT, \ + _unit, _base, exponent, 1, 0) +#define STATS_DESC_PEAK (SCOPE , _stat, _unit, _base, exponent) \ + STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_PEAK, \ + _unit, _base, exponent, 1, 0) +#define STATS_DESC_LINEAR_HIST (SCOPE , _stat, _unit, _base, exponent, _size, \ + _bucket_size) \ + STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_LINEAR_HIST, \ + _unit, _base, exponent, _size, _bucket_size) +#define STATS_DESC_LOG_HIST (SCOPE , _stat, _unit, _base, exponent, _size) \ + STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_LOG_HIST, \ + _unit, _base, exponent, _size, 0)/* Cumulative counter, read/write */ -#define STATS_DESC_COUNTER (SCOPE , stat) \ - STATS_DESC_CUMULATIVE(SCOPE, stat, KVM_STATS_UNIT_NONE, \ +#define STATS_DESC_COUNTER (SCOPE , _stat) \ + STATS_DESC_CUMULATIVE(SCOPE, _stat, KVM_STATS_UNIT_NONE, \ KVM_STATS_BASE_POW10, 0)/* Instantaneous counter, read only */ -#define STATS_DESC_ICOUNTER (SCOPE , stat) \ - STATS_DESC_INSTANT(SCOPE, stat, KVM_STATS_UNIT_NONE, \ +#define STATS_DESC_ICOUNTER (SCOPE , _stat) \ + STATS_DESC_INSTANT(SCOPE, _stat, KVM_STATS_UNIT_NONE, \ KVM_STATS_BASE_POW10, 0)/* Peak counter, read/write */ -#define STATS_DESC_PCOUNTER (SCOPE , stat) \ - STATS_DESC_PEAK(SCOPE, stat, KVM_STATS_UNIT_NONE, \ +#define STATS_DESC_PCOUNTER (SCOPE , _stat) \ + STATS_DESC_PEAK(SCOPE, _stat, KVM_STATS_UNIT_NONE, \ KVM_STATS_BASE_POW10, 0)/* Instantaneous boolean value, read only */ -#define STATS_DESC_IBOOLEAN (SCOPE , stat) \ - STATS_DESC_INSTANT(SCOPE, stat, KVM_STATS_UNIT_BOOLEAN, \ +#define STATS_DESC_IBOOLEAN (SCOPE , _stat) \ + STATS_DESC_INSTANT(SCOPE, _stat, KVM_STATS_UNIT_BOOLEAN, \ KVM_STATS_BASE_POW10, 0)/* Peak (sticky) boolean value, read/write */ -#define STATS_DESC_PBOOLEAN (SCOPE , stat) \ - STATS_DESC_PEAK(SCOPE, stat, KVM_STATS_UNIT_BOOLEAN, \ +#define STATS_DESC_PBOOLEAN (SCOPE , _stat) \ + STATS_DESC_PEAK(SCOPE, _stat, KVM_STATS_UNIT_BOOLEAN, \ KVM_STATS_BASE_POW10, 0)/* Cumulative time in nanosecond */ -#define STATS_DESC_TIME_NSEC (SCOPE , stat) \ - STATS_DESC_CUMULATIVE(SCOPE, stat, KVM_STATS_UNIT_SECONDS, \ +#define STATS_DESC_TIME_NSEC (SCOPE , _stat) \ + STATS_DESC_CUMULATIVE(SCOPE, _stat, KVM_STATS_UNIT_SECONDS, \ KVM_STATS_BASE_POW10, -9)/* Linear histogram for time in nanosecond */ -#define STATS_DESC_LINHIST_TIME_NSEC (SCOPE , stat, sz, bsz) \ - STATS_DESC_LINEAR_HIST(SCOPE, stat, KVM_STATS_UNIT_SECONDS, \ - KVM_STATS_BASE_POW10, -9, sz, bsz) +#define STATS_DESC_LINHIST_TIME_NSEC (SCOPE , _stat, _size, _bucket_size) \ + STATS_DESC_LINEAR_HIST(SCOPE, _stat, KVM_STATS_UNIT_SECONDS, \ + KVM_STATS_BASE_POW10, -9, _size, _bucket_size)/* Logarithmic histogram for time in nanosecond */ -#define STATS_DESC_LOGHIST_TIME_NSEC (SCOPE , stat, sz) \ - STATS_DESC_LOG_HIST(SCOPE, stat, KVM_STATS_UNIT_SECONDS, \ - KVM_STATS_BASE_POW10, -9, sz) +#define STATS_DESC_LOGHIST_TIME_NSEC (SCOPE , _stat, _size) \ + STATS_DESC_LOG_HIST(SCOPE, _stat, KVM_STATS_UNIT_SECONDS, \ + KVM_STATS_BASE_POW10, -9, _size)#define KVM_GENERIC_VM_STATS () \ STATS_DESC_COUNTER(VM_GENERIC, remote_tlb_flush), \
Signature · 1 line
2.39.0.246.g2a6d74b583-goog
PATCH 3/5 KVM: Fix indentation in stats macros
In reply to David MatlackFix the indentation in the various stats macros so that parameter lists that are split across lines are aligned with the open parenthesis on the previous line.
No functional change intended.
--- include/linux/kvm_host.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
include/linux/kvm_host.h +13 -13
@@ -1802,55 +1802,55 @@ struct _kvm_stats_desc {#define STATS_DESC_CUMULATIVE (SCOPE , _stat, _unit, _base, exponent) \ STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_CUMULATIVE, \ - _unit, _base, exponent, 1, 0) + _unit, _base, exponent, 1, 0)#define STATS_DESC_INSTANT (SCOPE , _stat, _unit, _base, exponent) \ STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_INSTANT, \ - _unit, _base, exponent, 1, 0) + _unit, _base, exponent, 1, 0)#define STATS_DESC_PEAK (SCOPE , _stat, _unit, _base, exponent) \ STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_PEAK, \ - _unit, _base, exponent, 1, 0) + _unit, _base, exponent, 1, 0)#define STATS_DESC_LINEAR_HIST (SCOPE , _stat, _unit, _base, exponent, _size, \ _bucket_size) \ STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_LINEAR_HIST, \ - _unit, _base, exponent, _size, _bucket_size) + _unit, _base, exponent, _size, _bucket_size)#define STATS_DESC_LOG_HIST (SCOPE , _stat, _unit, _base, exponent, _size) \ STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_LOG_HIST, \ - _unit, _base, exponent, _size, 0) + _unit, _base, exponent, _size, 0)/* Cumulative counter, read/write */ #define STATS_DESC_COUNTER (SCOPE , _stat) \ STATS_DESC_CUMULATIVE(SCOPE, _stat, KVM_STATS_UNIT_NONE, \ - KVM_STATS_BASE_POW10, 0) + KVM_STATS_BASE_POW10, 0)/* Instantaneous counter, read only */ #define STATS_DESC_ICOUNTER (SCOPE , _stat) \ STATS_DESC_INSTANT(SCOPE, _stat, KVM_STATS_UNIT_NONE, \ - KVM_STATS_BASE_POW10, 0) + KVM_STATS_BASE_POW10, 0)/* Peak counter, read/write */ #define STATS_DESC_PCOUNTER (SCOPE , _stat) \ STATS_DESC_PEAK(SCOPE, _stat, KVM_STATS_UNIT_NONE, \ - KVM_STATS_BASE_POW10, 0) + KVM_STATS_BASE_POW10, 0)/* Instantaneous boolean value, read only */ #define STATS_DESC_IBOOLEAN (SCOPE , _stat) \ STATS_DESC_INSTANT(SCOPE, _stat, KVM_STATS_UNIT_BOOLEAN, \ - KVM_STATS_BASE_POW10, 0) + KVM_STATS_BASE_POW10, 0)/* Peak (sticky) boolean value, read/write */ #define STATS_DESC_PBOOLEAN (SCOPE , _stat) \ STATS_DESC_PEAK(SCOPE, _stat, KVM_STATS_UNIT_BOOLEAN, \ - KVM_STATS_BASE_POW10, 0) + KVM_STATS_BASE_POW10, 0)/* Cumulative time in nanosecond */ #define STATS_DESC_TIME_NSEC (SCOPE , _stat) \ STATS_DESC_CUMULATIVE(SCOPE, _stat, KVM_STATS_UNIT_SECONDS, \ - KVM_STATS_BASE_POW10, -9) + KVM_STATS_BASE_POW10, -9)/* Linear histogram for time in nanosecond */ #define STATS_DESC_LINHIST_TIME_NSEC (SCOPE , _stat, _size, _bucket_size) \ STATS_DESC_LINEAR_HIST(SCOPE, _stat, KVM_STATS_UNIT_SECONDS, \ - KVM_STATS_BASE_POW10, -9, _size, _bucket_size) + KVM_STATS_BASE_POW10, -9, _size, _bucket_size)/* Logarithmic histogram for time in nanosecond */ #define STATS_DESC_LOGHIST_TIME_NSEC (SCOPE , _stat, _size) \ STATS_DESC_LOG_HIST(SCOPE, _stat, KVM_STATS_UNIT_SECONDS, \ - KVM_STATS_BASE_POW10, -9, _size) + KVM_STATS_BASE_POW10, -9, _size)#define KVM_GENERIC_VM_STATS () \ STATS_DESC_COUNTER(VM_GENERIC, remote_tlb_flush), \
Signature · 1 line
2.39.0.246.g2a6d74b583-goog
PATCH 4/5 KVM: Allow custom names for stats
In reply to David MatlackAllow custom names to be specified for stats by providing inner macros that allow passing a custom name. e.g.
STATS_DESC_COUNTER(VM, foo),
__STATS_DESC_COUNTER(VM, 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.
Support for stat names could be added incrementally (as needed) for all the different STAT_DESC_*() macros. But doing it all at once avoids future churn and ensures the different stat macros have a consistent interface for specifying the name.
No functional change intended.
--- include/linux/kvm_host.h | 104 ++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 40 deletions(-)
include/linux/kvm_host.h +64 -40
@@ -1753,18 +1753,18 @@ struct _kvm_stats_desc { .size = _size, \ .bucket_size = _bucket_size -#define VM_GENERIC_STATS_DESC (_stat, _type, _unit, _base, _exponent, _size, \ - _bucket_size) \ +#define VM_GENERIC_STATS_DESC (_stat, _type, _name, _unit, _base, _exponent, \ + _size, _bucket_size) \ { \ { \ STATS_DESC_COMMON(_type, _unit, _base, _exponent, \ _size, _bucket_size), \ .offset = offsetof(struct kvm_vm_stat, generic._stat) \ }, \ - .name = #_stat, \ + .name = _name, \ } -#define VCPU_GENERIC_STATS_DESC (_stat, _type, _unit, _base, _exponent, _size, \ - _bucket_size) \ +#define VCPU_GENERIC_STATS_DESC (_stat, _type, _name, _unit, _base, _exponent, \ + _size, _bucket_size) \ { \ { \ STATS_DESC_COMMON(_type, _unit, _base, _exponent, \
@@ -1772,9 +1772,9 @@ struct _kvm_stats_desc { .offset = \ offsetof(struct kvm_vcpu_stat, generic._stat) \ }, \ - .name = #_stat, \ + .name = _name, \ } -#define VM_STATS_DESC (_stat, _type, _unit, _base, _exponent, _size, \ +#define VM_STATS_DESC (_stat, _type, _name, _unit, _base, _exponent, _size, \ _bucket_size) \ { \ { \
@@ -1782,9 +1782,9 @@ struct _kvm_stats_desc { _size, _bucket_size), \ .offset = offsetof(struct kvm_vm_stat, _stat) \ }, \ - .name = #_stat, \ + .name = _name, \ } -#define VCPU_STATS_DESC (_stat, _type, _unit, _base, _exponent, _size, \ +#define VCPU_STATS_DESC (_stat, _type, _name, _unit, _base, _exponent, _size, \ _bucket_size) \ { \ { \
@@ -1792,65 +1792,89 @@ struct _kvm_stats_desc { _size, _bucket_size), \ .offset = offsetof(struct kvm_vcpu_stat, _stat) \ }, \ - .name = #_stat, \ + .name = _name, \ }/* SCOPE: VM, VM_GENERIC, VCPU, VCPU_GENERIC */ -#define STATS_DESC (SCOPE , _stat, _type, _unit, _base, _exponent, _size, \ +#define STATS_DESC (SCOPE , _stat, _name, _type, _unit, _base, _exponent, _size, \ _bucket_size) \ - SCOPE##_STATS_DESC(_stat, _type, _unit, _base, _exponent, _size, \ - _bucket_size) + SCOPE##_STATS_DESC(_stat, _type, _name, _unit, _base, _exponent, \ + _size, _bucket_size) \ -#define STATS_DESC_CUMULATIVE (SCOPE , _stat, _unit, _base, exponent) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_CUMULATIVE, \ +#define STATS_DESC_CUMULATIVE (SCOPE , _stat, _name, _unit, _base, exponent) \ + STATS_DESC(SCOPE, _stat, _name, KVM_STATS_TYPE_CUMULATIVE, \ _unit, _base, exponent, 1, 0) -#define STATS_DESC_INSTANT (SCOPE , _stat, _unit, _base, exponent) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_INSTANT, \ +#define STATS_DESC_INSTANT (SCOPE , _stat, _name, _unit, _base, exponent) \ + STATS_DESC(SCOPE, _stat, _name, KVM_STATS_TYPE_INSTANT, \ _unit, _base, exponent, 1, 0) -#define STATS_DESC_PEAK (SCOPE , _stat, _unit, _base, exponent) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_PEAK, \ +#define STATS_DESC_PEAK (SCOPE , _stat, _name, _unit, _base, exponent) \ + STATS_DESC(SCOPE, _stat, _name, KVM_STATS_TYPE_PEAK, \ _unit, _base, exponent, 1, 0) -#define STATS_DESC_LINEAR_HIST (SCOPE , _stat, _unit, _base, exponent, _size, \ - _bucket_size) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_LINEAR_HIST, \ +#define STATS_DESC_LINEAR_HIST (SCOPE , _stat, _name, _unit, _base, exponent, \ + _size, _bucket_size) \ + STATS_DESC(SCOPE, _stat, _name, KVM_STATS_TYPE_LINEAR_HIST, \ _unit, _base, exponent, _size, _bucket_size) -#define STATS_DESC_LOG_HIST (SCOPE , _stat, _unit, _base, exponent, _size) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_LOG_HIST, \ +#define STATS_DESC_LOG_HIST (SCOPE , _stat, _name, _unit, _base, exponent, \ + _size) \ + STATS_DESC(SCOPE, _stat, _name, KVM_STATS_TYPE_LOG_HIST, \ _unit, _base, exponent, _size, 0)/* Cumulative counter, read/write */ -#define STATS_DESC_COUNTER (SCOPE , _stat) \ - STATS_DESC_CUMULATIVE(SCOPE, _stat, KVM_STATS_UNIT_NONE, \ +#define __STATS_DESC_COUNTER (SCOPE , _stat, _name) \ + STATS_DESC_CUMULATIVE(SCOPE, _stat, _name, KVM_STATS_UNIT_NONE, \ KVM_STATS_BASE_POW10, 0) +#define STATS_DESC_COUNTER (SCOPE , _stat) \ + __STATS_DESC_COUNTER(SCOPE, _stat, #_stat) +/* Instantaneous counter, read only */ -#define STATS_DESC_ICOUNTER (SCOPE , _stat) \ - STATS_DESC_INSTANT(SCOPE, _stat, KVM_STATS_UNIT_NONE, \ +#define __STATS_DESC_ICOUNTER (SCOPE , _stat, _name) \ + STATS_DESC_INSTANT(SCOPE, _stat, _name, KVM_STATS_UNIT_NONE, \ KVM_STATS_BASE_POW10, 0) +#define STATS_DESC_ICOUNTER (SCOPE , _stat) \ + __STATS_DESC_ICOUNTER(SCOPE, _stat, #_stat) +/* Peak counter, read/write */ -#define STATS_DESC_PCOUNTER (SCOPE , _stat) \ - STATS_DESC_PEAK(SCOPE, _stat, KVM_STATS_UNIT_NONE, \ +#define __STATS_DESC_PCOUNTER (SCOPE , _stat, _name) \ + STATS_DESC_PEAK(SCOPE, _stat, _name, KVM_STATS_UNIT_NONE, \ KVM_STATS_BASE_POW10, 0) +#define STATS_DESC_PCOUNTER (SCOPE , _stat) \ + __STATS_DESC_PCOUNTER(SCOPE, _stat, #_stat)/* Instantaneous boolean value, read only */ -#define STATS_DESC_IBOOLEAN (SCOPE , _stat) \ - STATS_DESC_INSTANT(SCOPE, _stat, KVM_STATS_UNIT_BOOLEAN, \ +#define __STATS_DESC_IBOOLEAN (SCOPE , _stat, _name) \ + STATS_DESC_INSTANT(SCOPE, _stat, _name, KVM_STATS_UNIT_BOOLEAN, \ KVM_STATS_BASE_POW10, 0) +#define STATS_DESC_IBOOLEAN (SCOPE , _stat) \ + __STATS_DESC_IBOOLEAN(SCOPE, _stat, #_stat) +/* Peak (sticky) boolean value, read/write */ -#define STATS_DESC_PBOOLEAN (SCOPE , _stat) \ - STATS_DESC_PEAK(SCOPE, _stat, KVM_STATS_UNIT_BOOLEAN, \ +#define __STATS_DESC_PBOOLEAN (SCOPE , _stat, _name) \ + STATS_DESC_PEAK(SCOPE, _stat, _name, KVM_STATS_UNIT_BOOLEAN, \ KVM_STATS_BASE_POW10, 0) +#define STATS_DESC_PBOOLEAN (SCOPE , _stat) \ + __STATS_DESC_PBOOLEAN(SOPE, _stat, #_stat)/* Cumulative time in nanosecond */ -#define STATS_DESC_TIME_NSEC (SCOPE , _stat) \ - STATS_DESC_CUMULATIVE(SCOPE, _stat, KVM_STATS_UNIT_SECONDS, \ +#define __STATS_DESC_TIME_NSEC (SCOPE , _stat, _name) \ + STATS_DESC_CUMULATIVE(SCOPE, _stat, _name, KVM_STATS_UNIT_SECONDS, \ KVM_STATS_BASE_POW10, -9) +#define STATS_DESC_TIME_NSEC (SCOPE , _stat) \ + __STATS_DESC_TIME_NSEC(SCOPE, _stat, #_stat) +/* Linear histogram for time in nanosecond */ -#define STATS_DESC_LINHIST_TIME_NSEC (SCOPE , _stat, _size, _bucket_size) \ - STATS_DESC_LINEAR_HIST(SCOPE, _stat, KVM_STATS_UNIT_SECONDS, \ +#define __STATS_DESC_LINHIST_TIME_NSEC (SCOPE , _stat, _name, _size, \ + _bucket_size) \ + STATS_DESC_LINEAR_HIST(SCOPE, _stat, _name, KVM_STATS_UNIT_SECONDS, \ KVM_STATS_BASE_POW10, -9, _size, _bucket_size) +#define STATS_DESC_LINHIST_TIME_NSEC (SCOPE , _stat, _size, _bucket_size) \ + __STATS_DESC_LINHIST_TIME_NSEC(SCOPE, _stat, #_stat, _size, \ + _bucket_size) +/* Logarithmic histogram for time in nanosecond */ -#define STATS_DESC_LOGHIST_TIME_NSEC (SCOPE , _stat, _size) \ - STATS_DESC_LOG_HIST(SCOPE, _stat, KVM_STATS_UNIT_SECONDS, \ +#define __STATS_DESC_LOGHIST_TIME_NSEC (SCOPE , _stat, _name, _size) \ + STATS_DESC_LOG_HIST(SCOPE, _stat, _name, KVM_STATS_UNIT_SECONDS, \ KVM_STATS_BASE_POW10, -9, _size) +#define STATS_DESC_LOGHIST_TIME_NSEC (SCOPE , _stat, _size) \ + __STATS_DESC_LOGHIST_TIME_NSEC(SCOPE, _stat, #_stat, _size)#define KVM_GENERIC_VM_STATS () \ STATS_DESC_COUNTER(VM_GENERIC, remote_tlb_flush), \
Signature · 1 line
2.39.0.246.g2a6d74b583-goog
Sean Christopherson
maintainerRe: [PATCH 4/5] KVM: Allow custom names for stats
Review
Quoted 8 lines · David Matlack
/* SCOPE: VM,
VM_GENERIC, VCPU,VCPU_GENERIC*/(quoted diff) +3
-3-#define STATS_DESC(SCOPE, _stat, _type, _unit, _base, _exponent, _size, \ +#define STATS_DESC(SCOPE, _stat, _name, _type, _unit, _base, _exponent, _size, \ _bucket_size) \ - SCOPE##_STATS_DESC(_stat, _type, _unit, _base, _exponent, _size, \ - _bucket_size) + SCOPE##_STATS_DESC(_stat, _type, _name, _unit, _base, _exponent, \ + _size, _bucket_size) \
Bad trailing backslash snuck in. Probably doesn't cause problems because there's a blank line after it.
Quoted 36 lines
(quoted diff) +15
-13-#define STATS_DESC_CUMULATIVE(SCOPE, _stat, _unit, _base, exponent) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_CUMULATIVE, \ +#define STATS_DESC_CUMULATIVE(SCOPE, _stat, _name, _unit, _base, exponent) \ + STATS_DESC(SCOPE, _stat, _name, KVM_STATS_TYPE_CUMULATIVE, \ _unit, _base, exponent, 1, 0) -#define STATS_DESC_INSTANT(SCOPE, _stat, _unit, _base, exponent) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_INSTANT, \ +#define STATS_DESC_INSTANT(SCOPE, _stat, _name, _unit, _base, exponent) \ + STATS_DESC(SCOPE, _stat, _name, KVM_STATS_TYPE_INSTANT, \ _unit, _base, exponent, 1, 0) -#define STATS_DESC_PEAK(SCOPE, _stat, _unit, _base, exponent) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_PEAK, \ +#define STATS_DESC_PEAK(SCOPE, _stat, _name, _unit, _base, exponent) \ + STATS_DESC(SCOPE, _stat, _name, KVM_STATS_TYPE_PEAK, \ _unit, _base, exponent, 1, 0) -#define STATS_DESC_LINEAR_HIST(SCOPE, _stat, _unit, _base, exponent, _size, \ - _bucket_size) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_LINEAR_HIST, \ +#define STATS_DESC_LINEAR_HIST(SCOPE, _stat, _name, _unit, _base, exponent, \ + _size, _bucket_size) \ + STATS_DESC(SCOPE, _stat, _name, KVM_STATS_TYPE_LINEAR_HIST, \ _unit, _base, exponent, _size, _bucket_size) -#define STATS_DESC_LOG_HIST(SCOPE, _stat, _unit, _base, exponent, _size) \ - STATS_DESC(SCOPE, _stat, KVM_STATS_TYPE_LOG_HIST, \ +#define STATS_DESC_LOG_HIST(SCOPE, _stat, _name, _unit, _base, exponent, \ + _size) \ + STATS_DESC(SCOPE, _stat, _name, KVM_STATS_TYPE_LOG_HIST, \ _unit, _base, exponent, _size, 0) /* Cumulative counter, read/write */ -#define STATS_DESC_COUNTER(SCOPE, _stat) \ - STATS_DESC_CUMULATIVE(SCOPE, _stat, KVM_STATS_UNIT_NONE, \ +#define __STATS_DESC_COUNTER(SCOPE, _stat, _name) \ + STATS_DESC_CUMULATIVE(SCOPE, _stat, _name, KVM_STATS_UNIT_NONE, \ KVM_STATS_BASE_POW10, 0) +#define STATS_DESC_COUNTER(SCOPE, _stat) \
Review
Quoted 10 lines
(quoted diff) +6
-2+ __STATS_DESC_COUNTER(SCOPE, _stat, #_stat) + /* Instantaneous counter, read only */ -#define STATS_DESC_ICOUNTER(SCOPE, _stat) \ - STATS_DESC_INSTANT(SCOPE, _stat, KVM_STATS_UNIT_NONE, \ +#define __STATS_DESC_ICOUNTER(SCOPE, _stat, _name) \ + STATS_DESC_INSTANT(SCOPE, _stat, _name, KVM_STATS_UNIT_NONE, \ KVM_STATS_BASE_POW10, 0) +#define STATS_DESC_ICOUNTER(SCOPE, _stat) \ + __STATS_DESC_ICOUNTER(SCOPE, _stat, #_stat)
The amount of copy+paste is gnarly. Much of that is inherited, but adding the inner macros definitely exacerbates things.
I also dislike the shorthand that ends up getting using, e.g. until I looked at this patch, I assumed ICOUNTER meant "integer counter".
There are also several unused macros that presumably got added because of stats we have internally.
In short, I think adding macros for every flavor was a mistake.
I also vote not to add inner helpers until there's a need, though I suppose I'm not opposed to adding them if the majority opinion is to be nice to people carrying out-of-tree stats, i.e. us :-)
If we tweak the names to be shorter so that the TYPE and UNIT can be params, we only need four (five if we define KVM_HIST to be nice) top-level macros at this time, e.g.
#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, TYPE, _stat) \ STATS_DESC(SCOPE, _stat, #_stat, KVM_STATS_TYPE_##TYPE, \ KVM_STATS_UNIT_SECONDS, KVM_STATS_BASE_POW10, -9, 1, 0)
#define KVM_HIST(SCOPE, TYPE, UNIT, _stat) \ STATS_DESC(SCOPE, _stat, #_stat, KVM_STATS_TYPE_##TYPE##_HIST, \ KVM_STATS_UNIT_##UNIT, KVM_STATS_BASE_POW10, 0, _size, _bucket_size)
#define KVM_HIST_NSEC(SCOPE, TYPE, _stat, _size, _bucket_size) \ STATS_DESC(SCOPE, _stat, #_stat, KVM_STATS_TYPE_##TYPE##_HIST, \ KVM_STATS_UNIT_SECONDS, KVM_STATS_BASE_POW10, -9, _size, _bucket_size)
yields usage like so
const struct _kvm_stats_desc kvm_vm_stats_desc[] = {
KVM_GENERIC_VM_STATS(),
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[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)
};
and the below diff for x86 on top of this series (compile tested only, didn't poke at other architectures other than to verify that don't do anything fancy).
Very last thought, if people find the "NONE" type weird, we could add an alias, e.g. INTEGER.
--- arch/x86/kvm/x86.c | 94 +++++++++++++++--------------- include/linux/kvm_host.h | 121 +++++++++++---------------------------- 2 files changed, 79 insertions(+), 136 deletions(-)
arch/x86/kvm/x86.c +47 -47
@@ -231,19 +231,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[PG_LEVEL_4K -1 ],"pages_4k" ), -__STATS_DESC_ICOUNTER (VM , pages[PG_LEVEL_2M -1 ],"pages_2m" ), -__STATS_DESC_ICOUNTER (VM , pages[PG_LEVEL_1G -1 ],"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[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) };const struct kvm_stats_header kvm_vm_stats_header = {
@@ -257,40 +257,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 = {
include/linux/kvm_host.h +32 -89
135 lines not on this page · raw message
base-commit: 80e5e70ae8ec0a3317cf9900d98c5540955fd6de
PATCH 5/5 KVM: x86: Drop union for pages_{4k,2m,1g} stats
In reply to David MatlackDrop 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 MMU (see Link below).
An alternative would be to drop pages[] and have kvm_update_page_stats() update pages_{4k,2m,1g} directly. But that would make it harder to move the page stats logic into common code.
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 9 +-------- arch/x86/kvm/x86.c | 6 +++--- 2 files changed, 4 insertions(+), 11 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -8
@@ -1457,14 +1457,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;
arch/x86/kvm/x86.c +3 -3
@@ -240,9 +240,9 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = {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 , pages[PG_LEVEL_4K -1 ],"pages_4k" ), +__STATS_DESC_ICOUNTER (VM , pages[PG_LEVEL_2M -1 ],"pages_2m" ), +__STATS_DESC_ICOUNTER (VM , pages[PG_LEVEL_1G -1 ],"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)
Signature · 1 line
2.39.0.246.g2a6d74b583-goog