Skip to content

Commit 709b302

Browse files
isilenceaxboe
authored andcommitted
io_uring: simplify io_get_sqring
Make io_get_sqring() care only about sqes themselves, not initialising the io_kiocb. Also, split it into get + consume, that will be helpful in the future. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 45097da commit 709b302

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

fs/io_uring.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5781,8 +5781,7 @@ static void io_commit_sqring(struct io_ring_ctx *ctx)
57815781
* used, it's important that those reads are done through READ_ONCE() to
57825782
* prevent a re-load down the line.
57835783
*/
5784-
static bool io_get_sqring(struct io_ring_ctx *ctx, struct io_kiocb *req,
5785-
const struct io_uring_sqe **sqe_ptr)
5784+
static const struct io_uring_sqe *io_get_sqe(struct io_ring_ctx *ctx)
57865785
{
57875786
u32 *sq_array = ctx->sq_array;
57885787
unsigned head;
@@ -5796,25 +5795,18 @@ static bool io_get_sqring(struct io_ring_ctx *ctx, struct io_kiocb *req,
57965795
* though the application is the one updating it.
57975796
*/
57985797
head = READ_ONCE(sq_array[ctx->cached_sq_head & ctx->sq_mask]);
5799-
if (likely(head < ctx->sq_entries)) {
5800-
/*
5801-
* All io need record the previous position, if LINK vs DARIN,
5802-
* it can be used to mark the position of the first IO in the
5803-
* link list.
5804-
*/
5805-
req->sequence = ctx->cached_sq_head;
5806-
*sqe_ptr = &ctx->sq_sqes[head];
5807-
req->opcode = READ_ONCE((*sqe_ptr)->opcode);
5808-
req->user_data = READ_ONCE((*sqe_ptr)->user_data);
5809-
ctx->cached_sq_head++;
5810-
return true;
5811-
}
5798+
if (likely(head < ctx->sq_entries))
5799+
return &ctx->sq_sqes[head];
58125800

58135801
/* drop invalid entries */
5814-
ctx->cached_sq_head++;
58155802
ctx->cached_sq_dropped++;
58165803
WRITE_ONCE(ctx->rings->sq_dropped, ctx->cached_sq_dropped);
5817-
return false;
5804+
return NULL;
5805+
}
5806+
5807+
static inline void io_consume_sqe(struct io_ring_ctx *ctx)
5808+
{
5809+
ctx->cached_sq_head++;
58185810
}
58195811

58205812
static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
@@ -5858,11 +5850,23 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
58585850
submitted = -EAGAIN;
58595851
break;
58605852
}
5861-
if (!io_get_sqring(ctx, req, &sqe)) {
5853+
sqe = io_get_sqe(ctx);
5854+
if (!sqe) {
58625855
__io_req_do_free(req);
5856+
io_consume_sqe(ctx);
58635857
break;
58645858
}
58655859

5860+
/*
5861+
* All io need record the previous position, if LINK vs DARIN,
5862+
* it can be used to mark the position of the first IO in the
5863+
* link list.
5864+
*/
5865+
req->sequence = ctx->cached_sq_head;
5866+
req->opcode = READ_ONCE(sqe->opcode);
5867+
req->user_data = READ_ONCE(sqe->user_data);
5868+
io_consume_sqe(ctx);
5869+
58665870
/* will complete beyond this point, count as submitted */
58675871
submitted++;
58685872

0 commit comments

Comments
 (0)