Skip to contentSkip to conversation

mshv: Debugfs interface for mshv_root

PATCH Superseded Nuno Das Neves 3 participants 12 messages Jan 14 – Jan 20

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover mshv: Debugfs interface for mshv_root

Expose hypervisor, logical processor, partition, and virtual processor statistics via debugfs. These are provided by mapping 'stats' pages via hypercall.

Patch #1: Update hv_call_map_stats_page() to return success when
HV_STATS_AREA_PARENT is unavailable, which is the case on some hypervisor versions, where it can fall back to HV_STATS_AREA_SELF
Patch #2: Use struct hv_stats_page pointers instead of void * Patch #3: Make mshv_vp_stats_map/unmap() more flexible to use with debugfs code Patch #4: Always map vp stats page regardless of scheduler, to reuse in debugfs Patch #5: Introduce the definitions needed for the various stats pages Patch #6: Add mshv_debugfs.c, and integrate it with the mshv_root driver to
expose the partition and VP stats.

---
Changes in v3:
- Add 3 small refactor/cleanup patches (patches 2,3,4) from Stanislav. These simplify some of the debugfs code, and fix issues with mapping VP stats on L1VH.
- Fix cleanup of parent stats dentries on module removal (via squashing some internal patches into patch #6) [Praveen]
- Remove unused goto label [Stanislav, kernel bot]
- Use struct hv_stats_page * instead of void * in mshv_debugfs.c [Stanislav]
- Remove some redundant variables [Stanislav]
- Rename debugfs dentry fields for brevity [Stanislav]
- Use ERR_CAST() for the dentry error pointer returned from lp_debugfs_stats_create() [Stanislav]
- Fix leak of pages allocated for lp stats mappings by storing them in an array [Michael]
- Add comments to clarify PARENT vs SELF usage and edge cases [Michael]
- Add VpLoadAvg for x86 and print the stat [Michael]
- Add NUM_STATS_AREAS for array sizing in mshv_debugfs.c [Michael]

Changes in v2:
- Remove unnecessary pr_debug_once() in patch 1 [Stanislav Kinsburskii]
- CONFIG_X86 -> CONFIG_X86_64 in patch 2 [Stanislav Kinsburskii]

---
Nuno Das Neves (2):
mshv: Add definitions for stats pages
mshv: Add debugfs to view hypervisor statistics

Purna Pavan Chandra Aekkaladevi (1):
mshv: Ignore second stats page map result failure

Stanislav Kinsburskii (3):
mshv: Use typed hv_stats_page pointers
mshv: Improve mshv_vp_stats_map/unmap(), add them to mshv_root.h
mshv: Always map child vp stats pages regardless of scheduler type

 drivers/hv/Makefile            |    1 +
 drivers/hv/mshv_debugfs.c      | 1103 ++++++++++++++++++++++++++++++++
 drivers/hv/mshv_root.h         |   49 +-
 drivers/hv/mshv_root_hv_call.c |   64 +-
 drivers/hv/mshv_root_main.c    |  130 ++--
 include/hyperv/hvhdk.h         |  437 +++++++++++++
 6 files changed, 1721 insertions(+), 63 deletions(-)
 create mode 100644 drivers/hv/mshv_debugfs.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/6 mshv: Ignore second stats page map result failure

From: Purna Pavan Chandra Aekkaladevi <[email protected]>

Older versions of the hypervisor do not have a concept of separate SELF and PARENT stats areas. In this case, mapping the HV_STATS_AREA_SELF page is sufficient - it's the only page and it contains all available stats.

Mapping HV_STATS_AREA_PARENT returns HV_STATUS_INVALID_PARAMETER which currently causes module init to fail on older hypevisor versions.

Detect this case and gracefully fall back to populating stats_pages[HV_STATS_AREA_PARENT] with the already-mapped SELF page.

Add comments to clarify the behavior, including a clarification of why this isn't needed for hv_call_map_stats_page2() which always supports PARENT and SELF areas.

---
 drivers/hv/mshv_root_hv_call.c | 52 +++++++++++++++++++++++++++++++---
 drivers/hv/mshv_root_main.c    |  3 ++
 2 files changed, 51 insertions(+), 4 deletions(-)
drivers/hv/mshv_root_hv_call.c +48 -4
index 598eaff4ff29..1f93b94d7580 100644
@@ -813,6 +813,13 @@ hv_call_notify_port_ring_empty(u32 sint_index)
 	return hv_result_to_errno(status);
 }
 
+/*
+ * Equivalent of hv_call_map_stats_page() for cases when the caller provides
+ * the map location.
+ *
+ * NOTE: This is a newer hypercall that always supports SELF and PARENT stats
+ * areas, unlike hv_call_map_stats_page().
+ */
 static int hv_call_map_stats_page2(enum hv_stats_object_type type,
 				   const union hv_stats_object_identity *identity,
 				   u64 map_location)
@@ -855,6 +862,34 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
 	return ret;
 }
 
+static int
+hv_stats_get_area_type(enum hv_stats_object_type type,
+		       const union hv_stats_object_identity *identity)
+{
+	switch (type) {
+	case HV_STATS_OBJECT_HYPERVISOR:
+		return identity->hv.stats_area_type;
+	case HV_STATS_OBJECT_LOGICAL_PROCESSOR:
+		return identity->lp.stats_area_type;
+	case HV_STATS_OBJECT_PARTITION:
+		return identity->partition.stats_area_type;
+	case HV_STATS_OBJECT_VP:
+		return identity->vp.stats_area_type;
+	}
+
+	return -EINVAL;
+}
+
+/*
+ * Map a stats page, where the page location is provided by the hypervisor.
+ *
+ * NOTE: The concept of separate SELF and PARENT stats areas does not exist on
+ * older hypervisor versions. All the available stats information can be found
+ * on the SELF page. When attempting to map the PARENT area on a hypervisor
+ * that doesn't support it, return "success" but with a NULL address. The
+ * caller should check for this case and instead fallback to the SELF area
+ * alone.
+ */
 static int hv_call_map_stats_page(enum hv_stats_object_type type,
 				  const union hv_stats_object_identity *identity,
 				  void **addr)
@@ -863,7 +898,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
 	struct hv_input_map_stats_page *input;
 	struct hv_output_map_stats_page *output;
 	u64 status, pfn;
-	int ret = 0;
+	int hv_status, ret = 0;
 
 	do {
 		local_irq_save(flags);
@@ -878,11 +913,20 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
 		pfn = output->map_location;
 
 		local_irq_restore(flags);
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
-			ret = hv_result_to_errno(status);
+
+		hv_status = hv_result(status);
+		if (hv_status != HV_STATUS_INSUFFICIENT_MEMORY) {
 			if (hv_result_success(status))
 				break;
-			return ret;
+
+			if (hv_stats_get_area_type(type, identity) == HV_STATS_AREA_PARENT &&
+			    hv_status == HV_STATUS_INVALID_PARAMETER) {
+				*addr = NULL;
+				return 0;
+			}
+
+			hv_status_debug(status, "\n");
+			return hv_result_to_errno(status);
 		}
 
 		ret = hv_call_deposit_pages(NUMA_NO_NODE,
drivers/hv/mshv_root_main.c +3 -0
index 1134a82c7881..1777778f84b8 100644
@@ -992,6 +992,9 @@ static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
 	if (err)
 		goto unmap_self;
 
+	if (!stats_pages[HV_STATS_AREA_PARENT])
+		stats_pages[HV_STATS_AREA_PARENT] = stats_pages[HV_STATS_AREA_SELF];
+
 	return 0;
 
 unmap_self:
Signature · 1 line
2.34.1
#2 lore raw

PATCH v3 2/6 mshv: Use typed hv_stats_page pointers

In reply to Nuno Das Neves

From: Stanislav Kinsburskii <[email protected]>

Refactor all relevant functions to use struct hv_stats_page pointers instead of void pointers for stats page mapping and unmapping thus improving type safety and code clarity across the Hyper-V stats mapping APIs.

---
 drivers/hv/mshv_root.h         |  5 +++--
 drivers/hv/mshv_root_hv_call.c | 12 +++++++-----
 drivers/hv/mshv_root_main.c    |  8 ++++----
 3 files changed, 14 insertions(+), 11 deletions(-)
drivers/hv/mshv_root.h +3 -2
index 3c1d88b36741..05ba1f716f9e 100644
@@ -307,8 +307,9 @@ int hv_call_disconnect_port(u64 connection_partition_id,
 int hv_call_notify_port_ring_empty(u32 sint_index);
 int hv_map_stats_page(enum hv_stats_object_type type,
 		      const union hv_stats_object_identity *identity,
-		      void **addr);
-int hv_unmap_stats_page(enum hv_stats_object_type type, void *page_addr,
+		      struct hv_stats_page **addr);
+int hv_unmap_stats_page(enum hv_stats_object_type type,
+			struct hv_stats_page *page_addr,
 			const union hv_stats_object_identity *identity);
 int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages,
 				   u64 page_struct_count, u32 host_access,
drivers/hv/mshv_root_hv_call.c +7 -5
index 1f93b94d7580..daee036e48bc 100644
@@ -890,9 +890,10 @@ hv_stats_get_area_type(enum hv_stats_object_type type,
  * caller should check for this case and instead fallback to the SELF area
  * alone.
  */
-static int hv_call_map_stats_page(enum hv_stats_object_type type,
-				  const union hv_stats_object_identity *identity,
-				  void **addr)
+static int
+hv_call_map_stats_page(enum hv_stats_object_type type,
+		       const union hv_stats_object_identity *identity,
+		       struct hv_stats_page **addr)
 {
 	unsigned long flags;
 	struct hv_input_map_stats_page *input;
@@ -942,7 +943,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
 
 int hv_map_stats_page(enum hv_stats_object_type type,
 		      const union hv_stats_object_identity *identity,
-		      void **addr)
+		      struct hv_stats_page **addr)
 {
 	int ret;
 	struct page *allocated_page = NULL;
@@ -990,7 +991,8 @@ static int hv_call_unmap_stats_page(enum hv_stats_object_type type,
 	return hv_result_to_errno(status);
 }
 
-int hv_unmap_stats_page(enum hv_stats_object_type type, void *page_addr,
+int hv_unmap_stats_page(enum hv_stats_object_type type,
+			struct hv_stats_page *page_addr,
 			const union hv_stats_object_identity *identity)
 {
 	int ret;
drivers/hv/mshv_root_main.c +4 -4
index 1777778f84b8..be5ad0fbfbee 100644
@@ -957,7 +957,7 @@ mshv_vp_release(struct inode *inode, struct file *filp)
 }
 
 static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index,
-				void *stats_pages[])
+				struct hv_stats_page *stats_pages[])
 {
 	union hv_stats_object_identity identity = {
 		.vp.partition_id = partition_id,
@@ -972,7 +972,7 @@ static void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index,
 }
 
 static int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
-			     void *stats_pages[])
+			     struct hv_stats_page *stats_pages[])
 {
 	union hv_stats_object_identity identity = {
 		.vp.partition_id = partition_id,
@@ -1010,7 +1010,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 	struct mshv_create_vp args;
 	struct mshv_vp *vp;
 	struct page *intercept_msg_page, *register_page, *ghcb_page;
-	void *stats_pages[2];
+	struct hv_stats_page *stats_pages[2];
 	long ret;
 
 	if (copy_from_user(&args, arg, sizeof(args)))
@@ -1729,7 +1729,7 @@ static void destroy_partition(struct mshv_partition *partition)
 
 			if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
 				mshv_vp_stats_unmap(partition->pt_id, vp->vp_index,
-						    (void **)vp->vp_stats_pages);
+						    vp->vp_stats_pages);
 
 			if (vp->vp_register_page) {
 				(void)hv_unmap_vp_state_page(partition->pt_id,
Signature · 1 line
2.34.1
#3 lore raw

PATCH v3 3/6 mshv: Improve mshv_vp_stats_map/unmap(), add them to mshv_root.h

In reply to Nuno Das Neves

From: Stanislav Kinsburskii <[email protected]>

These functions are currently only used to map child partition VP stats, on root partition. However, they will soon be used on L1VH, and and also used for mapping the host's own VP stats.

Introduce a helper is_l1vh_parent() to determine whether we are mapping our own VP stats. In this case, do not attempt to map the PARENT area. Note this is a different case than mapping PARENT on an older hypervisor where it is not available at all, so must be handled separately.

On unmap, pass the stats pages since on L1VH the kernel allocates them and they must be freed in hv_unmap_stats_page().

---
 drivers/hv/mshv_root.h      | 10 ++++++
 drivers/hv/mshv_root_main.c | 61 ++++++++++++++++++++++++++-----------
 2 files changed, 54 insertions(+), 17 deletions(-)
drivers/hv/mshv_root.h +10 -0
index 05ba1f716f9e..e4912b0618fa 100644
@@ -254,6 +254,16 @@ struct mshv_partition *mshv_partition_get(struct mshv_partition *partition);
 void mshv_partition_put(struct mshv_partition *partition);
 struct mshv_partition *mshv_partition_find(u64 partition_id) __must_hold(RCU);
 
+static inline bool is_l1vh_parent(u64 partition_id)
+{
+	return hv_l1vh_partition() && (partition_id == HV_PARTITION_ID_SELF);
+}
+
+int mshv_vp_stats_map(u64 partition_id, u32 vp_index,
+		      struct hv_stats_page **stats_pages);
+void mshv_vp_stats_unmap(u64 partition_id, u32 vp_index,
+			 struct hv_stats_page **stats_pages);
+
 /* hypercalls */
 
 int hv_call_withdraw_memory(u64 count, int node, u64 partition_id);
drivers/hv/mshv_root_main.c +44 -17

90 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

PATCH v3 4/6 mshv: Always map child vp stats pages regardless of scheduler type

In reply to Nuno Das Neves

From: Stanislav Kinsburskii <[email protected]>

Currently vp->vp_stats_pages is only used by the root scheduler for fast interrupt injection.

Soon, vp_stats_pages will also be needed for exposing child VP stats to userspace via debugfs. Mapping the pages a second time to a different address causes an error on L1VH.

Remove the scheduler requirement and always map the vp stats pages.

---
 drivers/hv/mshv_root_main.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)
drivers/hv/mshv_root_main.c +8 -17
index faca3cc63e79..fbfc9e7d9fa4 100644
@@ -1077,16 +1077,10 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 			goto unmap_register_page;
 	}
 
-	/*
-	 * This mapping of the stats page is for detecting if dispatch thread
-	 * is blocked - only relevant for root scheduler
-	 */
-	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT) {
-		ret = mshv_vp_stats_map(partition->pt_id, args.vp_index,
-					stats_pages);
-		if (ret)
-			goto unmap_ghcb_page;
-	}
+	ret = mshv_vp_stats_map(partition->pt_id, args.vp_index,
+				stats_pages);
+	if (ret)
+		goto unmap_ghcb_page;
 
 	vp = kzalloc(sizeof(*vp), GFP_KERNEL);
 	if (!vp)
@@ -1110,8 +1104,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available())
 		vp->vp_ghcb_page = page_to_virt(ghcb_page);
 
-	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
-		memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages));
+	memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages));
 
 	/*
 	 * Keep anon_inode_getfd last: it installs fd in the file struct and
@@ -1133,8 +1126,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 free_vp:
 	kfree(vp);
 unmap_stats_pages:
-	if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
-		mshv_vp_stats_unmap(partition->pt_id, args.vp_index, stats_pages);
+	mshv_vp_stats_unmap(partition->pt_id, args.vp_index, stats_pages);
 unmap_ghcb_page:
 	if (mshv_partition_encrypted(partition) && is_ghcb_mapping_available())
 		hv_unmap_vp_state_page(partition->pt_id, args.vp_index,
@@ -1754,9 +1746,8 @@ static void destroy_partition(struct mshv_partition *partition)
 			if (!vp)
 				continue;
 
-			if (hv_scheduler_type == HV_SCHEDULER_TYPE_ROOT)
-				mshv_vp_stats_unmap(partition->pt_id, vp->vp_index,
-						    vp->vp_stats_pages);
+			mshv_vp_stats_unmap(partition->pt_id, vp->vp_index,
+					    vp->vp_stats_pages);
 
 			if (vp->vp_register_page) {
 				(void)hv_unmap_vp_state_page(partition->pt_id,
Signature · 1 line
2.34.1
#5 lore raw

PATCH v3 5/6 mshv: Add definitions for stats pages

In reply to Nuno Das Neves

Add the definitions for hypervisor, logical processor, and partition stats pages.

Move the definition for the VP stats page to its rightful place in hvhdk.h, and add the missing members.

While at it, correct the ARM64 value of VpRootDispatchThreadBlocked, (which is not yet used, so there is no impact).

These enum members retain their CamelCase style, since they are imported directly from the hypervisor code. They will be stringified when printing the stats out, and retain more readability in this form.

---
 drivers/hv/mshv_root_main.c |  17 --
 include/hyperv/hvhdk.h      | 437 ++++++++++++++++++++++++++++++++++++
 2 files changed, 437 insertions(+), 17 deletions(-)
drivers/hv/mshv_root_main.c +0 -17
index fbfc9e7d9fa4..724bbaa0b08c 100644
@@ -39,23 +39,6 @@ MODULE_AUTHOR("Microsoft");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Microsoft Hyper-V root partition VMM interface /dev/mshv");
 
-/* TODO move this to another file when debugfs code is added */
-enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
-#if defined(CONFIG_X86)
-	VpRootDispatchThreadBlocked			= 202,
-#elif defined(CONFIG_ARM64)
-	VpRootDispatchThreadBlocked			= 94,
-#endif
-	VpStatsMaxCounter
-};
-
-struct hv_stats_page {
-	union {
-		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
-		u8 data[HV_HYP_PAGE_SIZE];
-	};
-} __packed;
-
 struct mshv_root mshv_root;
 
 enum hv_scheduler_type hv_scheduler_type;
include/hyperv/hvhdk.h +437 -0

443 lines not on this page · raw message

Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH v3 5/6] mshv: Add definitions for stats pages

Quoted 3 lines · Nuno Das Neves

Add the definitions for hypervisor, logical processor, and partition stats pages.

The definitions in for partition and virtual processor are outdated. Now is the good time to sync the new values in.

Thanks,
Stanislav

Quoted 494 lines

Move the definition for the VP stats page to its rightful place in hvhdk.h, and add the missing members.

While at it, correct the ARM64 value of VpRootDispatchThreadBlocked, (which is not yet used, so there is no impact).

These enum members retain their CamelCase style, since they are imported directly from the hypervisor code. They will be stringified when printing the stats out, and retain more readability in this form.

---
 drivers/hv/mshv_root_main.c |  17 --
 include/hyperv/hvhdk.h      | 437 ++++++++++++++++++++++++++++++++++++
 2 files changed, 437 insertions(+), 17 deletions(-)
drivers/hv/mshv_root_main.c +0 -17
index fbfc9e7d9fa4..724bbaa0b08c 100644
@@ -39,23 +39,6 @@ MODULE_AUTHOR("Microsoft");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Microsoft Hyper-V root partition VMM interface /dev/mshv");
 
-/* TODO move this to another file when debugfs code is added */
-enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
-#if defined(CONFIG_X86)
-	VpRootDispatchThreadBlocked			= 202,
-#elif defined(CONFIG_ARM64)
-	VpRootDispatchThreadBlocked			= 94,
-#endif
-	VpStatsMaxCounter
-};
-
-struct hv_stats_page {
-	union {
-		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
-		u8 data[HV_HYP_PAGE_SIZE];
-	};
-} __packed;
-
 struct mshv_root mshv_root;
 
 enum hv_scheduler_type hv_scheduler_type;
include/hyperv/hvhdk.h +437 -0
index 469186df7826..8bddd11feeba 100644
@@ -10,6 +10,443 @@
 #include "hvhdk_mini.h"
 #include "hvgdk.h"
 
