X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=io_u.c;h=a87c58e32791e35cfbb770c705a2c34c9b41ee17;hb=e09231c214906b4ff8cbc3dc202c39755fbf6afd;hp=d35b8441b313b6efb28c9f65647aa0cb08b6cb3d;hpb=1294c3ec7a02d20a98b105c1c41b23358afc67e4;p=fio.git diff --git a/io_u.c b/io_u.c index d35b8441..a87c58e3 100644 --- a/io_u.c +++ b/io_u.c @@ -249,7 +249,16 @@ static int get_next_seq_block(struct thread_data *td, struct fio_file *f, assert(ddir_rw(ddir)); if (f->last_pos < f->real_file_size) { - *b = (f->last_pos - f->file_offset) / td->o.min_bs[ddir]; + unsigned long long pos; + + if (f->last_pos == f->file_offset && td->o.ddir_seq_add < 0) + f->last_pos = f->real_file_size; + + pos = f->last_pos - f->file_offset; + if (pos) + pos += td->o.ddir_seq_add; + + *b = pos / td->o.min_bs[ddir]; return 0; } @@ -341,6 +350,14 @@ static int get_next_offset(struct thread_data *td, struct io_u *io_u) return __get_next_offset(td, io_u); } +static inline int io_u_fits(struct thread_data *td, struct io_u *io_u, + unsigned int buflen) +{ + struct fio_file *f = io_u->file; + + return io_u->offset + buflen <= f->io_size + td->o.start_offset; +} + static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u) { const int ddir = io_u->ddir; @@ -353,14 +370,15 @@ static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u) minbs = td->o.min_bs[ddir]; maxbs = td->o.max_bs[ddir]; + if (minbs == maxbs) + return minbs; + if (td->o.use_os_rand) rand_max = OS_RAND_MAX; else rand_max = FRAND_MAX; - if (minbs == maxbs) - buflen = minbs; - else { + do { if (td->o.use_os_rand) r = os_random_long(&td->bsrange_state); else @@ -380,19 +398,16 @@ static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u) buflen = bsp->bs; perc += bsp->perc; - if (r <= ((rand_max / 100L) * perc)) + if ((r <= ((rand_max / 100L) * perc)) && + io_u_fits(td, io_u, buflen)) break; } } + if (!td->o.bs_unaligned && is_power_of_2(minbs)) buflen = (buflen + minbs - 1) & ~(minbs - 1); - } - if (io_u->offset + buflen > io_u->file->real_file_size) { - dprint(FD_IO, "lower buflen %u -> %u (ddir=%d)\n", buflen, - minbs, ddir); - buflen = minbs; - } + } while (!io_u_fits(td, io_u, buflen)); return buflen; } @@ -475,6 +490,16 @@ static enum fio_ddir rate_ddir(struct thread_data *td, enum fio_ddir ddir) } else usec = td->rate_pending_usleep[ddir]; + /* + * We are going to sleep, ensure that we flush anything pending as + * not to skew our latency numbers + */ + if (td->cur_depth) { + int fio_unused ret; + + ret = io_u_queued_complete(td, td->cur_depth, NULL); + } + fio_gettime(&t, NULL); usec_sleep(td, usec); usec = utime_since_now(&t); @@ -1425,7 +1450,7 @@ void io_u_fill_buffer(struct thread_data *td, struct io_u *io_u, io_u->buf_filled_len = 0; if (!td->o.zero_buffers) - fill_random_buf(io_u->buf, max_bs); + fill_random_buf(&td->buf_state, io_u->buf, max_bs); else memset(io_u->buf, 0, max_bs); }