ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev_iouring.c
(Generate patch)

Comparing libev/ev_iouring.c (file contents):
Revision 1.11 by root, Fri Dec 27 21:56:29 2019 UTC vs.
Revision 1.13 by root, Sat Dec 28 03:29:50 2019 UTC

87/* TODO: resize cq/sq size independently */ 87/* TODO: resize cq/sq size independently */
88 88
89#include <sys/timerfd.h> 89#include <sys/timerfd.h>
90#include <sys/mman.h> 90#include <sys/mman.h>
91#include <poll.h> 91#include <poll.h>
92#include <stdint.h>
92 93
93#define IOURING_INIT_ENTRIES 32 94#define IOURING_INIT_ENTRIES 32
94 95
95/*****************************************************************************/ 96/*****************************************************************************/
96/* syscall wrapdadoop - this section has the raw api/abi definitions */ 97/* syscall wrapdadoop - this section has the raw api/abi definitions */
173 __u32 resv[4]; 174 __u32 resv[4];
174 struct io_sqring_offsets sq_off; 175 struct io_sqring_offsets sq_off;
175 struct io_cqring_offsets cq_off; 176 struct io_cqring_offsets cq_off;
176}; 177};
177 178
179#define IORING_SETUP_CQSIZE 0x00000008
180
178#define IORING_OP_POLL_ADD 6 181#define IORING_OP_POLL_ADD 6
179#define IORING_OP_POLL_REMOVE 7 182#define IORING_OP_POLL_REMOVE 7
183#define IORING_OP_TIMEOUT 11
184#define IORING_OP_TIMEOUT_REMOVE 12
185
186/* relative or absolute, reference clock is CLOCK_MONOTONIC */
187struct iouring_kernel_timespec
188{
189 int64_t tv_sec;
190 long long tv_nsec;
191};
192
193#define IORING_TIMEOUT_ABS 0x00000001
180 194
181#define IORING_ENTER_GETEVENTS 0x01 195#define IORING_ENTER_GETEVENTS 0x01
182 196
183#define IORING_OFF_SQ_RING 0x00000000ULL 197#define IORING_OFF_SQ_RING 0x00000000ULL
184#define IORING_OFF_CQ_RING 0x08000000ULL 198#define IORING_OFF_CQ_RING 0x08000000ULL
185#define IORING_OFF_SQES 0x10000000ULL 199#define IORING_OFF_SQES 0x10000000ULL
186 200
187#define IORING_FEAT_SINGLE_MMAP 0x1 201#define IORING_FEAT_SINGLE_MMAP 0x00000001
188#define IORING_FEAT_NODROP 0x2 202#define IORING_FEAT_NODROP 0x00000002
189#define IORING_FEAT_SUBMIT_STABLE 0x4 203#define IORING_FEAT_SUBMIT_STABLE 0x00000004
190 204
191inline_size 205inline_size
192int 206int
193evsys_io_uring_setup (unsigned entries, struct io_uring_params *params) 207evsys_io_uring_setup (unsigned entries, struct io_uring_params *params)
194{ 208{
288 302
289 iouring_tfd = -1; 303 iouring_tfd = -1;
290 iouring_sq_ring = MAP_FAILED; 304 iouring_sq_ring = MAP_FAILED;
291 iouring_cq_ring = MAP_FAILED; 305 iouring_cq_ring = MAP_FAILED;
292 iouring_sqes = MAP_FAILED; 306 iouring_sqes = MAP_FAILED;
307
308 if (!have_monotonic) /* cannot really happen, but what if11 */
309 return -1;
293 310
294 for (;;) 311 for (;;)
295 { 312 {
296 iouring_fd = evsys_io_uring_setup (iouring_entries, &params); 313 iouring_fd = evsys_io_uring_setup (iouring_entries, &params);
297 314
383 { 400 {
384 /* we assume the sqe's are all "properly" initialised */ 401 /* we assume the sqe's are all "properly" initialised */
385 struct io_uring_sqe *sqe = iouring_sqe_get (EV_A); 402 struct io_uring_sqe *sqe = iouring_sqe_get (EV_A);
386 sqe->opcode = IORING_OP_POLL_REMOVE; 403 sqe->opcode = IORING_OP_POLL_REMOVE;
387 sqe->fd = fd; 404 sqe->fd = fd;
388 sqe->user_data = -1; 405 /* Jens Axboe notified me that user_data is not what is documented, but is
406 * some kind of unique ID that has to match, otherwise the request cannot
407 * be removed. Since we don't *really* have that, we pass in the old
408 * generation counter - if that fails, too bad, it will hopefully be removed
409 * at close time and then be ignored. */
410 sqe->user_data = (uint32_t)fd | ((__u64)(uint32_t)anfds [fd].egen << 32);
389 iouring_sqe_submit (EV_A_ sqe); 411 iouring_sqe_submit (EV_A_ sqe);
390 412
391 /* increment generation counter to avoid handling old events */ 413 /* increment generation counter to avoid handling old events */
392 ++anfds [fd].egen; 414 ++anfds [fd].egen;
393 } 415 }
434{ 456{
435 int fd = cqe->user_data & 0xffffffffU; 457 int fd = cqe->user_data & 0xffffffffU;
436 uint32_t gen = cqe->user_data >> 32; 458 uint32_t gen = cqe->user_data >> 32;
437 int res = cqe->res; 459 int res = cqe->res;
438 460
439 /* ignore fd removal events, if there are any. TODO: verify */
440 /* TODO: yes, this triggers */
441 if (cqe->user_data == (__u64)-1)
442 return;
443
444 assert (("libev: io_uring fd must be in-bounds", fd >= 0 && fd < anfdmax)); 461 assert (("libev: io_uring fd must be in-bounds", fd >= 0 && fd < anfdmax));
445 462
446 /* documentation lies, of course. the result value is NOT like 463 /* documentation lies, of course. the result value is NOT like
447 * normal syscalls, but like linux raw syscalls, i.e. negative 464 * normal syscalls, but like linux raw syscalls, i.e. negative
448 * error numbers. fortunate, as otherwise there would be no way 465 * error numbers. fortunate, as otherwise there would be no way
449 * to get error codes at all. still, why not document this? 466 * to get error codes at all. still, why not document this?
450 */ 467 */
451 468
452 /* ignore event if generation doesn't match */ 469 /* ignore event if generation doesn't match */
470 /* other than skipping removal events, */
453 /* this should actually be very rare */ 471 /* this should actually be very rare */
454 if (ecb_expect_false (gen != (uint32_t)anfds [fd].egen)) 472 if (ecb_expect_false (gen != (uint32_t)anfds [fd].egen))
455 return; 473 return;
456 474
457 if (ecb_expect_false (res < 0)) 475 if (ecb_expect_false (res < 0))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines