Skip to content

Commit 3581696

Browse files
isilenceaxboe
authored andcommitted
io_uring/napi: pass ktime to io_napi_adjust_timeout
Pass the waiting time for __io_napi_adjust_timeout as ktime and get rid of all timespec64 conversions. It's especially simpler since the caller already have a ktime. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/4f5b8e8eed4f53a1879e031a6712b25381adc23d.1722003776.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 342b2e3 commit 3581696

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

io_uring/io_uring.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,12 +2416,14 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
24162416

24172417
if (uts) {
24182418
struct timespec64 ts;
2419+
ktime_t dt;
24192420

24202421
if (get_timespec64(&ts, uts))
24212422
return -EFAULT;
24222423

2423-
iowq.timeout = ktime_add_ns(timespec64_to_ktime(ts), ktime_get_ns());
2424-
io_napi_adjust_timeout(ctx, &iowq, &ts);
2424+
dt = timespec64_to_ktime(ts);
2425+
iowq.timeout = ktime_add(dt, ktime_get());
2426+
io_napi_adjust_timeout(ctx, &iowq, dt);
24252427
}
24262428

24272429
if (sig) {

io_uring/napi.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,12 @@ int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg)
282282
* the NAPI timeout accordingly.
283283
*/
284284
void __io_napi_adjust_timeout(struct io_ring_ctx *ctx, struct io_wait_queue *iowq,
285-
struct timespec64 *ts)
285+
ktime_t to_wait)
286286
{
287287
ktime_t poll_dt = READ_ONCE(ctx->napi_busy_poll_dt);
288288

289-
if (ts) {
290-
struct timespec64 poll_to_ts;
291-
292-
poll_to_ts = ns_to_timespec64(ktime_to_ns(poll_dt));
293-
if (timespec64_compare(ts, &poll_to_ts) < 0) {
294-
s64 poll_to_ns = timespec64_to_ns(ts);
295-
if (poll_to_ns > 0)
296-
poll_dt = ns_to_ktime(poll_to_ns);
297-
}
298-
}
289+
if (to_wait)
290+
poll_dt = min(poll_dt, to_wait);
299291

300292
iowq->napi_busy_poll_dt = poll_dt;
301293
}

io_uring/napi.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg);
1818
void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock);
1919

2020
void __io_napi_adjust_timeout(struct io_ring_ctx *ctx,
21-
struct io_wait_queue *iowq, struct timespec64 *ts);
21+
struct io_wait_queue *iowq, ktime_t to_wait);
2222
void __io_napi_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq);
2323
int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx);
2424

@@ -29,11 +29,11 @@ static inline bool io_napi(struct io_ring_ctx *ctx)
2929

3030
static inline void io_napi_adjust_timeout(struct io_ring_ctx *ctx,
3131
struct io_wait_queue *iowq,
32-
struct timespec64 *ts)
32+
ktime_t to_wait)
3333
{
3434
if (!io_napi(ctx))
3535
return;
36-
__io_napi_adjust_timeout(ctx, iowq, ts);
36+
__io_napi_adjust_timeout(ctx, iowq, to_wait);
3737
}
3838

3939
static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
@@ -88,7 +88,7 @@ static inline void io_napi_add(struct io_kiocb *req)
8888
}
8989
static inline void io_napi_adjust_timeout(struct io_ring_ctx *ctx,
9090
struct io_wait_queue *iowq,
91-
struct timespec64 *ts)
91+
ktime_t to_wait)
9292
{
9393
}
9494
static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,

0 commit comments

Comments
 (0)