+enum hv_stats_hypervisor_counters {		/* HV_HYPERVISOR_COUNTER */
+	HvLogicalProcessors			= 1,
+	HvPartitions				= 2,
+	HvTotalPages				= 3,
+	HvVirtualProcessors			= 4,
+	HvMonitoredNotifications		= 5,
+	HvModernStandbyEntries			= 6,
+	HvPlatformIdleTransitions		= 7,
+	HvHypervisorStartupCost			= 8,
+	HvIOSpacePages				= 10,
+	HvNonEssentialPagesForDump		= 11,
+	HvSubsumedPages				= 12,
+	HvStatsMaxCounter
+};
+
+enum hv_stats_partition_counters {		/* HV_PROCESS_COUNTER */
+	PartitionVirtualProcessors		= 1,
+	PartitionTlbSize			= 3,
+	PartitionAddressSpaces			= 4,
+	PartitionDepositedPages			= 5,
+	PartitionGpaPages			= 6,
+	PartitionGpaSpaceModifications		= 7,
+	PartitionVirtualTlbFlushEntires		= 8,
+	PartitionRecommendedTlbSize		= 9,
+	PartitionGpaPages4K			= 10,
+	PartitionGpaPages2M			= 11,
+	PartitionGpaPages1G			= 12,
+	PartitionGpaPages512G			= 13,
+	PartitionDevicePages4K			= 14,
+	PartitionDevicePages2M			= 15,
+	PartitionDevicePages1G			= 16,
+	PartitionDevicePages512G		= 17,
+	PartitionAttachedDevices		= 18,
+	PartitionDeviceInterruptMappings	= 19,
+	PartitionIoTlbFlushes			= 20,
+	PartitionIoTlbFlushCost			= 21,
+	PartitionDeviceInterruptErrors		= 22,
+	PartitionDeviceDmaErrors		= 23,
+	PartitionDeviceInterruptThrottleEvents	= 24,
+	PartitionSkippedTimerTicks		= 25,
+	PartitionPartitionId			= 26,
+#if IS_ENABLED(CONFIG_X86_64)
+	PartitionNestedTlbSize			= 27,
+	PartitionRecommendedNestedTlbSize	= 28,
+	PartitionNestedTlbFreeListSize		= 29,
+	PartitionNestedTlbTrimmedPages		= 30,
+	PartitionPagesShattered			= 31,
+	PartitionPagesRecombined		= 32,
+	PartitionHwpRequestValue		= 33,
+#elif IS_ENABLED(CONFIG_ARM64)
+	PartitionHwpRequestValue		= 27,
+#endif
+	PartitionStatsMaxCounter
+};
+
+enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
+	VpTotalRunTime					= 1,
+	VpHypervisorRunTime				= 2,
+	VpRemoteNodeRunTime				= 3,
+	VpNormalizedRunTime				= 4,
+	VpIdealCpu					= 5,
+	VpHypercallsCount				= 7,
+	VpHypercallsTime				= 8,
+#if IS_ENABLED(CONFIG_X86_64)
+	VpPageInvalidationsCount			= 9,
+	VpPageInvalidationsTime				= 10,
+	VpControlRegisterAccessesCount			= 11,
+	VpControlRegisterAccessesTime			= 12,
+	VpIoInstructionsCount				= 13,
+	VpIoInstructionsTime				= 14,
+	VpHltInstructionsCount				= 15,
+	VpHltInstructionsTime				= 16,
+	VpMwaitInstructionsCount			= 17,
+	VpMwaitInstructionsTime				= 18,
+	VpCpuidInstructionsCount			= 19,
+	VpCpuidInstructionsTime				= 20,
+	VpMsrAccessesCount				= 21,
+	VpMsrAccessesTime				= 22,
+	VpOtherInterceptsCount				= 23,
+	VpOtherInterceptsTime				= 24,
+	VpExternalInterruptsCount			= 25,
+	VpExternalInterruptsTime			= 26,
+	VpPendingInterruptsCount			= 27,
+	VpPendingInterruptsTime				= 28,
+	VpEmulatedInstructionsCount			= 29,
+	VpEmulatedInstructionsTime			= 30,
+	VpDebugRegisterAccessesCount			= 31,
+	VpDebugRegisterAccessesTime			= 32,
+	VpPageFaultInterceptsCount			= 33,
+	VpPageFaultInterceptsTime			= 34,
+	VpGuestPageTableMaps				= 35,
+	VpLargePageTlbFills				= 36,
+	VpSmallPageTlbFills				= 37,
+	VpReflectedGuestPageFaults			= 38,
+	VpApicMmioAccesses				= 39,
+	VpIoInterceptMessages				= 40,
+	VpMemoryInterceptMessages			= 41,
+	VpApicEoiAccesses				= 42,
+	VpOtherMessages					= 43,
+	VpPageTableAllocations				= 44,
+	VpLogicalProcessorMigrations			= 45,
+	VpAddressSpaceEvictions				= 46,
+	VpAddressSpaceSwitches				= 47,
+	VpAddressDomainFlushes				= 48,
+	VpAddressSpaceFlushes				= 49,
+	VpGlobalGvaRangeFlushes				= 50,
+	VpLocalGvaRangeFlushes				= 51,
+	VpPageTableEvictions				= 52,
+	VpPageTableReclamations				= 53,
+	VpPageTableResets				= 54,
+	VpPageTableValidations				= 55,
+	VpApicTprAccesses				= 56,
+	VpPageTableWriteIntercepts			= 57,
+	VpSyntheticInterrupts				= 58,
+	VpVirtualInterrupts				= 59,
+	VpApicIpisSent					= 60,
+	VpApicSelfIpisSent				= 61,
+	VpGpaSpaceHypercalls				= 62,
+	VpLogicalProcessorHypercalls			= 63,
+	VpLongSpinWaitHypercalls			= 64,
+	VpOtherHypercalls				= 65,
+	VpSyntheticInterruptHypercalls			= 66,
+	VpVirtualInterruptHypercalls			= 67,
+	VpVirtualMmuHypercalls				= 68,
+	VpVirtualProcessorHypercalls			= 69,
+	VpHardwareInterrupts				= 70,
+	VpNestedPageFaultInterceptsCount		= 71,
+	VpNestedPageFaultInterceptsTime			= 72,
+	VpPageScans					= 73,
+	VpLogicalProcessorDispatches			= 74,
+	VpWaitingForCpuTime				= 75,
+	VpExtendedHypercalls				= 76,
+	VpExtendedHypercallInterceptMessages		= 77,
+	VpMbecNestedPageTableSwitches			= 78,
+	VpOtherReflectedGuestExceptions			= 79,
+	VpGlobalIoTlbFlushes				= 80,
+	VpGlobalIoTlbFlushCost				= 81,
+	VpLocalIoTlbFlushes				= 82,
+	VpLocalIoTlbFlushCost				= 83,
+	VpHypercallsForwardedCount			= 84,
+	VpHypercallsForwardingTime			= 85,
+	VpPageInvalidationsForwardedCount		= 86,
+	VpPageInvalidationsForwardingTime		= 87,
+	VpControlRegisterAccessesForwardedCount		= 88,
+	VpControlRegisterAccessesForwardingTime		= 89,
+	VpIoInstructionsForwardedCount			= 90,
+	VpIoInstructionsForwardingTime			= 91,
+	VpHltInstructionsForwardedCount			= 92,
+	VpHltInstructionsForwardingTime			= 93,
+	VpMwaitInstructionsForwardedCount		= 94,
+	VpMwaitInstructionsForwardingTime		= 95,
+	VpCpuidInstructionsForwardedCount		= 96,
+	VpCpuidInstructionsForwardingTime		= 97,
+	VpMsrAccessesForwardedCount			= 98,
+	VpMsrAccessesForwardingTime			= 99,
+	VpOtherInterceptsForwardedCount			= 100,
+	VpOtherInterceptsForwardingTime			= 101,
+	VpExternalInterruptsForwardedCount		= 102,
+	VpExternalInterruptsForwardingTime		= 103,
+	VpPendingInterruptsForwardedCount		= 104,
+	VpPendingInterruptsForwardingTime		= 105,
+	VpEmulatedInstructionsForwardedCount		= 106,
+	VpEmulatedInstructionsForwardingTime		= 107,
+	VpDebugRegisterAccessesForwardedCount		= 108,
+	VpDebugRegisterAccessesForwardingTime		= 109,
+	VpPageFaultInterceptsForwardedCount		= 110,
+	VpPageFaultInterceptsForwardingTime		= 111,
+	VpVmclearEmulationCount				= 112,
+	VpVmclearEmulationTime				= 113,
+	VpVmptrldEmulationCount				= 114,
+	VpVmptrldEmulationTime				= 115,
+	VpVmptrstEmulationCount				= 116,
+	VpVmptrstEmulationTime				= 117,
+	VpVmreadEmulationCount				= 118,
+	VpVmreadEmulationTime				= 119,
+	VpVmwriteEmulationCount				= 120,
+	VpVmwriteEmulationTime				= 121,
+	VpVmxoffEmulationCount				= 122,
+	VpVmxoffEmulationTime				= 123,
+	VpVmxonEmulationCount				= 124,
+	VpVmxonEmulationTime				= 125,
+	VpNestedVMEntriesCount				= 126,
+	VpNestedVMEntriesTime				= 127,
+	VpNestedSLATSoftPageFaultsCount			= 128,
+	VpNestedSLATSoftPageFaultsTime			= 129,
+	VpNestedSLATHardPageFaultsCount			= 130,
+	VpNestedSLATHardPageFaultsTime			= 131,
+	VpInvEptAllContextEmulationCount		= 132,
+	VpInvEptAllContextEmulationTime			= 133,
+	VpInvEptSingleContextEmulationCount		= 134,
+	VpInvEptSingleContextEmulationTime		= 135,
+	VpInvVpidAllContextEmulationCount		= 136,
+	VpInvVpidAllContextEmulationTime		= 137,
+	VpInvVpidSingleContextEmulationCount		= 138,
+	VpInvVpidSingleContextEmulationTime		= 139,
+	VpInvVpidSingleAddressEmulationCount		= 140,
+	VpInvVpidSingleAddressEmulationTime		= 141,
+	VpNestedTlbPageTableReclamations		= 142,
+	VpNestedTlbPageTableEvictions			= 143,
+	VpFlushGuestPhysicalAddressSpaceHypercalls	= 144,
+	VpFlushGuestPhysicalAddressListHypercalls	= 145,
+	VpPostedInterruptNotifications			= 146,
+	VpPostedInterruptScans				= 147,
+	VpTotalCoreRunTime				= 148,
+	VpMaximumRunTime				= 149,
+	VpHwpRequestContextSwitches			= 150,
+	VpWaitingForCpuTimeBucket0			= 151,
+	VpWaitingForCpuTimeBucket1			= 152,
+	VpWaitingForCpuTimeBucket2			= 153,
+	VpWaitingForCpuTimeBucket3			= 154,
+	VpWaitingForCpuTimeBucket4			= 155,
+	VpWaitingForCpuTimeBucket5			= 156,
+	VpWaitingForCpuTimeBucket6			= 157,
+	VpVmloadEmulationCount				= 158,
+	VpVmloadEmulationTime				= 159,
+	VpVmsaveEmulationCount				= 160,
+	VpVmsaveEmulationTime				= 161,
+	VpGifInstructionEmulationCount			= 162,
+	VpGifInstructionEmulationTime			= 163,
+	VpEmulatedErrataSvmInstructions			= 164,
+	VpPlaceholder1					= 165,
+	VpPlaceholder2					= 166,
+	VpPlaceholder3					= 167,
+	VpPlaceholder4					= 168,
+	VpPlaceholder5					= 169,
+	VpPlaceholder6					= 170,
+	VpPlaceholder7					= 171,
+	VpPlaceholder8					= 172,
+	VpPlaceholder9					= 173,
+	VpPlaceholder10					= 174,
+	VpSchedulingPriority				= 175,
+	VpRdpmcInstructionsCount			= 176,
+	VpRdpmcInstructionsTime				= 177,
+	VpPerfmonPmuMsrAccessesCount			= 178,
+	VpPerfmonLbrMsrAccessesCount			= 179,
+	VpPerfmonIptMsrAccessesCount			= 180,
+	VpPerfmonInterruptCount				= 181,
+	VpVtl1DispatchCount				= 182,
+	VpVtl2DispatchCount				= 183,
+	VpVtl2DispatchBucket0				= 184,
+	VpVtl2DispatchBucket1				= 185,
+	VpVtl2DispatchBucket2				= 186,
+	VpVtl2DispatchBucket3				= 187,
+	VpVtl2DispatchBucket4				= 188,
+	VpVtl2DispatchBucket5				= 189,
+	VpVtl2DispatchBucket6				= 190,
+	VpVtl1RunTime					= 191,
+	VpVtl2RunTime					= 192,
+	VpIommuHypercalls				= 193,
+	VpCpuGroupHypercalls				= 194,
+	VpVsmHypercalls					= 195,
+	VpEventLogHypercalls				= 196,
+	VpDeviceDomainHypercalls			= 197,
+	VpDepositHypercalls				= 198,
+	VpSvmHypercalls					= 199,
+	VpBusLockAcquisitionCount			= 200,
+	VpLoadAvg					= 201,
+	VpRootDispatchThreadBlocked			= 202,
+#elif IS_ENABLED(CONFIG_ARM64)
+	VpSysRegAccessesCount				= 9,
+	VpSysRegAccessesTime				= 10,
+	VpSmcInstructionsCount				= 11,
+	VpSmcInstructionsTime				= 12,
+	VpOtherInterceptsCount				= 13,
+	VpOtherInterceptsTime				= 14,
+	VpExternalInterruptsCount			= 15,
+	VpExternalInterruptsTime			= 16,
+	VpPendingInterruptsCount			= 17,
+	VpPendingInterruptsTime				= 18,
+	VpGuestPageTableMaps				= 19,
+	VpLargePageTlbFills				= 20,
+	VpSmallPageTlbFills				= 21,
+	VpReflectedGuestPageFaults			= 22,
+	VpMemoryInterceptMessages			= 23,
+	VpOtherMessages					= 24,
+	VpLogicalProcessorMigrations			= 25,
+	VpAddressDomainFlushes				= 26,
+	VpAddressSpaceFlushes				= 27,
+	VpSyntheticInterrupts				= 28,
+	VpVirtualInterrupts				= 29,
+	VpApicSelfIpisSent				= 30,
+	VpGpaSpaceHypercalls				= 31,
+	VpLogicalProcessorHypercalls			= 32,
+	VpLongSpinWaitHypercalls			= 33,
+	VpOtherHypercalls				= 34,
+	VpSyntheticInterruptHypercalls			= 35,
+	VpVirtualInterruptHypercalls			= 36,
+	VpVirtualMmuHypercalls				= 37,
+	VpVirtualProcessorHypercalls			= 38,
+	VpHardwareInterrupts				= 39,
+	VpNestedPageFaultInterceptsCount		= 40,
+	VpNestedPageFaultInterceptsTime			= 41,
+	VpLogicalProcessorDispatches			= 42,
+	VpWaitingForCpuTime				= 43,
+	VpExtendedHypercalls				= 44,
+	VpExtendedHypercallInterceptMessages		= 45,
+	VpMbecNestedPageTableSwitches			= 46,
+	VpOtherReflectedGuestExceptions			= 47,
+	VpGlobalIoTlbFlushes				= 48,
+	VpGlobalIoTlbFlushCost				= 49,
+	VpLocalIoTlbFlushes				= 50,
+	VpLocalIoTlbFlushCost				= 51,
+	VpFlushGuestPhysicalAddressSpaceHypercalls	= 52,
+	VpFlushGuestPhysicalAddressListHypercalls	= 53,
+	VpPostedInterruptNotifications			= 54,
+	VpPostedInterruptScans				= 55,
+	VpTotalCoreRunTime				= 56,
+	VpMaximumRunTime				= 57,
+	VpWaitingForCpuTimeBucket0			= 58,
+	VpWaitingForCpuTimeBucket1			= 59,
+	VpWaitingForCpuTimeBucket2			= 60,
+	VpWaitingForCpuTimeBucket3			= 61,
+	VpWaitingForCpuTimeBucket4			= 62,
+	VpWaitingForCpuTimeBucket5			= 63,
+	VpWaitingForCpuTimeBucket6			= 64,
+	VpHwpRequestContextSwitches			= 65,
+	VpPlaceholder2					= 66,
+	VpPlaceholder3					= 67,
+	VpPlaceholder4					= 68,
+	VpPlaceholder5					= 69,
+	VpPlaceholder6					= 70,
+	VpPlaceholder7					= 71,
+	VpPlaceholder8					= 72,
+	VpContentionTime				= 73,
+	VpWakeUpTime					= 74,
+	VpSchedulingPriority				= 75,
+	VpVtl1DispatchCount				= 76,
+	VpVtl2DispatchCount				= 77,
+	VpVtl2DispatchBucket0				= 78,
+	VpVtl2DispatchBucket1				= 79,
+	VpVtl2DispatchBucket2				= 80,
+	VpVtl2DispatchBucket3				= 81,
+	VpVtl2DispatchBucket4				= 82,
+	VpVtl2DispatchBucket5				= 83,
+	VpVtl2DispatchBucket6				= 84,
+	VpVtl1RunTime					= 85,
+	VpVtl2RunTime					= 86,
+	VpIommuHypercalls				= 87,
+	VpCpuGroupHypercalls				= 88,
+	VpVsmHypercalls					= 89,
+	VpEventLogHypercalls				= 90,
+	VpDeviceDomainHypercalls			= 91,
+	VpDepositHypercalls				= 92,
+	VpSvmHypercalls					= 93,
+	VpLoadAvg					= 94,
+	VpRootDispatchThreadBlocked			= 95,
+#endif
+	VpStatsMaxCounter
+};
+
+enum hv_stats_lp_counters {			/* HV_CPU_COUNTER */
+	LpGlobalTime				= 1,
+	LpTotalRunTime				= 2,
+	LpHypervisorRunTime			= 3,
+	LpHardwareInterrupts			= 4,
+	LpContextSwitches			= 5,
+	LpInterProcessorInterrupts		= 6,
+	LpSchedulerInterrupts			= 7,
+	LpTimerInterrupts			= 8,
+	LpInterProcessorInterruptsSent		= 9,
+	LpProcessorHalts			= 10,
+	LpMonitorTransitionCost			= 11,
+	LpContextSwitchTime			= 12,
+	LpC1TransitionsCount			= 13,
+	LpC1RunTime				= 14,
+	LpC2TransitionsCount			= 15,
+	LpC2RunTime				= 16,
+	LpC3TransitionsCount			= 17,
+	LpC3RunTime				= 18,
+	LpRootVpIndex				= 19,
+	LpIdleSequenceNumber			= 20,
+	LpGlobalTscCount			= 21,
+	LpActiveTscCount			= 22,
+	LpIdleAccumulation			= 23,
+	LpReferenceCycleCount0			= 24,
+	LpActualCycleCount0			= 25,
+	LpReferenceCycleCount1			= 26,
+	LpActualCycleCount1			= 27,
+	LpProximityDomainId			= 28,
+	LpPostedInterruptNotifications		= 29,
+	LpBranchPredictorFlushes		= 30,
+#if IS_ENABLED(CONFIG_X86_64)
+	LpL1DataCacheFlushes			= 31,
+	LpImmediateL1DataCacheFlushes		= 32,
+	LpMbFlushes				= 33,
+	LpCounterRefreshSequenceNumber		= 34,
+	LpCounterRefreshReferenceTime		= 35,
+	LpIdleAccumulationSnapshot		= 36,
+	LpActiveTscCountSnapshot		= 37,
+	LpHwpRequestContextSwitches		= 38,
+	LpPlaceholder1				= 39,
+	LpPlaceholder2				= 40,
+	LpPlaceholder3				= 41,
+	LpPlaceholder4				= 42,
+	LpPlaceholder5				= 43,
+	LpPlaceholder6				= 44,
+	LpPlaceholder7				= 45,
+	LpPlaceholder8				= 46,
+	LpPlaceholder9				= 47,
+	LpPlaceholder10				= 48,
+	LpReserveGroupId			= 49,
+	LpRunningPriority			= 50,
+	LpPerfmonInterruptCount			= 51,
+#elif IS_ENABLED(CONFIG_ARM64)
+	LpCounterRefreshSequenceNumber		= 31,
+	LpCounterRefreshReferenceTime		= 32,
+	LpIdleAccumulationSnapshot		= 33,
+	LpActiveTscCountSnapshot		= 34,
+	LpHwpRequestContextSwitches		= 35,
+	LpPlaceholder2				= 36,
+	LpPlaceholder3				= 37,
+	LpPlaceholder4				= 38,
+	LpPlaceholder5				= 39,
+	LpPlaceholder6				= 40,
+	LpPlaceholder7				= 41,
+	LpPlaceholder8				= 42,
+	LpPlaceholder9				= 43,
+	LpSchLocalRunListSize			= 44,
+	LpReserveGroupId			= 45,
+	LpRunningPriority			= 46,
+#endif
+	LpStatsMaxCounter
+};
+
+/*
+ * Hypervisor statistics page format
+ */
+struct hv_stats_page {
+	union {
+		u64 hv_cntrs[HvStatsMaxCounter];		/* Hypervisor counters */
+		u64 pt_cntrs[PartitionStatsMaxCounter];		/* Partition counters */
+		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
+		u64 lp_cntrs[LpStatsMaxCounter];		/* LP counters */
+		u8 data[HV_HYP_PAGE_SIZE];
+	};
+} __packed;
+
 /* Bits for dirty mask of hv_vp_register_page */
 #define HV_X64_REGISTER_CLASS_GENERAL	0
 #define HV_X64_REGISTER_CLASS_IP	1
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v3 5/6] mshv: Add definitions for stats pages

