Skip to content

Commit d5cce40

Browse files
isilenceaxboe
authored andcommitted
io_uring/napi: postpone napi timeout adjustment
Remove io_napi_adjust_timeout() and move the adjustments out of the common path into __io_napi_busy_loop(). Now the limit it's calculated based on struct io_wait_queue::timeout, for which we query current time another time. The overhead shouldn't be a problem, it's a polling path, however that can be optimised later by additionally saving the delta time value in io_cqring_wait(). Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/88e14686e245b3b42ff90a3c4d70895d48676206.1723039801.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 489b800 commit d5cce40

File tree

3 files changed

+7
-38
lines changed

3 files changed

+7
-38
lines changed

io_uring/io_uring.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,6 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
24232423

24242424
dt = timespec64_to_ktime(ts);
24252425
iowq.timeout = ktime_add(dt, ktime_get());
2426-
io_napi_adjust_timeout(ctx, &iowq, dt);
24272426
}
24282427

24292428
if (sig) {

io_uring/napi.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -269,27 +269,6 @@ int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg)
269269
return 0;
270270
}
271271

272-
/*
273-
* __io_napi_adjust_timeout() - adjust busy loop timeout
274-
* @ctx: pointer to io-uring context structure
275-
* @iowq: pointer to io wait queue
276-
* @ts: pointer to timespec or NULL
277-
*
278-
* Adjust the busy loop timeout according to timespec and busy poll timeout.
279-
* If the specified NAPI timeout is bigger than the wait timeout, then adjust
280-
* the NAPI timeout accordingly.
281-
*/
282-
void __io_napi_adjust_timeout(struct io_ring_ctx *ctx, struct io_wait_queue *iowq,
283-
ktime_t to_wait)
284-
{
285-
ktime_t poll_dt = READ_ONCE(ctx->napi_busy_poll_dt);
286-
287-
if (to_wait)
288-
poll_dt = min(poll_dt, to_wait);
289-
290-
iowq->napi_busy_poll_dt = poll_dt;
291-
}
292-
293272
/*
294273
* __io_napi_busy_loop() - execute busy poll loop
295274
* @ctx: pointer to io-uring context structure
@@ -302,6 +281,13 @@ void __io_napi_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq)
302281
if (ctx->flags & IORING_SETUP_SQPOLL)
303282
return;
304283

284+
iowq->napi_busy_poll_dt = READ_ONCE(ctx->napi_busy_poll_dt);
285+
if (iowq->timeout != KTIME_MAX) {
286+
ktime_t dt = ktime_sub(iowq->timeout, ktime_get());
287+
288+
iowq->napi_busy_poll_dt = min_t(u64, iowq->napi_busy_poll_dt, dt);
289+
}
290+
305291
iowq->napi_prefer_busy_poll = READ_ONCE(ctx->napi_prefer_busy_poll);
306292
io_napi_blocking_busy_loop(ctx, iowq);
307293
}

io_uring/napi.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg);
1717

1818
void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock);
1919

20-
void __io_napi_adjust_timeout(struct io_ring_ctx *ctx,
21-
struct io_wait_queue *iowq, ktime_t to_wait);
2220
void __io_napi_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq);
2321
int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx);
2422

@@ -27,15 +25,6 @@ static inline bool io_napi(struct io_ring_ctx *ctx)
2725
return !list_empty(&ctx->napi_list);
2826
}
2927

30-
static inline void io_napi_adjust_timeout(struct io_ring_ctx *ctx,
31-
struct io_wait_queue *iowq,
32-
ktime_t to_wait)
33-
{
34-
if (!io_napi(ctx))
35-
return;
36-
__io_napi_adjust_timeout(ctx, iowq, to_wait);
37-
}
38-
3928
static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
4029
struct io_wait_queue *iowq)
4130
{
@@ -86,11 +75,6 @@ static inline bool io_napi(struct io_ring_ctx *ctx)
8675
static inline void io_napi_add(struct io_kiocb *req)
8776
{
8877
}
89-
static inline void io_napi_adjust_timeout(struct io_ring_ctx *ctx,
90-
struct io_wait_queue *iowq,
91-
ktime_t to_wait)
92-
{
93-
}
9478
static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
9579
struct io_wait_queue *iowq)
9680
{

0 commit comments

Comments
 (0)