[PATCH 2/3] virtio_balloon: add tracepoint for host ack latency

From
<hidden>
Date
2026-10-30 02:59:06
Also in
lkml
Reply to
unknown sender, 2026-10-30
From: Qiang Liu <redacted>

Balloon inflate/deflate block in tell_host() for host buffer consumption.
Host-side stalls are easily mistaken for guest allocation issues.

Add virtio_balloon_host_ack to record tell_host() wait time,
virtqueue and PFN count, to split balloon latency between guest and host.

Signed-off-by: Qiang Liu <redacted>
---
 drivers/virtio/virtio_balloon.c       | 19 +++++++++++++++++--
 include/trace/events/virtio_balloon.h | 22 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 2d0b16383661..c4fdc6815b41 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -19,6 +19,7 @@
 #include <linux/wait.h>
 #include <linux/mm.h>
 #include <linux/page_reporting.h>
+#include <linux/ktime.h>
 #define CREATE_TRACE_POINTS
 #include <trace/events/virtio_balloon.h>
 
@@ -197,8 +198,22 @@ static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq)
 		return;
 	virtqueue_kick(vq);
 
-	/* When host has read buffer, this completes via balloon_ack */
-	wait_event(vb->acked, virtqueue_get_buf(vq, &len));
+	/*
+	 * When host has read buffer, this completes via balloon_ack.
+	 *
+	 * The latency is only measured when the tracepoint is enabled, so a
+	 * disabled tracepoint adds no clock reads on this (hot) path.
+	 */
+	if (trace_virtio_balloon_host_ack_enabled()) {
+		ktime_t start = ktime_get();
+
+		wait_event(vb->acked, virtqueue_get_buf(vq, &len));
+		trace_virtio_balloon_host_ack(vb->num_pfns,
+					      vq->name,
+					      ktime_to_ns(ktime_sub(ktime_get(), start)));
+	} else {
+		wait_event(vb->acked, virtqueue_get_buf(vq, &len));
+	}
 }
 
 static int virtballoon_free_page_report(struct page_reporting_dev_info *pr_dev_info,
diff --git a/include/trace/events/virtio_balloon.h b/include/trace/events/virtio_balloon.h
index f733fc360d8b..559deb997e88 100644
--- a/include/trace/events/virtio_balloon.h
+++ b/include/trace/events/virtio_balloon.h
@@ -81,6 +81,28 @@ TRACE_EVENT(virtio_balloon_deflate,
 		  __entry->requested, __entry->deflated, __entry->num_pages)
 );
 
+TRACE_EVENT(virtio_balloon_host_ack,
+
+	TP_PROTO(unsigned int num_pfns, const char *vq_name, s64 latency_ns),
+
+	TP_ARGS(num_pfns, vq_name, latency_ns),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, num_pfns)
+		__string(vq_name, vq_name)
+		__field(s64, latency_ns)
+	),
+
+	TP_fast_assign(
+		__entry->num_pfns = num_pfns;
+		__assign_str(vq_name);
+		__entry->latency_ns = latency_ns;
+	),
+
+	TP_printk("vq=%s num_pfns=%u latency=%lldns",
+		  __get_str(vq_name), __entry->num_pfns, __entry->latency_ns)
+);
+
 #endif /* _TRACE_VIRTIO_BALLOON_H */
 
 /* This part must be outside protection */
-- 
2.43.0


No virus found
		Checked by Hillstone Network AntiVirus
Thread (7 messages) 7 messages, 2 authors, last reply 14d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help