Quoted 11 lines · Stanislav Kinsburskii
Quoted 3 lines · Nuno Das Neves

Add the definitions for hypervisor, logical processor, and partition stats pages.

The definitions in for partition and virtual processor are outdated. Now is the good time to sync the new values in.

Thanks,
Stanislav

Good point, thanks, I will update it for v4.

I'm finally noticing that these counters are not really from hvhdk.h, in the windows code, but their own file. Since I'm still iterating on this, what do you think about creating a file just for the counters? e.g. drivers/hv/hvcounters.h, which combines hvcountersarm64 and amd64.

That would have a couple of advantages:
1. Not putting things in hvhdk.h which aren't actually there in the Windows source
2. Less visibility of CamelCase naming outside our driver
3. I could define the enums using "X macro"s to generate the show() code more cleanly in mshv_debugfs.c, which is something Michael suggested here:
https://lore.kernel.org/linux-hyperv/SN6PR02MB4157938404BC0D12978ACD9BD4A2A@SN6PR02MB4157.namprd02.prod.outlook.com/

It would look something like this:

In hvcounters.h:

#if is_enabled(CONFIG_X86_64)

#define HV_COUNTER_VP_LIST(X) \
	X(VpTotalRunTime, 1), \
	X(VpHypervisorRunTime, 2), \
	X(VpRemoteNodeRunTime, 3), \

/* <snip> */

#elif is_enabled(CONFIG_ARM64)

/* <snip> */

#endif

Just like now, it's a copy/paste from Windows + simple pattern replacement. Note with this approach we need separate lists for arm64 and x86, but that matches how the enums are defined in Windows.

Then, in mshv_debugfs.c:

/*
* We need the strings paired with their enum values.
* This structure can be used for all the different stat types. */

struct hv_counter_entry {
	char *name;
	int idx;
};

/* Define an array entry (again, reusable) */

#define HV_COUNTER_LIST(name, idx) \
	{ __stringify(name), idx },

/* Create our static array */
static struct hv_counter_entry hv_counter_vp_array[] = {
HV_ST_COUNTER_VP(HV_COUNTER_VP)
};

static int vp_stats_show(struct seq_file *m, void *v)

{
	const struct hv_stats_page **pstats = m->private;
	int i;

	for (i = 0; i < ARRAY_SIZE(hv_counter_vp_array); ++i) {
		struct hv_counter_entry entry = hv_counter_vp_array[i];
		u64 parent_val = pstats[HV_STATS_AREA_PARENT]->vp_cntrs[entry.idx];
		u64 self_val = pstats[HV_STATS_AREA_SELF]->vp_cntrs[entry.idx];

		/* Prioritize the PARENT area value */
		seq_printf(m, "%-30s: %llu\n", entry.name,
			   parent_val ? parent_val : self_val);
	}
}

Any thoughts? I was originally going to just go with the pattern we had, but since these definitions aren't from the hv*dk.h files, we can maybe get more creative and make the resulting code look a bit better.

Thanks
Nuno

Quoted 494 lines
Quoted 494 lines

Move the definition for the VP stats page to its rightful place in hvhdk.h, and add the missing members.

While at it, correct the ARM64 value of VpRootDispatchThreadBlocked, (which is not yet used, so there is no impact).

These enum members retain their CamelCase style, since they are imported directly from the hypervisor code. They will be stringified when printing the stats out, and retain more readability in this form.

---
 drivers/hv/mshv_root_main.c |  17 --
 include/hyperv/hvhdk.h      | 437 ++++++++++++++++++++++++++++++++++++
 2 files changed, 437 insertions(+), 17 deletions(-)
drivers/hv/mshv_root_main.c +0 -17
index fbfc9e7d9fa4..724bbaa0b08c 100644
@@ -39,23 +39,6 @@ MODULE_AUTHOR("Microsoft");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Microsoft Hyper-V root partition VMM interface /dev/mshv");
 
-/* TODO move this to another file when debugfs code is added */
-enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
-#if defined(CONFIG_X86)
-	VpRootDispatchThreadBlocked			= 202,
-#elif defined(CONFIG_ARM64)
-	VpRootDispatchThreadBlocked			= 94,
-#endif
-	VpStatsMaxCounter
-};
-
-struct hv_stats_page {
-	union {
-		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
-		u8 data[HV_HYP_PAGE_SIZE];
-	};
-} __packed;
-
 struct mshv_root mshv_root;
 
 enum hv_scheduler_type hv_scheduler_type;
include/hyperv/hvhdk.h +437 -0
index 469186df7826..8bddd11feeba 100644
@@ -10,6 +10,443 @@
 #include "hvhdk_mini.h"
 #include "hvgdk.h"
 
+enum hv_stats_hypervisor_counters {		/* HV_HYPERVISOR_COUNTER */
+	HvLogicalProcessors			= 1,
+	HvPartitions				= 2,
+	HvTotalPages				= 3,
+	HvVirtualProcessors			= 4,
+	HvMonitoredNotifications		= 5,
+	HvModernStandbyEntries			= 6,
+	HvPlatformIdleTransitions		= 7,
+	HvHypervisorStartupCost			= 8,
+	HvIOSpacePages				= 10,
+	HvNonEssentialPagesForDump		= 11,
+	HvSubsumedPages				= 12,
+	HvStatsMaxCounter
+};
+
+enum hv_stats_partition_counters {		/* HV_PROCESS_COUNTER */
+	PartitionVirtualProcessors		= 1,
+	PartitionTlbSize			= 3,
+	PartitionAddressSpaces			= 4,
+	PartitionDepositedPages			= 5,
+	PartitionGpaPages			= 6,
+	PartitionGpaSpaceModifications		= 7,
+	PartitionVirtualTlbFlushEntires		= 8,
+	PartitionRecommendedTlbSize		= 9,
+	PartitionGpaPages4K			= 10,
+	PartitionGpaPages2M			= 11,
+	PartitionGpaPages1G			= 12,
+	PartitionGpaPages512G			= 13,
+	PartitionDevicePages4K			= 14,
+	PartitionDevicePages2M			= 15,
+	PartitionDevicePages1G			= 16,
+	PartitionDevicePages512G		= 17,
+	PartitionAttachedDevices		= 18,
+	PartitionDeviceInterruptMappings	= 19,
+	PartitionIoTlbFlushes			= 20,
+	PartitionIoTlbFlushCost			= 21,
+	PartitionDeviceInterruptErrors		= 22,
+	PartitionDeviceDmaErrors		= 23,
+	PartitionDeviceInterruptThrottleEvents	= 24,
+	PartitionSkippedTimerTicks		= 25,
+	PartitionPartitionId			= 26,
+#if IS_ENABLED(CONFIG_X86_64)
+	PartitionNestedTlbSize			= 27,
+	PartitionRecommendedNestedTlbSize	= 28,
+	PartitionNestedTlbFreeListSize		= 29,
+	PartitionNestedTlbTrimmedPages		= 30,
+	PartitionPagesShattered			= 31,
+	PartitionPagesRecombined		= 32,
+	PartitionHwpRequestValue		= 33,
+#elif IS_ENABLED(CONFIG_ARM64)
+	PartitionHwpRequestValue		= 27,
+#endif
+	PartitionStatsMaxCounter
+};
+
+enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
+	VpTotalRunTime					= 1,
+	VpHypervisorRunTime				= 2,
+	VpRemoteNodeRunTime				= 3,
+	VpNormalizedRunTime				= 4,
+	VpIdealCpu					= 5,
+	VpHypercallsCount				= 7,
+	VpHypercallsTime				= 8,
+#if IS_ENABLED(CONFIG_X86_64)
+	VpPageInvalidationsCount			= 9,
+	VpPageInvalidationsTime				= 10,
+	VpControlRegisterAccessesCount			= 11,
+	VpControlRegisterAccessesTime			= 12,
+	VpIoInstructionsCount				= 13,
+	VpIoInstructionsTime				= 14,
+	VpHltInstructionsCount				= 15,
+	VpHltInstructionsTime				= 16,
+	VpMwaitInstructionsCount			= 17,
+	VpMwaitInstructionsTime				= 18,
+	VpCpuidInstructionsCount			= 19,
+	VpCpuidInstructionsTime				= 20,
+	VpMsrAccessesCount				= 21,
+	VpMsrAccessesTime				= 22,
+	VpOtherInterceptsCount				= 23,
+	VpOtherInterceptsTime				= 24,
+	VpExternalInterruptsCount			= 25,
+	VpExternalInterruptsTime			= 26,
+	VpPendingInterruptsCount			= 27,
+	VpPendingInterruptsTime				= 28,
+	VpEmulatedInstructionsCount			= 29,
+	VpEmulatedInstructionsTime			= 30,
+	VpDebugRegisterAccessesCount			= 31,
+	VpDebugRegisterAccessesTime			= 32,
+	VpPageFaultInterceptsCount			= 33,
+	VpPageFaultInterceptsTime			= 34,
+	VpGuestPageTableMaps				= 35,
+	VpLargePageTlbFills				= 36,
+	VpSmallPageTlbFills				= 37,
+	VpReflectedGuestPageFaults			= 38,
+	VpApicMmioAccesses				= 39,
+	VpIoInterceptMessages				= 40,
+	VpMemoryInterceptMessages			= 41,
+	VpApicEoiAccesses				= 42,
+	VpOtherMessages					= 43,
+	VpPageTableAllocations				= 44,
+	VpLogicalProcessorMigrations			= 45,
+	VpAddressSpaceEvictions				= 46,
+	VpAddressSpaceSwitches				= 47,
+	VpAddressDomainFlushes				= 48,
+	VpAddressSpaceFlushes				= 49,
+	VpGlobalGvaRangeFlushes				= 50,
+	VpLocalGvaRangeFlushes				= 51,
+	VpPageTableEvictions				= 52,
+	VpPageTableReclamations				= 53,
+	VpPageTableResets				= 54,
+	VpPageTableValidations				= 55,
+	VpApicTprAccesses				= 56,
+	VpPageTableWriteIntercepts			= 57,
+	VpSyntheticInterrupts				= 58,
+	VpVirtualInterrupts				= 59,
+	VpApicIpisSent					= 60,
+	VpApicSelfIpisSent				= 61,
+	VpGpaSpaceHypercalls				= 62,
+	VpLogicalProcessorHypercalls			= 63,
+	VpLongSpinWaitHypercalls			= 64,
+	VpOtherHypercalls				= 65,
+	VpSyntheticInterruptHypercalls			= 66,
+	VpVirtualInterruptHypercalls			= 67,
+	VpVirtualMmuHypercalls				= 68,
+	VpVirtualProcessorHypercalls			= 69,
+	VpHardwareInterrupts				= 70,
+	VpNestedPageFaultInterceptsCount		= 71,
+	VpNestedPageFaultInterceptsTime			= 72,
+	VpPageScans					= 73,
+	VpLogicalProcessorDispatches			= 74,
+	VpWaitingForCpuTime				= 75,
+	VpExtendedHypercalls				= 76,
+	VpExtendedHypercallInterceptMessages		= 77,
+	VpMbecNestedPageTableSwitches			= 78,
+	VpOtherReflectedGuestExceptions			= 79,
+	VpGlobalIoTlbFlushes				= 80,
+	VpGlobalIoTlbFlushCost				= 81,
+	VpLocalIoTlbFlushes				= 82,
+	VpLocalIoTlbFlushCost				= 83,
+	VpHypercallsForwardedCount			= 84,
+	VpHypercallsForwardingTime			= 85,
+	VpPageInvalidationsForwardedCount		= 86,
+	VpPageInvalidationsForwardingTime		= 87,
+	VpControlRegisterAccessesForwardedCount		= 88,
+	VpControlRegisterAccessesForwardingTime		= 89,
+	VpIoInstructionsForwardedCount			= 90,
+	VpIoInstructionsForwardingTime			= 91,
+	VpHltInstructionsForwardedCount			= 92,
+	VpHltInstructionsForwardingTime			= 93,
+	VpMwaitInstructionsForwardedCount		= 94,
+	VpMwaitInstructionsForwardingTime		= 95,
+	VpCpuidInstructionsForwardedCount		= 96,
+	VpCpuidInstructionsForwardingTime		= 97,
+	VpMsrAccessesForwardedCount			= 98,
+	VpMsrAccessesForwardingTime			= 99,
+	VpOtherInterceptsForwardedCount			= 100,
+	VpOtherInterceptsForwardingTime			= 101,
+	VpExternalInterruptsForwardedCount		= 102,
+	VpExternalInterruptsForwardingTime		= 103,
+	VpPendingInterruptsForwardedCount		= 104,
+	VpPendingInterruptsForwardingTime		= 105,
+	VpEmulatedInstructionsForwardedCount		= 106,
+	VpEmulatedInstructionsForwardingTime		= 107,
+	VpDebugRegisterAccessesForwardedCount		= 108,
+	VpDebugRegisterAccessesForwardingTime		= 109,
+	VpPageFaultInterceptsForwardedCount		= 110,
+	VpPageFaultInterceptsForwardingTime		= 111,
+	VpVmclearEmulationCount				= 112,
+	VpVmclearEmulationTime				= 113,
+	VpVmptrldEmulationCount				= 114,
+	VpVmptrldEmulationTime				= 115,
+	VpVmptrstEmulationCount				= 116,
+	VpVmptrstEmulationTime				= 117,
+	VpVmreadEmulationCount				= 118,
+	VpVmreadEmulationTime				= 119,
+	VpVmwriteEmulationCount				= 120,
+	VpVmwriteEmulationTime				= 121,
+	VpVmxoffEmulationCount				= 122,
+	VpVmxoffEmulationTime				= 123,
+	VpVmxonEmulationCount				= 124,
+	VpVmxonEmulationTime				= 125,
+	VpNestedVMEntriesCount				= 126,
+	VpNestedVMEntriesTime				= 127,
+	VpNestedSLATSoftPageFaultsCount			= 128,
+	VpNestedSLATSoftPageFaultsTime			= 129,
+	VpNestedSLATHardPageFaultsCount			= 130,
+	VpNestedSLATHardPageFaultsTime			= 131,
+	VpInvEptAllContextEmulationCount		= 132,
+	VpInvEptAllContextEmulationTime			= 133,
+	VpInvEptSingleContextEmulationCount		= 134,
+	VpInvEptSingleContextEmulationTime		= 135,
+	VpInvVpidAllContextEmulationCount		= 136,
+	VpInvVpidAllContextEmulationTime		= 137,
+	VpInvVpidSingleContextEmulationCount		= 138,
+	VpInvVpidSingleContextEmulationTime		= 139,
+	VpInvVpidSingleAddressEmulationCount		= 140,
+	VpInvVpidSingleAddressEmulationTime		= 141,
+	VpNestedTlbPageTableReclamations		= 142,
+	VpNestedTlbPageTableEvictions			= 143,
+	VpFlushGuestPhysicalAddressSpaceHypercalls	= 144,
+	VpFlushGuestPhysicalAddressListHypercalls	= 145,
+	VpPostedInterruptNotifications			= 146,
+	VpPostedInterruptScans				= 147,
+	VpTotalCoreRunTime				= 148,
+	VpMaximumRunTime				= 149,
+	VpHwpRequestContextSwitches			= 150,
+	VpWaitingForCpuTimeBucket0			= 151,
+	VpWaitingForCpuTimeBucket1			= 152,
+	VpWaitingForCpuTimeBucket2			= 153,
+	VpWaitingForCpuTimeBucket3			= 154,
+	VpWaitingForCpuTimeBucket4			= 155,
+	VpWaitingForCpuTimeBucket5			= 156,
+	VpWaitingForCpuTimeBucket6			= 157,
+	VpVmloadEmulationCount				= 158,
+	VpVmloadEmulationTime				= 159,
+	VpVmsaveEmulationCount				= 160,
+	VpVmsaveEmulationTime				= 161,
+	VpGifInstructionEmulationCount			= 162,
+	VpGifInstructionEmulationTime			= 163,
+	VpEmulatedErrataSvmInstructions			= 164,
+	VpPlaceholder1					= 165,
+	VpPlaceholder2					= 166,
+	VpPlaceholder3					= 167,
+	VpPlaceholder4					= 168,
+	VpPlaceholder5					= 169,
+	VpPlaceholder6					= 170,
+	VpPlaceholder7					= 171,
+	VpPlaceholder8					= 172,
+	VpPlaceholder9					= 173,
+	VpPlaceholder10					= 174,
+	VpSchedulingPriority				= 175,
+	VpRdpmcInstructionsCount			= 176,
+	VpRdpmcInstructionsTime				= 177,
+	VpPerfmonPmuMsrAccessesCount			= 178,
+	VpPerfmonLbrMsrAccessesCount			= 179,
+	VpPerfmonIptMsrAccessesCount			= 180,
+	VpPerfmonInterruptCount				= 181,
+	VpVtl1DispatchCount				= 182,
+	VpVtl2DispatchCount				= 183,
+	VpVtl2DispatchBucket0				= 184,
+	VpVtl2DispatchBucket1				= 185,
+	VpVtl2DispatchBucket2				= 186,
+	VpVtl2DispatchBucket3				= 187,
+	VpVtl2DispatchBucket4				= 188,
+	VpVtl2DispatchBucket5				= 189,
+	VpVtl2DispatchBucket6				= 190,
+	VpVtl1RunTime					= 191,
+	VpVtl2RunTime					= 192,
+	VpIommuHypercalls				= 193,
+	VpCpuGroupHypercalls				= 194,
+	VpVsmHypercalls					= 195,
+	VpEventLogHypercalls				= 196,
+	VpDeviceDomainHypercalls			= 197,
+	VpDepositHypercalls				= 198,
+	VpSvmHypercalls					= 199,
+	VpBusLockAcquisitionCount			= 200,
+	VpLoadAvg					= 201,
+	VpRootDispatchThreadBlocked			= 202,
+#elif IS_ENABLED(CONFIG_ARM64)
+	VpSysRegAccessesCount				= 9,
+	VpSysRegAccessesTime				= 10,
+	VpSmcInstructionsCount				= 11,
+	VpSmcInstructionsTime				= 12,
+	VpOtherInterceptsCount				= 13,
+	VpOtherInterceptsTime				= 14,
+	VpExternalInterruptsCount			= 15,
+	VpExternalInterruptsTime			= 16,
+	VpPendingInterruptsCount			= 17,
+	VpPendingInterruptsTime				= 18,
+	VpGuestPageTableMaps				= 19,
+	VpLargePageTlbFills				= 20,
+	VpSmallPageTlbFills				= 21,
+	VpReflectedGuestPageFaults			= 22,
+	VpMemoryInterceptMessages			= 23,
+	VpOtherMessages					= 24,
+	VpLogicalProcessorMigrations			= 25,
+	VpAddressDomainFlushes				= 26,
+	VpAddressSpaceFlushes				= 27,
+	VpSyntheticInterrupts				= 28,
+	VpVirtualInterrupts				= 29,
+	VpApicSelfIpisSent				= 30,
+	VpGpaSpaceHypercalls				= 31,
+	VpLogicalProcessorHypercalls			= 32,
+	VpLongSpinWaitHypercalls			= 33,
+	VpOtherHypercalls				= 34,
+	VpSyntheticInterruptHypercalls			= 35,
+	VpVirtualInterruptHypercalls			= 36,
+	VpVirtualMmuHypercalls				= 37,
+	VpVirtualProcessorHypercalls			= 38,
+	VpHardwareInterrupts				= 39,
+	VpNestedPageFaultInterceptsCount		= 40,
+	VpNestedPageFaultInterceptsTime			= 41,
+	VpLogicalProcessorDispatches			= 42,
+	VpWaitingForCpuTime				= 43,
+	VpExtendedHypercalls				= 44,
+	VpExtendedHypercallInterceptMessages		= 45,
+	VpMbecNestedPageTableSwitches			= 46,
+	VpOtherReflectedGuestExceptions			= 47,
+	VpGlobalIoTlbFlushes				= 48,
+	VpGlobalIoTlbFlushCost				= 49,
+	VpLocalIoTlbFlushes				= 50,
+	VpLocalIoTlbFlushCost				= 51,
+	VpFlushGuestPhysicalAddressSpaceHypercalls	= 52,
+	VpFlushGuestPhysicalAddressListHypercalls	= 53,
+	VpPostedInterruptNotifications			= 54,
+	VpPostedInterruptScans				= 55,
+	VpTotalCoreRunTime				= 56,
+	VpMaximumRunTime				= 57,
+	VpWaitingForCpuTimeBucket0			= 58,
+	VpWaitingForCpuTimeBucket1			= 59,
+	VpWaitingForCpuTimeBucket2			= 60,
+	VpWaitingForCpuTimeBucket3			= 61,
+	VpWaitingForCpuTimeBucket4			= 62,
+	VpWaitingForCpuTimeBucket5			= 63,
+	VpWaitingForCpuTimeBucket6			= 64,
+	VpHwpRequestContextSwitches			= 65,
+	VpPlaceholder2					= 66,
+	VpPlaceholder3					= 67,
+	VpPlaceholder4					= 68,
+	VpPlaceholder5					= 69,
+	VpPlaceholder6					= 70,
+	VpPlaceholder7					= 71,
+	VpPlaceholder8					= 72,
+	VpContentionTime				= 73,
+	VpWakeUpTime					= 74,
+	VpSchedulingPriority				= 75,
+	VpVtl1DispatchCount				= 76,
+	VpVtl2DispatchCount				= 77,
+	VpVtl2DispatchBucket0				= 78,
+	VpVtl2DispatchBucket1				= 79,
+	VpVtl2DispatchBucket2				= 80,
+	VpVtl2DispatchBucket3				= 81,
+	VpVtl2DispatchBucket4				= 82,
+	VpVtl2DispatchBucket5				= 83,
+	VpVtl2DispatchBucket6				= 84,
+	VpVtl1RunTime					= 85,
+	VpVtl2RunTime					= 86,
+	VpIommuHypercalls				= 87,
+	VpCpuGroupHypercalls				= 88,
+	VpVsmHypercalls					= 89,
+	VpEventLogHypercalls				= 90,
+	VpDeviceDomainHypercalls			= 91,
+	VpDepositHypercalls				= 92,
+	VpSvmHypercalls					= 93,
+	VpLoadAvg					= 94,
+	VpRootDispatchThreadBlocked			= 95,
+#endif
+	VpStatsMaxCounter
+};
+
+enum hv_stats_lp_counters {			/* HV_CPU_COUNTER */
+	LpGlobalTime				= 1,
+	LpTotalRunTime				= 2,
+	LpHypervisorRunTime			= 3,
+	LpHardwareInterrupts			= 4,
+	LpContextSwitches			= 5,
+	LpInterProcessorInterrupts		= 6,
+	LpSchedulerInterrupts			= 7,
+	LpTimerInterrupts			= 8,
+	LpInterProcessorInterruptsSent		= 9,
+	LpProcessorHalts			= 10,
+	LpMonitorTransitionCost			= 11,
+	LpContextSwitchTime			= 12,
+	LpC1TransitionsCount			= 13,
+	LpC1RunTime				= 14,
+	LpC2TransitionsCount			= 15,
+	LpC2RunTime				= 16,
+	LpC3TransitionsCount			= 17,
+	LpC3RunTime				= 18,
+	LpRootVpIndex				= 19,
+	LpIdleSequenceNumber			= 20,
+	LpGlobalTscCount			= 21,
+	LpActiveTscCount			= 22,
+	LpIdleAccumulation			= 23,
+	LpReferenceCycleCount0			= 24,
+	LpActualCycleCount0			= 25,
+	LpReferenceCycleCount1			= 26,
+	LpActualCycleCount1			= 27,
+	LpProximityDomainId			= 28,
+	LpPostedInterruptNotifications		= 29,
+	LpBranchPredictorFlushes		= 30,
+#if IS_ENABLED(CONFIG_X86_64)
+	LpL1DataCacheFlushes			= 31,
+	LpImmediateL1DataCacheFlushes		= 32,
+	LpMbFlushes				= 33,
+	LpCounterRefreshSequenceNumber		= 34,
+	LpCounterRefreshReferenceTime		= 35,
+	LpIdleAccumulationSnapshot		= 36,
+	LpActiveTscCountSnapshot		= 37,
+	LpHwpRequestContextSwitches		= 38,
+	LpPlaceholder1				= 39,
+	LpPlaceholder2				= 40,
+	LpPlaceholder3				= 41,
+	LpPlaceholder4				= 42,
+	LpPlaceholder5				= 43,
+	LpPlaceholder6				= 44,
+	LpPlaceholder7				= 45,
+	LpPlaceholder8				= 46,
+	LpPlaceholder9				= 47,
+	LpPlaceholder10				= 48,
+	LpReserveGroupId			= 49,
+	LpRunningPriority			= 50,
+	LpPerfmonInterruptCount			= 51,
+#elif IS_ENABLED(CONFIG_ARM64)
+	LpCounterRefreshSequenceNumber		= 31,
+	LpCounterRefreshReferenceTime		= 32,
+	LpIdleAccumulationSnapshot		= 33,
+	LpActiveTscCountSnapshot		= 34,
+	LpHwpRequestContextSwitches		= 35,
+	LpPlaceholder2				= 36,
+	LpPlaceholder3				= 37,
+	LpPlaceholder4				= 38,
+	LpPlaceholder5				= 39,
+	LpPlaceholder6				= 40,
+	LpPlaceholder7				= 41,
+	LpPlaceholder8				= 42,
+	LpPlaceholder9				= 43,
+	LpSchLocalRunListSize			= 44,
+	LpReserveGroupId			= 45,
+	LpRunningPriority			= 46,
+#endif
+	LpStatsMaxCounter
+};
+
+/*
+ * Hypervisor statistics page format
+ */
+struct hv_stats_page {
+	union {
+		u64 hv_cntrs[HvStatsMaxCounter];		/* Hypervisor counters */
+		u64 pt_cntrs[PartitionStatsMaxCounter];		/* Partition counters */
+		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
+		u64 lp_cntrs[LpStatsMaxCounter];		/* LP counters */
+		u8 data[HV_HYP_PAGE_SIZE];
+	};
+} __packed;
+
 /* Bits for dirty mask of hv_vp_register_page */
 #define HV_X64_REGISTER_CLASS_GENERAL	0
 #define HV_X64_REGISTER_CLASS_IP	1
