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