Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/sqpoll: wait on sqd->wait for thread parking

io_sqd_handle_event() just does a mutex unlock/lock dance when it's
supposed to park, somewhat relying on full ordering with the thread
trying to park it which does a similar unlock/lock dance on sqd->lock.
However, with adaptive spinning on mutexes, this can waste an awful
lot of time. Normally this isn't very noticeable, as parking and
unparking the thread isn't a common (or fast path) occurence. However,
in testing ring resizing, it's testing exactly that, as each resize
will require the SQPOLL to safely park and unpark.

Have io_sq_thread_park() explicitly wait on sqd->park_pending being
zero before attempting to grab the sqd->lock again.

In a resize test, this brings the runtime of SQPOLL down from about
60 seconds to a few seconds, just like the !SQPOLL tests. And saves
a ton of spinning time on the mutex, on both sides.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

+2 -1
+2 -1
io_uring/sqpoll.c
··· 40 40 if (atomic_dec_return(&sqd->park_pending)) 41 41 set_bit(IO_SQ_THREAD_SHOULD_PARK, &sqd->state); 42 42 mutex_unlock(&sqd->lock); 43 + wake_up(&sqd->wait); 43 44 } 44 45 45 46 void io_sq_thread_park(struct io_sq_data *sqd) ··· 216 215 mutex_unlock(&sqd->lock); 217 216 if (signal_pending(current)) 218 217 did_sig = get_signal(&ksig); 219 - cond_resched(); 218 + wait_event(sqd->wait, !atomic_read(&sqd->park_pending)); 220 219 mutex_lock(&sqd->lock); 221 220 sqd->sq_cpu = raw_smp_processor_id(); 222 221 }