--- libev/ev_iouring.c 2019/12/27 21:56:29 1.11 +++ 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); @@ -385,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 */ @@ -436,11 +458,6 @@ uint32_t gen = cqe->user_data >> 32; int res = cqe->res; - /* ignore fd removal events, if there are any. TODO: verify */ - /* TODO: yes, this triggers */ - if (cqe->user_data == (__u64)-1) - return; - assert (("libev: io_uring fd must be in-bounds", fd >= 0 && fd < anfdmax)); /* documentation lies, of course. the result value is NOT like @@ -450,6 +467,7 @@ */ /* 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;