8 struct flist_head list;
10 long long int flow_counter;
13 static struct flist_head *flow_list;
14 static struct fio_mutex *flow_lock;
16 int flow_threshold_exceeded(struct thread_data *td)
18 struct fio_flow *flow = td->flow;
24 sign = td->o.flow > 0 ? 1 : -1;
25 if (sign * flow->flow_counter > td->o.flow_watermark) {
26 if (td->o.flow_sleep) {
28 usleep(td->o.flow_sleep);
34 /* No synchronization needed because it doesn't
35 * matter if the flow count is slightly inaccurate */
36 flow->flow_counter += td->o.flow;
40 static struct fio_flow *flow_get(unsigned int id)
42 struct fio_flow *flow = NULL;
48 fio_mutex_down(flow_lock);
50 flist_for_each(n, flow_list) {
51 flow = flist_entry(n, struct fio_flow, list);
59 flow = smalloc(sizeof(*flow));
61 log_err("fio: smalloc pool exhausted\n");
62 fio_mutex_up(flow_lock);
66 INIT_FLIST_HEAD(&flow->list);
68 flow->flow_counter = 0;
70 flist_add_tail(&flow->list, flow_list);
74 fio_mutex_up(flow_lock);
78 static void flow_put(struct fio_flow *flow)
83 fio_mutex_down(flow_lock);
86 flist_del(&flow->list);
90 fio_mutex_up(flow_lock);
93 void flow_init_job(struct thread_data *td)
96 td->flow = flow_get(td->o.flow_id);
99 void flow_exit_job(struct thread_data *td)
109 flow_list = smalloc(sizeof(*flow_list));
111 log_err("fio: smalloc pool exhausted\n");
115 flow_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
117 log_err("fio: failed to allocate flow lock\n");
122 INIT_FLIST_HEAD(flow_list);
128 fio_mutex_remove(flow_lock);