X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=io_u.c;h=5383dcae4253d8871df7cec3732db413f592f0f5;hp=08969427dd41b3753058b831987492e845ac27f5;hb=4bb997ce64df39b65c8d86c3b4a0504e6ab6eb48;hpb=62977e09a378a713b31d64c63e15adcf9f6f9d9d diff --git a/io_u.c b/io_u.c index 08969427..5383dcae 100644 --- a/io_u.c +++ b/io_u.c @@ -194,13 +194,20 @@ static int get_next_offset(struct thread_data *td, struct io_u *io_u) if (td_random(td) && (td->o.ddir_nr && !--td->ddir_nr)) { td->ddir_nr = td->o.ddir_nr; - if (get_next_rand_offset(td, f, ddir, &b)) + if (get_next_rand_offset(td, f, ddir, &b)) { + dprint(FD_IO, "%s: getting rand offset failed\n", + f->file_name); return 1; + } } else { if (f->last_pos >= f->real_file_size) { if (!td_random(td) || - get_next_rand_offset(td, f, ddir, &b)) + get_next_rand_offset(td, f, ddir, &b)) { + dprint(FD_IO, "%s: pos %llu > size %llu\n", + f->file_name, f->last_pos, + f->real_file_size); return 1; + } } else b = (f->last_pos - f->file_offset) / td->o.min_bs[ddir]; } @@ -621,6 +628,7 @@ static struct fio_file *get_next_file_rand(struct thread_data *td, int goodf, 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))); @@ -628,10 +636,21 @@ static struct fio_file *get_next_file_rand(struct thread_data *td, int goodf, if (f->flags & FIO_FILE_DONE) continue; + if (!(f->flags & FIO_FILE_OPEN)) { + 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; } + if (opened) + td_io_close_file(td, f); } while (1); } @@ -645,20 +664,35 @@ static struct fio_file *get_next_file_rr(struct thread_data *td, int goodf, struct fio_file *f; do { + int opened = 0; + f = td->files[td->next_file]; td->next_file++; if (td->next_file >= td->o.nr_files) td->next_file = 0; + dprint(FD_FILE, "trying file %s %x\n", f->file_name, f->flags); if (f->flags & FIO_FILE_DONE) { f = NULL; continue; } + if (!(f->flags & FIO_FILE_OPEN)) { + int err; + + err = td_io_open_file(td, f); + if (err) + continue; + opened = 1; + } + if ((!goodf || (f->flags & goodf)) && !(f->flags & badf)) break; + if (opened) + td_io_close_file(td, f); + f = NULL; } while (td->next_file != old_next_file); @@ -681,10 +715,15 @@ static struct fio_file *get_next_file(struct thread_data *td) } f = td->file_service_file; - if (f && (f->flags & FIO_FILE_OPEN) && td->file_service_left--) - goto out; + if (f && (f->flags & FIO_FILE_OPEN) && !(f->flags & FIO_FILE_CLOSING)) { + if (td->o.file_service_type == FIO_FSERVICE_SEQ) + goto out; + if (td->file_service_left--) + goto out; + } - if (td->o.file_service_type == FIO_FSERVICE_RR) + if (td->o.file_service_type == FIO_FSERVICE_RR || + td->o.file_service_type == FIO_FSERVICE_SEQ) 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); @@ -692,7 +731,7 @@ static struct fio_file *get_next_file(struct thread_data *td) td->file_service_file = f; td->file_service_left = td->file_service_nr - 1; out: - dprint(FD_FILE, "get_next_file: %p\n", f); + dprint(FD_FILE, "get_next_file: %p [%s]\n", f, f->file_name); return f; } @@ -745,6 +784,7 @@ set_file: td_io_close_file(td, f); f->flags |= FIO_FILE_DONE; td->nr_done_files++; + dprint(FD_FILE, "%s: is done (%d of %d)\n", f->file_name, td->nr_done_files, td->o.nr_files); /* * probably not the right place to do this, but see @@ -753,8 +793,7 @@ set_file: if (td->nr_open_files < td->o.open_files && td->o.open_files != td->o.nr_files) { f = find_next_new_file(td); - - if (!f || td_io_open_file(td, f)) + if (!f) return 1; goto set_file; @@ -851,7 +890,8 @@ struct io_u *get_io_u(struct thread_data *td) out: if (!td_io_prep(td, io_u)) { - fio_gettime(&io_u->start_time, NULL); + if (!td->o.disable_slat) + fio_gettime(&io_u->start_time, NULL); return io_u; } err_put: @@ -881,7 +921,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 usec; + /* + * Older gcc's are too dumb to realize that usec is always used + * initialized, silence that warning. + */ + unsigned long uninitialized_var(usec); dprint_io_u(io_u, "io complete"); @@ -905,11 +949,16 @@ static void io_completed(struct thread_data *td, struct io_u *io_u, td->this_io_bytes[idx] += bytes; if (ramp_time_over(td)) { - usec = utime_since(&io_u->issue_time, &icd->time); + if (!td->o.disable_clat || !td->o.disable_bw) + usec = utime_since(&io_u->issue_time, + &icd->time); - add_clat_sample(td, idx, usec); - add_bw_sample(td, idx, &icd->time); - io_u_mark_latency(td, usec); + if (!td->o.disable_clat) { + add_clat_sample(td, idx, usec); + io_u_mark_latency(td, usec); + } + if (!td->o.disable_bw) + add_bw_sample(td, idx, &icd->time); } if (td_write(td) && idx == DDIR_WRITE && @@ -930,9 +979,11 @@ static void io_completed(struct thread_data *td, struct io_u *io_u, } } -static void init_icd(struct io_completion_data *icd, int nr) +static void init_icd(struct thread_data *td, struct io_completion_data *icd, + int nr) { - fio_gettime(&icd->time, NULL); + if (!td->o.disable_clat || !td->o.disable_bw) + fio_gettime(&icd->time, NULL); icd->nr = nr; @@ -961,7 +1012,7 @@ long io_u_sync_complete(struct thread_data *td, struct io_u *io_u) { struct io_completion_data icd; - init_icd(&icd, 1); + init_icd(td, &icd, 1); io_completed(td, io_u, &icd); put_io_u(td, io_u); @@ -994,7 +1045,7 @@ long io_u_queued_complete(struct thread_data *td, int min_evts) } else if (!ret) return ret; - init_icd(&icd, ret); + init_icd(td, &icd, ret); ios_completed(td, &icd); if (!icd.error) return icd.bytes_done[0] + icd.bytes_done[1]; @@ -1008,10 +1059,12 @@ long io_u_queued_complete(struct thread_data *td, int min_evts) */ void io_u_queued(struct thread_data *td, struct io_u *io_u) { - unsigned long slat_time; + if (!td->o.disable_slat) { + unsigned long slat_time; - slat_time = utime_since(&io_u->start_time, &io_u->issue_time); - add_slat_sample(td, io_u->ddir, slat_time); + slat_time = utime_since(&io_u->start_time, &io_u->issue_time); + add_slat_sample(td, io_u->ddir, slat_time); + } } /*