Signature · 1 line
2.34.1
#8 lore raw

RE: [PATCH v3 5/6] mshv: Add definitions for stats pages

From: Nuno Das Neves <[email protected]> Sent: Thursday, January 15, 2026 11:35 AM

Quoted 58 lines · Stanislav Kinsburskii
Quoted 11 lines · Nuno Das Neves
Quoted 3 lines

Add the definitions for hypervisor, logical processor, and partition stats pages.

The definitions in for partition and virtual processor are outdated. Now is the good time to sync the new values in.

Thanks,
Stanislav

Good point, thanks, I will update it for v4.

I'm finally noticing that these counters are not really from hvhdk.h, in the windows code, but their own file. Since I'm still iterating on this, what do you think about creating a file just for the counters? e.g. drivers/hv/hvcounters.h, which combines hvcountersarm64 and amd64.

That would have a couple of advantages:
1. Not putting things in hvhdk.h which aren't actually there in the Windows source
2. Less visibility of CamelCase naming outside our driver
3. I could define the enums using "X macro"s to generate the show() code more cleanly in mshv_debugfs.c, which is something Michael suggested here:
https://lore.kernel.org/linux-hyperv/SN6PR02MB4157938404BC0D12978ACD9BD4A2A@SN6PR02MB4157.namprd02.prod.outlook.com/

It would look something like this:

In hvcounters.h:

#if is_enabled(CONFIG_X86_64)

#define HV_COUNTER_VP_LIST(X) \
	X(VpTotalRunTime, 1), \
	X(VpHypervisorRunTime, 2), \
	X(VpRemoteNodeRunTime, 3), \

/* <snip> */

#elif is_enabled(CONFIG_ARM64)

/* <snip> */

#endif

Just like now, it's a copy/paste from Windows + simple pattern replacement. Note with this approach we need separate lists for arm64 and x86, but that matches how the enums are defined in Windows.

Then, in mshv_debugfs.c:

/*
* We need the strings paired with their enum values.
* This structure can be used for all the different stat types. */

Quoted 8 lines
struct hv_counter_entry {
	char *name;
	int idx;
};

/* Define an array entry (again, reusable) */

#define HV_COUNTER_LIST(name, idx) \
	{ __stringify(name), idx },

Couldn't this also go in hvcounters.h, so it doesn't need to be passed as a parameter to HV_COUNTER_VP_LIST() and friends? Or is the goal to keep hvcounters.h as bare minimum as possible?

Quoted 5 lines

/* Create our static array */
static struct hv_counter_entry hv_counter_vp_array[] = {
HV_ST_COUNTER_VP(HV_COUNTER_VP)
};

Shouldn't the above be HV_COUNTER_VP_LIST(HV_COUNTER_LIST) to match the #define in hvcounters.h, and the macro that does the __stringify()? Assuming so, I think I understand the overall idea you are proposing. It's pretty clever. :-)

The #define of HV_COUNTER_VP_LIST() in hvcounters.h gets large for VP stats -- the #define will be about 200 lines. I have no sense of whether being that large is problematic for the tooling. And that question needs to be considered beyond just the C preprocessor and compiler, to include things like sparse, cscope, and other tools that parse source code. I had originally suggested building the static array directly in a .c file, which would avoid the need for the big #define. And maybe you could still do that with a separate .c source file just for the static arrays -- i.e., hvcounters.h becomes hvcounters.c. It seems like the " it's a copy/paste from Windows + simple pattern replacement" could be done to generate a .c file as easily as a .h file while still keeping the file contents to a bare minimum.

Either way (.h or .c file), I like the idea.

Michael

Quoted 522 lines

static int vp_stats_show(struct seq_file *m, void *v)

{
	const struct hv_stats_page **pstats = m->private;
	int i;

	for (i = 0; i < ARRAY_SIZE(hv_counter_vp_array); ++i) {
		struct hv_counter_entry entry = hv_counter_vp_array[i];
		u64 parent_val = pstats[HV_STATS_AREA_PARENT]->vp_cntrs[entry.idx];
		u64 self_val = pstats[HV_STATS_AREA_SELF]->vp_cntrs[entry.idx];

		/* Prioritize the PARENT area value */
		seq_printf(m, "%-30s: %llu\n", entry.name,
			   parent_val ? parent_val : self_val);
	}
}

Any thoughts? I was originally going to just go with the pattern we had, but since these definitions aren't from the hv*dk.h files, we can maybe get more creative and make the resulting code look a bit better.

Thanks
Nuno

Quoted 16 lines
Quoted 16 lines

Move the definition for the VP stats page to its rightful place in hvhdk.h, and add the missing members.

While at it, correct the ARM64 value of VpRootDispatchThreadBlocked, (which is not yet used, so there is no impact).

These enum members retain their CamelCase style, since they are imported directly from the hypervisor code. They will be stringified when printing the stats out, and retain more readability in this form.

---
 drivers/hv/mshv_root_main.c |  17 --
 include/hyperv/hvhdk.h      | 437 ++++++++++++++++++++++++++++++++++++
 2 files changed, 437 insertions(+), 17 deletions(-)
Quoted 7 lines

drivers/hv/mshv_root_main.c MODULE_AUTHOR("Microsoft"); · line 40

Quoted 7 lines
drivers/hv/mshv_root_main.c +0 -0
index fbfc9e7d9fa4..724bbaa0b08c 100644
@@ -39,23 +39,6 @@ MODULE_AUTHOR("Microsoft");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Microsoft Hyper-V root partition VMM interface

/dev/mshv");

Quoted 29 lines
Quoted 29 lines
drivers/hv/mshv_root_main.c +0 -17
-/* TODO move this to another file when debugfs code is added */
-enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
-#if defined(CONFIG_X86)
-	VpRootDispatchThreadBlocked			= 202,
-#elif defined(CONFIG_ARM64)
-	VpRootDispatchThreadBlocked			= 94,
-#endif
-	VpStatsMaxCounter
-};
-
-struct hv_stats_page {
-	union {
-		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
-		u8 data[HV_HYP_PAGE_SIZE];
-	};
-} __packed;
-
 struct mshv_root mshv_root;
 
 enum hv_scheduler_type hv_scheduler_type;
include/hyperv/hvhdk.h +0 -0
index 469186df7826..8bddd11feeba 100644
@@ -10,6 +10,443 @@
 #include "hvhdk_mini.h"
 #include "hvgdk.h"
 
Quoted 1 line

include/hyperv/hvhdk.h line 13

