From e2239016d4839aeb54b5da61f94baf0d518233fb Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 8 Jan 2019 06:20:58 -0700 Subject: [PATCH] io_uring: use kernel header directly The kernel header has been designed as such that it doesn't require a special userland version of it. Use it directly. Signed-off-by: Jens Axboe --- engines/io_uring.c | 30 +++++++----------- os/io_uring.h | 78 +++++++++++++++++++++++++++------------------- t/io_uring.c | 31 +++++++----------- 3 files changed, 70 insertions(+), 69 deletions(-) diff --git a/engines/io_uring.c b/engines/io_uring.c index ebca08c8..15a4d475 100644 --- a/engines/io_uring.c +++ b/engines/io_uring.c @@ -20,28 +20,22 @@ #ifdef ARCH_HAVE_IOURING -typedef uint64_t u64; -typedef uint32_t u32; -typedef int32_t s32; -typedef uint16_t u16; -typedef uint8_t u8; - #include "../os/io_uring.h" struct io_sq_ring { - u32 *head; - u32 *tail; - u32 *ring_mask; - u32 *ring_entries; - u32 *flags; - u32 *array; + unsigned *head; + unsigned *tail; + unsigned *ring_mask; + unsigned *ring_entries; + unsigned *flags; + unsigned *array; }; struct io_cq_ring { - u32 *head; - u32 *tail; - u32 *ring_mask; - u32 *ring_entries; + unsigned *head; + unsigned *tail; + unsigned *ring_mask; + unsigned *ring_entries; struct io_uring_event *events; }; @@ -211,7 +205,7 @@ static int fio_ioring_cqring_reap(struct thread_data *td, unsigned int events, { struct ioring_data *ld = td->io_ops_data; struct io_cq_ring *ring = &ld->cq_ring; - u32 head, reaped = 0; + unsigned head, reaped = 0; head = *ring->head; do { @@ -401,7 +395,7 @@ static int fio_ioring_mmap(struct ioring_data *ld, struct io_uring_params *p) struct io_cq_ring *cring = &ld->cq_ring; void *ptr; - ld->mmap[0].len = p->sq_off.array + p->sq_entries * sizeof(u32); + ld->mmap[0].len = p->sq_off.array + p->sq_entries * sizeof(__u32); ptr = mmap(0, ld->mmap[0].len, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, ld->ring_fd, IORING_OFF_SQ_RING); diff --git a/os/io_uring.h b/os/io_uring.h index 8dda7951..7dd21126 100644 --- a/os/io_uring.h +++ b/os/io_uring.h @@ -1,25 +1,33 @@ -#ifndef IO_URING_H -#define IO_URING_H +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Header file for the io_uring interface. + * + * Copyright (C) 2019 Jens Axboe + * Copyright (C) 2019 Christoph Hellwig + */ +#ifndef LINUX_IO_URING_H +#define LINUX_IO_URING_H #include +#include /* * IO submission data structure */ struct io_uring_iocb { - u8 opcode; - u8 flags; - u16 ioprio; - s32 fd; - u64 off; + __u8 opcode; + __u8 flags; + __u16 ioprio; + __s32 fd; + __u64 off; union { void *addr; - u64 __pad; + __u64 __pad; }; - u32 len; + __u32 len; union { __kernel_rwf_t rw_flags; - u32 __resv; + __u32 __resv; }; }; @@ -44,10 +52,13 @@ struct io_uring_iocb { */ struct io_uring_event { __u64 index; /* what iocb this event came from */ - s32 res; /* result code for this event */ - u32 flags; + __s32 res; /* result code for this event */ + __u32 flags; }; +/* + * io_uring_event->flags + */ #define IOEV_FLAG_CACHEHIT (1 << 0) /* IO did not hit media */ /* @@ -61,39 +72,42 @@ struct io_uring_event { * Filled with the offset for mmap(2) */ struct io_sqring_offsets { - u32 head; - u32 tail; - u32 ring_mask; - u32 ring_entries; - u32 flags; - u32 dropped; - u32 array; - u32 resv[3]; + __u32 head; + __u32 tail; + __u32 ring_mask; + __u32 ring_entries; + __u32 flags; + __u32 dropped; + __u32 array; + __u32 resv[3]; }; #define IORING_SQ_NEED_WAKEUP (1 << 0) /* needs io_uring_enter wakeup */ struct io_cqring_offsets { - u32 head; - u32 tail; - u32 ring_mask; - u32 ring_entries; - u32 overflow; - u32 events; - u32 resv[4]; + __u32 head; + __u32 tail; + __u32 ring_mask; + __u32 ring_entries; + __u32 overflow; + __u32 events; + __u32 resv[4]; }; +/* + * io_uring_enter(2) flags + */ #define IORING_ENTER_GETEVENTS (1 << 0) /* * Passed in for io_uring_setup(2). Copied back with updated info on success */ struct io_uring_params { - u32 sq_entries; - u32 cq_entries; - u32 flags; - u16 sq_thread_cpu; - u16 resv[9]; + __u32 sq_entries; + __u32 cq_entries; + __u32 flags; + __u16 sq_thread_cpu; + __u16 resv[9]; struct io_sqring_offsets sq_off; struct io_cqring_offsets cq_off; }; diff --git a/t/io_uring.c b/t/io_uring.c index 83d723f9..4efc015d 100644 --- a/t/io_uring.c +++ b/t/io_uring.c @@ -21,13 +21,6 @@ #include #include "../arch/arch.h" - -typedef uint64_t u64; -typedef uint32_t u32; -typedef int32_t s32; -typedef uint16_t u16; -typedef uint8_t u8; - #include "../os/io_uring.h" #define barrier() __asm__ __volatile__("": : :"memory") @@ -35,18 +28,18 @@ typedef uint8_t u8; #define min(a, b) ((a < b) ? (a) : (b)) struct io_sq_ring { - u32 *head; - u32 *tail; - u32 *ring_mask; - u32 *ring_entries; - u32 *array; + unsigned *head; + unsigned *tail; + unsigned *ring_mask; + unsigned *ring_entries; + unsigned *array; }; struct io_cq_ring { - u32 *head; - u32 *tail; - u32 *ring_mask; - u32 *ring_entries; + unsigned *head; + unsigned *tail; + unsigned *ring_mask; + unsigned *ring_entries; struct io_uring_event *events; }; @@ -125,7 +118,7 @@ static void init_io(struct submitter *s, int fd, unsigned index) static int prep_more_ios(struct submitter *s, int fd, int max_ios) { struct io_sq_ring *ring = &s->sq_ring; - u32 index, tail, next_tail, prepped = 0; + unsigned index, tail, next_tail, prepped = 0; next_tail = tail = *ring->tail; do { @@ -176,7 +169,7 @@ static int reap_events(struct submitter *s) { struct io_cq_ring *ring = &s->cq_ring; struct io_uring_event *ev; - u32 head, reaped = 0; + unsigned head, reaped = 0; head = *ring->head; do { @@ -345,7 +338,7 @@ static int setup_ring(struct submitter *s) } s->ring_fd = fd; - ptr = mmap(0, p.sq_off.array + p.sq_entries * sizeof(u32), + ptr = mmap(0, p.sq_off.array + p.sq_entries * sizeof(__u32), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_SQ_RING); printf("sq_ring ptr = 0x%p\n", ptr); -- 2.25.1