1 #ifndef INTERNAL_IO_WQ_H
2 #define INTERNAL_IO_WQ_H
4 #include <linux/refcount.h>
5 #include <linux/io_uring.h>
10 IO_WQ_WORK_CANCEL = 1,
11 IO_WQ_WORK_HASHED = 2,
12 IO_WQ_WORK_UNBOUND = 4,
13 IO_WQ_WORK_CONCURRENT = 16,
15 IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */
19 IO_WQ_CANCEL_OK, /* cancelled before started */
20 IO_WQ_CANCEL_RUNNING, /* found, running, and attempted cancelled */
21 IO_WQ_CANCEL_NOTFOUND, /* work not found */
24 static inline void wq_list_add_after(struct io_wq_work_node *node,
25 struct io_wq_work_node *pos,
26 struct io_wq_work_list *list)
28 struct io_wq_work_node *next = pos->next;
36 static inline void wq_list_add_tail(struct io_wq_work_node *node,
37 struct io_wq_work_list *list)
41 WRITE_ONCE(list->first, node);
43 list->last->next = node;
49 static inline void wq_list_cut(struct io_wq_work_list *list,
50 struct io_wq_work_node *last,
51 struct io_wq_work_node *prev)
53 /* first in the list, if prev==NULL */
55 WRITE_ONCE(list->first, last->next);
57 prev->next = last->next;
59 if (last == list->last)
64 static inline void wq_list_del(struct io_wq_work_list *list,
65 struct io_wq_work_node *node,
66 struct io_wq_work_node *prev)
68 wq_list_cut(list, node, prev);
71 #define wq_list_for_each(pos, prv, head) \
72 for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
74 #define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
75 #define INIT_WQ_LIST(list) do { \
76 (list)->first = NULL; \
77 (list)->last = NULL; \
81 struct io_wq_work_node list;
83 unsigned short personality;
86 static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
91 return container_of(work->list.next, struct io_wq_work, list);
94 typedef struct io_wq_work *(free_work_fn)(struct io_wq_work *);
95 typedef void (io_wq_work_fn)(struct io_wq_work *);
100 struct wait_queue_head wait;
103 static inline void io_wq_put_hash(struct io_wq_hash *hash)
105 if (refcount_dec_and_test(&hash->refs))
110 struct io_wq_hash *hash;
111 io_wq_work_fn *do_work;
112 free_work_fn *free_work;
115 struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
116 void io_wq_put(struct io_wq *wq);
117 void io_wq_put_and_exit(struct io_wq *wq);
119 void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
120 void io_wq_hash_work(struct io_wq_work *work, void *val);
122 static inline bool io_wq_is_hashed(struct io_wq_work *work)
124 return work->flags & IO_WQ_WORK_HASHED;
127 typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
129 enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
130 void *data, bool cancel_all);
132 #if defined(CONFIG_IO_WQ)
133 extern void io_wq_worker_sleeping(struct task_struct *);
134 extern void io_wq_worker_running(struct task_struct *);
136 static inline void io_wq_worker_sleeping(struct task_struct *tsk)
139 static inline void io_wq_worker_running(struct task_struct *tsk)
144 static inline bool io_wq_current_is_worker(void)
146 return in_task() && (current->flags & PF_IO_WORKER) &&
147 current->pf_io_worker;