95 lines
2.2 KiB
C
95 lines
2.2 KiB
C
#ifndef __DISK_IOURING_H__
|
|
#define __DISK_IOURING_H__
|
|
|
|
#include <liburing.h>
|
|
#include <pthread.h>
|
|
#include <stdint.h>
|
|
#include <stdatomic.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/uio.h>
|
|
#include <unistd.h>
|
|
|
|
typedef enum { TASK_READ, TASK_WRITE, TASK_FSYNC } task_op_t;
|
|
|
|
struct task;
|
|
typedef void (*task_destroy_cb_t)(struct task *t, void *arg);
|
|
|
|
typedef struct task {
|
|
task_op_t op;
|
|
int fd;
|
|
off_t off;
|
|
unsigned fsync_flags;
|
|
unsigned sqe_flags;
|
|
|
|
int res;
|
|
_Atomic int done;
|
|
|
|
struct iovec *iovs;
|
|
int iovcnt;
|
|
int free_iov_bases;
|
|
task_destroy_cb_t on_destroy;
|
|
void *on_destroy_arg;
|
|
|
|
struct task *next;
|
|
} task_t;
|
|
|
|
typedef struct {
|
|
_Atomic(task_t *) head;
|
|
} destroy_queue_t;
|
|
|
|
typedef struct {
|
|
task_t **slots;
|
|
uint32_t cap;
|
|
_Atomic uint32_t head;
|
|
_Atomic uint32_t tail;
|
|
_Atomic uint32_t size;
|
|
} spsc_queue_t;
|
|
|
|
struct iouring_ctx_s;
|
|
typedef struct iouring_ctx_s iouring_ctx_t;
|
|
|
|
typedef struct {
|
|
struct io_uring ring;
|
|
pthread_t th;
|
|
int event_fd;
|
|
_Atomic int in_flight;
|
|
int max_in_flight;
|
|
int worker_id;
|
|
spsc_queue_t submit_q;
|
|
iouring_ctx_t *parent;
|
|
} iouring_worker_t;
|
|
|
|
struct iouring_ctx_s {
|
|
iouring_worker_t *workers;
|
|
int worker_nr;
|
|
unsigned entries_per_worker;
|
|
|
|
_Atomic int stop;
|
|
_Atomic uint32_t rr_next;
|
|
|
|
destroy_queue_t destroy_queue;
|
|
};
|
|
|
|
void task_init(task_t *t);
|
|
void task_finish(task_t *t, int res);
|
|
int task_wait(task_t *t);
|
|
void task_destroy(task_t *t);
|
|
|
|
int iouring_init(iouring_ctx_t *ctx, unsigned entries);
|
|
void iouring_shutdown(iouring_ctx_t *ctx);
|
|
|
|
task_t *submit_write(iouring_ctx_t *ctx, int fd, void **bufs, size_t *lens, int count, off_t off);
|
|
task_t *submit_write_ref(iouring_ctx_t *ctx, int fd, void **bufs, size_t *lens, int count, off_t off,
|
|
int free_iov_bases, task_destroy_cb_t on_destroy, void *on_destroy_arg);
|
|
task_t *submit_fsync_ref(iouring_ctx_t *ctx, int fd, int worker_id, int drain,
|
|
task_destroy_cb_t on_destroy, void *on_destroy_arg);
|
|
int uring_task_complete(iouring_ctx_t *ctx);
|
|
void cleanup_finished_iouring_tasks(iouring_ctx_t *ctx);
|
|
void iouring_profile_dump(iouring_ctx_t *ctx);
|
|
|
|
extern iouring_ctx_t global_uring_ctx;
|
|
|
|
#endif
|