+ /*
+ * No log, let the seq/rand engine retrieve the next buflen and
+ * position.
+ */
+ if (get_next_offset(td, io_u)) {
+ dprint(FD_IO, "io_u %p, failed getting offset\n", io_u);
+ return 1;
+ }
+
+ io_u->buflen = get_next_buflen(td, io_u);
+ if (!io_u->buflen) {
+ dprint(FD_IO, "io_u %p, failed getting buflen\n", io_u);
+ return 1;
+ }
+
+ if (io_u->offset + io_u->buflen > io_u->file->real_file_size) {
+ dprint(FD_IO, "io_u %p, offset too large\n", io_u);
+ dprint(FD_IO, " off=%llu/%lu > %llu\n", io_u->offset,
+ io_u->buflen, io_u->file->real_file_size);
+ return 1;
+ }
+
+ /*
+ * mark entry before potentially trimming io_u
+ */
+ if (td_random(td) && file_randommap(td, io_u->file))
+ mark_random_map(td, io_u);
+
+ /*
+ * If using a write iolog, store this entry.
+ */
+out:
+ dprint_io_u(io_u, "fill_io_u");
+ td->zone_bytes += io_u->buflen;
+ log_io_u(td, io_u);
+ return 0;
+}
+
+static void __io_u_mark_map(unsigned int *map, unsigned int nr)
+{
+ int index = 0;
+
+ switch (nr) {
+ default:
+ index = 6;
+ break;
+ case 33 ... 64:
+ index = 5;
+ break;
+ case 17 ... 32:
+ index = 4;
+ break;
+ case 9 ... 16:
+ index = 3;
+ break;
+ case 5 ... 8:
+ index = 2;
+ break;
+ case 1 ... 4:
+ index = 1;
+ case 0:
+ break;
+ }
+
+ map[index]++;
+}
+
+void io_u_mark_submit(struct thread_data *td, unsigned int nr)
+{
+ __io_u_mark_map(td->ts.io_u_submit, nr);
+ td->ts.total_submit++;
+}
+
+void io_u_mark_complete(struct thread_data *td, unsigned int nr)
+{
+ __io_u_mark_map(td->ts.io_u_complete, nr);
+ td->ts.total_complete++;
+}
+
+void io_u_mark_depth(struct thread_data *td, unsigned int nr)
+{
+ int index = 0;
+
+ switch (td->cur_depth) {
+ default:
+ index = 6;
+ break;
+ case 32 ... 63:
+ index = 5;
+ break;
+ case 16 ... 31:
+ index = 4;
+ break;
+ case 8 ... 15:
+ index = 3;
+ break;
+ case 4 ... 7:
+ index = 2;
+ break;
+ case 2 ... 3:
+ index = 1;
+ case 1:
+ break;
+ }
+
+ td->ts.io_u_map[index] += nr;
+}
+
+static void io_u_mark_lat_usec(struct thread_data *td, unsigned long usec)
+{
+ int index = 0;
+
+ assert(usec < 1000);
+
+ switch (usec) {
+ case 750 ... 999:
+ index = 9;
+ break;
+ case 500 ... 749:
+ index = 8;
+ break;
+ case 250 ... 499:
+ index = 7;
+ break;
+ case 100 ... 249:
+ index = 6;
+ break;
+ case 50 ... 99:
+ index = 5;
+ break;
+ case 20 ... 49:
+ index = 4;
+ break;
+ case 10 ... 19:
+ index = 3;
+ break;
+ case 4 ... 9:
+ index = 2;
+ break;
+ case 2 ... 3:
+ index = 1;
+ case 0 ... 1:
+ break;
+ }
+
+ assert(index < FIO_IO_U_LAT_U_NR);
+ td->ts.io_u_lat_u[index]++;
+}
+
+static void io_u_mark_lat_msec(struct thread_data *td, unsigned long msec)
+{
+ int index = 0;
+
+ switch (msec) {
+ default:
+ index = 11;
+ break;
+ case 1000 ... 1999:
+ index = 10;
+ break;
+ case 750 ... 999:
+ index = 9;
+ break;
+ case 500 ... 749:
+ index = 8;
+ break;
+ case 250 ... 499:
+ index = 7;
+ break;
+ case 100 ... 249:
+ index = 6;
+ break;
+ case 50 ... 99:
+ index = 5;
+ break;
+ case 20 ... 49:
+ index = 4;
+ break;
+ case 10 ... 19:
+ index = 3;
+ break;
+ case 4 ... 9:
+ index = 2;
+ break;
+ case 2 ... 3:
+ index = 1;
+ case 0 ... 1:
+ break;
+ }
+
+ assert(index < FIO_IO_U_LAT_M_NR);
+ td->ts.io_u_lat_m[index]++;
+}
+
+static void io_u_mark_latency(struct thread_data *td, unsigned long usec)
+{
+ if (usec < 1000)
+ io_u_mark_lat_usec(td, usec);
+ else
+ io_u_mark_lat_msec(td, usec / 1000);
+}
+
+/*
+ * Get next file to service by choosing one at random
+ */
+static struct fio_file *get_next_file_rand(struct thread_data *td, int goodf,
+ int badf)
+{
+ struct fio_file *f;
+ int fno;
+
+ do {
+ long r = os_random_long(&td->next_file_state);
+ int opened = 0;
+
+ fno = (unsigned int) ((double) td->o.nr_files
+ * (r / (OS_RAND_MAX + 1.0)));
+ f = td->files[fno];
+ if (f->flags & FIO_FILE_DONE)
+ continue;
+
+ if (!(f->flags & FIO_FILE_OPEN)) {
+ int err;
+
+ err = td_io_open_file(td, f);
+ if (err)
+ continue;
+ opened = 1;
+ }
+
+ if ((!goodf || (f->flags & goodf)) && !(f->flags & badf)) {
+ dprint(FD_FILE, "get_next_file_rand: %p\n", f);
+ return f;
+ }
+ if (opened)
+ td_io_close_file(td, f);
+ } while (1);
+}
+
+/*
+ * Get next file to service by doing round robin between all available ones
+ */
+static struct fio_file *get_next_file_rr(struct thread_data *td, int goodf,
+ int badf)
+{
+ unsigned int old_next_file = td->next_file;
+ struct fio_file *f;
+
+ do {
+ int opened = 0;
+
+ f = td->files[td->next_file];
+
+ td->next_file++;
+ if (td->next_file >= td->o.nr_files)
+ td->next_file = 0;
+
+ dprint(FD_FILE, "trying file %s %x\n", f->file_name, f->flags);
+ if (f->flags & FIO_FILE_DONE) {
+ f = NULL;
+ continue;