io_uring: use kernel header directly
authorJens Axboe <axboe@kernel.dk>
Tue, 8 Jan 2019 13:20:58 +0000 (06:20 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 8 Jan 2019 13:20:58 +0000 (06:20 -0700)
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 <axboe@kernel.dk>
engines/io_uring.c
os/io_uring.h
t/io_uring.c

index ebca08c874d446c11ab36c3dc8a94831742269e3..15a4d4753639ce3bf6ef73b1d752a491fc520129 100644 (file)
 
 #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);
index 8dda79512bbcc40398679408973e1ae44b4b2e42..7dd21126f142c5c856d85f67fc3d5340b035828f 100644 (file)
@@ -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 <linux/fs.h>
+#include <linux/types.h>
 
 /*
  * 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;
 };
index 83d723f938e88d547bcab93482441fdecd73caa4..4efc015d6fb0fb6bca8a8916bf39cfbe4fc3ffec 100644 (file)
 #include <sched.h>
 
 #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);