9 struct flist_head list;
10 unsigned long flow_counter;
11 unsigned int total_weight;
14 static struct flist_head *flow_list;
15 static struct fio_sem *flow_lock;
17 int flow_threshold_exceeded(struct thread_data *td)
19 struct fio_flow *flow = td->flow;
20 double flow_counter_ratio, flow_weight_ratio;
25 flow_counter_ratio = (double)td->flow_counter /
26 atomic_load_relaxed(&flow->flow_counter);
27 flow_weight_ratio = (double)td->o.flow /
28 atomic_load_relaxed(&flow->total_weight);
31 * each thread/process executing a fio job will stall based on the
32 * expected user ratio for a given flow_id group. the idea is to keep
33 * 2 counters, flow and job-specific counter to test if the
34 * ratio between them is proportional to other jobs in the same flow_id
36 if (flow_counter_ratio > flow_weight_ratio) {
37 if (td->o.flow_sleep) {
39 usleep(td->o.flow_sleep);
46 * increment flow(shared counter, therefore atomically)
47 * and job-specific counter
49 atomic_add(&flow->flow_counter, 1);
55 static struct fio_flow *flow_get(unsigned int id)
57 struct fio_flow *flow = NULL;
63 fio_sem_down(flow_lock);
65 flist_for_each(n, flow_list) {
66 flow = flist_entry(n, struct fio_flow, list);
74 flow = smalloc(sizeof(*flow));
76 fio_sem_up(flow_lock);
80 INIT_FLIST_HEAD(&flow->list);
82 flow->flow_counter = 1;
83 flow->total_weight = 0;
85 flist_add_tail(&flow->list, flow_list);
89 fio_sem_up(flow_lock);
93 static void flow_put(struct fio_flow *flow, unsigned long flow_counter,
99 fio_sem_down(flow_lock);
101 atomic_sub(&flow->flow_counter, flow_counter);
102 atomic_sub(&flow->total_weight, weight);
105 assert(flow->flow_counter == 1);
106 flist_del(&flow->list);
110 fio_sem_up(flow_lock);
113 void flow_init_job(struct thread_data *td)
116 td->flow = flow_get(td->o.flow_id);
117 td->flow_counter = 0;
118 atomic_add(&td->flow->total_weight, td->o.flow);
122 void flow_exit_job(struct thread_data *td)
125 flow_put(td->flow, td->flow_counter, td->o.flow);
132 flow_list = smalloc(sizeof(*flow_list));
134 log_err("fio: smalloc pool exhausted\n");
138 flow_lock = fio_sem_init(FIO_SEM_UNLOCKED);
140 log_err("fio: failed to allocate flow lock\n");
145 INIT_FLIST_HEAD(flow_list);
151 fio_sem_remove(flow_lock);