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);
40 } else if (td->o.zone_mode == ZONE_MODE_ZBD) {
48 * increment flow(shared counter, therefore atomically)
49 * and job-specific counter
51 atomic_add(&flow->flow_counter, 1);
57 static struct fio_flow *flow_get(unsigned int id)
59 struct fio_flow *flow = NULL;
65 fio_sem_down(flow_lock);
67 flist_for_each(n, flow_list) {
68 flow = flist_entry(n, struct fio_flow, list);
76 flow = smalloc(sizeof(*flow));
78 fio_sem_up(flow_lock);
82 INIT_FLIST_HEAD(&flow->list);
84 flow->flow_counter = 1;
85 flow->total_weight = 0;
87 flist_add_tail(&flow->list, flow_list);
91 fio_sem_up(flow_lock);
95 static void flow_put(struct fio_flow *flow, unsigned long flow_counter,
101 fio_sem_down(flow_lock);
103 atomic_sub(&flow->flow_counter, flow_counter);
104 atomic_sub(&flow->total_weight, weight);
107 assert(flow->flow_counter == 1);
108 flist_del(&flow->list);
112 fio_sem_up(flow_lock);
115 void flow_init_job(struct thread_data *td)
118 td->flow = flow_get(td->o.flow_id);
119 td->flow_counter = 0;
120 atomic_add(&td->flow->total_weight, td->o.flow);
124 void flow_exit_job(struct thread_data *td)
127 flow_put(td->flow, td->flow_counter, td->o.flow);
134 flow_list = smalloc(sizeof(*flow_list));
136 log_err("fio: smalloc pool exhausted\n");
140 flow_lock = fio_sem_init(FIO_SEM_UNLOCKED);
142 log_err("fio: failed to allocate flow lock\n");
147 INIT_FLIST_HEAD(flow_list);
153 fio_sem_remove(flow_lock);