]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - fs/io-wq.h
io-wq: optimise out *next_work() double lock
[mirror_ubuntu-hirsute-kernel.git] / fs / io-wq.h
CommitLineData
771b53d0
JA
1#ifndef INTERNAL_IO_WQ_H
2#define INTERNAL_IO_WQ_H
3
4struct io_wq;
5
6enum {
7 IO_WQ_WORK_CANCEL = 1,
771b53d0 8 IO_WQ_WORK_HASHED = 4,
c5def4ab 9 IO_WQ_WORK_UNBOUND = 32,
0c9d5ccd 10 IO_WQ_WORK_NO_CANCEL = 256,
895e2ca0 11 IO_WQ_WORK_CONCURRENT = 512,
771b53d0
JA
12
13 IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */
14};
15
16enum io_wq_cancel {
17 IO_WQ_CANCEL_OK, /* cancelled before started */
18 IO_WQ_CANCEL_RUNNING, /* found, running, and attempted cancelled */
19 IO_WQ_CANCEL_NOTFOUND, /* work not found */
20};
21
6206f0e1
JA
22struct io_wq_work_node {
23 struct io_wq_work_node *next;
24};
25
26struct io_wq_work_list {
27 struct io_wq_work_node *first;
28 struct io_wq_work_node *last;
29};
30
31static inline void wq_list_add_tail(struct io_wq_work_node *node,
32 struct io_wq_work_list *list)
33{
34 if (!list->first) {
e995d512
JA
35 list->last = node;
36 WRITE_ONCE(list->first, node);
6206f0e1
JA
37 } else {
38 list->last->next = node;
39 list->last = node;
40 }
41}
42
43static inline void wq_node_del(struct io_wq_work_list *list,
44 struct io_wq_work_node *node,
45 struct io_wq_work_node *prev)
46{
47 if (node == list->first)
e995d512 48 WRITE_ONCE(list->first, node->next);
6206f0e1
JA
49 if (node == list->last)
50 list->last = prev;
51 if (prev)
52 prev->next = node->next;
08bdcc35 53 node->next = NULL;
6206f0e1
JA
54}
55
56#define wq_list_for_each(pos, prv, head) \
57 for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
58
e995d512 59#define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
6206f0e1
JA
60#define INIT_WQ_LIST(list) do { \
61 (list)->first = NULL; \
62 (list)->last = NULL; \
63} while (0)
64
771b53d0 65struct io_wq_work {
b76da70f 66 union {
6206f0e1 67 struct io_wq_work_node list;
b76da70f
JA
68 void *data;
69 };
771b53d0 70 void (*func)(struct io_wq_work **);
fcb323cc 71 struct files_struct *files;
cccf0ee8
JA
72 struct mm_struct *mm;
73 const struct cred *creds;
9392a27d 74 struct fs_struct *fs;
6206f0e1 75 unsigned flags;
36282881 76 pid_t task_pid;
771b53d0
JA
77};
78
2d141dd2
JA
79#define INIT_IO_WORK(work, _func) \
80 do { \
81 *(work) = (struct io_wq_work){ .func = _func }; \
82 } while (0) \
771b53d0 83
7d723065
JA
84typedef void (get_work_fn)(struct io_wq_work *);
85typedef void (put_work_fn)(struct io_wq_work *);
86
576a347b 87struct io_wq_data {
576a347b
JA
88 struct user_struct *user;
89
90 get_work_fn *get_work;
91 put_work_fn *put_work;
92};
93
94struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
eba6f5a3 95bool io_wq_get(struct io_wq *wq, struct io_wq_data *data);
771b53d0
JA
96void io_wq_destroy(struct io_wq *wq);
97
98void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
99void io_wq_enqueue_hashed(struct io_wq *wq, struct io_wq_work *work, void *val);
771b53d0
JA
100
101void io_wq_cancel_all(struct io_wq *wq);
102enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
36282881 103enum io_wq_cancel io_wq_cancel_pid(struct io_wq *wq, pid_t pid);
771b53d0 104
62755e35
JA
105typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
106
107enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
108 void *data);
109
771b53d0
JA
110#if defined(CONFIG_IO_WQ)
111extern void io_wq_worker_sleeping(struct task_struct *);
112extern void io_wq_worker_running(struct task_struct *);
113#else
114static inline void io_wq_worker_sleeping(struct task_struct *tsk)
115{
116}
117static inline void io_wq_worker_running(struct task_struct *tsk)
118{
119}
525b305d 120#endif
771b53d0 121
525b305d
JA
122static inline bool io_wq_current_is_worker(void)
123{
124 return in_task() && (current->flags & PF_IO_WORKER);
125}
126#endif