io-wq.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef INTERNAL_IO_WQ_H
  2. #define INTERNAL_IO_WQ_H
  3. #include <linux/refcount.h>
  4. #include <linux/io_uring_types.h>
  5. struct io_wq;
  6. enum {
  7. IO_WQ_WORK_CANCEL = 1,
  8. IO_WQ_WORK_HASHED = 2,
  9. IO_WQ_WORK_UNBOUND = 4,
  10. IO_WQ_WORK_CONCURRENT = 16,
  11. IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */
  12. };
  13. enum io_wq_cancel {
  14. IO_WQ_CANCEL_OK, /* cancelled before started */
  15. IO_WQ_CANCEL_RUNNING, /* found, running, and attempted cancelled */
  16. IO_WQ_CANCEL_NOTFOUND, /* work not found */
  17. };
  18. typedef struct io_wq_work *(free_work_fn)(struct io_wq_work *);
  19. typedef void (io_wq_work_fn)(struct io_wq_work *);
  20. struct io_wq_hash {
  21. refcount_t refs;
  22. unsigned long map;
  23. struct wait_queue_head wait;
  24. };
  25. static inline void io_wq_put_hash(struct io_wq_hash *hash)
  26. {
  27. if (refcount_dec_and_test(&hash->refs))
  28. kfree(hash);
  29. }
  30. struct io_wq_data {
  31. struct io_wq_hash *hash;
  32. struct task_struct *task;
  33. io_wq_work_fn *do_work;
  34. free_work_fn *free_work;
  35. };
  36. struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
  37. void io_wq_exit_start(struct io_wq *wq);
  38. void io_wq_put_and_exit(struct io_wq *wq);
  39. void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
  40. void io_wq_hash_work(struct io_wq_work *work, void *val);
  41. int io_wq_cpu_affinity(struct io_uring_task *tctx, cpumask_var_t mask);
  42. int io_wq_max_workers(struct io_wq *wq, int *new_count);
  43. bool io_wq_worker_stopped(void);
  44. static inline bool io_wq_is_hashed(struct io_wq_work *work)
  45. {
  46. return atomic_read(&work->flags) & IO_WQ_WORK_HASHED;
  47. }
  48. typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
  49. enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
  50. void *data, bool cancel_all);
  51. #if defined(CONFIG_IO_WQ)
  52. extern void io_wq_worker_sleeping(struct task_struct *);
  53. extern void io_wq_worker_running(struct task_struct *);
  54. #else
  55. static inline void io_wq_worker_sleeping(struct task_struct *tsk)
  56. {
  57. }
  58. static inline void io_wq_worker_running(struct task_struct *tsk)
  59. {
  60. }
  61. #endif
  62. static inline bool io_wq_current_is_worker(void)
  63. {
  64. return in_task() && (current->flags & PF_IO_WORKER) &&
  65. current->worker_private;
  66. }
  67. #endif