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.13 by root, Sat Dec 28 03:29:50 2019 UTC vs.
Revision 1.14 by root, Sat Dec 28 05:20:17 2019 UTC

228 228
229/* the submit/completion queue entries */ 229/* the submit/completion queue entries */
230#define EV_SQES ((struct io_uring_sqe *) iouring_sqes) 230#define EV_SQES ((struct io_uring_sqe *) iouring_sqes)
231#define EV_CQES ((struct io_uring_cqe *)((char *)iouring_cq_ring + iouring_cq_cqes)) 231#define EV_CQES ((struct io_uring_cqe *)((char *)iouring_cq_ring + iouring_cq_cqes))
232 232
233/* TODO: this is not enough, we might have to reap events */
234/* TODO: but we can't, as that will re-arm events, causing */
235/* TODO: an endless loop in fd_reify */
236static int
237iouring_enter (EV_P_ ev_tstamp timeout)
238{
239 int res;
240
241 EV_RELEASE_CB;
242
243 res = evsys_io_uring_enter (iouring_fd, iouring_to_submit, 1,
244 timeout > EV_TS_CONST (0.) ? IORING_ENTER_GETEVENTS : 0, 0, 0);
245
246 assert (("libev: io_uring_enter did not consume all sqes", (res < 0 || res == iouring_to_submit)));
247
248 iouring_to_submit = 0;
249
250 EV_ACQUIRE_CB;
251
252 return res;
253}
254
233static 255static
234struct io_uring_sqe * 256struct io_uring_sqe *
235iouring_sqe_get (EV_P) 257iouring_sqe_get (EV_P)
236{ 258{
237 unsigned tail = EV_SQ_VAR (tail); 259 unsigned tail = EV_SQ_VAR (tail);
238 260
239 if (tail + 1 - EV_SQ_VAR (head) > EV_SQ_VAR (ring_entries)) 261 while (ecb_expect_false (tail + 1 - EV_SQ_VAR (head) > EV_SQ_VAR (ring_entries)))
240 { 262 {
241 /* queue full, flush */ 263 /* queue full, need to flush */
242 evsys_io_uring_enter (iouring_fd, iouring_to_submit, 0, 0, 0, 0);
243 iouring_to_submit = 0;
244 }
245 264
265 int res = iouring_enter (EV_A_ EV_TS_CONST (0.));
266
267 /* io_uring_enter might fail with EBUSY and won't submit anything */
268 /* unfortunately, we can't handle this at the moment */
269
270 if (res < 0 && errno == EBUSY)
271 //TODO
272 ev_syserr ("(libev) io_uring_enter could not clear sq");
273 else
274 break;
275
276 /* iouring_poll should have done ECB_MEMORY_FENCE_ACQUIRE */
277 }
278
246 assert (("libev: io_uring queue full after flush", tail + 1 - EV_SQ_VAR (head) <= EV_SQ_VAR (ring_entries))); 279 /*assert (("libev: io_uring queue full after flush", tail + 1 - EV_SQ_VAR (head) <= EV_SQ_VAR (ring_entries)));*/
247 280
248 return EV_SQES + (tail & EV_SQ_VAR (ring_mask)); 281 return EV_SQES + (tail & EV_SQ_VAR (ring_mask));
249} 282}
250 283
251inline_size 284inline_size
598 iouring_tfd_update (EV_A_ timeout); 631 iouring_tfd_update (EV_A_ timeout);
599 632
600 /* only enter the kernel if we have something to submit, or we need to wait */ 633 /* only enter the kernel if we have something to submit, or we need to wait */
601 if (timeout || iouring_to_submit) 634 if (timeout || iouring_to_submit)
602 { 635 {
603 int res; 636 int res = iouring_enter (EV_A_ timeout);
604
605 EV_RELEASE_CB;
606
607 res = evsys_io_uring_enter (iouring_fd, iouring_to_submit, 1,
608 timeout > EV_TS_CONST (0.) ? IORING_ENTER_GETEVENTS : 0, 0, 0);
609 iouring_to_submit = 0;
610
611 EV_ACQUIRE_CB;
612 637
613 if (ecb_expect_false (res < 0)) 638 if (ecb_expect_false (res < 0))
614 if (errno == EINTR) 639 if (errno == EINTR)
615 /* ignore */; 640 /* ignore */;
641 else if (errno == EBUSY)
642 /* cq full, cannot submit - should be rare because we flush the cq first, so simply ignore */;
616 else 643 else
617 ev_syserr ("(libev) iouring setup"); 644 ev_syserr ("(libev) iouring setup");
618 else 645 else
619 iouring_handle_cq (EV_A); 646 iouring_handle_cq (EV_A);
620 } 647 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines