Commit | Line | Data |
---|---|---|
a9da8ab2 JA |
1 | #ifndef FIO_RATE_H |
2 | #define FIO_RATE_H | |
3 | ||
4 | #include "flist.h" | |
5 | ||
88271841 JA |
6 | struct workqueue_work { |
7 | struct flist_head list; | |
8 | }; | |
9 | ||
ee2b6d6e JA |
10 | struct submit_worker { |
11 | pthread_t thread; | |
12 | pthread_mutex_t lock; | |
13 | pthread_cond_t cond; | |
14 | struct flist_head work_list; | |
15 | unsigned int flags; | |
16 | unsigned int index; | |
17 | uint64_t seq; | |
18 | struct workqueue *wq; | |
19 | void *private; | |
20 | }; | |
21 | ||
155f2f02 | 22 | typedef int (workqueue_work_fn)(struct submit_worker *, struct workqueue_work *); |
ee2b6d6e JA |
23 | typedef bool (workqueue_pre_sleep_flush_fn)(struct submit_worker *); |
24 | typedef void (workqueue_pre_sleep_fn)(struct submit_worker *); | |
25 | typedef int (workqueue_alloc_worker_fn)(struct submit_worker *); | |
26 | typedef void (workqueue_free_worker_fn)(struct submit_worker *); | |
80ea26a8 | 27 | typedef int (workqueue_init_worker_fn)(struct submit_worker *); |
c35c582d | 28 | typedef void (workqueue_exit_worker_fn)(struct submit_worker *, unsigned int *); |
17ecadc3 | 29 | typedef void (workqueue_update_acct_fn)(struct submit_worker *); |
5bb79f69 JA |
30 | |
31 | struct workqueue_ops { | |
32 | workqueue_work_fn *fn; | |
33 | workqueue_pre_sleep_flush_fn *pre_sleep_flush_fn; | |
34 | workqueue_pre_sleep_fn *pre_sleep_fn; | |
df8472e1 | 35 | |
17ecadc3 JA |
36 | workqueue_update_acct_fn *update_acct_fn; |
37 | ||
ee2b6d6e JA |
38 | workqueue_alloc_worker_fn *alloc_worker_fn; |
39 | workqueue_free_worker_fn *free_worker_fn; | |
df8472e1 | 40 | |
80ea26a8 | 41 | workqueue_init_worker_fn *init_worker_fn; |
df8472e1 | 42 | workqueue_exit_worker_fn *exit_worker_fn; |
f6496ba7 JA |
43 | |
44 | unsigned int nice; | |
5bb79f69 | 45 | }; |
a9da8ab2 JA |
46 | |
47 | struct workqueue { | |
48 | unsigned int max_workers; | |
49 | ||
50 | struct thread_data *td; | |
5bb79f69 | 51 | struct workqueue_ops ops; |
a9da8ab2 JA |
52 | |
53 | uint64_t work_seq; | |
54 | struct submit_worker *workers; | |
55 | unsigned int next_free_worker; | |
56 | ||
57 | pthread_cond_t flush_cond; | |
58 | pthread_mutex_t flush_lock; | |
2a274336 | 59 | pthread_mutex_t stat_lock; |
a9da8ab2 JA |
60 | volatile int wake_idle; |
61 | }; | |
62 | ||
5bb79f69 | 63 | int workqueue_init(struct thread_data *td, struct workqueue *wq, struct workqueue_ops *ops, unsigned int max_workers); |
a9da8ab2 JA |
64 | void workqueue_exit(struct workqueue *wq); |
65 | ||
26de50cf | 66 | void workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work); |
a9da8ab2 JA |
67 | void workqueue_flush(struct workqueue *wq); |
68 | ||
ee2b6d6e | 69 | static inline bool workqueue_pre_sleep_check(struct submit_worker *sw) |
5bb79f69 | 70 | { |
ee2b6d6e JA |
71 | struct workqueue *wq = sw->wq; |
72 | ||
5bb79f69 JA |
73 | if (!wq->ops.pre_sleep_flush_fn) |
74 | return false; | |
75 | ||
ee2b6d6e | 76 | return wq->ops.pre_sleep_flush_fn(sw); |
5bb79f69 JA |
77 | } |
78 | ||
ee2b6d6e | 79 | static inline void workqueue_pre_sleep(struct submit_worker *sw) |
5bb79f69 | 80 | { |
ee2b6d6e JA |
81 | struct workqueue *wq = sw->wq; |
82 | ||
5bb79f69 | 83 | if (wq->ops.pre_sleep_fn) |
ee2b6d6e | 84 | wq->ops.pre_sleep_fn(sw); |
5bb79f69 JA |
85 | } |
86 | ||
80ea26a8 JA |
87 | static inline int workqueue_init_worker(struct submit_worker *sw) |
88 | { | |
89 | struct workqueue *wq = sw->wq; | |
90 | ||
91 | if (!wq->ops.init_worker_fn) | |
92 | return 0; | |
93 | ||
94 | return wq->ops.init_worker_fn(sw); | |
95 | } | |
96 | ||
c35c582d JA |
97 | static inline void workqueue_exit_worker(struct submit_worker *sw, |
98 | unsigned int *sum_cnt) | |
df8472e1 JA |
99 | { |
100 | struct workqueue *wq = sw->wq; | |
c35c582d | 101 | unsigned int tmp = 1; |
df8472e1 JA |
102 | |
103 | if (!wq->ops.exit_worker_fn) | |
104 | return; | |
105 | ||
c35c582d JA |
106 | if (!sum_cnt) |
107 | sum_cnt = &tmp; | |
108 | ||
109 | wq->ops.exit_worker_fn(sw, sum_cnt); | |
df8472e1 | 110 | } |
a9da8ab2 | 111 | #endif |