82 lines
1.6 KiB
C
82 lines
1.6 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_op_t;
|
|
|
|
typedef struct task {
|
|
task_op_t op;
|
|
int fd;
|
|
off_t off;
|
|
|
|
int res;
|
|
_Atomic int done;
|
|
|
|
struct iovec *iovs;
|
|
int iovcnt;
|
|
|
|
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);
|
|
int uring_task_complete(iouring_ctx_t *ctx);
|
|
void cleanup_finished_iouring_tasks(iouring_ctx_t *ctx);
|
|
|
|
extern iouring_ctx_t global_uring_ctx;
|
|
|
|
#endif
|