+ /*
+ * 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,
+ enum fio_file_flags goodf,
+ enum fio_file_flags 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 (fio_file_done(f))
+ continue;
+
+ if (!fio_file_open(f)) {
+ 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;