[PATCH 4/5] KVM: Allow custom names for stats

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allow 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.

Link: https://lore.kernel.org/all/20211019000459.3163029-1-jingzhangos@xxxxxxxxxx/
Suggested-by: Jing Zhang <jingzhangos@xxxxxxxxxx>
Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
---
 include/linux/kvm_host.h | 104 ++++++++++++++++++++++++---------------
 1 file changed, 64 insertions(+), 40 deletions(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index cceb159727b5..5e37acc2e80e 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -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),		       \
-- 
2.39.0.246.g2a6d74b583-goog




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux