Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / io_uring / napi.h
blobfa742f42e09b472356ca549a146912506c98d0c9
1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef IOU_NAPI_H
4 #define IOU_NAPI_H
6 #include <linux/kernel.h>
7 #include <linux/io_uring.h>
8 #include <net/busy_poll.h>
10 #ifdef CONFIG_NET_RX_BUSY_POLL
12 void io_napi_init(struct io_ring_ctx *ctx);
13 void io_napi_free(struct io_ring_ctx *ctx);
15 int io_register_napi(struct io_ring_ctx *ctx, void __user *arg);
16 int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg);
18 int __io_napi_add_id(struct io_ring_ctx *ctx, unsigned int napi_id);
20 void __io_napi_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq);
21 int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx);
23 static inline bool io_napi(struct io_ring_ctx *ctx)
25 return !list_empty(&ctx->napi_list);
28 static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
29 struct io_wait_queue *iowq)
31 if (!io_napi(ctx))
32 return;
33 __io_napi_busy_loop(ctx, iowq);
37 * io_napi_add() - Add napi id to the busy poll list
38 * @req: pointer to io_kiocb request
40 * Add the napi id of the socket to the napi busy poll list and hash table.
42 static inline void io_napi_add(struct io_kiocb *req)
44 struct io_ring_ctx *ctx = req->ctx;
45 struct socket *sock;
47 if (READ_ONCE(ctx->napi_track_mode) != IO_URING_NAPI_TRACKING_DYNAMIC)
48 return;
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));
55 #else
57 static inline void io_napi_init(struct io_ring_ctx *ctx)
60 static inline void io_napi_free(struct io_ring_ctx *ctx)
63 static inline int io_register_napi(struct io_ring_ctx *ctx, void __user *arg)
65 return -EOPNOTSUPP;
67 static inline int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg)
69 return -EOPNOTSUPP;
71 static inline bool io_napi(struct io_ring_ctx *ctx)
73 return false;
75 static inline void io_napi_add(struct io_kiocb *req)
78 static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
79 struct io_wait_queue *iowq)
82 static inline int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx)
84 return 0;
86 #endif /* CONFIG_NET_RX_BUSY_POLL */
88 #endif