[RFC 1/2] io_uring/loop: add a structure for loop state

Pavel Begunkov <[email protected]>
Newsgroups org.kernel.vger.io-uring
Message-ID <896b5971e721400d17df94868ceefb9636bb3ce1.1780395120.git.asml.silence@gmail.com>
struct iou_loop_params is BPF accessible, but I'll need to keep extra
state that BPF programs shouldn't see. Add a new structure, which is
just wrapping around the params for now but will be extended later.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 io_uring/loop.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/io_uring/loop.c b/io_uring/loop.c
index bbbb6ef14e6a..affaee440dc3 100644
--- a/io_uring/loop.c
+++ b/io_uring/loop.c
@@ -3,6 +3,10 @@
 #include "wait.h"
 #include "loop.h"
 
+struct io_loop_state {
+	struct iou_loop_params lp;
+};
+
 static inline int io_loop_nr_cqes(const struct io_ring_ctx *ctx,
 				  const struct iou_loop_params *lp)
 {
@@ -21,9 +25,11 @@ static inline void io_loop_wait_finish(struct io_ring_ctx *ctx)
 	atomic_set(&ctx->cq_wait_nr, IO_CQ_WAKE_INIT);
 }
 
-static void io_loop_wait(struct io_ring_ctx *ctx, struct iou_loop_params *lp,
+static void io_loop_wait(struct io_ring_ctx *ctx, struct io_loop_state *ls,
 			 unsigned nr_wait)
 {
+	struct iou_loop_params *lp = &ls->lp;
+
 	io_loop_wait_start(ctx, nr_wait);
 
 	if (unlikely(io_local_work_pending(ctx) ||
@@ -41,7 +47,7 @@ static void io_loop_wait(struct io_ring_ctx *ctx, struct iou_loop_params *lp,
 
 static int __io_run_loop(struct io_ring_ctx *ctx)
 {
-	struct iou_loop_params lp = {};
+	struct io_loop_state ls = {};
 
 	while (true) {
 		int nr_wait, step_res;
@@ -49,15 +55,15 @@ static int __io_run_loop(struct io_ring_ctx *ctx)
 		if (unlikely(!ctx->loop_step))
 			return -EFAULT;
 
-		step_res = ctx->loop_step(io_loop_mangle_ctx(ctx), &lp);
+		step_res = ctx->loop_step(io_loop_mangle_ctx(ctx), &ls.lp);
 		if (step_res == IOU_LOOP_STOP)
 			break;
 		if (step_res != IOU_LOOP_CONTINUE)
 			return -EINVAL;
 
-		nr_wait = io_loop_nr_cqes(ctx, &lp);
+		nr_wait = io_loop_nr_cqes(ctx, &ls.lp);
 		if (nr_wait > 0)
-			io_loop_wait(ctx, &lp, nr_wait);
+			io_loop_wait(ctx, &ls, nr_wait);
 		else
 			nr_wait = 0;
 
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.