Quoted 1 line
include/hyperv/hvhdk.h +1 -0
+enum hv_stats_hypervisor_counters {		/* HV_HYPERVISOR_COUNTER

*/

Quoted 421 lines
Quoted 421 lines
include/hyperv/hvhdk.h +421 -0
+	HvLogicalProcessors			= 1,
+	HvPartitions				= 2,
+	HvTotalPages				= 3,
+	HvVirtualProcessors			= 4,
+	HvMonitoredNotifications		= 5,
+	HvModernStandbyEntries			= 6,
+	HvPlatformIdleTransitions		= 7,
+	HvHypervisorStartupCost			= 8,
+	HvIOSpacePages				= 10,
+	HvNonEssentialPagesForDump		= 11,
+	HvSubsumedPages				= 12,
+	HvStatsMaxCounter
+};
+
+enum hv_stats_partition_counters {		/* HV_PROCESS_COUNTER */
+	PartitionVirtualProcessors		= 1,
+	PartitionTlbSize			= 3,
+	PartitionAddressSpaces			= 4,
+	PartitionDepositedPages			= 5,
+	PartitionGpaPages			= 6,
+	PartitionGpaSpaceModifications		= 7,
+	PartitionVirtualTlbFlushEntires		= 8,
+	PartitionRecommendedTlbSize		= 9,
+	PartitionGpaPages4K			= 10,
+	PartitionGpaPages2M			= 11,
+	PartitionGpaPages1G			= 12,
+	PartitionGpaPages512G			= 13,
+	PartitionDevicePages4K			= 14,
+	PartitionDevicePages2M			= 15,
+	PartitionDevicePages1G			= 16,
+	PartitionDevicePages512G		= 17,
+	PartitionAttachedDevices		= 18,
+	PartitionDeviceInterruptMappings	= 19,
+	PartitionIoTlbFlushes			= 20,
+	PartitionIoTlbFlushCost			= 21,
+	PartitionDeviceInterruptErrors		= 22,
+	PartitionDeviceDmaErrors		= 23,
+	PartitionDeviceInterruptThrottleEvents	= 24,
+	PartitionSkippedTimerTicks		= 25,
+	PartitionPartitionId			= 26,
+#if IS_ENABLED(CONFIG_X86_64)
+	PartitionNestedTlbSize			= 27,
+	PartitionRecommendedNestedTlbSize	= 28,
+	PartitionNestedTlbFreeListSize		= 29,
+	PartitionNestedTlbTrimmedPages		= 30,
+	PartitionPagesShattered			= 31,
+	PartitionPagesRecombined		= 32,
+	PartitionHwpRequestValue		= 33,
+#elif IS_ENABLED(CONFIG_ARM64)
+	PartitionHwpRequestValue		= 27,
+#endif
+	PartitionStatsMaxCounter
+};
+
+enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
+	VpTotalRunTime					= 1,
+	VpHypervisorRunTime				= 2,
+	VpRemoteNodeRunTime				= 3,
+	VpNormalizedRunTime				= 4,
+	VpIdealCpu					= 5,
+	VpHypercallsCount				= 7,
+	VpHypercallsTime				= 8,
+#if IS_ENABLED(CONFIG_X86_64)
+	VpPageInvalidationsCount			= 9,
+	VpPageInvalidationsTime				= 10,
+	VpControlRegisterAccessesCount			= 11,
+	VpControlRegisterAccessesTime			= 12,
+	VpIoInstructionsCount				= 13,
+	VpIoInstructionsTime				= 14,
+	VpHltInstructionsCount				= 15,
+	VpHltInstructionsTime				= 16,
+	VpMwaitInstructionsCount			= 17,
+	VpMwaitInstructionsTime				= 18,
+	VpCpuidInstructionsCount			= 19,
+	VpCpuidInstructionsTime				= 20,
+	VpMsrAccessesCount				= 21,
+	VpMsrAccessesTime				= 22,
+	VpOtherInterceptsCount				= 23,
+	VpOtherInterceptsTime				= 24,
+	VpExternalInterruptsCount			= 25,
+	VpExternalInterruptsTime			= 26,
+	VpPendingInterruptsCount			= 27,
+	VpPendingInterruptsTime				= 28,
+	VpEmulatedInstructionsCount			= 29,
+	VpEmulatedInstructionsTime			= 30,
+	VpDebugRegisterAccessesCount			= 31,
+	VpDebugRegisterAccessesTime			= 32,
+	VpPageFaultInterceptsCount			= 33,
+	VpPageFaultInterceptsTime			= 34,
+	VpGuestPageTableMaps				= 35,
+	VpLargePageTlbFills				= 36,
+	VpSmallPageTlbFills				= 37,
+	VpReflectedGuestPageFaults			= 38,
+	VpApicMmioAccesses				= 39,
+	VpIoInterceptMessages				= 40,
+	VpMemoryInterceptMessages			= 41,
+	VpApicEoiAccesses				= 42,
+	VpOtherMessages					= 43,
+	VpPageTableAllocations				= 44,
+	VpLogicalProcessorMigrations			= 45,
+	VpAddressSpaceEvictions				= 46,
+	VpAddressSpaceSwitches				= 47,
+	VpAddressDomainFlushes				= 48,
+	VpAddressSpaceFlushes				= 49,
+	VpGlobalGvaRangeFlushes				= 50,
+	VpLocalGvaRangeFlushes				= 51,
+	VpPageTableEvictions				= 52,
+	VpPageTableReclamations				= 53,
+	VpPageTableResets				= 54,
+	VpPageTableValidations				= 55,
+	VpApicTprAccesses				= 56,
+	VpPageTableWriteIntercepts			= 57,
+	VpSyntheticInterrupts				= 58,
+	VpVirtualInterrupts				= 59,
+	VpApicIpisSent					= 60,
+	VpApicSelfIpisSent				= 61,
+	VpGpaSpaceHypercalls				= 62,
+	VpLogicalProcessorHypercalls			= 63,
+	VpLongSpinWaitHypercalls			= 64,
+	VpOtherHypercalls				= 65,
+	VpSyntheticInterruptHypercalls			= 66,
+	VpVirtualInterruptHypercalls			= 67,
+	VpVirtualMmuHypercalls				= 68,
+	VpVirtualProcessorHypercalls			= 69,
+	VpHardwareInterrupts				= 70,
+	VpNestedPageFaultInterceptsCount		= 71,
+	VpNestedPageFaultInterceptsTime			= 72,
+	VpPageScans					= 73,
+	VpLogicalProcessorDispatches			= 74,
+	VpWaitingForCpuTime				= 75,
+	VpExtendedHypercalls				= 76,
+	VpExtendedHypercallInterceptMessages		= 77,
+	VpMbecNestedPageTableSwitches			= 78,
+	VpOtherReflectedGuestExceptions			= 79,
+	VpGlobalIoTlbFlushes				= 80,
+	VpGlobalIoTlbFlushCost				= 81,
+	VpLocalIoTlbFlushes				= 82,
+	VpLocalIoTlbFlushCost				= 83,
+	VpHypercallsForwardedCount			= 84,
+	VpHypercallsForwardingTime			= 85,
+	VpPageInvalidationsForwardedCount		= 86,
+	VpPageInvalidationsForwardingTime		= 87,
+	VpControlRegisterAccessesForwardedCount		= 88,
+	VpControlRegisterAccessesForwardingTime		= 89,
+	VpIoInstructionsForwardedCount			= 90,
+	VpIoInstructionsForwardingTime			= 91,
+	VpHltInstructionsForwardedCount			= 92,
+	VpHltInstructionsForwardingTime			= 93,
+	VpMwaitInstructionsForwardedCount		= 94,
+	VpMwaitInstructionsForwardingTime		= 95,
+	VpCpuidInstructionsForwardedCount		= 96,
+	VpCpuidInstructionsForwardingTime		= 97,
+	VpMsrAccessesForwardedCount			= 98,
+	VpMsrAccessesForwardingTime			= 99,
+	VpOtherInterceptsForwardedCount			= 100,
+	VpOtherInterceptsForwardingTime			= 101,
+	VpExternalInterruptsForwardedCount		= 102,
+	VpExternalInterruptsForwardingTime		= 103,
+	VpPendingInterruptsForwardedCount		= 104,
+	VpPendingInterruptsForwardingTime		= 105,
+	VpEmulatedInstructionsForwardedCount		= 106,
+	VpEmulatedInstructionsForwardingTime		= 107,
+	VpDebugRegisterAccessesForwardedCount		= 108,
+	VpDebugRegisterAccessesForwardingTime		= 109,
+	VpPageFaultInterceptsForwardedCount		= 110,
+	VpPageFaultInterceptsForwardingTime		= 111,
+	VpVmclearEmulationCount				= 112,
+	VpVmclearEmulationTime				= 113,
+	VpVmptrldEmulationCount				= 114,
+	VpVmptrldEmulationTime				= 115,
+	VpVmptrstEmulationCount				= 116,
+	VpVmptrstEmulationTime				= 117,
+	VpVmreadEmulationCount				= 118,
+	VpVmreadEmulationTime				= 119,
+	VpVmwriteEmulationCount				= 120,
+	VpVmwriteEmulationTime				= 121,
+	VpVmxoffEmulationCount				= 122,
+	VpVmxoffEmulationTime				= 123,
+	VpVmxonEmulationCount				= 124,
+	VpVmxonEmulationTime				= 125,
+	VpNestedVMEntriesCount				= 126,
+	VpNestedVMEntriesTime				= 127,
+	VpNestedSLATSoftPageFaultsCount			= 128,
+	VpNestedSLATSoftPageFaultsTime			= 129,
+	VpNestedSLATHardPageFaultsCount			= 130,
+	VpNestedSLATHardPageFaultsTime			= 131,
+	VpInvEptAllContextEmulationCount		= 132,
+	VpInvEptAllContextEmulationTime			= 133,
+	VpInvEptSingleContextEmulationCount		= 134,
+	VpInvEptSingleContextEmulationTime		= 135,
+	VpInvVpidAllContextEmulationCount		= 136,
+	VpInvVpidAllContextEmulationTime		= 137,
+	VpInvVpidSingleContextEmulationCount		= 138,
+	VpInvVpidSingleContextEmulationTime		= 139,
+	VpInvVpidSingleAddressEmulationCount		= 140,
+	VpInvVpidSingleAddressEmulationTime		= 141,
+	VpNestedTlbPageTableReclamations		= 142,
+	VpNestedTlbPageTableEvictions			= 143,
+	VpFlushGuestPhysicalAddressSpaceHypercalls	= 144,
+	VpFlushGuestPhysicalAddressListHypercalls	= 145,
+	VpPostedInterruptNotifications			= 146,
+	VpPostedInterruptScans				= 147,
+	VpTotalCoreRunTime				= 148,
+	VpMaximumRunTime				= 149,
+	VpHwpRequestContextSwitches			= 150,
+	VpWaitingForCpuTimeBucket0			= 151,
+	VpWaitingForCpuTimeBucket1			= 152,
+	VpWaitingForCpuTimeBucket2			= 153,
+	VpWaitingForCpuTimeBucket3			= 154,
+	VpWaitingForCpuTimeBucket4			= 155,
+	VpWaitingForCpuTimeBucket5			= 156,
+	VpWaitingForCpuTimeBucket6			= 157,
+	VpVmloadEmulationCount				= 158,
+	VpVmloadEmulationTime				= 159,
+	VpVmsaveEmulationCount				= 160,
+	VpVmsaveEmulationTime				= 161,
+	VpGifInstructionEmulationCount			= 162,
+	VpGifInstructionEmulationTime			= 163,
+	VpEmulatedErrataSvmInstructions			= 164,
+	VpPlaceholder1					= 165,
+	VpPlaceholder2					= 166,
+	VpPlaceholder3					= 167,
+	VpPlaceholder4					= 168,
+	VpPlaceholder5					= 169,
+	VpPlaceholder6					= 170,
+	VpPlaceholder7					= 171,
+	VpPlaceholder8					= 172,
+	VpPlaceholder9					= 173,
+	VpPlaceholder10					= 174,
+	VpSchedulingPriority				= 175,
+	VpRdpmcInstructionsCount			= 176,
+	VpRdpmcInstructionsTime				= 177,
+	VpPerfmonPmuMsrAccessesCount			= 178,
+	VpPerfmonLbrMsrAccessesCount			= 179,
+	VpPerfmonIptMsrAccessesCount			= 180,
+	VpPerfmonInterruptCount				= 181,
+	VpVtl1DispatchCount				= 182,
+	VpVtl2DispatchCount				= 183,
+	VpVtl2DispatchBucket0				= 184,
+	VpVtl2DispatchBucket1				= 185,
+	VpVtl2DispatchBucket2				= 186,
+	VpVtl2DispatchBucket3				= 187,
+	VpVtl2DispatchBucket4				= 188,
+	VpVtl2DispatchBucket5				= 189,
+	VpVtl2DispatchBucket6				= 190,
+	VpVtl1RunTime					= 191,
+	VpVtl2RunTime					= 192,
+	VpIommuHypercalls				= 193,
+	VpCpuGroupHypercalls				= 194,
+	VpVsmHypercalls					= 195,
+	VpEventLogHypercalls				= 196,
+	VpDeviceDomainHypercalls			= 197,
+	VpDepositHypercalls				= 198,
+	VpSvmHypercalls					= 199,
+	VpBusLockAcquisitionCount			= 200,
+	VpLoadAvg					= 201,
+	VpRootDispatchThreadBlocked			= 202,
+#elif IS_ENABLED(CONFIG_ARM64)
+	VpSysRegAccessesCount				= 9,
+	VpSysRegAccessesTime				= 10,
+	VpSmcInstructionsCount				= 11,
+	VpSmcInstructionsTime				= 12,
+	VpOtherInterceptsCount				= 13,
+	VpOtherInterceptsTime				= 14,
+	VpExternalInterruptsCount			= 15,
+	VpExternalInterruptsTime			= 16,
+	VpPendingInterruptsCount			= 17,
+	VpPendingInterruptsTime				= 18,
+	VpGuestPageTableMaps				= 19,
+	VpLargePageTlbFills				= 20,
+	VpSmallPageTlbFills				= 21,
+	VpReflectedGuestPageFaults			= 22,
+	VpMemoryInterceptMessages			= 23,
+	VpOtherMessages					= 24,
+	VpLogicalProcessorMigrations			= 25,
+	VpAddressDomainFlushes				= 26,
+	VpAddressSpaceFlushes				= 27,
+	VpSyntheticInterrupts				= 28,
+	VpVirtualInterrupts				= 29,
+	VpApicSelfIpisSent				= 30,
+	VpGpaSpaceHypercalls				= 31,
+	VpLogicalProcessorHypercalls			= 32,
+	VpLongSpinWaitHypercalls			= 33,
+	VpOtherHypercalls				= 34,
+	VpSyntheticInterruptHypercalls			= 35,
+	VpVirtualInterruptHypercalls			= 36,
+	VpVirtualMmuHypercalls				= 37,
+	VpVirtualProcessorHypercalls			= 38,
+	VpHardwareInterrupts				= 39,
+	VpNestedPageFaultInterceptsCount		= 40,
+	VpNestedPageFaultInterceptsTime			= 41,
+	VpLogicalProcessorDispatches			= 42,
+	VpWaitingForCpuTime				= 43,
+	VpExtendedHypercalls				= 44,
+	VpExtendedHypercallInterceptMessages		= 45,
+	VpMbecNestedPageTableSwitches			= 46,
+	VpOtherReflectedGuestExceptions			= 47,
+	VpGlobalIoTlbFlushes				= 48,
+	VpGlobalIoTlbFlushCost				= 49,
+	VpLocalIoTlbFlushes				= 50,
+	VpLocalIoTlbFlushCost				= 51,
+	VpFlushGuestPhysicalAddressSpaceHypercalls	= 52,
+	VpFlushGuestPhysicalAddressListHypercalls	= 53,
+	VpPostedInterruptNotifications			= 54,
+	VpPostedInterruptScans				= 55,
+	VpTotalCoreRunTime				= 56,
+	VpMaximumRunTime				= 57,
+	VpWaitingForCpuTimeBucket0			= 58,
+	VpWaitingForCpuTimeBucket1			= 59,
+	VpWaitingForCpuTimeBucket2			= 60,
+	VpWaitingForCpuTimeBucket3			= 61,
+	VpWaitingForCpuTimeBucket4			= 62,
+	VpWaitingForCpuTimeBucket5			= 63,
+	VpWaitingForCpuTimeBucket6			= 64,
+	VpHwpRequestContextSwitches			= 65,
+	VpPlaceholder2					= 66,
+	VpPlaceholder3					= 67,
+	VpPlaceholder4					= 68,
+	VpPlaceholder5					= 69,
+	VpPlaceholder6					= 70,
+	VpPlaceholder7					= 71,
+	VpPlaceholder8					= 72,
+	VpContentionTime				= 73,
+	VpWakeUpTime					= 74,
+	VpSchedulingPriority				= 75,
+	VpVtl1DispatchCount				= 76,
+	VpVtl2DispatchCount				= 77,
+	VpVtl2DispatchBucket0				= 78,
+	VpVtl2DispatchBucket1				= 79,
+	VpVtl2DispatchBucket2				= 80,
+	VpVtl2DispatchBucket3				= 81,
+	VpVtl2DispatchBucket4				= 82,
+	VpVtl2DispatchBucket5				= 83,
+	VpVtl2DispatchBucket6				= 84,
+	VpVtl1RunTime					= 85,
+	VpVtl2RunTime					= 86,
+	VpIommuHypercalls				= 87,
+	VpCpuGroupHypercalls				= 88,
+	VpVsmHypercalls					= 89,
+	VpEventLogHypercalls				= 90,
+	VpDeviceDomainHypercalls			= 91,
+	VpDepositHypercalls				= 92,
+	VpSvmHypercalls					= 93,
+	VpLoadAvg					= 94,
+	VpRootDispatchThreadBlocked			= 95,
+#endif
+	VpStatsMaxCounter
+};
+
+enum hv_stats_lp_counters {			/* HV_CPU_COUNTER */
+	LpGlobalTime				= 1,
+	LpTotalRunTime				= 2,
+	LpHypervisorRunTime			= 3,
+	LpHardwareInterrupts			= 4,
+	LpContextSwitches			= 5,
+	LpInterProcessorInterrupts		= 6,
+	LpSchedulerInterrupts			= 7,
+	LpTimerInterrupts			= 8,
+	LpInterProcessorInterruptsSent		= 9,
+	LpProcessorHalts			= 10,
+	LpMonitorTransitionCost			= 11,
+	LpContextSwitchTime			= 12,
+	LpC1TransitionsCount			= 13,
+	LpC1RunTime				= 14,
+	LpC2TransitionsCount			= 15,
+	LpC2RunTime				= 16,
+	LpC3TransitionsCount			= 17,
+	LpC3RunTime				= 18,
+	LpRootVpIndex				= 19,
+	LpIdleSequenceNumber			= 20,
+	LpGlobalTscCount			= 21,
+	LpActiveTscCount			= 22,
+	LpIdleAccumulation			= 23,
+	LpReferenceCycleCount0			= 24,
+	LpActualCycleCount0			= 25,
+	LpReferenceCycleCount1			= 26,
+	LpActualCycleCount1			= 27,
+	LpProximityDomainId			= 28,
+	LpPostedInterruptNotifications		= 29,
+	LpBranchPredictorFlushes		= 30,
+#if IS_ENABLED(CONFIG_X86_64)
+	LpL1DataCacheFlushes			= 31,
+	LpImmediateL1DataCacheFlushes		= 32,
+	LpMbFlushes				= 33,
+	LpCounterRefreshSequenceNumber		= 34,
+	LpCounterRefreshReferenceTime		= 35,
+	LpIdleAccumulationSnapshot		= 36,
+	LpActiveTscCountSnapshot		= 37,
+	LpHwpRequestContextSwitches		= 38,
+	LpPlaceholder1				= 39,
+	LpPlaceholder2				= 40,
+	LpPlaceholder3				= 41,
+	LpPlaceholder4				= 42,
+	LpPlaceholder5				= 43,
+	LpPlaceholder6				= 44,
+	LpPlaceholder7				= 45,
+	LpPlaceholder8				= 46,
+	LpPlaceholder9				= 47,
+	LpPlaceholder10				= 48,
+	LpReserveGroupId			= 49,
+	LpRunningPriority			= 50,
+	LpPerfmonInterruptCount			= 51,
+#elif IS_ENABLED(CONFIG_ARM64)
+	LpCounterRefreshSequenceNumber		= 31,
+	LpCounterRefreshReferenceTime		= 32,
+	LpIdleAccumulationSnapshot		= 33,
+	LpActiveTscCountSnapshot		= 34,
+	LpHwpRequestContextSwitches		= 35,
+	LpPlaceholder2				= 36,
+	LpPlaceholder3				= 37,
+	LpPlaceholder4				= 38,
+	LpPlaceholder5				= 39,
+	LpPlaceholder6				= 40,
+	LpPlaceholder7				= 41,
+	LpPlaceholder8				= 42,
+	LpPlaceholder9				= 43,
+	LpSchLocalRunListSize			= 44,
+	LpReserveGroupId			= 45,
+	LpRunningPriority			= 46,
+#endif
+	LpStatsMaxCounter
Quoted 8 lines

include/hyperv/hvhdk.h

Quoted 8 lines
include/hyperv/hvhdk.h +8 -0
+};
+
+/*
+ * Hypervisor statistics page format
+ */
+struct hv_stats_page {
+	union {
+		u64 hv_cntrs[HvStatsMaxCounter];		/* Hypervisor counters

*/

Quoted 1 line

include/hyperv/hvhdk.h line 443

Quoted 1 line
include/hyperv/hvhdk.h +1 -0
+		u64 pt_cntrs[PartitionStatsMaxCounter];		/* Partition

counters */

Quoted 11 lines
Quoted 11 lines
include/hyperv/hvhdk.h +6 -1
+		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
+		u64 lp_cntrs[LpStatsMaxCounter];		/* LP counters */
+		u8 data[HV_HYP_PAGE_SIZE];
+	};
+} __packed;
+
 /* Bits for dirty mask of hv_vp_register_page */
 #define HV_X64_REGISTER_CLASS_GENERAL	0
 #define HV_X64_REGISTER_CLASS_IP	1
--

2.34.1

#9 lore raw

Re: [PATCH v3 5/6] mshv: Add definitions for stats pages

Quoted 64 lines · Michael Kelley

From: Nuno Das Neves <[email protected]> Sent: Thursday, January 15, 2026 11:35 AM

Quoted 63 lines · Stanislav Kinsburskii
Quoted 11 lines · Nuno Das Neves
Quoted 3 lines

Add the definitions for hypervisor, logical processor, and partition stats pages.

The definitions in for partition and virtual processor are outdated. Now is the good time to sync the new values in.

Thanks,
Stanislav

Good point, thanks, I will update it for v4.

I'm finally noticing that these counters are not really from hvhdk.h, in the windows code, but their own file. Since I'm still iterating on this, what do you think about creating a file just for the counters? e.g. drivers/hv/hvcounters.h, which combines hvcountersarm64 and amd64.

That would have a couple of advantages:
1. Not putting things in hvhdk.h which aren't actually there in the Windows source
2. Less visibility of CamelCase naming outside our driver
3. I could define the enums using "X macro"s to generate the show() code more cleanly in mshv_debugfs.c, which is something Michael suggested here:
https://lore.kernel.org/linux-hyperv/SN6PR02MB4157938404BC0D12978ACD9BD4A2A@SN6PR02MB4157.namprd02.prod.outlook.com/

It would look something like this:

In hvcounters.h:

#if is_enabled(CONFIG_X86_64)

#define HV_COUNTER_VP_LIST(X) \
	X(VpTotalRunTime, 1), \
	X(VpHypervisorRunTime, 2), \
	X(VpRemoteNodeRunTime, 3), \

/* <snip> */

#elif is_enabled(CONFIG_ARM64)

/* <snip> */

#endif

Just like now, it's a copy/paste from Windows + simple pattern replacement. Note with this approach we need separate lists for arm64 and x86, but that matches how the enums are defined in Windows.

Then, in mshv_debugfs.c:

/*
* We need the strings paired with their enum values.
* This structure can be used for all the different stat types. */

struct hv_counter_entry {
	char *name;
	int idx;
};
Quoted 8 lines
Quoted 3 lines

/* Define an array entry (again, reusable) */

#define HV_COUNTER_LIST(name, idx) \
	{ __stringify(name), idx },

Couldn't this also go in hvcounters.h, so it doesn't need to be passed as a parameter to HV_COUNTER_VP_LIST() and friends? Or is the goal to keep hvcounters.h as bare minimum as possible?

Oh, yes certainly the struct and macros could all be hv_counters.h.

Quoted 11 lines
Quoted 5 lines

/* Create our static array */
static struct hv_counter_entry hv_counter_vp_array[] = {
HV_ST_COUNTER_VP(HV_COUNTER_VP)
};

Shouldn't the above be HV_COUNTER_VP_LIST(HV_COUNTER_LIST) to match the #define in hvcounters.h, and the macro that does the __stringify()? Assuming so, I think I understand the overall idea you are proposing. It's pretty clever. :-)

Oh, yes it should be HV_COUNTER_VP_LIST(HV_COUNTER_LIST)

Quoted 4 lines

The #define of HV_COUNTER_VP_LIST() in hvcounters.h gets large for VP stats -- the #define will be about 200 lines. I have no sense of whether being that large is problematic for the tooling. And that question needs to be considered beyond just the C preprocessor and

Quoted 9 lines

compiler, to include things like sparse, cscope, and other tools that parse source code. I had originally suggested building the static array directly in a .c file, which would avoid the need for the big #define. And maybe you could still do that with a separate .c source file just for the static arrays -- i.e., hvcounters.h becomes hvcounters.c. It seems like the " it's a copy/paste from Windows + simple pattern replacement" could be done to generate a .c file as easily as a .h file while still keeping the file contents to a bare minimum.

Good point... I usually reach for this "X macros" technique when I have a list of things that needs to be repeated in multiple places (e.g. defining a big enum AND also using the enum values in a big switch statement).

Since we don't need the enum after all, apparently (it's not in hvhdk.h), your original suggestion is probably the most straightforward thing; just putting the values into a static array directly.

Putting it in it's own .c file and including that might be the easiest thing, I'll give that a go and see how it looks.

