From: Jens Axboe <[email protected]>
To: Xiaoguang Wang <[email protected]>,
[email protected]
Cc: [email protected], [email protected]
Subject: Re: [PATCH 1/2] io_uring: refactor io_sq_thread() handling
Date: Tue, 27 Oct 2020 10:56:22 -0600 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
On 10/20/20 2:23 AM, Xiaoguang Wang wrote:
> @@ -6638,24 +6578,52 @@ static int io_sq_thread(void *data)
> }
> io_sq_thread_associate_blkcg(ctx, &cur_css);
>
> - ret |= __io_sq_thread(ctx, start_jiffies, cap_entries);
> + ret = __io_sq_thread(ctx, cap_entries);
> + if (!sqt_spin && (ret > 0 || !list_empty(&ctx->iopoll_list)))
> + sqt_spin = true;
> + }
>
> - io_sq_thread_drop_mm();
> + if (sqt_spin) {
> + io_run_task_work();
> + cond_resched();
> + continue;
> }
>
> - if (ret & SQT_SPIN) {
> + if (!time_after(jiffies, timeout)) {
> io_run_task_work();
> cond_resched();
> - } else if (ret == SQT_IDLE) {
> - if (kthread_should_park())
> - continue;
> + io_sq_thread_drop_mm();
> + continue;
> + }
> +
> + needs_sched = true;
> + prepare_to_wait(&sqd->wait, &wait, TASK_INTERRUPTIBLE);
> + list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
> + if ((ctx->flags & IORING_SETUP_IOPOLL) &&
> + !list_empty_careful(&ctx->iopoll_list)) {
> + needs_sched = false;
> + break;
> + }
> + to_submit = io_sqring_entries(ctx);
> + if (to_submit) {
> + needs_sched = false;
> + break;
> + }
> + }
> +
> + if (needs_sched) {
> list_for_each_entry(ctx, &sqd->ctx_list, sqd_list)
> io_ring_set_wakeup_flag(ctx);
> + }
> +
> + if (needs_sched) {
> schedule();
> - start_jiffies = jiffies;
> list_for_each_entry(ctx, &sqd->ctx_list, sqd_list)
> io_ring_clear_wakeup_flag(ctx);
> - }
> + finish_wait(&sqd->wait, &wait);
> + } else
> + finish_wait(&sqd->wait, &wait);
> + timeout = jiffies + sqd->sq_thread_idle;
> }
Not sure why, but you have two
if (needs_sched) {
}
right after each other, that should be folded into one.
And I'd get rid of the to_submit, just do:
if (io_sqring_entries(ctx)) {
needs_sched = false;
break;
}
as we're not going to be using that value anyway.
As a minor style thing, always includes bracket on both cases if one has
it, don't do this:
if (foo) {
...
...
} else
bar();
--
Jens Axboe
next prev parent reply other threads:[~2020-10-27 16:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-20 8:23 [PATCH 0/2] improve SQPOLL handling Xiaoguang Wang
2020-10-20 8:23 ` [PATCH 1/2] io_uring: refactor io_sq_thread() handling Xiaoguang Wang
2020-10-27 16:56 ` Jens Axboe [this message]
2020-10-20 8:23 ` [PATCH 2/2] io_uring: support multiple rings to share same poll thread by specifying same cpu Xiaoguang Wang
2020-10-27 17:01 ` Jens Axboe
2020-11-01 14:22 ` Xiaoguang Wang
2020-11-02 12:00 ` Xiaoguang Wang
2020-10-27 13:34 ` [PATCH 0/2] improve SQPOLL handling Xiaoguang Wang
2020-10-27 13:48 ` 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 \
[email protected] \
[email protected] \
[email protected] \
[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