Skip to contentSkip to conversation

mshv_vtl: Add a per-CPU transition statistics ioctl

PATCH New Naman Jain 1 participant 1 message Nov 17

Subsystems (3)
lore
Share & tools
lore

Naman Jain

author
#0 lore raw

PATCH 1/1 mshv_vtl: Add a per-CPU transition statistics ioctl

The VTL driver does not expose per-CPU transition counts or timing. This information is important to track number of VTL transitions based on the use-case, debug issues where a VP gets stuck in VTL2 etc. Add MSHV_GET_VTL_STATS IOCTL so userspace can query them and print this information periodically or on error handling paths. Report entry and return counts, the latest timestamps, and total and maximum interval durations. Include the last observed state so userspace
can calculate the age of an unfinished interval. These are elapsed times, not exclusive CPU execution times.

While at it, remove the unused num_vtl0_transitions counter. Add documentation in a generic VTL interface file. Documentation for existing ioctls is outside the scope of this patch.

---
 Documentation/virt/hyperv/index.rst    |  1 +
 Documentation/virt/hyperv/mshv-vtl.rst | 98 ++++++++++++++++++++++++++
 drivers/hv/mshv_vtl_main.c             | 72 ++++++++++++++++++-
 include/uapi/linux/mshv.h              | 35 +++++++++
 4 files changed, 204 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/virt/hyperv/mshv-vtl.rst
Documentation/virt/hyperv/index.rst +1 -0
index c84c40fd61c91..9fcff8c0f7db8 100644
@@ -13,3 +13,4 @@ Hyper-V Enlightenments
    vpci
    hibernation
    coco
+   mshv-vtl
Documentation/virt/hyperv/mshv-vtl.rst new file +98 -0

98 lines not on this page · raw message

drivers/hv/mshv_vtl_main.c +70 -2

115 lines not on this page · raw message

include/uapi/linux/mshv.h +35 -0
index 32ff92b6342b2..a15d6eb3b95ab 100644
@@ -365,6 +365,40 @@ struct mshv_vtl_set_poll_file {
 	__u32 fd;
 };
 
+#define MSHV_VTL_STATS_STATE_UNKNOWN	0
+#define MSHV_VTL_STATS_STATE_VTL2		1
+#define MSHV_VTL_STATS_STATE_LOWER_VTL	2
+
+/**
+ * struct mshv_vtl_stats - arguments for MSHV_GET_VTL_STATS
+ * @cpu: Input Linux CPU number; all other fields are output.
+ * @state: Last observed MSHV_VTL_STATS_STATE_* software state.
+ * @entry_count: Number of lower-VTL switch attempts.
+ * @exit_count: Number of switch calls that returned to VTL2.
+ * @last_entry_ns: CLOCK_MONOTONIC timestamp of the last entry attempt.
+ * @last_exit_ns: CLOCK_MONOTONIC timestamp of the last return.
+ * @lower_vtl_total_ns: Total duration of completed entry-to-return intervals.
+ * @lower_vtl_max_ns: Maximum duration of a completed entry-to-return interval.
+ * @vtl2_total_ns: Total duration of completed return-to-next-entry intervals.
+ * @vtl2_max_ns: Maximum duration of a completed return-to-next-entry interval.
+ * @snapshot_ns: CLOCK_MONOTONIC timestamp of this snapshot.
+ *
+ * Durations are elapsed nanoseconds, not exclusive CPU execution time.
+ */
+struct mshv_vtl_stats {
+	__u32 cpu;
+	__u32 state;
+	__u64 entry_count;
+	__u64 exit_count;
+	__u64 last_entry_ns;
+	__u64 last_exit_ns;
+	__u64 lower_vtl_total_ns;
+	__u64 lower_vtl_max_ns;
+	__u64 vtl2_total_ns;
+	__u64 vtl2_max_ns;
+	__u64 snapshot_ns;
+};
+
 struct mshv_vtl_hvcall_setup {
 	__u64 bitmap_array_size; /* stores number of bytes */
 	__u64 allow_bitmap_ptr;
@@ -392,6 +426,7 @@ struct mshv_sint_mask {
 #define MSHV_ADD_VTL0_MEMORY	_IOW(MSHV_IOCTL, 0x21, struct mshv_vtl_ram_disposition)
 #define MSHV_SET_POLL_FILE		_IOW(MSHV_IOCTL, 0x25, struct mshv_vtl_set_poll_file)
 #define MSHV_RETURN_TO_LOWER_VTL	_IO(MSHV_IOCTL, 0x27)
+#define MSHV_GET_VTL_STATS	_IOWR(MSHV_IOCTL, 0x41, struct mshv_vtl_stats)
 #define MSHV_GET_VP_REGISTERS		_IOWR(MSHV_IOCTL, 0x05, struct mshv_vp_registers)
 #define MSHV_SET_VP_REGISTERS		_IOW(MSHV_IOCTL, 0x06, struct mshv_vp_registers)
 
Signature · 1 line
2.43.0