--- libev/ev_iouring.c 2019/12/27 16:08:24 1.8 +++ libev/ev_iouring.c 2019/12/27 22:16:10 1.12 @@ -82,9 +82,14 @@ * or might not get fixed (do I hold my breath?). */ +/* TODO: use internal TIMEOUT */ +/* TODO: take advantage of single mmap, NODROP etc. */ +/* TODO: resize cq/sq size independently */ + #include #include #include +#include #define IOURING_INIT_ENTRIES 32 @@ -171,8 +176,21 @@ struct io_cqring_offsets cq_off; }; -#define IORING_OP_POLL_ADD 6 -#define IORING_OP_POLL_REMOVE 7 +#define IORING_SETUP_CQSIZE 0x00000008 + +#define IORING_OP_POLL_ADD 6 +#define IORING_OP_POLL_REMOVE 7 +#define IORING_OP_TIMEOUT 11 +#define IORING_OP_TIMEOUT_REMOVE 12 + +/* relative or absolute, reference clock is CLOCK_MONOTONIC */ +struct iouring_kernel_timespec +{ + int64_t tv_sec; + long long tv_nsec; +}; + +#define IORING_TIMEOUT_ABS 0x00000001 #define IORING_ENTER_GETEVENTS 0x01 @@ -180,9 +198,9 @@ #define IORING_OFF_CQ_RING 0x08000000ULL #define IORING_OFF_SQES 0x10000000ULL -#define IORING_FEAT_SINGLE_MMAP 0x1 -#define IORING_FEAT_NODROP 0x2 -#define IORING_FEAT_SUBMIT_STABLE 0x4 +#define IORING_FEAT_SINGLE_MMAP 0x00000001 +#define IORING_FEAT_NODROP 0x00000002 +#define IORING_FEAT_SUBMIT_STABLE 0x00000004 inline_size int @@ -287,6 +305,9 @@ iouring_cq_ring = MAP_FAILED; iouring_sqes = MAP_FAILED; + if (!have_monotonic) /* cannot really happen, but what if11 */ + return -1; + for (;;) { iouring_fd = evsys_io_uring_setup (iouring_entries, ¶ms); @@ -297,6 +318,11 @@ if (errno != EINVAL) return -1; /* we failed */ +#if TODO + if ((~params.features) & (IORING_FEAT_NODROP | IORING_FEATURE_SINGLE_MMAP)) + return -1; /* we require the above features */ +#endif + /* EINVAL: lots of possible reasons, but maybe * it is because we hit the unqueryable hardcoded size limit */ @@ -428,8 +454,9 @@ int res = cqe->res; /* ignore fd removal events, if there are any. TODO: verify */ + /* TODO: yes, this triggers */ if (cqe->user_data == (__u64)-1) - abort ();//D + return; assert (("libev: io_uring fd must be in-bounds", fd >= 0 && fd < anfdmax)); @@ -446,8 +473,8 @@ if (ecb_expect_false (res < 0)) { - //TODO: EINVAL handling (was something failed with this fd) - //TODO: EBUSY happens when? + /*TODO: EINVAL handling (was something failed with this fd)*/ + /*TODO: EBUSY happens when?*/ if (res == -EBADF) { @@ -485,7 +512,7 @@ /* we have two options, resize the queue (by tearing down * everything and recreating it, or living with it * and polling. - * we implement this by resizing tghe queue, and, if that fails, + * we implement this by resizing the queue, and, if that fails, * we just recreate the state on every failure, which * kind of is a very inefficient poll. * one danger is, due to the bios toward lower fds, @@ -507,12 +534,12 @@ /* we hit the kernel limit, we should fall back to something else. * we can either poll() a few times and hope for the best, * poll always, or switch to epoll. - * since we use epoll anyways, go epoll. + * TODO: is this necessary with newer kernels? */ iouring_internal_destroy (EV_A); - /* this should make it so that on return, we don'T call any uring functions */ + /* this should make it so that on return, we don't call any uring functions */ iouring_to_submit = 0; for (;;)