Skip to content

Commit cb3d897

Browse files
isilenceaxboe
authored andcommitted
io_uring: refactor io_iopoll_req_issued
A simple refactoring of io_iopoll_req_issued(), move in_async inside so we don't pass it around and save on double checking it. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/1513bfde4f0c835be25ac69a82737ab0668d7665.1623634181.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 382cb03 commit cb3d897

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

fs/io_uring.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,9 +2525,14 @@ static void io_complete_rw_iopoll(struct kiocb *kiocb, long res, long res2)
25252525
* find it from a io_do_iopoll() thread before the issuer is done
25262526
* accessing the kiocb cookie.
25272527
*/
2528-
static void io_iopoll_req_issued(struct io_kiocb *req, bool in_async)
2528+
static void io_iopoll_req_issued(struct io_kiocb *req)
25292529
{
25302530
struct io_ring_ctx *ctx = req->ctx;
2531+
const bool in_async = io_wq_current_is_worker();
2532+
2533+
/* workqueue context doesn't hold uring_lock, grab it now */
2534+
if (unlikely(in_async))
2535+
mutex_lock(&ctx->uring_lock);
25312536

25322537
/*
25332538
* Track whether we have multiple files in our lists. This will impact
@@ -2554,14 +2559,19 @@ static void io_iopoll_req_issued(struct io_kiocb *req, bool in_async)
25542559
else
25552560
list_add_tail(&req->inflight_entry, &ctx->iopoll_list);
25562561

2557-
/*
2558-
* If IORING_SETUP_SQPOLL is enabled, sqes are either handled in sq thread
2559-
* task context or in io worker task context. If current task context is
2560-
* sq thread, we don't need to check whether should wake up sq thread.
2561-
*/
2562-
if (in_async && (ctx->flags & IORING_SETUP_SQPOLL) &&
2563-
wq_has_sleeper(&ctx->sq_data->wait))
2564-
wake_up(&ctx->sq_data->wait);
2562+
if (unlikely(in_async)) {
2563+
/*
2564+
* If IORING_SETUP_SQPOLL is enabled, sqes are either handle
2565+
* in sq thread task context or in io worker task context. If
2566+
* current task context is sq thread, we don't need to check
2567+
* whether should wake up sq thread.
2568+
*/
2569+
if ((ctx->flags & IORING_SETUP_SQPOLL) &&
2570+
wq_has_sleeper(&ctx->sq_data->wait))
2571+
wake_up(&ctx->sq_data->wait);
2572+
2573+
mutex_unlock(&ctx->uring_lock);
2574+
}
25652575
}
25662576

25672577
static inline void io_state_file_put(struct io_submit_state *state)
@@ -6215,23 +6225,11 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
62156225

62166226
if (creds)
62176227
revert_creds(creds);
6218-
62196228
if (ret)
62206229
return ret;
6221-
62226230
/* If the op doesn't have a file, we're not polling for it */
6223-
if ((ctx->flags & IORING_SETUP_IOPOLL) && req->file) {
6224-
const bool in_async = io_wq_current_is_worker();
6225-
6226-
/* workqueue context doesn't hold uring_lock, grab it now */
6227-
if (in_async)
6228-
mutex_lock(&ctx->uring_lock);
6229-
6230-
io_iopoll_req_issued(req, in_async);
6231-
6232-
if (in_async)
6233-
mutex_unlock(&ctx->uring_lock);
6234-
}
6231+
if ((ctx->flags & IORING_SETUP_IOPOLL) && req->file)
6232+
io_iopoll_req_issued(req);
62356233

62366234
return 0;
62376235
}

0 commit comments

Comments
 (0)