- if (elapsed >= td->rwmixcycle) {
- unsigned int v;
- long r;
-
- r = os_random_long(&td->rwmix_state);
- v = 1 + (int) (100.0 * (r / (RAND_MAX + 1.0)));
- if (v < td->rwmixread)
- td->rwmix_ddir = DDIR_READ;
- else
- td->rwmix_ddir = DDIR_WRITE;
+ if (elapsed >= cycle ||
+ td->io_bytes[td->rwmix_ddir] >= td->rwmix_bytes) {
+ unsigned long long max_bytes;
+ enum fio_ddir ddir;
+
+ /*
+ * Put a top limit on how many bytes we do for
+ * one data direction, to avoid overflowing the
+ * ranges too much
+ */
+ ddir = get_rand_ddir(td);
+ max_bytes = td->this_io_bytes[ddir];
+ if (max_bytes >= (td->io_size * td->o.rwmix[ddir] / 100)) {
+ if (!td->rw_end_set[ddir]) {
+ td->rw_end_set[ddir] = 1;
+ memcpy(&td->rw_end[ddir], &now, sizeof(now));
+ }
+ ddir ^= 1;
+ }
+
+ if (ddir != td->rwmix_ddir)
+ set_rwmix_bytes(td);
+
+ td->rwmix_ddir = ddir;