+/*
+ * used to calculate the next io time for rate control
+ *
+ */
+static long long usec_for_io(struct thread_data *td, enum fio_ddir ddir)
+{
+ uint64_t secs, remainder, bps, bytes, iops;
+
+ assert(!(td->flags & TD_F_CHILD));
+ bytes = td->rate_io_issue_bytes[ddir];
+ bps = td->rate_bps[ddir];
+
+ if (td->o.rate_process == RATE_PROCESS_POISSON) {
+ uint64_t val;
+ iops = bps / td->o.bs[ddir];
+ val = (int64_t) (1000000 / iops) *
+ -logf(__rand_0_1(&td->poisson_state));
+ if (val) {
+ dprint(FD_RATE, "poisson rate iops=%llu\n",
+ (unsigned long long) 1000000 / val);
+ }
+ td->last_usec += val;
+ return td->last_usec;
+ } else if (bps) {
+ secs = bytes / bps;
+ remainder = bytes % bps;
+ return remainder * 1000000 / bps + secs * 1000000;
+ }
+
+ return 0;
+}
+