X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=io_u.c;h=6fb754e7f44701cbfddc628abe4f7164eeccd1aa;hp=ab85193d1c95166dfcbd4eeea45a28637c788d4c;hb=0aabe160c38efc3c42157fac2a9af08e070341c6;hpb=5945b9b45474a9a717a3db2310822aa5064fb38b;ds=inline diff --git a/io_u.c b/io_u.c index ab85193d..6fb754e7 100644 --- a/io_u.c +++ b/io_u.c @@ -325,7 +325,27 @@ static void io_u_mark_latency(struct thread_data *td, unsigned long msec) td->io_u_lat[index]++; } -static struct fio_file *get_next_file(struct thread_data *td) +/* + * Get next file to service by choosing one at random + */ +static struct fio_file *get_next_file_rand(struct thread_data *td) +{ + long r = os_random_long(&td->next_file_state); + unsigned int fileno; + struct fio_file *f; + + do { + fileno = (unsigned int) ((double) (td->nr_files - 1) * r / (RAND_MAX + 1.0)); + f = &td->files[fileno]; + if (f->fd != -1) + 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) { unsigned int old_next_file = td->next_file; struct fio_file *f; @@ -393,7 +413,11 @@ struct io_u *get_io_u(struct thread_data *td) if (io_u->file) goto out; - f = get_next_file(td); + if (td->file_service_type == FIO_FSERVICE_RR) + f = get_next_file_rr(td); + else + f = get_next_file_rand(td); + if (!f) { put_io_u(td, io_u); return NULL;