From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH for-next 3/7] io_uring: improve io_get_sqe
Date: Mon, 23 Jan 2023 14:37:15 +0000 [thread overview]
Message-ID: <9cceb11329240ea097dffef6bf0a675bca14cf42.1674484266.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Return an SQE from io_get_sqe() as a parameter and use the return value
to determine if it failed or not. This lets the compiler to compile out
the sqe NULL check when we know that the return SQE is valid.
Signed-off-by: Pavel Begunkov <[email protected]>
---
io_uring/io_uring.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 118b2fe254ba..6af11a60dc8a 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2370,7 +2370,7 @@ static void io_commit_sqring(struct io_ring_ctx *ctx)
* used, it's important that those reads are done through READ_ONCE() to
* prevent a re-load down the line.
*/
-static const struct io_uring_sqe *io_get_sqe(struct io_ring_ctx *ctx)
+static const bool io_get_sqe(struct io_ring_ctx *ctx, const struct io_uring_sqe **sqe)
{
unsigned head, mask = ctx->sq_entries - 1;
unsigned sq_idx = ctx->cached_sq_head++ & mask;
@@ -2388,14 +2388,15 @@ static const struct io_uring_sqe *io_get_sqe(struct io_ring_ctx *ctx)
/* double index for 128-byte SQEs, twice as long */
if (ctx->flags & IORING_SETUP_SQE128)
head <<= 1;
- return &ctx->sq_sqes[head];
+ *sqe = &ctx->sq_sqes[head];
+ return true;
}
/* drop invalid entries */
ctx->cq_extra--;
WRITE_ONCE(ctx->rings->sq_dropped,
READ_ONCE(ctx->rings->sq_dropped) + 1);
- return NULL;
+ return false;
}
int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
@@ -2419,8 +2420,7 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
if (unlikely(!io_alloc_req_refill(ctx)))
break;
req = io_alloc_req(ctx);
- sqe = io_get_sqe(ctx);
- if (unlikely(!sqe)) {
+ if (unlikely(!io_get_sqe(ctx, &sqe))) {
io_req_add_to_cache(req, ctx);
break;
}
--
2.38.1
next prev parent reply other threads:[~2023-01-23 14:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-23 14:37 [PATCH for-next 0/7] normal tw optimisation + refactoring Pavel Begunkov
2023-01-23 14:37 ` [PATCH for-next 1/7] io_uring: use user visible tail in io_uring_poll() Pavel Begunkov
2023-01-23 18:25 ` Jens Axboe
2023-01-23 20:56 ` Pavel Begunkov
2023-01-23 21:09 ` Jens Axboe
2023-01-23 14:37 ` [PATCH for-next 2/7] io_uring: kill outdated comment about overflow flush Pavel Begunkov
2023-01-23 14:37 ` Pavel Begunkov [this message]
2023-01-23 14:37 ` [PATCH for-next 4/7] io_uring: refactor req allocation Pavel Begunkov
2023-01-23 14:37 ` [PATCH for-next 5/7] io_uring: refactor io_put_task helpers Pavel Begunkov
2023-01-23 14:37 ` [PATCH for-next 6/7] io_uring: refactor tctx_task_work Pavel Begunkov
2023-01-23 14:37 ` [PATCH for-next 7/7] io_uring: return normal tw run linking optimisation Pavel Begunkov
2023-01-23 21:14 ` [PATCH for-next 0/7] normal tw optimisation + refactoring Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9cceb11329240ea097dffef6bf0a675bca14cf42.1674484266.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox