Skip to contentSkip to conversation

wait/9p: Account 9P RPC waiting time as I/O wait

PATCH In review Remi Pommarel 2 participants 4 messages Jan 23 – Jan 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover wait/9p: Account 9P RPC waiting time as I/O wait

This patch serie helps to attribute the time spent waiting for server responses during 9P RPC calls to I/O wait time in system metrics. As a result, I/O-intensive operations on a 9pfs mount will now be reflected in the "wa" column instead of the "id" one of tools like top.

Changes since v1:
- Convert a bunch of other 9P's wait_event_killable candidates

Remi Pommarel (2):
wait: Introduce io_wait_event_killable()
9p: Track 9P RPC waiting time as IO

 include/linux/wait.h  | 15 +++++++++++++++
 net/9p/client.c       |  4 ++--
 net/9p/trans_virtio.c | 14 +++++++-------
 net/9p/trans_xen.c    |  4 ++--
 4 files changed, 26 insertions(+), 11 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/2 wait: Introduce io_wait_event_killable()

Add io_wait_event_killable(), a variant of wait_event_killable() that uses io_schedule() instead of schedule(). This is to be used in situation where waiting time is to be accounted as IO wait time.

---
 include/linux/wait.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
include/linux/wait.h +15 -0
index f648044466d5..dce055e6add3 100644
@@ -937,6 +937,21 @@ extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *);
 	__ret;									\
 })
 
+#define __io_wait_event_killable(wq, condition)					\
+	___wait_event(wq, condition, TASK_KILLABLE, 0, 0, io_schedule())
+
+/*
+ * wait_event_killable() - link wait_event_killable but with io_schedule()
+ */
+#define io_wait_event_killable(wq_head, condition)				\
+({										\
+	int __ret = 0;								\
+	might_sleep();								\
+	if (!(condition))							\
+		__ret = __io_wait_event_killable(wq_head, condition);		\
+	__ret;									\
+})
+
 #define __wait_event_state(wq, condition, state)				\
 	___wait_event(wq, condition, state, 0, 0, schedule())
 
Signature · 1 line
2.50.1
#2 lore raw

PATCH v2 2/2 9p: Track 9P RPC waiting time as IO

In reply to Remi Pommarel

Use io_wait_event_killable() to ensure that time spent waiting for 9P RPC transactions is accounted as IO wait time.

---
 net/9p/client.c       |  4 ++--
 net/9p/trans_virtio.c | 14 +++++++-------
 net/9p/trans_xen.c    |  4 ++--
 3 files changed, 11 insertions(+), 11 deletions(-)
net/9p/client.c +2 -2
index f60d1d041adb..1b475525ac5b 100644
@@ -590,8 +590,8 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
 	}
 again:
 	/* Wait for the response */
-	err = wait_event_killable(req->wq,
-				  READ_ONCE(req->status) >= REQ_STATUS_RCVD);
+	err = io_wait_event_killable(req->wq,
+				     READ_ONCE(req->status) >= REQ_STATUS_RCVD);
 
 	/* Make sure our req is coherent with regard to updates in other
 	 * threads - echoes to wmb() in the callback
net/9p/trans_virtio.c +7 -7
index 10c2dd486438..370f4f37dcec 100644
@@ -284,8 +284,8 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req)
 		if (err == -ENOSPC) {
 			chan->ring_bufs_avail = 0;
 			spin_unlock_irqrestore(&chan->lock, flags);
-			err = wait_event_killable(*chan->vc_wq,
-						  chan->ring_bufs_avail);
+			err = io_wait_event_killable(*chan->vc_wq,
+						     chan->ring_bufs_avail);
 			if (err  == -ERESTARTSYS)
 				return err;
 
@@ -325,7 +325,7 @@ static int p9_get_mapped_pages(struct virtio_chan *chan,
 		 * Other zc request to finish here
 		 */
 		if (atomic_read(&vp_pinned) >= chan->p9_max_pages) {
-			err = wait_event_killable(vp_wq,
+			err = io_wait_event_killable(vp_wq,
 			      (atomic_read(&vp_pinned) < chan->p9_max_pages));
 			if (err == -ERESTARTSYS)
 				return err;
@@ -512,8 +512,8 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
 		if (err == -ENOSPC) {
 			chan->ring_bufs_avail = 0;
 			spin_unlock_irqrestore(&chan->lock, flags);
-			err = wait_event_killable(*chan->vc_wq,
-						  chan->ring_bufs_avail);
+			err = io_wait_event_killable(*chan->vc_wq,
+						     chan->ring_bufs_avail);
 			if (err  == -ERESTARTSYS)
 				goto err_out;
 
@@ -531,8 +531,8 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
 	spin_unlock_irqrestore(&chan->lock, flags);
 	kicked = 1;
 	p9_debug(P9_DEBUG_TRANS, "virtio request kicked\n");
-	err = wait_event_killable(req->wq,
-			          READ_ONCE(req->status) >= REQ_STATUS_RCVD);
+	err = io_wait_event_killable(req->wq,
+				     READ_ONCE(req->status) >= REQ_STATUS_RCVD);
 	// RERROR needs reply (== error string) in static data
 	if (READ_ONCE(req->status) == REQ_STATUS_RCVD &&
 	    unlikely(req->rc.sdata[4] == P9_RERROR))
net/9p/trans_xen.c +2 -2
index 12f752a92332..d57965e6aab0 100644
@@ -136,8 +136,8 @@ static int p9_xen_request(struct p9_client *client, struct p9_req_t *p9_req)
 	ring = &priv->rings[num];
 
 again:
-	while (wait_event_killable(ring->wq,
-				   p9_xen_write_todo(ring, size)) != 0)
+	while (io_wait_event_killable(ring->wq,
+				      p9_xen_write_todo(ring, size)) != 0)
 		;
 
 	spin_lock_irqsave(&ring->lock, flags);
Signature · 1 line
2.50.1
maintainer Acked-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] 9p: Track 9P RPC waiting time as IO

Remi Pommarel wrote on Fri, Jan 23, 2026 at 03:48:08PM +0100:

Quoted 4 lines

Use io_wait_event_killable() to ensure that time spent waiting for 9P RPC transactions is accounted as IO wait time.

Thank you!

Peter, Ingo -- I'll take both patches unless you prefer to take all changes to include/linux/wait.h in the scheduler tree, please let me know.

If this doesn't go through my tree:

Signature · 1 line
Dominique Martinet | Asmadeus