]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - fs/io-wq.h
1 #ifndef INTERNAL_IO_WQ_H
2 #define INTERNAL_IO_WQ_H
4 #include <linux/refcount.h>
10 IO_WQ_WORK_HASHED
= 2,
11 IO_WQ_WORK_UNBOUND
= 4,
12 IO_WQ_WORK_CONCURRENT
= 16,
14 IO_WQ_HASH_SHIFT
= 24, /* upper 8 bits are used for hash key */
18 IO_WQ_CANCEL_OK
, /* cancelled before started */
19 IO_WQ_CANCEL_RUNNING
, /* found, running, and attempted cancelled */
20 IO_WQ_CANCEL_NOTFOUND
, /* work not found */
23 struct io_wq_work_node
{
24 struct io_wq_work_node
*next
;
27 struct io_wq_work_list
{
28 struct io_wq_work_node
*first
;
29 struct io_wq_work_node
*last
;
32 static inline void wq_list_add_after(struct io_wq_work_node
*node
,
33 struct io_wq_work_node
*pos
,
34 struct io_wq_work_list
*list
)
36 struct io_wq_work_node
*next
= pos
->next
;
44 static inline void wq_list_add_tail(struct io_wq_work_node
*node
,
45 struct io_wq_work_list
*list
)
50 WRITE_ONCE(list
->first
, node
);
52 list
->last
->next
= node
;
57 static inline void wq_list_cut(struct io_wq_work_list
*list
,
58 struct io_wq_work_node
*last
,
59 struct io_wq_work_node
*prev
)
61 /* first in the list, if prev==NULL */
63 WRITE_ONCE(list
->first
, last
->next
);
65 prev
->next
= last
->next
;
67 if (last
== list
->last
)
72 static inline void wq_list_del(struct io_wq_work_list
*list
,
73 struct io_wq_work_node
*node
,
74 struct io_wq_work_node
*prev
)
76 wq_list_cut(list
, node
, prev
);
79 #define wq_list_for_each(pos, prv, head) \
80 for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
82 #define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
83 #define INIT_WQ_LIST(list) do { \
84 (list)->first = NULL; \
85 (list)->last = NULL; \
89 struct io_wq_work_node list
;
93 static inline struct io_wq_work
*wq_next_work(struct io_wq_work
*work
)
98 return container_of(work
->list
.next
, struct io_wq_work
, list
);
101 typedef struct io_wq_work
*(free_work_fn
)(struct io_wq_work
*);
102 typedef void (io_wq_work_fn
)(struct io_wq_work
*);
107 struct wait_queue_head wait
;
110 static inline void io_wq_put_hash(struct io_wq_hash
*hash
)
112 if (refcount_dec_and_test(&hash
->refs
))
117 struct io_wq_hash
*hash
;
118 struct task_struct
*task
;
119 io_wq_work_fn
*do_work
;
120 free_work_fn
*free_work
;
123 struct io_wq
*io_wq_create(unsigned bounded
, struct io_wq_data
*data
);
124 void io_wq_exit_start(struct io_wq
*wq
);
125 void io_wq_put_and_exit(struct io_wq
*wq
);
127 void io_wq_enqueue(struct io_wq
*wq
, struct io_wq_work
*work
);
128 void io_wq_hash_work(struct io_wq_work
*work
, void *val
);
130 int io_wq_cpu_affinity(struct io_wq
*wq
, cpumask_var_t mask
);
131 int io_wq_max_workers(struct io_wq
*wq
, int *new_count
);
133 static inline bool io_wq_is_hashed(struct io_wq_work
*work
)
135 return work
->flags
& IO_WQ_WORK_HASHED
;
138 typedef bool (work_cancel_fn
)(struct io_wq_work
*, void *);
140 enum io_wq_cancel
io_wq_cancel_cb(struct io_wq
*wq
, work_cancel_fn
*cancel
,
141 void *data
, bool cancel_all
);
143 #if defined(CONFIG_IO_WQ)
144 extern void io_wq_worker_sleeping(struct task_struct
*);
145 extern void io_wq_worker_running(struct task_struct
*);
147 static inline void io_wq_worker_sleeping(struct task_struct
*tsk
)
150 static inline void io_wq_worker_running(struct task_struct
*tsk
)
155 static inline bool io_wq_current_is_worker(void)
157 return in_task() && (current
->flags
& PF_IO_WORKER
) &&
158 current
->pf_io_worker
;