8 struct flist_head list;
10 long long int flow_counter;
13 static struct flist_head *flow_list;
14 static struct fio_sem *flow_lock;
16 int flow_threshold_exceeded(struct thread_data *td)
18 struct fio_flow *flow = td->flow;
19 long long flow_counter;
25 flow_counter = flow->flow_counter;
27 flow_counter = -flow->flow_counter;
29 if (flow_counter > td->o.flow_watermark) {
30 if (td->o.flow_sleep) {
32 usleep(td->o.flow_sleep);
38 /* No synchronization needed because it doesn't
39 * matter if the flow count is slightly inaccurate */
40 flow->flow_counter += td->o.flow;
44 static struct fio_flow *flow_get(unsigned int id)
46 struct fio_flow *flow = NULL;
52 fio_sem_down(flow_lock);
54 flist_for_each(n, flow_list) {
55 flow = flist_entry(n, struct fio_flow, list);
63 flow = smalloc(sizeof(*flow));
65 fio_sem_up(flow_lock);
69 INIT_FLIST_HEAD(&flow->list);
71 flow->flow_counter = 0;
73 flist_add_tail(&flow->list, flow_list);
77 fio_sem_up(flow_lock);
81 static void flow_put(struct fio_flow *flow)
86 fio_sem_down(flow_lock);
89 flist_del(&flow->list);
93 fio_sem_up(flow_lock);
96 void flow_init_job(struct thread_data *td)
99 td->flow = flow_get(td->o.flow_id);
102 void flow_exit_job(struct thread_data *td)
112 flow_list = smalloc(sizeof(*flow_list));
114 log_err("fio: smalloc pool exhausted\n");
118 flow_lock = fio_sem_init(FIO_SEM_UNLOCKED);
120 log_err("fio: failed to allocate flow lock\n");
125 INIT_FLIST_HEAD(flow_list);
131 fio_sem_remove(flow_lock);