* [PATCH v2] io_uring: unlock sqd->lock before sq thread release CPU
[not found] <CGME20230525082004epcas5p1d05da68508feff3f9dd82646a0b40aff@epcas5p1.samsung.com>
@ 2023-05-25 8:26 ` Wenwen Chen
2023-05-25 15:30 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Wenwen Chen @ 2023-05-25 8:26 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring, Wenwen Chen, Kanchan Joshi
The sq thread actively releases CPU resources by calling the
cond_resched() and schedule() interfaces when it is idle. Therefore,
more resources are available for other threads to run.
There exists a problem in sq thread: it does not unlock sqd->lock before
releasing CPU resources every time. This makes other threads pending on
sqd->lock for a long time. For example, the following interfaces all
require sqd->lock: io_sq_offload_create(), io_register_iowq_max_workers()
and io_ring_exit_work().
Before the sq thread releases CPU resources, unlocking sqd->lock will
provide the user a better experience because it can respond quickly to
user requests.
Signed-off-by: Kanchan Joshi<[email protected]>
Signed-off-by: Wenwen Chen<[email protected]>
---
V1 -> V2: Make sqd lock shuffle dependent on the need to reschedule
io_uring/sqpoll.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index 9db4bc1f521a..5e329e3cd470 100644
--- a/io_uring/sqpoll.c
+++ b/io_uring/sqpoll.c
@@ -255,9 +255,13 @@ static int io_sq_thread(void *data)
sqt_spin = true;
if (sqt_spin || !time_after(jiffies, timeout)) {
- cond_resched();
if (sqt_spin)
timeout = jiffies + sqd->sq_thread_idle;
+ if (unlikely(need_resched())) {
+ mutex_unlock(&sqd->lock);
+ cond_resched();
+ mutex_lock(&sqd->lock);
+ }
continue;
}
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread