X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=io_u.c;h=74c3295b8f1157ee6e9d9cb6d45076bad8082259;hp=c662470a09142fa83c3ba337a84b7125ace2ed12;hb=6162f5249479e4be69bcd0c0bf09d1c09ea99523;hpb=8f7e39dd35a40d088a31f33f12402a1eaf31b2c4 diff --git a/io_u.c b/io_u.c index c662470a..74c3295b 100644 --- a/io_u.c +++ b/io_u.c @@ -43,40 +43,53 @@ static void mark_random_map(struct thread_data *td, struct io_u *io_u) unsigned int min_bs = td->o.rw_min_bs; struct fio_file *f = io_u->file; unsigned long long block; - unsigned int blocks; - unsigned int nr_blocks; + unsigned int blocks, nr_blocks; block = (io_u->offset - f->file_offset) / (unsigned long long) min_bs; - blocks = 0; nr_blocks = (io_u->buflen + min_bs - 1) / min_bs; + blocks = 0; - while (blocks < nr_blocks) { + while (nr_blocks) { + unsigned int this_blocks, mask; unsigned int idx, bit; /* * If we have a mixed random workload, we may * encounter blocks we already did IO to. */ - if ((td->o.ddir_nr == 1) && !random_map_free(f, block)) + if ((td->o.ddir_nr == 1) && !random_map_free(f, block)) { + if (!blocks) + blocks = 1; break; + } idx = RAND_MAP_IDX(f, block); bit = RAND_MAP_BIT(f, block); fio_assert(td, idx < f->num_maps); - f->file_map[idx] |= (1 << bit); - block++; - blocks++; + this_blocks = nr_blocks; + if (this_blocks + bit > BLOCKS_PER_MAP) + this_blocks = BLOCKS_PER_MAP - bit; + + if (this_blocks == BLOCKS_PER_MAP) + mask = -1U; + else + mask = ((1U << this_blocks) - 1) << bit; + + fio_assert(td, !(f->file_map[idx] & mask)); + f->file_map[idx] |= mask; + nr_blocks -= this_blocks; + blocks += this_blocks; + block += this_blocks; } if ((blocks * min_bs) < io_u->buflen) io_u->buflen = blocks * min_bs; } -static inline unsigned long long last_block(struct thread_data *td, - struct fio_file *f, - enum fio_ddir ddir) +static unsigned long long last_block(struct thread_data *td, struct fio_file *f, + enum fio_ddir ddir) { unsigned long long max_blocks; unsigned long long max_size; @@ -306,8 +319,10 @@ static enum fio_ddir get_rw_ddir(struct thread_data *td) max_bytes = td->this_io_bytes[ddir]; if (max_bytes >= (td->o.size * td->o.rwmix[ddir] / 100)) { - if (!td->rw_end_set[ddir]) + if (!td->rw_end_set[ddir]) { td->rw_end_set[ddir] = 1; + fio_gettime(&td->rw_end[ddir], NULL); + } ddir ^= 1; } @@ -341,8 +356,8 @@ void put_io_u(struct thread_data *td, struct io_u *io_u) put_file_log(td, io_u->file); io_u->file = NULL; - list_del(&io_u->list); - list_add(&io_u->list, &td->io_u_freelist); + flist_del(&io_u->list); + flist_add(&io_u->list, &td->io_u_freelist); td->cur_depth--; } @@ -358,8 +373,8 @@ void requeue_io_u(struct thread_data *td, struct io_u **io_u) __io_u->flags &= ~IO_U_F_FLIGHT; - list_del(&__io_u->list); - list_add_tail(&__io_u->list, &td->io_u_requeues); + flist_del(&__io_u->list); + flist_add_tail(&__io_u->list, &td->io_u_requeues); td->cur_depth--; *io_u = NULL; } @@ -751,10 +766,10 @@ struct io_u *__get_io_u(struct thread_data *td) { struct io_u *io_u = NULL; - if (!list_empty(&td->io_u_requeues)) - io_u = list_entry(td->io_u_requeues.next, struct io_u, list); + if (!flist_empty(&td->io_u_requeues)) + io_u = flist_entry(td->io_u_requeues.next, struct io_u, list); else if (!queue_full(td)) { - io_u = list_entry(td->io_u_freelist.next, struct io_u, list); + io_u = flist_entry(td->io_u_freelist.next, struct io_u, list); io_u->buflen = 0; io_u->resid = 0; @@ -767,8 +782,8 @@ struct io_u *__get_io_u(struct thread_data *td) io_u->flags &= ~IO_U_F_FREE; io_u->error = 0; - list_del(&io_u->list); - list_add(&io_u->list, &td->io_u_busylist); + flist_del(&io_u->list); + flist_add(&io_u->list, &td->io_u_busylist); td->cur_depth++; } @@ -1047,7 +1062,7 @@ static void io_u_timeout_handler(int fio_unused sig) { struct thread_data *td, *__td; pid_t pid = getpid(); - struct list_head *entry; + struct flist_head *entry; struct io_u *io_u; int i; @@ -1076,8 +1091,8 @@ static void io_u_timeout_handler(int fio_unused sig) log_err("fio: io_u timeout: job=%s, pid=%d\n", td->o.name, td->pid); - list_for_each(entry, &td->io_u_busylist) { - io_u = list_entry(entry, struct io_u, list); + flist_for_each(entry, &td->io_u_busylist) { + io_u = flist_entry(entry, struct io_u, list); io_u_dump(io_u); }