X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=io_u.c;h=1e9018c4f6ee85bc5362aea312b9b2ec15a15978;hp=0d55c09ae59dd2c70ea60313dff4bc1ddfef29a6;hb=b0f65863844b4de92d10fefaabde80ea5bc3e5cc;hpb=a086c25771b195d04651d293f299f0a63f7d2a23 diff --git a/io_u.c b/io_u.c index 0d55c09a..1e9018c4 100644 --- a/io_u.c +++ b/io_u.c @@ -95,7 +95,7 @@ static unsigned long long last_block(struct thread_data *td, struct fio_file *f, if (max_size > f->real_file_size) max_size = f->real_file_size; - max_blocks = max_size / (unsigned long long) td->o.min_bs[ddir]; + max_blocks = max_size / (unsigned long long) td->o.ba[ddir]; if (!max_blocks) return 0; @@ -113,7 +113,8 @@ static int get_next_free_block(struct thread_data *td, struct fio_file *f, i = f->last_free_lookup; *b = (i * BLOCKS_PER_MAP); - while ((*b) * min_bs < f->real_file_size) { + while ((*b) * min_bs < f->real_file_size && + (*b) * min_bs < f->io_size) { if (f->file_map[i] != (unsigned int) -1) { *b += ffz(f->file_map[i]); if (*b > last_block(td, f, ddir)) @@ -194,18 +195,25 @@ 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]; } - io_u->offset = b * td->o.min_bs[ddir]; + io_u->offset = b * td->o.ba[ddir]; if (io_u->offset >= f->io_size) { dprint(FD_IO, "get_next_offset: offset %llu >= io_size %llu\n", io_u->offset, f->io_size); @@ -241,7 +249,7 @@ static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u) buflen = minbs; else { r = os_random_long(&td->bsrange_state); - if (!td->o.bssplit_nr) { + if (!td->o.bssplit_nr[ddir]) { buflen = 1 + (unsigned int) ((double) maxbs * (r / (OS_RAND_MAX + 1.0))); if (buflen < minbs) @@ -250,8 +258,8 @@ static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u) long perc = 0; unsigned int i; - for (i = 0; i < td->o.bssplit_nr; i++) { - struct bssplit *bsp = &td->o.bssplit[i]; + for (i = 0; i < td->o.bssplit_nr[ddir]; i++) { + struct bssplit *bsp = &td->o.bssplit[ddir][i]; buflen = bsp->bs; perc += bsp->perc; @@ -621,6 +629,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 +637,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 +665,40 @@ 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) { + dprint(FD_FILE, "error %d on open of %s\n", + err, f->file_name); + f = NULL; + continue; + } + opened = 1; + } + + dprint(FD_FILE, "goodf=%x, badf=%x, ff=%x\n", goodf, badf, f->flags); 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); @@ -672,7 +712,7 @@ static struct fio_file *get_next_file(struct thread_data *td) assert(td->o.nr_files <= td->files_index); - if (!td->nr_open_files || td->nr_done_files >= td->o.nr_files) { + if (td->nr_done_files >= td->o.nr_files) { dprint(FD_FILE, "get_next_file: nr_open=%d, nr_done=%d," " nr_files=%d\n", td->nr_open_files, td->nr_done_files, @@ -681,7 +721,7 @@ static struct fio_file *get_next_file(struct thread_data *td) } f = td->file_service_file; - if (f && (f->flags & FIO_FILE_OPEN)) { + 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--) @@ -697,22 +737,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); - 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); - + dprint(FD_FILE, "get_next_file: %p [%s]\n", f, f->file_name); return f; } @@ -725,45 +750,18 @@ static int set_io_u_file(struct thread_data *td, struct io_u *io_u) if (!f) return 1; -set_file: io_u->file = f; get_file(f); if (!fill_io_u(td, io_u)) break; - /* - * optimization to prevent close/open of the same file. This - * way we preserve queueing etc. - */ - if (td->o.nr_files == 1 && td->o.time_based) { - put_file_log(td, f); - fio_file_reset(f); - goto set_file; - } - - /* - * td_io_close() does a put_file() as well, so no need to - * do that here. - */ - io_u->file = NULL; + put_file_log(td, f); td_io_close_file(td, f); + io_u->file = NULL; f->flags |= FIO_FILE_DONE; td->nr_done_files++; - - /* - * probably not the right place to do this, but see - * if we need to open a new 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)) - return 1; - - goto set_file; - } + dprint(FD_FILE, "%s: is done (%d of %d)\n", f->file_name, td->nr_done_files, td->o.nr_files); } while (1); return 0; @@ -841,7 +839,7 @@ struct io_u *get_io_u(struct thread_data *td) f->last_pos = io_u->offset + io_u->buflen; - if (td->o.verify != VERIFY_NONE) + if (td->o.verify != VERIFY_NONE && io_u->ddir == DDIR_WRITE) populate_verify_io_u(td, io_u); else if (td->o.refill_buffers && io_u->ddir == DDIR_WRITE) io_u_fill_buffer(td, io_u, io_u->xfer_buflen); @@ -920,11 +918,11 @@ static void io_completed(struct thread_data *td, struct io_u *io_u, &icd->time); if (!td->o.disable_clat) { - add_clat_sample(td, idx, usec); + add_clat_sample(td, idx, usec, bytes); io_u_mark_latency(td, usec); } if (!td->o.disable_bw) - add_bw_sample(td, idx, &icd->time); + add_bw_sample(td, idx, bytes, &icd->time); } if (td_write(td) && idx == DDIR_WRITE && @@ -1029,7 +1027,7 @@ void io_u_queued(struct thread_data *td, struct io_u *io_u) 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); + add_slat_sample(td, io_u->ddir, io_u->xfer_buflen, slat_time); } }