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) {
27 usleep(td->o.flow_sleep);
31 /* No synchronization needed because it doesn't
32 * matter if the flow count is slightly inaccurate */
33 flow->flow_counter += td->o.flow;
37 static struct fio_flow *flow_get(unsigned int id)
39 struct fio_flow *flow = NULL;
45 fio_mutex_down(flow_lock);
47 flist_for_each(n, flow_list) {
48 flow = flist_entry(n, struct fio_flow, list);
56 flow = smalloc(sizeof(*flow));
58 log_err("fio: smalloc pool exhausted\n");
62 INIT_FLIST_HEAD(&flow->list);
64 flow->flow_counter = 0;
66 flist_add_tail(&flow->list, flow_list);
70 fio_mutex_up(flow_lock);
74 static void flow_put(struct fio_flow *flow)
79 fio_mutex_down(flow_lock);
82 flist_del(&flow->list);
86 fio_mutex_up(flow_lock);
89 void flow_init_job(struct thread_data *td)
92 td->flow = flow_get(td->o.flow_id);
95 void flow_exit_job(struct thread_data *td)
105 flow_list = smalloc(sizeof(*flow_list));
107 log_err("fio: smalloc pool exhausted\n");
111 flow_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
113 log_err("fio: failed to allocate flow lock\n");
118 INIT_FLIST_HEAD(flow_list);
124 fio_mutex_remove(flow_lock);