io_uring/sqpoll: wait on sqd->wait for thread parking
authorJens Axboe <axboe@kernel.dk>
Mon, 28 Oct 2024 19:18:27 +0000 (13:18 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 28 Oct 2024 19:18:27 +0000 (13:18 -0600)
commitdc75d0d637326693fecef37a79c2afa2eedfe9da
tree61600c780a92d858d24a9c5e7f20321d3417712f
parent909b9acefcc3bc7a722bc9804dfddbc02721eaa7
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>
io_uring/sqpoll.c