X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=io_u.c;h=53921e85ddbb121e026b594ceb63835e88d74d83;hp=0487857e74851b3752d38747b5307fcbebbf4416;hb=ea2accc50fe911f7c24f08e62db55de4d2386b71;hpb=d460eb318f784876812bedfed382afb00e57c62a diff --git a/io_u.c b/io_u.c index 0487857e..53921e85 100644 --- a/io_u.c +++ b/io_u.c @@ -84,7 +84,7 @@ static int get_next_free_block(struct thread_data *td, struct fio_file *f, *b = (i * BLOCKS_PER_MAP); while ((*b) * td->o.rw_min_bs < f->real_file_size) { if (f->file_map[i] != -1UL) { - *b += ffz(f->file_map[i]); + *b += fio_ffz(f->file_map[i]); f->last_free_lookup = i; return 0; } @@ -109,20 +109,40 @@ static int get_next_rand_offset(struct thread_data *td, struct fio_file *f, *b = 0; else *b = ((max_blocks - 1) * r / (unsigned long long) (RAND_MAX+1.0)); + /* + * if we are not maintaining a random map, we are done. + */ if (td->o.norandommap) - break; + return 0; + + /* + * calculate map offset and chec if it's free + */ rb = *b + (f->file_offset / td->o.min_bs[ddir]); - loops--; - } while (!random_map_free(td, f, rb) && loops); + if (random_map_free(td, f, rb)) + return 0; + + } while (--loops); /* - * if we failed to retrieve a truly random offset within - * the loops assigned, see if there are free ones left at all + * we get here, if we didn't suceed in looking up a block. generate + * a random start offset into the filemap, and find the first free + * block from there. */ - if (!loops && get_next_free_block(td, f, b)) - return 1; + loops = 10; + do { + f->last_free_lookup = (f->num_maps - 1) * (r / (RAND_MAX+1.0)); + if (!get_next_free_block(td, f, b)) + return 0; - return 0; + r = os_random_long(&td->random_state); + } while (--loops); + + /* + * that didn't work either, try exhaustive search from the start + */ + f->last_free_lookup = 0; + return get_next_free_block(td, f, b); } /* @@ -265,6 +285,9 @@ void put_io_u(struct thread_data *td, struct io_u *io_u) assert((io_u->flags & IO_U_F_FREE) == 0); io_u->flags |= IO_U_F_FREE; + if (io_u->file) + put_file(td, io_u->file); + io_u->file = NULL; list_del(&io_u->list); list_add(&io_u->list, &td->io_u_freelist); @@ -289,7 +312,7 @@ static int fill_io_u(struct thread_data *td, struct io_u *io_u) /* * If using an iolog, grab next piece if any available. */ - if (td->o.read_iolog) + if (td->o.read_iolog_file) return read_iolog_get(td, io_u); /* @@ -540,12 +563,14 @@ struct io_u *get_io_u(struct thread_data *td) set_file: io_u->file = f; + get_file(f); if (!fill_io_u(td, io_u)) break; /* - * No more to do for this file, close it + * td_io_close() does a put_file() as well, so no need to + * do that here. */ io_u->file = NULL; td_io_close_file(td, f); @@ -568,6 +593,8 @@ set_file: } } while (1); + assert(io_u->file->flags & FIO_FILE_OPEN); + if (td->zone_bytes >= td->o.zone_size) { td->zone_bytes = 0; f->last_pos += td->o.zone_skip; @@ -622,13 +649,11 @@ void io_u_log_error(struct thread_data *td, struct io_u *io_u) static void io_completed(struct thread_data *td, struct io_u *io_u, struct io_completion_data *icd) { - unsigned long msec; + unsigned long usec; assert(io_u->flags & IO_U_F_FLIGHT); io_u->flags &= ~IO_U_F_FLIGHT; - put_file(td, io_u->file); - if (io_u->ddir == DDIR_SYNC) { td->last_was_sync = 1; return; @@ -648,13 +673,13 @@ static void io_completed(struct thread_data *td, struct io_u *io_u, io_u->file->last_completed_pos = io_u->endpos; - msec = mtime_since(&io_u->issue_time, &icd->time); + usec = utime_since(&io_u->issue_time, &icd->time); - add_clat_sample(td, idx, msec); + add_clat_sample(td, idx, usec); add_bw_sample(td, idx, &icd->time); - io_u_mark_latency(td, msec); + io_u_mark_latency(td, usec / 1000); - if ((td_rw(td) || td_write(td)) && idx == DDIR_WRITE && + if (td_write(td) && idx == DDIR_WRITE && td->o.verify != VERIFY_NONE) log_io_piece(td, io_u); @@ -749,7 +774,7 @@ void io_u_queued(struct thread_data *td, struct io_u *io_u) { unsigned long slat_time; - slat_time = mtime_since(&io_u->start_time, &io_u->issue_time); + slat_time = utime_since(&io_u->start_time, &io_u->issue_time); add_slat_sample(td, io_u->ddir, slat_time); }