io-wq.h 2.1 KB

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