linux/linux

the linux kernel

git clone https://git.t4t.associates/linux/linux

Linus TorvaldsLinux 7.3-rc1cee9395acd80

master
2.1 KiB90 linesraw
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		     unsigned int mode);
20
21void __io_napi_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq);
22int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx);
23
24static inline bool io_napi(struct io_ring_ctx *ctx)
25{
26	return !list_empty(&ctx->napi_list);
27}
28
29static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
30				     struct io_wait_queue *iowq)
31{
32	if (!io_napi(ctx))
33		return;
34	__io_napi_busy_loop(ctx, iowq);
35}
36
37/*
38 * io_napi_add() - Add napi id to the busy poll list
39 * @req: pointer to io_kiocb request
40 *
41 * Add the napi id of the socket to the napi busy poll list and hash table.
42 */
43static inline void io_napi_add(struct io_kiocb *req)
44{
45	struct io_ring_ctx *ctx = req->ctx;
46	struct socket *sock;
47	unsigned int mode = IO_URING_NAPI_TRACKING_DYNAMIC;
48
49	if (READ_ONCE(ctx->napi_track_mode) != mode)
50		return;
51
52	sock = sock_from_file(req->file);
53	if (sock && sock->sk)
54		__io_napi_add_id(ctx, READ_ONCE(sock->sk->sk_napi_id), mode);
55}
56
57#else
58
59static inline void io_napi_init(struct io_ring_ctx *ctx)
60{
61}
62static inline void io_napi_free(struct io_ring_ctx *ctx)
63{
64}
65static inline int io_register_napi(struct io_ring_ctx *ctx, void __user *arg)
66{
67	return -EOPNOTSUPP;
68}
69static inline int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg)
70{
71	return -EOPNOTSUPP;
72}
73static inline bool io_napi(struct io_ring_ctx *ctx)
74{
75	return false;
76}
77static inline void io_napi_add(struct io_kiocb *req)
78{
79}
80static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
81				     struct io_wait_queue *iowq)
82{
83}
84static inline int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx)
85{
86	return 0;
87}
88#endif /* CONFIG_NET_RX_BUSY_POLL */
89
90#endif