--- libev/ev_iouring.c 2019/12/27 16:15:58 1.9 +++ libev/ev_iouring.c 2019/12/28 03:29:50 1.13 @@ -89,6 +89,7 @@ #include #include #include +#include #define IOURING_INIT_ENTRIES 32 @@ -175,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 @@ -184,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 @@ -291,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); @@ -301,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 */ @@ -380,7 +402,12 @@ struct io_uring_sqe *sqe = iouring_sqe_get (EV_A); sqe->opcode = IORING_OP_POLL_REMOVE; sqe->fd = fd; - sqe->user_data = -1; + /* Jens Axboe notified me that user_data is not what is documented, but is + * some kind of unique ID that has to match, otherwise the request cannot + * be removed. Since we don't *really* have that, we pass in the old + * generation counter - if that fails, too bad, it will hopefully be removed + * at close time and then be ignored. */ + sqe->user_data = (uint32_t)fd | ((__u64)(uint32_t)anfds [fd].egen << 32); iouring_sqe_submit (EV_A_ sqe); /* increment generation counter to avoid handling old events */ @@ -431,10 +458,6 @@ uint32_t gen = cqe->user_data >> 32; int res = cqe->res; - /* ignore fd removal events, if there are any. TODO: verify */ - if (cqe->user_data == (__u64)-1) - abort ();//D - assert (("libev: io_uring fd must be in-bounds", fd >= 0 && fd < anfdmax)); /* documentation lies, of course. the result value is NOT like @@ -444,14 +467,15 @@ */ /* ignore event if generation doesn't match */ + /* other than skipping removal events, */ /* this should actually be very rare */ if (ecb_expect_false (gen != (uint32_t)anfds [fd].egen)) return; 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) { @@ -489,7 +513,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, @@ -511,12 +535,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 (;;)