Quoted 526 lines

Either way (.h or .c file), I like the idea.

Michael

Quoted 522 lines

static int vp_stats_show(struct seq_file *m, void *v)

{
	const struct hv_stats_page **pstats = m->private;
	int i;

	for (i = 0; i < ARRAY_SIZE(hv_counter_vp_array); ++i) {
		struct hv_counter_entry entry = hv_counter_vp_array[i];
		u64 parent_val = pstats[HV_STATS_AREA_PARENT]->vp_cntrs[entry.idx];
		u64 self_val = pstats[HV_STATS_AREA_SELF]->vp_cntrs[entry.idx];

		/* Prioritize the PARENT area value */
		seq_printf(m, "%-30s: %llu\n", entry.name,
			   parent_val ? parent_val : self_val);
	}
}

Any thoughts? I was originally going to just go with the pattern we had, but since these definitions aren't from the hv*dk.h files, we can maybe get more creative and make the resulting code look a bit better.

Thanks
Nuno

Quoted 16 lines
Quoted 16 lines

Move the definition for the VP stats page to its rightful place in hvhdk.h, and add the missing members.

While at it, correct the ARM64 value of VpRootDispatchThreadBlocked, (which is not yet used, so there is no impact).

These enum members retain their CamelCase style, since they are imported directly from the hypervisor code. They will be stringified when printing the stats out, and retain more readability in this form.

---
 drivers/hv/mshv_root_main.c |  17 --
 include/hyperv/hvhdk.h      | 437 ++++++++++++++++++++++++++++++++++++
 2 files changed, 437 insertions(+), 17 deletions(-)
Quoted 7 lines

drivers/hv/mshv_root_main.c MODULE_AUTHOR("Microsoft"); · line 40

Quoted 7 lines
drivers/hv/mshv_root_main.c +0 -0
index fbfc9e7d9fa4..724bbaa0b08c 100644
@@ -39,23 +39,6 @@ MODULE_AUTHOR("Microsoft");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Microsoft Hyper-V root partition VMM interface

/dev/mshv");

Quoted 29 lines
Quoted 29 lines
drivers/hv/mshv_root_main.c +0 -17
-/* TODO move this to another file when debugfs code is added */
-enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
-#if defined(CONFIG_X86)
-	VpRootDispatchThreadBlocked			= 202,
-#elif defined(CONFIG_ARM64)
-	VpRootDispatchThreadBlocked			= 94,
-#endif
-	VpStatsMaxCounter
-};
-
-struct hv_stats_page {
-	union {
-		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
-		u8 data[HV_HYP_PAGE_SIZE];
-	};
-} __packed;
-
 struct mshv_root mshv_root;
 
 enum hv_scheduler_type hv_scheduler_type;
include/hyperv/hvhdk.h +0 -0
index 469186df7826..8bddd11feeba 100644
@@ -10,6 +10,443 @@
 #include "hvhdk_mini.h"
 #include "hvgdk.h"
 
Quoted 1 line

include/hyperv/hvhdk.h line 13

Quoted 1 line
include/hyperv/hvhdk.h +1 -0
+enum hv_stats_hypervisor_counters {		/* HV_HYPERVISOR_COUNTER

*/

Quoted 421 lines
Quoted 421 lines
include/hyperv/hvhdk.h +421 -0
+	HvLogicalProcessors			= 1,
+	HvPartitions				= 2,
+	HvTotalPages				= 3,
+	HvVirtualProcessors			= 4,
+	HvMonitoredNotifications		= 5,
+	HvModernStandbyEntries			= 6,
+	HvPlatformIdleTransitions		= 7,
+	HvHypervisorStartupCost			= 8,
+	HvIOSpacePages				= 10,
+	HvNonEssentialPagesForDump		= 11,
+	HvSubsumedPages				= 12,
+	HvStatsMaxCounter
+};
+
+enum hv_stats_partition_counters {		/* HV_PROCESS_COUNTER */
+	PartitionVirtualProcessors		= 1,
+	PartitionTlbSize			= 3,
+	PartitionAddressSpaces			= 4,
+	PartitionDepositedPages			= 5,
+	PartitionGpaPages			= 6,
+	PartitionGpaSpaceModifications		= 7,
+	PartitionVirtualTlbFlushEntires		= 8,
+	PartitionRecommendedTlbSize		= 9,
+	PartitionGpaPages4K			= 10,
+	PartitionGpaPages2M			= 11,
+	PartitionGpaPages1G			= 12,
+	PartitionGpaPages512G			= 13,
+	PartitionDevicePages4K			= 14,
+	PartitionDevicePages2M			= 15,
+	PartitionDevicePages1G			= 16,
+	PartitionDevicePages512G		= 17,
+	PartitionAttachedDevices		= 18,
+	PartitionDeviceInterruptMappings	= 19,
+	PartitionIoTlbFlushes			= 20,
+	PartitionIoTlbFlushCost			= 21,
+	PartitionDeviceInterruptErrors		= 22,
+	PartitionDeviceDmaErrors		= 23,
+	PartitionDeviceInterruptThrottleEvents	= 24,
+	PartitionSkippedTimerTicks		= 25,
+	PartitionPartitionId			= 26,
+#if IS_ENABLED(CONFIG_X86_64)
+	PartitionNestedTlbSize			= 27,
+	PartitionRecommendedNestedTlbSize	= 28,
+	PartitionNestedTlbFreeListSize		= 29,
+	PartitionNestedTlbTrimmedPages		= 30,
+	PartitionPagesShattered			= 31,
+	PartitionPagesRecombined		= 32,
+	PartitionHwpRequestValue		= 33,
+#elif IS_ENABLED(CONFIG_ARM64)
+	PartitionHwpRequestValue		= 27,
+#endif
+	PartitionStatsMaxCounter
+};
+
+enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
+	VpTotalRunTime					= 1,
+	VpHypervisorRunTime				= 2,
+	VpRemoteNodeRunTime				= 3,
+	VpNormalizedRunTime				= 4,
+	VpIdealCpu					= 5,
+	VpHypercallsCount				= 7,
+	VpHypercallsTime				= 8,
+#if IS_ENABLED(CONFIG_X86_64)
+	VpPageInvalidationsCount			= 9,
+	VpPageInvalidationsTime				= 10,
+	VpControlRegisterAccessesCount			= 11,
+	VpControlRegisterAccessesTime			= 12,
+	VpIoInstructionsCount				= 13,
+	VpIoInstructionsTime				= 14,
+	VpHltInstructionsCount				= 15,
+	VpHltInstructionsTime				= 16,
+	VpMwaitInstructionsCount			= 17,
+	VpMwaitInstructionsTime				= 18,
+	VpCpuidInstructionsCount			= 19,
+	VpCpuidInstructionsTime				= 20,
+	VpMsrAccessesCount				= 21,
+	VpMsrAccessesTime				= 22,
+	VpOtherInterceptsCount				= 23,
+	VpOtherInterceptsTime				= 24,
+	VpExternalInterruptsCount			= 25,
+	VpExternalInterruptsTime			= 26,
+	VpPendingInterruptsCount			= 27,
+	VpPendingInterruptsTime				= 28,
+	VpEmulatedInstructionsCount			= 29,
+	VpEmulatedInstructionsTime			= 30,
+	VpDebugRegisterAccessesCount			= 31,
+	VpDebugRegisterAccessesTime			= 32,
+	VpPageFaultInterceptsCount			= 33,
+	VpPageFaultInterceptsTime			= 34,
+	VpGuestPageTableMaps				= 35,
+	VpLargePageTlbFills				= 36,
+	VpSmallPageTlbFills				= 37,
+	VpReflectedGuestPageFaults			= 38,
+	VpApicMmioAccesses				= 39,
+	VpIoInterceptMessages				= 40,
+	VpMemoryInterceptMessages			= 41,
+	VpApicEoiAccesses				= 42,
+	VpOtherMessages					= 43,
+	VpPageTableAllocations				= 44,
+	VpLogicalProcessorMigrations			= 45,
+	VpAddressSpaceEvictions				= 46,
+	VpAddressSpaceSwitches				= 47,
+	VpAddressDomainFlushes				= 48,
+	VpAddressSpaceFlushes				= 49,
+	VpGlobalGvaRangeFlushes				= 50,
+	VpLocalGvaRangeFlushes				= 51,
+	VpPageTableEvictions				= 52,
+	VpPageTableReclamations				= 53,
+	VpPageTableResets				= 54,
+	VpPageTableValidations				= 55,
+	VpApicTprAccesses				= 56,
+	VpPageTableWriteIntercepts			= 57,
+	VpSyntheticInterrupts				= 58,
+	VpVirtualInterrupts				= 59,
+	VpApicIpisSent					= 60,
+	VpApicSelfIpisSent				= 61,
+	VpGpaSpaceHypercalls				= 62,
+	VpLogicalProcessorHypercalls			= 63,
+	VpLongSpinWaitHypercalls			= 64,
+	VpOtherHypercalls				= 65,
+	VpSyntheticInterruptHypercalls			= 66,
+	VpVirtualInterruptHypercalls			= 67,
+	VpVirtualMmuHypercalls				= 68,
+	VpVirtualProcessorHypercalls			= 69,
+	VpHardwareInterrupts				= 70,
+	VpNestedPageFaultInterceptsCount		= 71,
+	VpNestedPageFaultInterceptsTime			= 72,
+	VpPageScans					= 73,
+	VpLogicalProcessorDispatches			= 74,
+	VpWaitingForCpuTime				= 75,
+	VpExtendedHypercalls				= 76,
+	VpExtendedHypercallInterceptMessages		= 77,
+	VpMbecNestedPageTableSwitches			= 78,
+	VpOtherReflectedGuestExceptions			= 79,
+	VpGlobalIoTlbFlushes				= 80,
+	VpGlobalIoTlbFlushCost				= 81,
+	VpLocalIoTlbFlushes				= 82,
+	VpLocalIoTlbFlushCost				= 83,
+	VpHypercallsForwardedCount			= 84,
+	VpHypercallsForwardingTime			= 85,
+	VpPageInvalidationsForwardedCount		= 86,
+	VpPageInvalidationsForwardingTime		= 87,
+	VpControlRegisterAccessesForwardedCount		= 88,
+	VpControlRegisterAccessesForwardingTime		= 89,
+	VpIoInstructionsForwardedCount			= 90,
+	VpIoInstructionsForwardingTime			= 91,
+	VpHltInstructionsForwardedCount			= 92,
+	VpHltInstructionsForwardingTime			= 93,
+	VpMwaitInstructionsForwardedCount		= 94,
+	VpMwaitInstructionsForwardingTime		= 95,
+	VpCpuidInstructionsForwardedCount		= 96,
+	VpCpuidInstructionsForwardingTime		= 97,
+	VpMsrAccessesForwardedCount			= 98,
+	VpMsrAccessesForwardingTime			= 99,
+	VpOtherInterceptsForwardedCount			= 100,
+	VpOtherInterceptsForwardingTime			= 101,
+	VpExternalInterruptsForwardedCount		= 102,
+	VpExternalInterruptsForwardingTime		= 103,
+	VpPendingInterruptsForwardedCount		= 104,
+	VpPendingInterruptsForwardingTime		= 105,
+	VpEmulatedInstructionsForwardedCount		= 106,
+	VpEmulatedInstructionsForwardingTime		= 107,
+	VpDebugRegisterAccessesForwardedCount		= 108,
+	VpDebugRegisterAccessesForwardingTime		= 109,
+	VpPageFaultInterceptsForwardedCount		= 110,
+	VpPageFaultInterceptsForwardingTime		= 111,
+	VpVmclearEmulationCount				= 112,
+	VpVmclearEmulationTime				= 113,
+	VpVmptrldEmulationCount				= 114,
+	VpVmptrldEmulationTime				= 115,
+	VpVmptrstEmulationCount				= 116,
+	VpVmptrstEmulationTime				= 117,
+	VpVmreadEmulationCount				= 118,
+	VpVmreadEmulationTime				= 119,
+	VpVmwriteEmulationCount				= 120,
+	VpVmwriteEmulationTime				= 121,
+	VpVmxoffEmulationCount				= 122,
+	VpVmxoffEmulationTime				= 123,
+	VpVmxonEmulationCount				= 124,
+	VpVmxonEmulationTime				= 125,
+	VpNestedVMEntriesCount				= 126,
+	VpNestedVMEntriesTime				= 127,
+	VpNestedSLATSoftPageFaultsCount			= 128,
+	VpNestedSLATSoftPageFaultsTime			= 129,
+	VpNestedSLATHardPageFaultsCount			= 130,
+	VpNestedSLATHardPageFaultsTime			= 131,
+	VpInvEptAllContextEmulationCount		= 132,
+	VpInvEptAllContextEmulationTime			= 133,
+	VpInvEptSingleContextEmulationCount		= 134,
+	VpInvEptSingleContextEmulationTime		= 135,
+	VpInvVpidAllContextEmulationCount		= 136,
+	VpInvVpidAllContextEmulationTime		= 137,
+	VpInvVpidSingleContextEmulationCount		= 138,
+	VpInvVpidSingleContextEmulationTime		= 139,
+	VpInvVpidSingleAddressEmulationCount		= 140,
+	VpInvVpidSingleAddressEmulationTime		= 141,
+	VpNestedTlbPageTableReclamations		= 142,
+	VpNestedTlbPageTableEvictions			= 143,
+	VpFlushGuestPhysicalAddressSpaceHypercalls	= 144,
+	VpFlushGuestPhysicalAddressListHypercalls	= 145,
+	VpPostedInterruptNotifications			= 146,
+	VpPostedInterruptScans				= 147,
+	VpTotalCoreRunTime				= 148,
+	VpMaximumRunTime				= 149,
+	VpHwpRequestContextSwitches			= 150,
+	VpWaitingForCpuTimeBucket0			= 151,
+	VpWaitingForCpuTimeBucket1			= 152,
+	VpWaitingForCpuTimeBucket2			= 153,
+	VpWaitingForCpuTimeBucket3			= 154,
+	VpWaitingForCpuTimeBucket4			= 155,
+	VpWaitingForCpuTimeBucket5			= 156,
+	VpWaitingForCpuTimeBucket6			= 157,
+	VpVmloadEmulationCount				= 158,
+	VpVmloadEmulationTime				= 159,
+	VpVmsaveEmulationCount				= 160,
+	VpVmsaveEmulationTime				= 161,
+	VpGifInstructionEmulationCount			= 162,
+	VpGifInstructionEmulationTime			= 163,
+	VpEmulatedErrataSvmInstructions			= 164,
+	VpPlaceholder1					= 165,
+	VpPlaceholder2					= 166,
+	VpPlaceholder3					= 167,
+	VpPlaceholder4					= 168,
+	VpPlaceholder5					= 169,
+	VpPlaceholder6					= 170,
+	VpPlaceholder7					= 171,
+	VpPlaceholder8					= 172,
+	VpPlaceholder9					= 173,
+	VpPlaceholder10					= 174,
+	VpSchedulingPriority				= 175,
+	VpRdpmcInstructionsCount			= 176,
+	VpRdpmcInstructionsTime				= 177,
+	VpPerfmonPmuMsrAccessesCount			= 178,
+	VpPerfmonLbrMsrAccessesCount			= 179,
+	VpPerfmonIptMsrAccessesCount			= 180,
+	VpPerfmonInterruptCount				= 181,
+	VpVtl1DispatchCount				= 182,
+	VpVtl2DispatchCount				= 183,
+	VpVtl2DispatchBucket0				= 184,
+	VpVtl2DispatchBucket1				= 185,
+	VpVtl2DispatchBucket2				= 186,
+	VpVtl2DispatchBucket3				= 187,
+	VpVtl2DispatchBucket4				= 188,
+	VpVtl2DispatchBucket5				= 189,
+	VpVtl2DispatchBucket6				= 190,
+	VpVtl1RunTime					= 191,
+	VpVtl2RunTime					= 192,
+	VpIommuHypercalls				= 193,
+	VpCpuGroupHypercalls				= 194,
+	VpVsmHypercalls					= 195,
+	VpEventLogHypercalls				= 196,
+	VpDeviceDomainHypercalls			= 197,
+	VpDepositHypercalls				= 198,
+	VpSvmHypercalls					= 199,
+	VpBusLockAcquisitionCount			= 200,
+	VpLoadAvg					= 201,
+	VpRootDispatchThreadBlocked			= 202,
+#elif IS_ENABLED(CONFIG_ARM64)
+	VpSysRegAccessesCount				= 9,
+	VpSysRegAccessesTime				= 10,
+	VpSmcInstructionsCount				= 11,
+	VpSmcInstructionsTime				= 12,
+	VpOtherInterceptsCount				= 13,
+	VpOtherInterceptsTime				= 14,
+	VpExternalInterruptsCount			= 15,
+	VpExternalInterruptsTime			= 16,
+	VpPendingInterruptsCount			= 17,
+	VpPendingInterruptsTime				= 18,
+	VpGuestPageTableMaps				= 19,
+	VpLargePageTlbFills				= 20,
+	VpSmallPageTlbFills				= 21,
+	VpReflectedGuestPageFaults			= 22,
+	VpMemoryInterceptMessages			= 23,
+	VpOtherMessages					= 24,
+	VpLogicalProcessorMigrations			= 25,
+	VpAddressDomainFlushes				= 26,
+	VpAddressSpaceFlushes				= 27,
+	VpSyntheticInterrupts				= 28,
+	VpVirtualInterrupts				= 29,
+	VpApicSelfIpisSent				= 30,
+	VpGpaSpaceHypercalls				= 31,
+	VpLogicalProcessorHypercalls			= 32,
+	VpLongSpinWaitHypercalls			= 33,
+	VpOtherHypercalls				= 34,
+	VpSyntheticInterruptHypercalls			= 35,
+	VpVirtualInterruptHypercalls			= 36,
+	VpVirtualMmuHypercalls				= 37,
+	VpVirtualProcessorHypercalls			= 38,
+	VpHardwareInterrupts				= 39,
+	VpNestedPageFaultInterceptsCount		= 40,
+	VpNestedPageFaultInterceptsTime			= 41,
+	VpLogicalProcessorDispatches			= 42,
+	VpWaitingForCpuTime				= 43,
+	VpExtendedHypercalls				= 44,
+	VpExtendedHypercallInterceptMessages		= 45,
+	VpMbecNestedPageTableSwitches			= 46,
+	VpOtherReflectedGuestExceptions			= 47,
+	VpGlobalIoTlbFlushes				= 48,
+	VpGlobalIoTlbFlushCost				= 49,
+	VpLocalIoTlbFlushes				= 50,
+	VpLocalIoTlbFlushCost				= 51,
+	VpFlushGuestPhysicalAddressSpaceHypercalls	= 52,
+	VpFlushGuestPhysicalAddressListHypercalls	= 53,
+	VpPostedInterruptNotifications			= 54,
+	VpPostedInterruptScans				= 55,
+	VpTotalCoreRunTime				= 56,
+	VpMaximumRunTime				= 57,
+	VpWaitingForCpuTimeBucket0			= 58,
+	VpWaitingForCpuTimeBucket1			= 59,
+	VpWaitingForCpuTimeBucket2			= 60,
+	VpWaitingForCpuTimeBucket3			= 61,
+	VpWaitingForCpuTimeBucket4			= 62,
+	VpWaitingForCpuTimeBucket5			= 63,
+	VpWaitingForCpuTimeBucket6			= 64,
+	VpHwpRequestContextSwitches			= 65,
+	VpPlaceholder2					= 66,
+	VpPlaceholder3					= 67,
+	VpPlaceholder4					= 68,
+	VpPlaceholder5					= 69,
+	VpPlaceholder6					= 70,
+	VpPlaceholder7					= 71,
+	VpPlaceholder8					= 72,
+	VpContentionTime				= 73,
+	VpWakeUpTime					= 74,
+	VpSchedulingPriority				= 75,
+	VpVtl1DispatchCount				= 76,
+	VpVtl2DispatchCount				= 77,
+	VpVtl2DispatchBucket0				= 78,
+	VpVtl2DispatchBucket1				= 79,
+	VpVtl2DispatchBucket2				= 80,
+	VpVtl2DispatchBucket3				= 81,
+	VpVtl2DispatchBucket4				= 82,
+	VpVtl2DispatchBucket5				= 83,
+	VpVtl2DispatchBucket6				= 84,
+	VpVtl1RunTime					= 85,
+	VpVtl2RunTime					= 86,
+	VpIommuHypercalls				= 87,
+	VpCpuGroupHypercalls				= 88,
+	VpVsmHypercalls					= 89,
+	VpEventLogHypercalls				= 90,
+	VpDeviceDomainHypercalls			= 91,
+	VpDepositHypercalls				= 92,
+	VpSvmHypercalls					= 93,
+	VpLoadAvg					= 94,
+	VpRootDispatchThreadBlocked			= 95,
+#endif
+	VpStatsMaxCounter
+};
+
+enum hv_stats_lp_counters {			/* HV_CPU_COUNTER */
+	LpGlobalTime				= 1,
+	LpTotalRunTime				= 2,
+	LpHypervisorRunTime			= 3,
+	LpHardwareInterrupts			= 4,
+	LpContextSwitches			= 5,
+	LpInterProcessorInterrupts		= 6,
+	LpSchedulerInterrupts			= 7,
+	LpTimerInterrupts			= 8,
+	LpInterProcessorInterruptsSent		= 9,
+	LpProcessorHalts			= 10,
+	LpMonitorTransitionCost			= 11,
+	LpContextSwitchTime			= 12,
+	LpC1TransitionsCount			= 13,
+	LpC1RunTime				= 14,
+	LpC2TransitionsCount			= 15,
+	LpC2RunTime				= 16,
+	LpC3TransitionsCount			= 17,
+	LpC3RunTime				= 18,
+	LpRootVpIndex				= 19,
+	LpIdleSequenceNumber			= 20,
+	LpGlobalTscCount			= 21,
+	LpActiveTscCount			= 22,
+	LpIdleAccumulation			= 23,
+	LpReferenceCycleCount0			= 24,
+	LpActualCycleCount0			= 25,
+	LpReferenceCycleCount1			= 26,
+	LpActualCycleCount1			= 27,
+	LpProximityDomainId			= 28,
+	LpPostedInterruptNotifications		= 29,
+	LpBranchPredictorFlushes		= 30,
+#if IS_ENABLED(CONFIG_X86_64)
+	LpL1DataCacheFlushes			= 31,
+	LpImmediateL1DataCacheFlushes		= 32,
+	LpMbFlushes				= 33,
+	LpCounterRefreshSequenceNumber		= 34,
+	LpCounterRefreshReferenceTime		= 35,
+	LpIdleAccumulationSnapshot		= 36,
+	LpActiveTscCountSnapshot		= 37,
+	LpHwpRequestContextSwitches		= 38,
+	LpPlaceholder1				= 39,
+	LpPlaceholder2				= 40,
+	LpPlaceholder3				= 41,
+	LpPlaceholder4				= 42,
+	LpPlaceholder5				= 43,
+	LpPlaceholder6				= 44,
+	LpPlaceholder7				= 45,
+	LpPlaceholder8				= 46,
+	LpPlaceholder9				= 47,
+	LpPlaceholder10				= 48,
+	LpReserveGroupId			= 49,
+	LpRunningPriority			= 50,
+	LpPerfmonInterruptCount			= 51,
+#elif IS_ENABLED(CONFIG_ARM64)
+	LpCounterRefreshSequenceNumber		= 31,
+	LpCounterRefreshReferenceTime		= 32,
+	LpIdleAccumulationSnapshot		= 33,
+	LpActiveTscCountSnapshot		= 34,
+	LpHwpRequestContextSwitches		= 35,
+	LpPlaceholder2				= 36,
+	LpPlaceholder3				= 37,
+	LpPlaceholder4				= 38,
+	LpPlaceholder5				= 39,
+	LpPlaceholder6				= 40,
+	LpPlaceholder7				= 41,
+	LpPlaceholder8				= 42,
+	LpPlaceholder9				= 43,
+	LpSchLocalRunListSize			= 44,
+	LpReserveGroupId			= 45,
+	LpRunningPriority			= 46,
+#endif
+	LpStatsMaxCounter
Quoted 8 lines

include/hyperv/hvhdk.h

Quoted 8 lines
include/hyperv/hvhdk.h +8 -0
+};
+
+/*
+ * Hypervisor statistics page format
+ */
+struct hv_stats_page {
+	union {
+		u64 hv_cntrs[HvStatsMaxCounter];		/* Hypervisor counters

*/

Quoted 1 line

include/hyperv/hvhdk.h line 443

Quoted 1 line
include/hyperv/hvhdk.h +1 -0
+		u64 pt_cntrs[PartitionStatsMaxCounter];		/* Partition

counters */

Quoted 11 lines
Quoted 11 lines
include/hyperv/hvhdk.h +6 -1
+		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
+		u64 lp_cntrs[LpStatsMaxCounter];		/* LP counters */
+		u8 data[HV_HYP_PAGE_SIZE];
+	};
+} __packed;
+
 /* Bits for dirty mask of hv_vp_register_page */
 #define HV_X64_REGISTER_CLASS_GENERAL	0
 #define HV_X64_REGISTER_CLASS_IP	1
