static int plist_len = 17;
#ifndef IORING_REGISTER_MAP_BUFFERS
-#define IORING_REGISTER_MAP_BUFFERS 22
+#define IORING_REGISTER_MAP_BUFFERS 26
struct io_uring_map_buffers {
__s32 fd;
__u32 buf_start;
struct io_uring_probe *p;
int ret;
- p = malloc(sizeof(*p) + 256 * sizeof(struct io_uring_probe_op));
+ p = calloc(1, sizeof(*p) + 256 * sizeof(struct io_uring_probe_op));
if (!p)
return;
- memset(p, 0, sizeof(*p) + 256 * sizeof(struct io_uring_probe_op));
ret = syscall(__NR_io_uring_register, fd, IORING_REGISTER_PROBE, p, 256);
if (ret < 0)
goto out;
long r;
if (random_io) {
+ unsigned long long block;
+
r = __rand64(&s->rand_state);
- offset = (r % (f->max_blocks - 1)) * bs;
+ block = r % f->max_blocks;
+ offset = block * (unsigned long long) bs;
} else {
offset = f->cur_off;
f->cur_off += bs;
return offset;
}
-static void init_io(struct submitter *s, unsigned index)
+static struct file *init_new_io(struct submitter *s)
{
- struct io_uring_sqe *sqe = &s->sqes[index];
struct file *f;
- if (do_nop) {
- sqe->opcode = IORING_OP_NOP;
- return;
- }
-
if (s->nr_files == 1) {
f = &s->files[0];
} else {
f = &s->files[s->cur_file];
}
}
+
f->pending_ios++;
+ return f;
+}
+
+static void init_io(struct submitter *s, unsigned index)
+{
+ struct io_uring_sqe *sqe = &s->sqes[index];
+ struct file *f;
+
+ if (do_nop) {
+ sqe->opcode = IORING_OP_NOP;
+ return;
+ }
+
+ f = init_new_io(s);
if (register_files) {
sqe->flags = IOSQE_FIXED_FILE;
struct nvme_uring_cmd *cmd;
unsigned long long slba;
unsigned long long nlb;
- long r;
- if (s->nr_files == 1) {
- f = &s->files[0];
- } else {
- f = &s->files[s->cur_file];
- if (f->pending_ios >= file_depth(s)) {
- s->cur_file++;
- if (s->cur_file == s->nr_files)
- s->cur_file = 0;
- f = &s->files[s->cur_file];
- }
- }
- f->pending_ios++;
+ f = init_new_io(s);
- 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;
- }
+ offset = get_offset(s, f);
if (register_files) {
sqe->fd = f->fixed_fd;
cmd->cdw12 = nlb;
cmd->addr = (unsigned long) s->iovecs[index].iov_base;
cmd->data_len = bs;
+ if (fixedbufs) {
+ sqe->uring_cmd_flags = IORING_URING_CMD_FIXED;
+ sqe->buf_index = index;
+ }
cmd->nsid = f->nsid;
cmd->opcode = 2;
}
static int prep_more_ios_uring(struct submitter *s, int max_ios)
{
struct io_sq_ring *ring = &s->sq_ring;
- unsigned index, tail, next_tail, prepped = 0;
- unsigned int head = atomic_load_acquire(ring->head);
+ unsigned head, index, tail, next_tail, prepped = 0;
+
+ if (sq_thread_poll)
+ head = atomic_load_acquire(ring->head);
+ else
+ head = *ring->head;
next_tail = tail = *ring->tail;
do {
bs, lbs);
return -1;
}
- f->max_blocks = nlba / bs;
+ f->max_blocks = nlba;
f->max_size = nlba;
f->lba_shift = ilog2(lbs);
return 0;
do {
struct file *f;
- read_barrier();
if (head == atomic_load_acquire(ring->tail))
break;
cqe = &ring->cqes[head & cq_ring_mask];
do {
struct file *f;
- read_barrier();
if (head == atomic_load_acquire(ring->tail))
break;
index = head & cq_ring_mask;
char str[128];
int ret, fd, node;
- sprintf(str, "/sys/block/%s/device/numa_node", base);
+ if (pt)
+ sprintf(str, "/sys/class/nvme-generic/%s/device/numa_node", base);
+ else
+ sprintf(str, "/sys/block/%s/device/numa_node", base);
fd = open(str, O_RDONLY);
if (fd < 0)
return -1;
while (index < max_ios) {
struct iocb *iocb = &iocbs[index];
- if (s->nr_files == 1) {
- f = &s->files[0];
- } else {
- f = &s->files[s->cur_file];
- if (f->pending_ios >= file_depth(s)) {
- s->cur_file++;
- if (s->cur_file == s->nr_files)
- s->cur_file = 0;
- f = &s->files[s->cur_file];
- }
- }
- f->pending_ios++;
+ f = init_new_io(s);
io_prep_pread(iocb, f->real_fd, s->iovecs[index].iov_base,
s->iovecs[index].iov_len, get_offset(s, f));
uint64_t offset;
struct file *f;
- if (s->nr_files == 1) {
- f = &s->files[0];
- } else {
- f = &s->files[s->cur_file];
- if (f->pending_ios >= file_depth(s)) {
- s->cur_file++;
- if (s->cur_file == s->nr_files)
- s->cur_file = 0;
- f = &s->files[s->cur_file];
- }
- }
- f->pending_ios++;
+ f = init_new_io(s);
#ifdef ARCH_HAVE_CPU_CLOCK
if (stats)