+ td->ts.io_u_map[index]++;
+ td->ts.total_io_u[io_u->ddir]++;
+}
+
+static void io_u_mark_latency(struct thread_data *td, unsigned long msec)
+{
+ int index = 0;
+
+ switch (msec) {
+ default:
+ index++;
+ case 1000 ... 1999:
+ index++;
+ case 750 ... 999:
+ index++;
+ case 500 ... 749:
+ index++;
+ case 250 ... 499:
+ index++;
+ case 100 ... 249:
+ index++;
+ case 50 ... 99:
+ index++;
+ case 20 ... 49:
+ index++;
+ case 10 ... 19:
+ index++;
+ case 4 ... 9:
+ index++;
+ case 2 ... 3:
+ index++;
+ case 0 ... 1:
+ break;
+ }
+
+ td->ts.io_u_lat[index]++;
+}
+
+/*
+ * 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);
+
+ fno = (unsigned int) ((double) td->o.nr_files * (r / (RAND_MAX + 1.0)));
+ f = &td->files[fno];
+ if (f->flags & FIO_FILE_DONE)
+ continue;
+
+ if ((!goodf || (f->flags & goodf)) && !(f->flags & badf))
+ return 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 {
+ f = &td->files[td->next_file];
+
+ td->next_file++;
+ if (td->next_file >= td->o.nr_files)
+ td->next_file = 0;
+
+ if (f->flags & FIO_FILE_DONE) {
+ f = NULL;
+ continue;
+ }
+
+ if ((!goodf || (f->flags & goodf)) && !(f->flags & badf))
+ break;
+
+ f = NULL;
+ } while (td->next_file != old_next_file);
+
+ return f;
+}
+
+static struct fio_file *get_next_file(struct thread_data *td)
+{
+ struct fio_file *f;
+
+ assert(td->o.nr_files <= td->files_index);
+
+ if (!td->nr_open_files || td->nr_done_files >= td->o.nr_files)
+ return NULL;
+
+ f = td->file_service_file;
+ if (f && (f->flags & FIO_FILE_OPEN) && td->file_service_left--)
+ return f;
+
+ if (td->o.file_service_type == FIO_FSERVICE_RR)
+ f = get_next_file_rr(td, FIO_FILE_OPEN, FIO_FILE_CLOSING);
+ else
+ f = get_next_file_rand(td, FIO_FILE_OPEN, FIO_FILE_CLOSING);
+
+ td->file_service_file = f;
+ td->file_service_left = td->file_service_nr - 1;
+ return f;
+}
+
+static struct fio_file *find_next_new_file(struct thread_data *td)
+{
+ struct fio_file *f;
+
+ if (!td->nr_open_files || td->nr_done_files >= td->o.nr_files)
+ return NULL;
+
+ if (td->o.file_service_type == FIO_FSERVICE_RR)
+ f = get_next_file_rr(td, 0, FIO_FILE_OPEN);
+ else
+ f = get_next_file_rand(td, 0, FIO_FILE_OPEN);
+
+ return f;