mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-11-01 17:08:10 +00:00
21b4aa5d20
This adds two test programs in tools/io_uring/ that demonstrate both the raw io_uring API (and all features) through a small benchmark app, io_uring-bench, and the liburing exposed API in a simplified cp(1) implementation through io_uring-cp. Signed-off-by: Jens Axboe <axboe@kernel.dk>
143 lines
3.5 KiB
C
143 lines
3.5 KiB
C
#ifndef LIB_URING_H
|
|
#define LIB_URING_H
|
|
|
|
#include <sys/uio.h>
|
|
#include <signal.h>
|
|
#include <string.h>
|
|
#include "../../include/uapi/linux/io_uring.h"
|
|
|
|
/*
|
|
* Library interface to io_uring
|
|
*/
|
|
struct io_uring_sq {
|
|
unsigned *khead;
|
|
unsigned *ktail;
|
|
unsigned *kring_mask;
|
|
unsigned *kring_entries;
|
|
unsigned *kflags;
|
|
unsigned *kdropped;
|
|
unsigned *array;
|
|
struct io_uring_sqe *sqes;
|
|
|
|
unsigned sqe_head;
|
|
unsigned sqe_tail;
|
|
|
|
size_t ring_sz;
|
|
};
|
|
|
|
struct io_uring_cq {
|
|
unsigned *khead;
|
|
unsigned *ktail;
|
|
unsigned *kring_mask;
|
|
unsigned *kring_entries;
|
|
unsigned *koverflow;
|
|
struct io_uring_cqe *cqes;
|
|
|
|
size_t ring_sz;
|
|
};
|
|
|
|
struct io_uring {
|
|
struct io_uring_sq sq;
|
|
struct io_uring_cq cq;
|
|
int ring_fd;
|
|
};
|
|
|
|
/*
|
|
* System calls
|
|
*/
|
|
extern int io_uring_setup(unsigned entries, struct io_uring_params *p);
|
|
extern int io_uring_enter(unsigned fd, unsigned to_submit,
|
|
unsigned min_complete, unsigned flags, sigset_t *sig);
|
|
extern int io_uring_register(int fd, unsigned int opcode, void *arg,
|
|
unsigned int nr_args);
|
|
|
|
/*
|
|
* Library interface
|
|
*/
|
|
extern int io_uring_queue_init(unsigned entries, struct io_uring *ring,
|
|
unsigned flags);
|
|
extern int io_uring_queue_mmap(int fd, struct io_uring_params *p,
|
|
struct io_uring *ring);
|
|
extern void io_uring_queue_exit(struct io_uring *ring);
|
|
extern int io_uring_get_completion(struct io_uring *ring,
|
|
struct io_uring_cqe **cqe_ptr);
|
|
extern int io_uring_wait_completion(struct io_uring *ring,
|
|
struct io_uring_cqe **cqe_ptr);
|
|
extern int io_uring_submit(struct io_uring *ring);
|
|
extern struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring);
|
|
|
|
/*
|
|
* Command prep helpers
|
|
*/
|
|
static inline void io_uring_sqe_set_data(struct io_uring_sqe *sqe, void *data)
|
|
{
|
|
sqe->user_data = (unsigned long) data;
|
|
}
|
|
|
|
static inline void io_uring_prep_rw(int op, struct io_uring_sqe *sqe, int fd,
|
|
void *addr, unsigned len, off_t offset)
|
|
{
|
|
memset(sqe, 0, sizeof(*sqe));
|
|
sqe->opcode = op;
|
|
sqe->fd = fd;
|
|
sqe->off = offset;
|
|
sqe->addr = (unsigned long) addr;
|
|
sqe->len = len;
|
|
}
|
|
|
|
static inline void io_uring_prep_readv(struct io_uring_sqe *sqe, int fd,
|
|
struct iovec *iovecs, unsigned nr_vecs,
|
|
off_t offset)
|
|
{
|
|
io_uring_prep_rw(IORING_OP_READV, sqe, fd, iovecs, nr_vecs, offset);
|
|
}
|
|
|
|
static inline void io_uring_prep_read_fixed(struct io_uring_sqe *sqe, int fd,
|
|
void *buf, unsigned nbytes,
|
|
off_t offset)
|
|
{
|
|
io_uring_prep_rw(IORING_OP_READ_FIXED, sqe, fd, buf, nbytes, offset);
|
|
}
|
|
|
|
static inline void io_uring_prep_writev(struct io_uring_sqe *sqe, int fd,
|
|
struct iovec *iovecs, unsigned nr_vecs,
|
|
off_t offset)
|
|
{
|
|
io_uring_prep_rw(IORING_OP_WRITEV, sqe, fd, iovecs, nr_vecs, offset);
|
|
}
|
|
|
|
static inline void io_uring_prep_write_fixed(struct io_uring_sqe *sqe, int fd,
|
|
void *buf, unsigned nbytes,
|
|
off_t offset)
|
|
{
|
|
io_uring_prep_rw(IORING_OP_WRITE_FIXED, sqe, fd, buf, nbytes, offset);
|
|
}
|
|
|
|
static inline void io_uring_prep_poll_add(struct io_uring_sqe *sqe, int fd,
|
|
short poll_mask)
|
|
{
|
|
memset(sqe, 0, sizeof(*sqe));
|
|
sqe->opcode = IORING_OP_POLL_ADD;
|
|
sqe->fd = fd;
|
|
sqe->poll_events = poll_mask;
|
|
}
|
|
|
|
static inline void io_uring_prep_poll_remove(struct io_uring_sqe *sqe,
|
|
void *user_data)
|
|
{
|
|
memset(sqe, 0, sizeof(*sqe));
|
|
sqe->opcode = IORING_OP_POLL_REMOVE;
|
|
sqe->addr = (unsigned long) user_data;
|
|
}
|
|
|
|
static inline void io_uring_prep_fsync(struct io_uring_sqe *sqe, int fd,
|
|
int datasync)
|
|
{
|
|
memset(sqe, 0, sizeof(*sqe));
|
|
sqe->opcode = IORING_OP_FSYNC;
|
|
sqe->fd = fd;
|
|
if (datasync)
|
|
sqe->fsync_flags = IORING_FSYNC_DATASYNC;
|
|
}
|
|
|
|
#endif
|