Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef IOU_NAPI_H
4#define IOU_NAPI_H
5
6#include <linux/kernel.h>
7#include <linux/io_uring.h>
8#include <net/busy_poll.h>
9
10#ifdef CONFIG_NET_RX_BUSY_POLL
11
12void io_napi_init(struct io_ring_ctx *ctx);
13void io_napi_free(struct io_ring_ctx *ctx);
14
15int io_register_napi(struct io_ring_ctx *ctx, void __user *arg);
16int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg);
17
18int __io_napi_add_id(struct io_ring_ctx *ctx, unsigned int napi_id);
19
20void __io_napi_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq);
21int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx);
22
23static inline bool io_napi(struct io_ring_ctx *ctx)
24{
25 return !list_empty(&ctx->napi_list);
26}
27
28static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
29 struct io_wait_queue *iowq)
30{
31 if (!io_napi(ctx))
32 return;
33 __io_napi_busy_loop(ctx, iowq);
34}
35
36/*
37 * io_napi_add() - Add napi id to the busy poll list
38 * @req: pointer to io_kiocb request
39 *
40 * Add the napi id of the socket to the napi busy poll list and hash table.
41 */
42static inline void io_napi_add(struct io_kiocb *req)
43{
44 struct io_ring_ctx *ctx = req->ctx;
45 struct socket *sock;
46
47 if (READ_ONCE(ctx->napi_track_mode) != IO_URING_NAPI_TRACKING_DYNAMIC)
48 return;
49
50 sock = sock_from_file(req->file);
51 if (sock && sock->sk)
52 __io_napi_add_id(ctx, READ_ONCE(sock->sk->sk_napi_id));
53}
54
55#else
56
57static inline void io_napi_init(struct io_ring_ctx *ctx)
58{
59}
60static inline void io_napi_free(struct io_ring_ctx *ctx)
61{
62}
63static inline int io_register_napi(struct io_ring_ctx *ctx, void __user *arg)
64{
65 return -EOPNOTSUPP;
66}
67static inline int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg)
68{
69 return -EOPNOTSUPP;
70}
71static inline bool io_napi(struct io_ring_ctx *ctx)
72{
73 return false;
74}
75static inline void io_napi_add(struct io_kiocb *req)
76{
77}
78static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
79 struct io_wait_queue *iowq)
80{
81}
82static inline int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx)
83{
84 return 0;
85}
86#endif /* CONFIG_NET_RX_BUSY_POLL */
87
88#endif
1/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef IOU_NAPI_H
4#define IOU_NAPI_H
5
6#include <linux/kernel.h>
7#include <linux/io_uring.h>
8#include <net/busy_poll.h>
9
10#ifdef CONFIG_NET_RX_BUSY_POLL
11
12void io_napi_init(struct io_ring_ctx *ctx);
13void io_napi_free(struct io_ring_ctx *ctx);
14
15int io_register_napi(struct io_ring_ctx *ctx, void __user *arg);
16int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg);
17
18void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock);
19
20void __io_napi_adjust_timeout(struct io_ring_ctx *ctx,
21 struct io_wait_queue *iowq, struct timespec64 *ts);
22void __io_napi_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq);
23int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx);
24
25static inline bool io_napi(struct io_ring_ctx *ctx)
26{
27 return !list_empty(&ctx->napi_list);
28}
29
30static inline void io_napi_adjust_timeout(struct io_ring_ctx *ctx,
31 struct io_wait_queue *iowq,
32 struct timespec64 *ts)
33{
34 if (!io_napi(ctx))
35 return;
36 __io_napi_adjust_timeout(ctx, iowq, ts);
37}
38
39static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
40 struct io_wait_queue *iowq)
41{
42 if (!io_napi(ctx))
43 return;
44 __io_napi_busy_loop(ctx, iowq);
45}
46
47/*
48 * io_napi_add() - Add napi id to the busy poll list
49 * @req: pointer to io_kiocb request
50 *
51 * Add the napi id of the socket to the napi busy poll list and hash table.
52 */
53static inline void io_napi_add(struct io_kiocb *req)
54{
55 struct io_ring_ctx *ctx = req->ctx;
56 struct socket *sock;
57
58 if (!READ_ONCE(ctx->napi_busy_poll_to))
59 return;
60
61 sock = sock_from_file(req->file);
62 if (sock)
63 __io_napi_add(ctx, sock);
64}
65
66#else
67
68static inline void io_napi_init(struct io_ring_ctx *ctx)
69{
70}
71static inline void io_napi_free(struct io_ring_ctx *ctx)
72{
73}
74static inline int io_register_napi(struct io_ring_ctx *ctx, void __user *arg)
75{
76 return -EOPNOTSUPP;
77}
78static inline int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg)
79{
80 return -EOPNOTSUPP;
81}
82static inline bool io_napi(struct io_ring_ctx *ctx)
83{
84 return false;
85}
86static inline void io_napi_add(struct io_kiocb *req)
87{
88}
89static inline void io_napi_adjust_timeout(struct io_ring_ctx *ctx,
90 struct io_wait_queue *iowq,
91 struct timespec64 *ts)
92{
93}
94static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
95 struct io_wait_queue *iowq)
96{
97}
98static inline int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx)
99{
100 return 0;
101}
102#endif /* CONFIG_NET_RX_BUSY_POLL */
103
104#endif