wait.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0
  2. #ifndef IOU_WAIT_H
  3. #define IOU_WAIT_H
  4. #include <linux/io_uring_types.h>
  5. /*
  6. * No waiters. It's larger than any valid value of the tw counter
  7. * so that tests against ->cq_wait_nr would fail and skip wake_up().
  8. */
  9. #define IO_CQ_WAKE_INIT (-1U)
  10. /* Forced wake up if there is a waiter regardless of ->cq_wait_nr */
  11. #define IO_CQ_WAKE_FORCE (IO_CQ_WAKE_INIT >> 1)
  12. struct ext_arg {
  13. size_t argsz;
  14. struct timespec64 ts;
  15. const sigset_t __user *sig;
  16. ktime_t min_time;
  17. bool ts_set;
  18. bool iowait;
  19. };
  20. int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
  21. struct ext_arg *ext_arg);
  22. int io_run_task_work_sig(struct io_ring_ctx *ctx);
  23. void io_cqring_do_overflow_flush(struct io_ring_ctx *ctx);
  24. static inline unsigned int __io_cqring_events(struct io_ring_ctx *ctx)
  25. {
  26. struct io_rings *rings = io_get_rings(ctx);
  27. return ctx->cached_cq_tail - READ_ONCE(rings->cq.head);
  28. }
  29. static inline unsigned int __io_cqring_events_user(struct io_ring_ctx *ctx)
  30. {
  31. struct io_rings *rings = io_get_rings(ctx);
  32. return READ_ONCE(rings->cq.tail) - READ_ONCE(rings->cq.head);
  33. }
  34. /*
  35. * Reads the tail/head of the CQ ring while providing an acquire ordering,
  36. * see comment at top of io_uring.c.
  37. */
  38. static inline unsigned io_cqring_events(struct io_ring_ctx *ctx)
  39. {
  40. smp_rmb();
  41. return __io_cqring_events(ctx);
  42. }
  43. #endif