napi.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef IOU_NAPI_H
  3. #define IOU_NAPI_H
  4. #include <linux/kernel.h>
  5. #include <linux/io_uring.h>
  6. #include <net/busy_poll.h>
  7. #ifdef CONFIG_NET_RX_BUSY_POLL
  8. void io_napi_init(struct io_ring_ctx *ctx);
  9. void io_napi_free(struct io_ring_ctx *ctx);
  10. int io_register_napi(struct io_ring_ctx *ctx, void __user *arg);
  11. int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg);
  12. void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock);
  13. void __io_napi_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq);
  14. int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx);
  15. static inline bool io_napi(struct io_ring_ctx *ctx)
  16. {
  17. return !list_empty(&ctx->napi_list);
  18. }
  19. static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
  20. struct io_wait_queue *iowq)
  21. {
  22. if (!io_napi(ctx))
  23. return;
  24. __io_napi_busy_loop(ctx, iowq);
  25. }
  26. /*
  27. * io_napi_add() - Add napi id to the busy poll list
  28. * @req: pointer to io_kiocb request
  29. *
  30. * Add the napi id of the socket to the napi busy poll list and hash table.
  31. */
  32. static inline void io_napi_add(struct io_kiocb *req)
  33. {
  34. struct io_ring_ctx *ctx = req->ctx;
  35. struct socket *sock;
  36. if (!READ_ONCE(ctx->napi_enabled))
  37. return;
  38. sock = sock_from_file(req->file);
  39. if (sock)
  40. __io_napi_add(ctx, sock);
  41. }
  42. #else
  43. static inline void io_napi_init(struct io_ring_ctx *ctx)
  44. {
  45. }
  46. static inline void io_napi_free(struct io_ring_ctx *ctx)
  47. {
  48. }
  49. static inline int io_register_napi(struct io_ring_ctx *ctx, void __user *arg)
  50. {
  51. return -EOPNOTSUPP;
  52. }
  53. static inline int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg)
  54. {
  55. return -EOPNOTSUPP;
  56. }
  57. static inline bool io_napi(struct io_ring_ctx *ctx)
  58. {
  59. return false;
  60. }
  61. static inline void io_napi_add(struct io_kiocb *req)
  62. {
  63. }
  64. static inline void io_napi_busy_loop(struct io_ring_ctx *ctx,
  65. struct io_wait_queue *iowq)
  66. {
  67. }
  68. static inline int io_napi_sqpoll_busy_poll(struct io_ring_ctx *ctx)
  69. {
  70. return 0;
  71. }
  72. #endif /* CONFIG_NET_RX_BUSY_POLL */
  73. #endif