t/io_uring: make submits/reaps per-second reflected with sq thread poll
[fio.git] / os / io_uring.h
CommitLineData
e2239016
JA
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Header file for the io_uring interface.
4 *
5 * Copyright (C) 2019 Jens Axboe
6 * Copyright (C) 2019 Christoph Hellwig
7 */
8#ifndef LINUX_IO_URING_H
9#define LINUX_IO_URING_H
e31b8288 10
6e70fd30 11#include <linux/fs.h>
e2239016 12#include <linux/types.h>
6e70fd30 13
e31b8288 14/*
f0403f94 15 * IO submission data structure (Submission Queue Entry)
e31b8288 16 */
f0403f94 17struct io_uring_sqe {
a7086591
JA
18 __u8 opcode; /* type of operation for this sqe */
19 __u8 flags; /* as of now unused */
20 __u16 ioprio; /* ioprio for the request */
21 __s32 fd; /* file descriptor to do IO on */
22 __u64 off; /* offset into file */
e31b8288 23 union {
a7086591 24 void *addr; /* buffer or iovecs */
e2239016 25 __u64 __pad;
e31b8288 26 };
a7086591 27 __u32 len; /* buffer size or number of iovecs */
e31b8288
JA
28 union {
29 __kernel_rwf_t rw_flags;
e2239016 30 __u32 __resv;
e31b8288 31 };
2ea53ca3 32 __u16 buf_index; /* index into fixed buffers, if used */
a7086591
JA
33 __u16 __pad2[3];
34 __u64 data; /* data to be passed back at completion time */
e31b8288
JA
35};
36
2ea53ca3
JA
37/*
38 * sqe->flags
39 */
40#define IOSQE_FIXED_BUFFER (1 << 0) /* use fixed buffer */
41
e31b8288
JA
42/*
43 * io_uring_setup() flags
44 */
45#define IORING_SETUP_IOPOLL (1 << 0) /* io_context is polled */
2ea53ca3
JA
46#define IORING_SETUP_SQPOLL (1 << 1) /* SQ poll thread */
47#define IORING_SETUP_SQ_AFF (1 << 2) /* sq_thread_cpu is valid */
e31b8288 48
f0403f94
JA
49#define IORING_OP_READV 1
50#define IORING_OP_WRITEV 2
e31b8288
JA
51#define IORING_OP_FSYNC 3
52#define IORING_OP_FDSYNC 4
e31b8288
JA
53
54/*
f0403f94 55 * IO completion data structure (Completion Queue Entry)
e31b8288 56 */
f0403f94 57struct io_uring_cqe {
a7086591 58 __u64 data; /* sqe->data submission passed back */
e2239016
JA
59 __s32 res; /* result code for this event */
60 __u32 flags;
e31b8288
JA
61};
62
e2239016
JA
63/*
64 * io_uring_event->flags
65 */
f0403f94 66#define IOCQE_FLAG_CACHEHIT (1 << 0) /* IO did not hit media */
e31b8288
JA
67
68/*
69 * Magic offsets for the application to mmap the data it needs
70 */
71#define IORING_OFF_SQ_RING 0ULL
72#define IORING_OFF_CQ_RING 0x8000000ULL
f0403f94 73#define IORING_OFF_SQES 0x10000000ULL
e31b8288
JA
74
75/*
76 * Filled with the offset for mmap(2)
77 */
78struct io_sqring_offsets {
e2239016
JA
79 __u32 head;
80 __u32 tail;
81 __u32 ring_mask;
82 __u32 ring_entries;
83 __u32 flags;
84 __u32 dropped;
85 __u32 array;
86 __u32 resv[3];
e31b8288
JA
87};
88
89#define IORING_SQ_NEED_WAKEUP (1 << 0) /* needs io_uring_enter wakeup */
90
91struct io_cqring_offsets {
e2239016
JA
92 __u32 head;
93 __u32 tail;
94 __u32 ring_mask;
95 __u32 ring_entries;
96 __u32 overflow;
f0403f94 97 __u32 cqes;
e2239016 98 __u32 resv[4];
e31b8288
JA
99};
100
e2239016
JA
101/*
102 * io_uring_enter(2) flags
103 */
e31b8288
JA
104#define IORING_ENTER_GETEVENTS (1 << 0)
105
106/*
107 * Passed in for io_uring_setup(2). Copied back with updated info on success
108 */
109struct io_uring_params {
e2239016
JA
110 __u32 sq_entries;
111 __u32 cq_entries;
112 __u32 flags;
113 __u16 sq_thread_cpu;
114 __u16 resv[9];
e31b8288
JA
115 struct io_sqring_offsets sq_off;
116 struct io_cqring_offsets cq_off;
117};
118
2ea53ca3
JA
119/*
120 * io_uring_register(2) opcodes and arguments
121 */
122#define IORING_REGISTER_BUFFERS 0
123#define IORING_UNREGISTER_BUFFERS 1
124
125struct io_uring_register_buffers {
126 struct iovec *iovecs;
127 unsigned nr_iovecs;
128};
129
e31b8288 130#endif