--

2.34.1

#10 lore raw

Re: [PATCH v3 5/6] mshv: Add definitions for stats pages

In reply to Nuno Das Neves
Quoted 13 lines · Nuno Das Neves
Quoted 11 lines · Stanislav Kinsburskii
Quoted 3 lines · Nuno Das Neves

Add the definitions for hypervisor, logical processor, and partition stats pages.

The definitions in for partition and virtual processor are outdated. Now is the good time to sync the new values in.

Thanks,
Stanislav

Quoted 7 lines

Good point, thanks, I will update it for v4.

I'm finally noticing that these counters are not really from hvhdk.h, in the windows code, but their own file. Since I'm still iterating on this, what do you think about creating a file just for the counters? e.g. drivers/hv/hvcounters.h, which combines hvcountersarm64 and amd64.

I don't have a preference as I personanly think the the while idea of keeping the headers in sync with Windows naming scheme isn't great, but if you think it makes sense, go ahead.

Quoted 67 lines

That would have a couple of advantages:
1. Not putting things in hvhdk.h which aren't actually there in the Windows source
2. Less visibility of CamelCase naming outside our driver
3. I could define the enums using "X macro"s to generate the show() code more cleanly in mshv_debugfs.c, which is something Michael suggested here:
https://lore.kernel.org/linux-hyperv/SN6PR02MB4157938404BC0D12978ACD9BD4A2A@SN6PR02MB4157.namprd02.prod.outlook.com/

It would look something like this:

In hvcounters.h:

#if is_enabled(CONFIG_X86_64)

#define HV_COUNTER_VP_LIST(X) \
	X(VpTotalRunTime, 1), \
	X(VpHypervisorRunTime, 2), \
	X(VpRemoteNodeRunTime, 3), \

/* <snip> */

#elif is_enabled(CONFIG_ARM64)

/* <snip> */

#endif

Just like now, it's a copy/paste from Windows + simple pattern replacement. Note with this approach we need separate lists for arm64 and x86, but that matches how the enums are defined in Windows.

Then, in mshv_debugfs.c:

/*
* We need the strings paired with their enum values.
* This structure can be used for all the different stat types. */

struct hv_counter_entry {
	char *name;
	int idx;
};

/* Define an array entry (again, reusable) */

#define HV_COUNTER_LIST(name, idx) \
	{ __stringify(name), idx },

/* Create our static array */
static struct hv_counter_entry hv_counter_vp_array[] = {
HV_ST_COUNTER_VP(HV_COUNTER_VP)
};

static int vp_stats_show(struct seq_file *m, void *v)

{
	const struct hv_stats_page **pstats = m->private;
	int i;

	for (i = 0; i < ARRAY_SIZE(hv_counter_vp_array); ++i) {
		struct hv_counter_entry entry = hv_counter_vp_array[i];
		u64 parent_val = pstats[HV_STATS_AREA_PARENT]->vp_cntrs[entry.idx];
		u64 self_val = pstats[HV_STATS_AREA_SELF]->vp_cntrs[entry.idx];

		/* Prioritize the PARENT area value */
		seq_printf(m, "%-30s: %llu\n", entry.name,
			   parent_val ? parent_val : self_val);
	}
}
Quoted 4 lines

Any thoughts? I was originally going to just go with the pattern we had, but since these definitions aren't from the hv*dk.h files, we can maybe get more creative and make the resulting code look a bit better.

Looks good to me.

Thanks,
Stanislav

Quoted 497 lines

Thanks
Nuno

Quoted 494 lines
Quoted 494 lines

Move the definition for the VP stats page to its rightful place in hvhdk.h, and add the missing members.

While at it, correct the ARM64 value of VpRootDispatchThreadBlocked, (which is not yet used, so there is no impact).

These enum members retain their CamelCase style, since they are imported directly from the hypervisor code. They will be stringified when printing the stats out, and retain more readability in this form.

---
 drivers/hv/mshv_root_main.c |  17 --
 include/hyperv/hvhdk.h      | 437 ++++++++++++++++++++++++++++++++++++
 2 files changed, 437 insertions(+), 17 deletions(-)
drivers/hv/mshv_root_main.c +0 -17
index fbfc9e7d9fa4..724bbaa0b08c 100644
@@ -39,23 +39,6 @@ MODULE_AUTHOR("Microsoft");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Microsoft Hyper-V root partition VMM interface /dev/mshv");
 
-/* TODO move this to another file when debugfs code is added */
-enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
-#if defined(CONFIG_X86)
-	VpRootDispatchThreadBlocked			= 202,
-#elif defined(CONFIG_ARM64)
-	VpRootDispatchThreadBlocked			= 94,
-#endif
-	VpStatsMaxCounter
-};
-
-struct hv_stats_page {
-	union {
-		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
-		u8 data[HV_HYP_PAGE_SIZE];
-	};
-} __packed;
-
 struct mshv_root mshv_root;
 
 enum hv_scheduler_type hv_scheduler_type;
include/hyperv/hvhdk.h +437 -0
index 469186df7826..8bddd11feeba 100644
@@ -10,6 +10,443 @@
 #include "hvhdk_mini.h"
 #include "hvgdk.h"
 
