drm/panfrost: perfcnt: Reserve/use the AS attached to the perfcnt MMU context
[linux/fpc-iii.git] / fs / io-wq.h
blob50b3378febf2f3bb01d9b9cf0a8f582d0a72a50e
1 #ifndef INTERNAL_IO_WQ_H
2 #define INTERNAL_IO_WQ_H
4 struct io_wq;
6 enum {
7 IO_WQ_WORK_CANCEL = 1,
8 IO_WQ_WORK_HAS_MM = 2,
9 IO_WQ_WORK_HASHED = 4,
10 IO_WQ_WORK_UNBOUND = 32,
11 IO_WQ_WORK_INTERNAL = 64,
12 IO_WQ_WORK_CB = 128,
13 IO_WQ_WORK_NO_CANCEL = 256,
14 IO_WQ_WORK_CONCURRENT = 512,
16 IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */
19 enum 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 */
25 struct io_wq_work_node {
26 struct io_wq_work_node *next;
29 struct io_wq_work_list {
30 struct io_wq_work_node *first;
31 struct io_wq_work_node *last;
34 static inline void wq_list_add_tail(struct io_wq_work_node *node,
35 struct io_wq_work_list *list)
37 if (!list->first) {
38 list->last = node;
39 WRITE_ONCE(list->first, node);
40 } else {
41 list->last->next = node;
42 list->last = node;
46 static 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)
50 if (node == list->first)
51 WRITE_ONCE(list->first, node->next);
52 if (node == list->last)
53 list->last = prev;
54 if (prev)
55 prev->next = node->next;
56 node->next = NULL;
59 #define wq_list_for_each(pos, prv, head) \
60 for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
62 #define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
63 #define INIT_WQ_LIST(list) do { \
64 (list)->first = NULL; \
65 (list)->last = NULL; \
66 } while (0)
68 struct io_wq_work {
69 union {
70 struct io_wq_work_node list;
71 void *data;
73 void (*func)(struct io_wq_work **);
74 struct files_struct *files;
75 struct mm_struct *mm;
76 const struct cred *creds;
77 unsigned flags;
80 #define INIT_IO_WORK(work, _func) \
81 do { \
82 (work)->list.next = NULL; \
83 (work)->func = _func; \
84 (work)->flags = 0; \
85 (work)->files = NULL; \
86 (work)->mm = NULL; \
87 (work)->creds = NULL; \
88 } while (0) \
90 typedef void (get_work_fn)(struct io_wq_work *);
91 typedef void (put_work_fn)(struct io_wq_work *);
93 struct io_wq_data {
94 struct user_struct *user;
96 get_work_fn *get_work;
97 put_work_fn *put_work;
100 struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
101 bool io_wq_get(struct io_wq *wq, struct io_wq_data *data);
102 void io_wq_destroy(struct io_wq *wq);
104 void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
105 void io_wq_enqueue_hashed(struct io_wq *wq, struct io_wq_work *work, void *val);
106 void io_wq_flush(struct io_wq *wq);
108 void io_wq_cancel_all(struct io_wq *wq);
109 enum io_wq_cancel io_wq_cancel_work(struct io_wq *wq, struct io_wq_work *cwork);
111 typedef bool (work_cancel_fn)(struct io_wq_work *, void *);
113 enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
114 void *data);
116 #if defined(CONFIG_IO_WQ)
117 extern void io_wq_worker_sleeping(struct task_struct *);
118 extern void io_wq_worker_running(struct task_struct *);
119 #else
120 static inline void io_wq_worker_sleeping(struct task_struct *tsk)
123 static inline void io_wq_worker_running(struct task_struct *tsk)
126 #endif
128 static inline bool io_wq_current_is_worker(void)
130 return in_task() && (current->flags & PF_IO_WORKER);
132 #endif