Skip to content

Commit e8c328c

Browse files
isilenceaxboe
authored andcommitted
io_uring: deduplicate io_get_cqe() calls
Deduplicate calls to io_get_cqe() from __io_fill_cqe_req(). Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/4fa077986cc3abab7c59ff4e7c390c783885465f.1655455613.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ae5735c commit e8c328c

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

io_uring/io_uring.h

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,40 +45,28 @@ static inline bool __io_fill_cqe_req(struct io_ring_ctx *ctx,
4545
req->cqe.res, req->cqe.flags,
4646
(req->flags & REQ_F_CQE32_INIT) ? req->extra1 : 0,
4747
(req->flags & REQ_F_CQE32_INIT) ? req->extra2 : 0);
48+
/*
49+
* If we can't get a cq entry, userspace overflowed the
50+
* submission (by quite a lot). Increment the overflow count in
51+
* the ring.
52+
*/
53+
cqe = io_get_cqe(ctx);
54+
if (unlikely(!cqe))
55+
return io_req_cqe_overflow(req);
56+
memcpy(cqe, &req->cqe, sizeof(*cqe));
4857

49-
if (!(ctx->flags & IORING_SETUP_CQE32)) {
50-
/*
51-
* If we can't get a cq entry, userspace overflowed the
52-
* submission (by quite a lot). Increment the overflow count in
53-
* the ring.
54-
*/
55-
cqe = io_get_cqe(ctx);
56-
if (likely(cqe)) {
57-
memcpy(cqe, &req->cqe, sizeof(*cqe));
58-
return true;
59-
}
60-
} else {
58+
if (ctx->flags & IORING_SETUP_CQE32) {
6159
u64 extra1 = 0, extra2 = 0;
6260

6361
if (req->flags & REQ_F_CQE32_INIT) {
6462
extra1 = req->extra1;
6563
extra2 = req->extra2;
6664
}
6765

68-
/*
69-
* If we can't get a cq entry, userspace overflowed the
70-
* submission (by quite a lot). Increment the overflow count in
71-
* the ring.
72-
*/
73-
cqe = io_get_cqe(ctx);
74-
if (likely(cqe)) {
75-
memcpy(cqe, &req->cqe, sizeof(struct io_uring_cqe));
76-
WRITE_ONCE(cqe->big_cqe[0], extra1);
77-
WRITE_ONCE(cqe->big_cqe[1], extra2);
78-
return true;
79-
}
66+
WRITE_ONCE(cqe->big_cqe[0], extra1);
67+
WRITE_ONCE(cqe->big_cqe[1], extra2);
8068
}
81-
return io_req_cqe_overflow(req);
69+
return true;
8270
}
8371

8472
static inline void req_set_fail(struct io_kiocb *req)

0 commit comments

Comments
 (0)