]>
Commit | Line | Data |
---|---|---|
771b53d0 JA |
1 | #ifndef INTERNAL_IO_WQ_H |
2 | #define INTERNAL_IO_WQ_H | |
3 | ||
e941894e | 4 | #include <linux/refcount.h> |
ab1c84d8 | 5 | #include <linux/io_uring_types.h> |
98447d65 | 6 | |
771b53d0 JA |
7 | struct io_wq; |
8 | ||
9 | enum { | |
10 | IO_WQ_WORK_CANCEL = 1, | |
e883a79d PB |
11 | IO_WQ_WORK_HASHED = 2, |
12 | IO_WQ_WORK_UNBOUND = 4, | |
e883a79d | 13 | IO_WQ_WORK_CONCURRENT = 16, |
771b53d0 JA |
14 | |
15 | IO_WQ_HASH_SHIFT = 24, /* upper 8 bits are used for hash key */ | |
16 | }; | |
17 | ||
18 | enum io_wq_cancel { | |
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 */ | |
22 | }; | |
23 | ||
5280f7e5 PB |
24 | typedef struct io_wq_work *(free_work_fn)(struct io_wq_work *); |
25 | typedef void (io_wq_work_fn)(struct io_wq_work *); | |
7d723065 | 26 | |
e941894e JA |
27 | struct io_wq_hash { |
28 | refcount_t refs; | |
29 | unsigned long map; | |
30 | struct wait_queue_head wait; | |
31 | }; | |
32 | ||
33 | static inline void io_wq_put_hash(struct io_wq_hash *hash) | |
34 | { | |
35 | if (refcount_dec_and_test(&hash->refs)) | |
36 | kfree(hash); | |
37 | } | |
38 | ||
576a347b | 39 | struct io_wq_data { |
e941894e | 40 | struct io_wq_hash *hash; |
685fe7fe | 41 | struct task_struct *task; |
f5fa38c5 | 42 | io_wq_work_fn *do_work; |
e9fd9396 | 43 | free_work_fn *free_work; |
576a347b JA |
44 | }; |
45 | ||
46 | struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data); | |
17a91051 | 47 | void io_wq_exit_start(struct io_wq *wq); |
afcc4015 | 48 | void io_wq_put_and_exit(struct io_wq *wq); |
771b53d0 JA |
49 | |
50 | void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work); | |
8766dd51 PB |
51 | void io_wq_hash_work(struct io_wq_work *work, void *val); |
52 | ||
fe76421d | 53 | int io_wq_cpu_affinity(struct io_wq *wq, cpumask_var_t mask); |
2e480058 | 54 | int io_wq_max_workers(struct io_wq *wq, int *new_count); |
fe76421d | 55 | |
8766dd51 PB |
56 | static inline bool io_wq_is_hashed(struct io_wq_work *work) |
57 | { | |
58 | return work->flags & IO_WQ_WORK_HASHED; | |
59 | } | |
771b53d0 | 60 | |
62755e35 JA |
61 | typedef bool (work_cancel_fn)(struct io_wq_work *, void *); |
62 | ||
63 | enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel, | |
4f26bda1 | 64 | void *data, bool cancel_all); |
62755e35 | 65 | |
771b53d0 JA |
66 | #if defined(CONFIG_IO_WQ) |
67 | extern void io_wq_worker_sleeping(struct task_struct *); | |
68 | extern void io_wq_worker_running(struct task_struct *); | |
69 | #else | |
70 | static inline void io_wq_worker_sleeping(struct task_struct *tsk) | |
71 | { | |
72 | } | |
73 | static inline void io_wq_worker_running(struct task_struct *tsk) | |
74 | { | |
75 | } | |
525b305d | 76 | #endif |
771b53d0 | 77 | |
525b305d JA |
78 | static inline bool io_wq_current_is_worker(void) |
79 | { | |
3bfe6106 | 80 | return in_task() && (current->flags & PF_IO_WORKER) && |
e32cf5df | 81 | current->worker_private; |
525b305d JA |
82 | } |
83 | #endif |