+enum hv_stats_hypervisor_counters {		/* HV_HYPERVISOR_COUNTER */
+	HvLogicalProcessors			= 1,
+	HvPartitions				= 2,
+	HvTotalPages				= 3,
+	HvVirtualProcessors			= 4,
+	HvMonitoredNotifications		= 5,
+	HvModernStandbyEntries			= 6,
+	HvPlatformIdleTransitions		= 7,
+	HvHypervisorStartupCost			= 8,
+	HvIOSpacePages				= 10,
+	HvNonEssentialPagesForDump		= 11,
+	HvSubsumedPages				= 12,
+	HvStatsMaxCounter
+};
+
+enum hv_stats_partition_counters {		/* HV_PROCESS_COUNTER */
+	PartitionVirtualProcessors		= 1,
+	PartitionTlbSize			= 3,
+	PartitionAddressSpaces			= 4,
+	PartitionDepositedPages			= 5,
+	PartitionGpaPages			= 6,
+	PartitionGpaSpaceModifications		= 7,
+	PartitionVirtualTlbFlushEntires		= 8,
+	PartitionRecommendedTlbSize		= 9,
+	PartitionGpaPages4K			= 10,
+	PartitionGpaPages2M			= 11,
+	PartitionGpaPages1G			= 12,
+	PartitionGpaPages512G			= 13,
+	PartitionDevicePages4K			= 14,
+	PartitionDevicePages2M			= 15,
+	PartitionDevicePages1G			= 16,
+	PartitionDevicePages512G		= 17,
+	PartitionAttachedDevices		= 18,
+	PartitionDeviceInterruptMappings	= 19,
+	PartitionIoTlbFlushes			= 20,
+	PartitionIoTlbFlushCost			= 21,
+	PartitionDeviceInterruptErrors		= 22,
+	PartitionDeviceDmaErrors		= 23,
+	PartitionDeviceInterruptThrottleEvents	= 24,
+	PartitionSkippedTimerTicks		= 25,
+	PartitionPartitionId			= 26,
+#if IS_ENABLED(CONFIG_X86_64)
+	PartitionNestedTlbSize			= 27,
+	PartitionRecommendedNestedTlbSize	= 28,
+	PartitionNestedTlbFreeListSize		= 29,
+	PartitionNestedTlbTrimmedPages		= 30,
+	PartitionPagesShattered			= 31,
+	PartitionPagesRecombined		= 32,
+	PartitionHwpRequestValue		= 33,
+#elif IS_ENABLED(CONFIG_ARM64)
+	PartitionHwpRequestValue		= 27,
+#endif
+	PartitionStatsMaxCounter
+};
+
+enum hv_stats_vp_counters {			/* HV_THREAD_COUNTER */
+	VpTotalRunTime					= 1,
+	VpHypervisorRunTime				= 2,
+	VpRemoteNodeRunTime				= 3,
+	VpNormalizedRunTime				= 4,
+	VpIdealCpu					= 5,
+	VpHypercallsCount				= 7,
+	VpHypercallsTime				= 8,
+#if IS_ENABLED(CONFIG_X86_64)
+	VpPageInvalidationsCount			= 9,
+	VpPageInvalidationsTime				= 10,
+	VpControlRegisterAccessesCount			= 11,
+	VpControlRegisterAccessesTime			= 12,
+	VpIoInstructionsCount				= 13,
+	VpIoInstructionsTime				= 14,
+	VpHltInstructionsCount				= 15,
+	VpHltInstructionsTime				= 16,
+	VpMwaitInstructionsCount			= 17,
+	VpMwaitInstructionsTime				= 18,
+	VpCpuidInstructionsCount			= 19,
+	VpCpuidInstructionsTime				= 20,
+	VpMsrAccessesCount				= 21,
+	VpMsrAccessesTime				= 22,
+	VpOtherInterceptsCount				= 23,
+	VpOtherInterceptsTime				= 24,
+	VpExternalInterruptsCount			= 25,
+	VpExternalInterruptsTime			= 26,
+	VpPendingInterruptsCount			= 27,
+	VpPendingInterruptsTime				= 28,
+	VpEmulatedInstructionsCount			= 29,
+	VpEmulatedInstructionsTime			= 30,
+	VpDebugRegisterAccessesCount			= 31,
+	VpDebugRegisterAccessesTime			= 32,
+	VpPageFaultInterceptsCount			= 33,
+	VpPageFaultInterceptsTime			= 34,
+	VpGuestPageTableMaps				= 35,
+	VpLargePageTlbFills				= 36,
+	VpSmallPageTlbFills				= 37,
+	VpReflectedGuestPageFaults			= 38,
+	VpApicMmioAccesses				= 39,
+	VpIoInterceptMessages				= 40,
+	VpMemoryInterceptMessages			= 41,
+	VpApicEoiAccesses				= 42,
+	VpOtherMessages					= 43,
+	VpPageTableAllocations				= 44,
+	VpLogicalProcessorMigrations			= 45,
+	VpAddressSpaceEvictions				= 46,
+	VpAddressSpaceSwitches				= 47,
+	VpAddressDomainFlushes				= 48,
+	VpAddressSpaceFlushes				= 49,
+	VpGlobalGvaRangeFlushes				= 50,
+	VpLocalGvaRangeFlushes				= 51,
+	VpPageTableEvictions				= 52,
+	VpPageTableReclamations				= 53,
+	VpPageTableResets				= 54,
+	VpPageTableValidations				= 55,
+	VpApicTprAccesses				= 56,
+	VpPageTableWriteIntercepts			= 57,
+	VpSyntheticInterrupts				= 58,
+	VpVirtualInterrupts				= 59,
+	VpApicIpisSent					= 60,
+	VpApicSelfIpisSent				= 61,
+	VpGpaSpaceHypercalls				= 62,
+	VpLogicalProcessorHypercalls			= 63,
+	VpLongSpinWaitHypercalls			= 64,
+	VpOtherHypercalls				= 65,
+	VpSyntheticInterruptHypercalls			= 66,
+	VpVirtualInterruptHypercalls			= 67,
+	VpVirtualMmuHypercalls				= 68,
+	VpVirtualProcessorHypercalls			= 69,
+	VpHardwareInterrupts				= 70,
+	VpNestedPageFaultInterceptsCount		= 71,
+	VpNestedPageFaultInterceptsTime			= 72,
+	VpPageScans					= 73,
+	VpLogicalProcessorDispatches			= 74,
+	VpWaitingForCpuTime				= 75,
+	VpExtendedHypercalls				= 76,
+	VpExtendedHypercallInterceptMessages		= 77,
+	VpMbecNestedPageTableSwitches			= 78,
+	VpOtherReflectedGuestExceptions			= 79,
+	VpGlobalIoTlbFlushes				= 80,
+	VpGlobalIoTlbFlushCost				= 81,
+	VpLocalIoTlbFlushes				= 82,
+	VpLocalIoTlbFlushCost				= 83,
+	VpHypercallsForwardedCount			= 84,
+	VpHypercallsForwardingTime			= 85,
+	VpPageInvalidationsForwardedCount		= 86,
+	VpPageInvalidationsForwardingTime		= 87,
+	VpControlRegisterAccessesForwardedCount		= 88,
+	VpControlRegisterAccessesForwardingTime		= 89,
+	VpIoInstructionsForwardedCount			= 90,
+	VpIoInstructionsForwardingTime			= 91,
+	VpHltInstructionsForwardedCount			= 92,
+	VpHltInstructionsForwardingTime			= 93,
+	VpMwaitInstructionsForwardedCount		= 94,
+	VpMwaitInstructionsForwardingTime		= 95,
+	VpCpuidInstructionsForwardedCount		= 96,
+	VpCpuidInstructionsForwardingTime		= 97,
+	VpMsrAccessesForwardedCount			= 98,
+	VpMsrAccessesForwardingTime			= 99,
+	VpOtherInterceptsForwardedCount			= 100,
+	VpOtherInterceptsForwardingTime			= 101,
+	VpExternalInterruptsForwardedCount		= 102,
+	VpExternalInterruptsForwardingTime		= 103,
+	VpPendingInterruptsForwardedCount		= 104,
+	VpPendingInterruptsForwardingTime		= 105,
+	VpEmulatedInstructionsForwardedCount		= 106,
+	VpEmulatedInstructionsForwardingTime		= 107,
+	VpDebugRegisterAccessesForwardedCount		= 108,
+	VpDebugRegisterAccessesForwardingTime		= 109,
+	VpPageFaultInterceptsForwardedCount		= 110,
+	VpPageFaultInterceptsForwardingTime		= 111,
+	VpVmclearEmulationCount				= 112,
+	VpVmclearEmulationTime				= 113,
+	VpVmptrldEmulationCount				= 114,
+	VpVmptrldEmulationTime				= 115,
+	VpVmptrstEmulationCount				= 116,
+	VpVmptrstEmulationTime				= 117,
+	VpVmreadEmulationCount				= 118,
+	VpVmreadEmulationTime				= 119,
+	VpVmwriteEmulationCount				= 120,
+	VpVmwriteEmulationTime				= 121,
+	VpVmxoffEmulationCount				= 122,
+	VpVmxoffEmulationTime				= 123,
+	VpVmxonEmulationCount				= 124,
+	VpVmxonEmulationTime				= 125,
+	VpNestedVMEntriesCount				= 126,
+	VpNestedVMEntriesTime				= 127,
+	VpNestedSLATSoftPageFaultsCount			= 128,
+	VpNestedSLATSoftPageFaultsTime			= 129,
+	VpNestedSLATHardPageFaultsCount			= 130,
+	VpNestedSLATHardPageFaultsTime			= 131,
+	VpInvEptAllContextEmulationCount		= 132,
+	VpInvEptAllContextEmulationTime			= 133,
+	VpInvEptSingleContextEmulationCount		= 134,
+	VpInvEptSingleContextEmulationTime		= 135,
+	VpInvVpidAllContextEmulationCount		= 136,
+	VpInvVpidAllContextEmulationTime		= 137,
+	VpInvVpidSingleContextEmulationCount		= 138,
+	VpInvVpidSingleContextEmulationTime		= 139,
+	VpInvVpidSingleAddressEmulationCount		= 140,
+	VpInvVpidSingleAddressEmulationTime		= 141,
+	VpNestedTlbPageTableReclamations		= 142,
+	VpNestedTlbPageTableEvictions			= 143,
+	VpFlushGuestPhysicalAddressSpaceHypercalls	= 144,
+	VpFlushGuestPhysicalAddressListHypercalls	= 145,
+	VpPostedInterruptNotifications			= 146,
+	VpPostedInterruptScans				= 147,
+	VpTotalCoreRunTime				= 148,
+	VpMaximumRunTime				= 149,
+	VpHwpRequestContextSwitches			= 150,
+	VpWaitingForCpuTimeBucket0			= 151,
+	VpWaitingForCpuTimeBucket1			= 152,
+	VpWaitingForCpuTimeBucket2			= 153,
+	VpWaitingForCpuTimeBucket3			= 154,
+	VpWaitingForCpuTimeBucket4			= 155,
+	VpWaitingForCpuTimeBucket5			= 156,
+	VpWaitingForCpuTimeBucket6			= 157,
+	VpVmloadEmulationCount				= 158,
+	VpVmloadEmulationTime				= 159,
+	VpVmsaveEmulationCount				= 160,
+	VpVmsaveEmulationTime				= 161,
+	VpGifInstructionEmulationCount			= 162,
+	VpGifInstructionEmulationTime			= 163,
+	VpEmulatedErrataSvmInstructions			= 164,
+	VpPlaceholder1					= 165,
+	VpPlaceholder2					= 166,
+	VpPlaceholder3					= 167,
+	VpPlaceholder4					= 168,
+	VpPlaceholder5					= 169,
+	VpPlaceholder6					= 170,
+	VpPlaceholder7					= 171,
+	VpPlaceholder8					= 172,
+	VpPlaceholder9					= 173,
+	VpPlaceholder10					= 174,
+	VpSchedulingPriority				= 175,
+	VpRdpmcInstructionsCount			= 176,
+	VpRdpmcInstructionsTime				= 177,
+	VpPerfmonPmuMsrAccessesCount			= 178,
+	VpPerfmonLbrMsrAccessesCount			= 179,
+	VpPerfmonIptMsrAccessesCount			= 180,
+	VpPerfmonInterruptCount				= 181,
+	VpVtl1DispatchCount				= 182,
+	VpVtl2DispatchCount				= 183,
+	VpVtl2DispatchBucket0				= 184,
+	VpVtl2DispatchBucket1				= 185,
+	VpVtl2DispatchBucket2				= 186,
+	VpVtl2DispatchBucket3				= 187,
+	VpVtl2DispatchBucket4				= 188,
+	VpVtl2DispatchBucket5				= 189,
+	VpVtl2DispatchBucket6				= 190,
+	VpVtl1RunTime					= 191,
+	VpVtl2RunTime					= 192,
+	VpIommuHypercalls				= 193,
+	VpCpuGroupHypercalls				= 194,
+	VpVsmHypercalls					= 195,
+	VpEventLogHypercalls				= 196,
+	VpDeviceDomainHypercalls			= 197,
+	VpDepositHypercalls				= 198,
+	VpSvmHypercalls					= 199,
+	VpBusLockAcquisitionCount			= 200,
+	VpLoadAvg					= 201,
+	VpRootDispatchThreadBlocked			= 202,
+#elif IS_ENABLED(CONFIG_ARM64)
+	VpSysRegAccessesCount				= 9,
+	VpSysRegAccessesTime				= 10,
+	VpSmcInstructionsCount				= 11,
+	VpSmcInstructionsTime				= 12,
+	VpOtherInterceptsCount				= 13,
+	VpOtherInterceptsTime				= 14,
+	VpExternalInterruptsCount			= 15,
+	VpExternalInterruptsTime			= 16,
+	VpPendingInterruptsCount			= 17,
+	VpPendingInterruptsTime				= 18,
+	VpGuestPageTableMaps				= 19,
+	VpLargePageTlbFills				= 20,
+	VpSmallPageTlbFills				= 21,
+	VpReflectedGuestPageFaults			= 22,
+	VpMemoryInterceptMessages			= 23,
+	VpOtherMessages					= 24,
+	VpLogicalProcessorMigrations			= 25,
+	VpAddressDomainFlushes				= 26,
+	VpAddressSpaceFlushes				= 27,
+	VpSyntheticInterrupts				= 28,
+	VpVirtualInterrupts				= 29,
+	VpApicSelfIpisSent				= 30,
+	VpGpaSpaceHypercalls				= 31,
+	VpLogicalProcessorHypercalls			= 32,
+	VpLongSpinWaitHypercalls			= 33,
+	VpOtherHypercalls				= 34,
+	VpSyntheticInterruptHypercalls			= 35,
+	VpVirtualInterruptHypercalls			= 36,
+	VpVirtualMmuHypercalls				= 37,
+	VpVirtualProcessorHypercalls			= 38,
+	VpHardwareInterrupts				= 39,
+	VpNestedPageFaultInterceptsCount		= 40,
+	VpNestedPageFaultInterceptsTime			= 41,
+	VpLogicalProcessorDispatches			= 42,
+	VpWaitingForCpuTime				= 43,
+	VpExtendedHypercalls				= 44,
+	VpExtendedHypercallInterceptMessages		= 45,
+	VpMbecNestedPageTableSwitches			= 46,
+	VpOtherReflectedGuestExceptions			= 47,
+	VpGlobalIoTlbFlushes				= 48,
+	VpGlobalIoTlbFlushCost				= 49,
+	VpLocalIoTlbFlushes				= 50,
+	VpLocalIoTlbFlushCost				= 51,
+	VpFlushGuestPhysicalAddressSpaceHypercalls	= 52,
+	VpFlushGuestPhysicalAddressListHypercalls	= 53,
+	VpPostedInterruptNotifications			= 54,
+	VpPostedInterruptScans				= 55,
+	VpTotalCoreRunTime				= 56,
+	VpMaximumRunTime				= 57,
+	VpWaitingForCpuTimeBucket0			= 58,
+	VpWaitingForCpuTimeBucket1			= 59,
+	VpWaitingForCpuTimeBucket2			= 60,
+	VpWaitingForCpuTimeBucket3			= 61,
+	VpWaitingForCpuTimeBucket4			= 62,
+	VpWaitingForCpuTimeBucket5			= 63,
+	VpWaitingForCpuTimeBucket6			= 64,
+	VpHwpRequestContextSwitches			= 65,
+	VpPlaceholder2					= 66,
+	VpPlaceholder3					= 67,
+	VpPlaceholder4					= 68,
+	VpPlaceholder5					= 69,
+	VpPlaceholder6					= 70,
+	VpPlaceholder7					= 71,
+	VpPlaceholder8					= 72,
+	VpContentionTime				= 73,
+	VpWakeUpTime					= 74,
+	VpSchedulingPriority				= 75,
+	VpVtl1DispatchCount				= 76,
+	VpVtl2DispatchCount				= 77,
+	VpVtl2DispatchBucket0				= 78,
+	VpVtl2DispatchBucket1				= 79,
+	VpVtl2DispatchBucket2				= 80,
+	VpVtl2DispatchBucket3				= 81,
+	VpVtl2DispatchBucket4				= 82,
+	VpVtl2DispatchBucket5				= 83,
+	VpVtl2DispatchBucket6				= 84,
+	VpVtl1RunTime					= 85,
+	VpVtl2RunTime					= 86,
+	VpIommuHypercalls				= 87,
+	VpCpuGroupHypercalls				= 88,
+	VpVsmHypercalls					= 89,
+	VpEventLogHypercalls				= 90,
+	VpDeviceDomainHypercalls			= 91,
+	VpDepositHypercalls				= 92,
+	VpSvmHypercalls					= 93,
+	VpLoadAvg					= 94,
+	VpRootDispatchThreadBlocked			= 95,
+#endif
+	VpStatsMaxCounter
+};
+
+enum hv_stats_lp_counters {			/* HV_CPU_COUNTER */
+	LpGlobalTime				= 1,
+	LpTotalRunTime				= 2,
+	LpHypervisorRunTime			= 3,
+	LpHardwareInterrupts			= 4,
+	LpContextSwitches			= 5,
+	LpInterProcessorInterrupts		= 6,
+	LpSchedulerInterrupts			= 7,
+	LpTimerInterrupts			= 8,
+	LpInterProcessorInterruptsSent		= 9,
+	LpProcessorHalts			= 10,
+	LpMonitorTransitionCost			= 11,
+	LpContextSwitchTime			= 12,
+	LpC1TransitionsCount			= 13,
+	LpC1RunTime				= 14,
+	LpC2TransitionsCount			= 15,
+	LpC2RunTime				= 16,
+	LpC3TransitionsCount			= 17,
+	LpC3RunTime				= 18,
+	LpRootVpIndex				= 19,
+	LpIdleSequenceNumber			= 20,
+	LpGlobalTscCount			= 21,
+	LpActiveTscCount			= 22,
+	LpIdleAccumulation			= 23,
+	LpReferenceCycleCount0			= 24,
+	LpActualCycleCount0			= 25,
+	LpReferenceCycleCount1			= 26,
+	LpActualCycleCount1			= 27,
+	LpProximityDomainId			= 28,
+	LpPostedInterruptNotifications		= 29,
+	LpBranchPredictorFlushes		= 30,
+#if IS_ENABLED(CONFIG_X86_64)
+	LpL1DataCacheFlushes			= 31,
+	LpImmediateL1DataCacheFlushes		= 32,
+	LpMbFlushes				= 33,
+	LpCounterRefreshSequenceNumber		= 34,
+	LpCounterRefreshReferenceTime		= 35,
+	LpIdleAccumulationSnapshot		= 36,
+	LpActiveTscCountSnapshot		= 37,
+	LpHwpRequestContextSwitches		= 38,
+	LpPlaceholder1				= 39,
+	LpPlaceholder2				= 40,
+	LpPlaceholder3				= 41,
+	LpPlaceholder4				= 42,
+	LpPlaceholder5				= 43,
+	LpPlaceholder6				= 44,
+	LpPlaceholder7				= 45,
+	LpPlaceholder8				= 46,
+	LpPlaceholder9				= 47,
+	LpPlaceholder10				= 48,
+	LpReserveGroupId			= 49,
+	LpRunningPriority			= 50,
+	LpPerfmonInterruptCount			= 51,
+#elif IS_ENABLED(CONFIG_ARM64)
+	LpCounterRefreshSequenceNumber		= 31,
+	LpCounterRefreshReferenceTime		= 32,
+	LpIdleAccumulationSnapshot		= 33,
+	LpActiveTscCountSnapshot		= 34,
+	LpHwpRequestContextSwitches		= 35,
+	LpPlaceholder2				= 36,
+	LpPlaceholder3				= 37,
+	LpPlaceholder4				= 38,
+	LpPlaceholder5				= 39,
+	LpPlaceholder6				= 40,
+	LpPlaceholder7				= 41,
+	LpPlaceholder8				= 42,
+	LpPlaceholder9				= 43,
+	LpSchLocalRunListSize			= 44,
+	LpReserveGroupId			= 45,
+	LpRunningPriority			= 46,
+#endif
+	LpStatsMaxCounter
+};
+
+/*
+ * Hypervisor statistics page format
+ */
+struct hv_stats_page {
+	union {
+		u64 hv_cntrs[HvStatsMaxCounter];		/* Hypervisor counters */
+		u64 pt_cntrs[PartitionStatsMaxCounter];		/* Partition counters */
+		u64 vp_cntrs[VpStatsMaxCounter];		/* VP counters */
+		u64 lp_cntrs[LpStatsMaxCounter];		/* LP counters */
+		u8 data[HV_HYP_PAGE_SIZE];
+	};
+} __packed;
+
 /* Bits for dirty mask of hv_vp_register_page */
 #define HV_X64_REGISTER_CLASS_GENERAL	0
 #define HV_X64_REGISTER_CLASS_IP	1
Signature · 1 line
2.34.1
#11 lore raw

PATCH v3 6/6 mshv: Add debugfs to view hypervisor statistics

In reply to Nuno Das Neves

Introduce a debugfs interface to expose root and child partition stats when running with mshv_root.

Create a debugfs directory "mshv" containing 'stats' files organized by type and id. A stats file contains a number of counters depending on its type. e.g. an excerpt from a VP stats file:

TotalRunTime : 1997602722
HypervisorRunTime : 649671371
RemoteNodeRunTime : 0
NormalizedRunTime : 1997602721
IdealCpu : 0
HypercallsCount : 1708169
HypercallsTime : 111914774
PageInvalidationsCount : 0
PageInvalidationsTime : 0

On a root partition with some active child partitions, the entire directory structure may look like:

mshv/

  stats             # hypervisor stats
  lp/               # logical processors
    0/              # LP id
      stats         # LP 0 stats
    1/
    2/
    3/
  partition/        # partition stats
    1/              # root partition id
      stats         # root partition stats
      vp/           # root virtual processors
        0/          # root VP id
          stats     # root VP 0 stats
        1/
        2/
        3/
    42/             # child partition id
      stats         # child partition stats
      vp/           # child VPs
        0/          # child VP id
          stats     # child VP 0 stats
        1/
    43/
    55/

On L1VH, some stats are not present as it does not own the hardware like the root partition does:
- The hypervisor and lp stats are not present
- L1VH's partition directory is named "self" because it can't get its own id
- Some of L1VH's partition and VP stats fields are not populated, because it can't map its own HV_STATS_AREA_PARENT page.

---
 drivers/hv/Makefile         |    1 +
 drivers/hv/mshv_debugfs.c   | 1103 +++++++++++++++++++++++++++++++++++
 drivers/hv/mshv_root.h      |   34 ++
 drivers/hv/mshv_root_main.c |   26 +-
 4 files changed, 1162 insertions(+), 2 deletions(-)
 create mode 100644 drivers/hv/mshv_debugfs.c
drivers/hv/Makefile +1 -0
index a49f93c2d245..2593711c3628 100644
@@ -15,6 +15,7 @@ hv_vmbus-$(CONFIG_HYPERV_TESTING)	+= hv_debugfs.o
 hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_utils_transport.o
 mshv_root-y := mshv_root_main.o mshv_synic.o mshv_eventfd.o mshv_irq.o \
 	       mshv_root_hv_call.o mshv_portid_table.o mshv_regions.o
+mshv_root-$(CONFIG_DEBUG_FS) += mshv_debugfs.o
 mshv_vtl-y := mshv_vtl_main.o
 
 # Code that must be built-in
drivers/hv/mshv_debugfs.c new file +1103 -0

1,103 lines not on this page · raw message

drivers/hv/mshv_root.h +34 -0
index e4912b0618fa..7332d9af8373 100644
@@ -52,6 +52,9 @@ struct mshv_vp {
 		unsigned int kicked_by_hv;
 		wait_queue_head_t vp_suspend_queue;
 	} run;
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+	struct dentry *vp_stats_dentry;
+#endif
 };
 
 #define vp_fmt(fmt) "p%lluvp%u: " fmt
@@ -136,6 +139,10 @@ struct mshv_partition {
 	u64 isolation_type;
 	bool import_completed;
 	bool pt_initialized;
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+	struct dentry *pt_stats_dentry;
+	struct dentry *pt_vp_dentry;
+#endif
 };
 
 #define pt_fmt(fmt) "p%llu: " fmt
@@ -327,6 +334,33 @@ int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages,
 int hv_call_get_partition_property_ex(u64 partition_id, u64 property_code, u64 arg,
 				      void *property_value, size_t property_value_sz);
 
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+int __init mshv_debugfs_init(void);
+void mshv_debugfs_exit(void);
+
+int mshv_debugfs_partition_create(struct mshv_partition *partition);
+void mshv_debugfs_partition_remove(struct mshv_partition *partition);
+int mshv_debugfs_vp_create(struct mshv_vp *vp);
+void mshv_debugfs_vp_remove(struct mshv_vp *vp);
+#else
+static inline int __init mshv_debugfs_init(void)
+{
+	return 0;
+}
+static inline void mshv_debugfs_exit(void) { }
+
+static inline int mshv_debugfs_partition_create(struct mshv_partition *partition)
+{
+	return 0;
+}
+static inline void mshv_debugfs_partition_remove(struct mshv_partition *partition) { }
+static inline int mshv_debugfs_vp_create(struct mshv_vp *vp)
+{
+	return 0;
+}
+static inline void mshv_debugfs_vp_remove(struct mshv_vp *vp) { }
+#endif
+
 extern struct mshv_root mshv_root;
 extern enum hv_scheduler_type hv_scheduler_type;
 extern u8 * __percpu *hv_synic_eventring_tail;
drivers/hv/mshv_root_main.c +24 -2
index 724bbaa0b08c..9d46ddb43d70 100644
@@ -1089,6 +1089,10 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 
 	memcpy(vp->vp_stats_pages, stats_pages, sizeof(stats_pages));
 
+	ret = mshv_debugfs_vp_create(vp);
+	if (ret)
+		goto put_partition;
+
 	/*
 	 * Keep anon_inode_getfd last: it installs fd in the file struct and
 	 * thus makes the state accessible in user space.
@@ -1096,7 +1100,7 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 	ret = anon_inode_getfd("mshv_vp", &mshv_vp_fops, vp,
 			       O_RDWR | O_CLOEXEC);
 	if (ret < 0)
-		goto put_partition;
+		goto remove_debugfs_vp;
 
 	/* already exclusive with the partition mutex for all ioctls */
 	partition->pt_vp_count++;
@@ -1104,6 +1108,8 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition,
 
 	return ret;
 
+remove_debugfs_vp:
+	mshv_debugfs_vp_remove(vp);
 put_partition:
 	mshv_partition_put(partition);
 free_vp:
@@ -1546,10 +1552,16 @@ mshv_partition_ioctl_initialize(struct mshv_partition *partition)
 	if (ret)
 		goto withdraw_mem;
 
+	ret = mshv_debugfs_partition_create(partition);
+	if (ret)
+		goto finalize_partition;
+
 	partition->pt_initialized = true;
 
 	return 0;
 
+finalize_partition:
+	hv_call_finalize_partition(partition->pt_id);
 withdraw_mem:
 	hv_call_withdraw_memory(U64_MAX, NUMA_NO_NODE, partition->pt_id);
 
@@ -1729,6 +1741,7 @@ static void destroy_partition(struct mshv_partition *partition)
 			if (!vp)
 				continue;
 
+			mshv_debugfs_vp_remove(vp);
 			mshv_vp_stats_unmap(partition->pt_id, vp->vp_index,
 					    vp->vp_stats_pages);
 
@@ -1762,6 +1775,8 @@ static void destroy_partition(struct mshv_partition *partition)
 			partition->pt_vp_array[i] = NULL;
 		}
 
+		mshv_debugfs_partition_remove(partition);
+
 		/* Deallocates and unmaps everything including vcpus, GPA mappings etc */
 		hv_call_finalize_partition(partition->pt_id);
 
@@ -2307,10 +2322,14 @@ static int __init mshv_parent_partition_init(void)
 
 	mshv_init_vmm_caps(dev);
 
-	ret = mshv_irqfd_wq_init();
+	ret = mshv_debugfs_init();
 	if (ret)
 		goto exit_partition;
 
+	ret = mshv_irqfd_wq_init();
+	if (ret)
+		goto exit_debugfs;
+
 	spin_lock_init(&mshv_root.pt_ht_lock);
 	hash_init(mshv_root.pt_htable);
 
@@ -2318,6 +2337,8 @@ static int __init mshv_parent_partition_init(void)
 
 	return 0;
 
+exit_debugfs:
+	mshv_debugfs_exit();
 exit_partition:
 	if (hv_root_partition())
 		mshv_root_partition_exit();
@@ -2334,6 +2355,7 @@ static void __exit mshv_parent_partition_exit(void)
 {
 	hv_setup_mshv_handler(NULL);
 	mshv_port_table_fini();
+	mshv_debugfs_exit();
 	misc_deregister(&mshv_dev);
 	mshv_irqfd_wq_cleanup();
 	if (hv_root_partition())
Signature · 1 line
2.34.1