return buflen;
}
+static void set_rwmix_bytes(struct thread_data *td)
+{
+ unsigned long long rbytes;
+ unsigned int diff;
+
+ /*
+ * we do time or byte based switch. this is needed because
+ * buffered writes may issue a lot quicker than they complete,
+ * whereas reads do not.
+ */
+ rbytes = td->io_bytes[td->rwmix_ddir] - td->rwmix_bytes;
+ diff = td->o.rwmix[td->rwmix_ddir ^ 1];
+
+ td->rwmix_bytes = td->io_bytes[td->rwmix_ddir] + (rbytes * ((100 - diff)) / diff);
+}
+
+static inline enum fio_ddir get_rand_ddir(struct thread_data *td)
+{
+ 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->o.rwmix[DDIR_READ])
+ return DDIR_READ;
+
+ return DDIR_WRITE;
+}
+
/*
* Return the data direction for the next io_u. If the job is a
* mixed read/write workload, check the rwmix cycle and switch if
if (td_rw(td)) {
struct timeval now;
unsigned long elapsed;
+ unsigned int cycle;
fio_gettime(&now, NULL);
elapsed = mtime_since_now(&td->rwmix_switch);
+ /*
+ * if this is the first cycle, make it shorter
+ */
+ cycle = td->o.rwmixcycle;
+ if (!td->rwmix_bytes)
+ cycle /= 10;
+
/*
* Check if it's time to seed a new data direction.
*/
- if (elapsed >= td->o.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->o.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;
memcpy(&td->rwmix_switch, &now, sizeof(now));
}
return td->rwmix_ddir;