Move it into a helper, and use it from all three methods. This also fixes
an issue with the aio method not honoring random IO or not.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
return (depth + s->nr_files - 1) / s->nr_files;
}
return (depth + s->nr_files - 1) / s->nr_files;
}
+static unsigned long long get_offset(struct submitter *s, struct file *f)
+{
+ unsigned long long offset;
+ long r;
+
+ if (random_io) {
+ r = __rand64(&s->rand_state);
+ offset = (r % (f->max_blocks - 1)) * bs;
+ } else {
+ offset = f->cur_off;
+ f->cur_off += bs;
+ if (f->cur_off + bs > f->max_size)
+ f->cur_off = 0;
+ }
+
+ return offset;
+}
+
static void init_io(struct submitter *s, unsigned index)
{
struct io_uring_sqe *sqe = &s->sqes[index];
static void init_io(struct submitter *s, unsigned index)
{
struct io_uring_sqe *sqe = &s->sqes[index];
if (do_nop) {
sqe->opcode = IORING_OP_NOP;
if (do_nop) {
sqe->opcode = IORING_OP_NOP;
- if (random_io) {
- r = __rand64(&s->rand_state);
- offset = (r % (f->max_blocks - 1)) * bs;
- } else {
- offset = f->cur_off;
- f->cur_off += bs;
- if (f->cur_off + bs > f->max_size)
- f->cur_off = 0;
- }
-
if (register_files) {
sqe->flags = IOSQE_FIXED_FILE;
sqe->fd = f->fixed_fd;
if (register_files) {
sqe->flags = IOSQE_FIXED_FILE;
sqe->fd = f->fixed_fd;
sqe->buf_index = 0;
}
sqe->ioprio = 0;
sqe->buf_index = 0;
}
sqe->ioprio = 0;
+ sqe->off = get_offset(s, f);
sqe->user_data = (unsigned long) f->fileno;
if (stats && stats_running)
sqe->user_data |= ((uint64_t)s->clock_index << 32);
sqe->user_data = (unsigned long) f->fileno;
if (stats && stats_running)
sqe->user_data |= ((uint64_t)s->clock_index << 32);
static int prep_more_ios_aio(struct submitter *s, int max_ios, struct iocb *iocbs)
{
uint64_t data;
static int prep_more_ios_aio(struct submitter *s, int max_ios, struct iocb *iocbs)
{
uint64_t data;
struct file *f;
unsigned index;
struct file *f;
unsigned index;
index = 0;
while (index < max_ios) {
index = 0;
while (index < max_ios) {
- r = lrand48();
- offset = (r % (f->max_blocks - 1)) * bs;
io_prep_pread(iocb, f->real_fd, s->iovecs[index].iov_base,
io_prep_pread(iocb, f->real_fd, s->iovecs[index].iov_base,
- s->iovecs[index].iov_len, offset);
+ s->iovecs[index].iov_len, get_offset(s, f));
data = f->fileno;
if (stats && stats_running)
data = f->fileno;
if (stats && stats_running)
do {
uint64_t offset;
struct file *f;
do {
uint64_t offset;
struct file *f;
if (s->nr_files == 1) {
f = &s->files[0];
if (s->nr_files == 1) {
f = &s->files[0];
- if (random_io) {
- r = __rand64(&s->rand_state);
- offset = (r % (f->max_blocks - 1)) * bs;
- } else {
- offset = f->cur_off;
- f->cur_off += bs;
- if (f->cur_off + bs > f->max_size)
- f->cur_off = 0;
- }
-
#ifdef ARCH_HAVE_CPU_CLOCK
if (stats)
s->clock_batch[s->clock_index] = get_cpu_clock();
#ifdef ARCH_HAVE_CPU_CLOCK
if (stats)
s->clock_batch[s->clock_index] = get_cpu_clock();
s->inflight++;
s->calls++;
s->inflight++;
s->calls++;
+ offset = get_offset(s, f);
if (polled)
ret = preadv2(f->real_fd, &s->iovecs[0], 1, offset, RWF_HIPRI);
else
if (polled)
ret = preadv2(f->real_fd, &s->iovecs[0], 1, offset, RWF_HIPRI);
else