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

Comparing libev/ev_linuxaio.c (file contents):
Revision 1.40 by root, Mon Jul 1 20:35:17 2019 UTC vs.
Revision 1.42 by root, Mon Jul 1 20:47:38 2019 UTC

286linuxaio_modify (EV_P_ int fd, int oev, int nev) 286linuxaio_modify (EV_P_ int fd, int oev, int nev)
287{ 287{
288 array_needsize (ANIOCBP, linuxaio_iocbps, linuxaio_iocbpmax, fd + 1, linuxaio_array_needsize_iocbp); 288 array_needsize (ANIOCBP, linuxaio_iocbps, linuxaio_iocbpmax, fd + 1, linuxaio_array_needsize_iocbp);
289 ANIOCBP iocb = linuxaio_iocbps [fd]; 289 ANIOCBP iocb = linuxaio_iocbps [fd];
290 290
291 if (iocb->io.aio_reqprio < 0) 291 if (ecb_expect_false (iocb->io.aio_reqprio < 0))
292 { 292 {
293 /* we handed this fd over to epoll, so undo this first */ 293 /* we handed this fd over to epoll, so undo this first */
294 /* we do it manually because the optimisations on epoll_modify won't do us any good */ 294 /* we do it manually because the optimisations on epoll_modify won't do us any good */
295 epoll_ctl (backend_fd, EPOLL_CTL_DEL, fd, 0); 295 epoll_ctl (backend_fd, EPOLL_CTL_DEL, fd, 0);
296 anfds [fd].emask = 0; 296 anfds [fd].emask = 0;
297 iocb->io.aio_reqprio = 0; 297 iocb->io.aio_reqprio = 0;
298 } 298 }
299 299
300 if (iocb->io.aio_buf) 300 if (ecb_expect_false (iocb->io.aio_buf))
301 { 301 {
302 /* iocb active, so cancel it first before resubmit */
302 for (;;) 303 for (;;)
303 { 304 {
304 /* on all relevant kernels, io_cancel fails with EINPROGRESS on "success" */ 305 /* on all relevant kernels, io_cancel fails with EINPROGRESS on "success" */
305 if (expect_false (evsys_io_cancel (linuxaio_ctx, &iocb->io, (struct io_event *)0) == 0)) 306 if (ecb_expect_false (evsys_io_cancel (linuxaio_ctx, &iocb->io, (struct io_event *)0) == 0))
306 break; 307 break;
307 308
308 if (expect_true (errno == EINPROGRESS)) 309 if (ecb_expect_true (errno == EINPROGRESS))
309 break; 310 break;
310 311
311 /* the EINPROGRESS test is for nicer error message. clumsy. */ 312 /* the EINPROGRESS test is for nicer error message. clumsy. */
312 assert (("libev: linuxaio unexpected io_cancel failed", errno != EINPROGRESS && errno != EINTR)); 313 assert (("libev: linuxaio unexpected io_cancel failed", errno != EINPROGRESS && errno != EINTR));
313 } 314 }
314 } 315 }
315 316
317 iocb->io.aio_buf =
318 (nev & EV_READ ? POLLIN : 0)
319 | (nev & EV_WRITE ? POLLOUT : 0);
320
316 if (nev) 321 if (nev)
317 { 322 {
318 iocb->io.aio_buf =
319 (nev & EV_READ ? POLLIN : 0)
320 | (nev & EV_WRITE ? POLLOUT : 0);
321
322 /* queue iocb up for io_submit */ 323 /* queue iocb up for io_submit */
323 /* this assumes we only ever get one call per fd per loop iteration */ 324 /* this assumes we only ever get one call per fd per loop iteration */
324 ++linuxaio_submitcnt; 325 ++linuxaio_submitcnt;
325 array_needsize (struct iocb *, linuxaio_submits, linuxaio_submitmax, linuxaio_submitcnt, array_needsize_noinit); 326 array_needsize (struct iocb *, linuxaio_submits, linuxaio_submitmax, linuxaio_submitcnt, array_needsize_noinit);
326 linuxaio_submits [linuxaio_submitcnt - 1] = &iocb->io; 327 linuxaio_submits [linuxaio_submitcnt - 1] = &iocb->io;
406int 407int
407linuxaio_ringbuf_valid (EV_P) 408linuxaio_ringbuf_valid (EV_P)
408{ 409{
409 struct aio_ring *ring = (struct aio_ring *)linuxaio_ctx; 410 struct aio_ring *ring = (struct aio_ring *)linuxaio_ctx;
410 411
411 return expect_true (ring->magic == AIO_RING_MAGIC) 412 return ecb_expect_true (ring->magic == AIO_RING_MAGIC)
412 && ring->incompat_features == EV_AIO_RING_INCOMPAT_FEATURES 413 && ring->incompat_features == EV_AIO_RING_INCOMPAT_FEATURES
413 && ring->header_length == sizeof (struct aio_ring); /* TODO: or use it to find io_event[0]? */ 414 && ring->header_length == sizeof (struct aio_ring); /* TODO: or use it to find io_event[0]? */
414} 415}
415 416
416/* read at least one event from kernel, or timeout */ 417/* read at least one event from kernel, or timeout */
421 struct timespec ts; 422 struct timespec ts;
422 struct io_event ioev[8]; /* 256 octet stack space */ 423 struct io_event ioev[8]; /* 256 octet stack space */
423 int want = 1; /* how many events to request */ 424 int want = 1; /* how many events to request */
424 int ringbuf_valid = linuxaio_ringbuf_valid (EV_A); 425 int ringbuf_valid = linuxaio_ringbuf_valid (EV_A);
425 426
426 if (expect_true (ringbuf_valid)) 427 if (ecb_expect_true (ringbuf_valid))
427 { 428 {
428 /* if the ring buffer has any events, we don't wait or call the kernel at all */ 429 /* if the ring buffer has any events, we don't wait or call the kernel at all */
429 if (linuxaio_get_events_from_ring (EV_A)) 430 if (linuxaio_get_events_from_ring (EV_A))
430 return; 431 return;
431 432
461 else if (res) 462 else if (res)
462 { 463 {
463 /* at least one event available, handle them */ 464 /* at least one event available, handle them */
464 linuxaio_parse_events (EV_A_ ioev, res); 465 linuxaio_parse_events (EV_A_ ioev, res);
465 466
466 if (expect_true (ringbuf_valid)) 467 if (ecb_expect_true (ringbuf_valid))
467 { 468 {
468 /* if we have a ring buffer, handle any remaining events in it */ 469 /* if we have a ring buffer, handle any remaining events in it */
469 linuxaio_get_events_from_ring (EV_A); 470 linuxaio_get_events_from_ring (EV_A);
470 471
471 /* at this point, we should have handled all outstanding events */ 472 /* at this point, we should have handled all outstanding events */
502 /* which allows us to pinpoint the erroneous iocb */ 503 /* which allows us to pinpoint the erroneous iocb */
503 for (submitted = 0; submitted < linuxaio_submitcnt; ) 504 for (submitted = 0; submitted < linuxaio_submitcnt; )
504 { 505 {
505 int res = evsys_io_submit (linuxaio_ctx, linuxaio_submitcnt - submitted, linuxaio_submits + submitted); 506 int res = evsys_io_submit (linuxaio_ctx, linuxaio_submitcnt - submitted, linuxaio_submits + submitted);
506 507
507 if (expect_false (res < 0)) 508 if (ecb_expect_false (res < 0))
508 if (errno == EINVAL) 509 if (errno == EINVAL)
509 { 510 {
510 /* This happens for unsupported fds, officially, but in my testing, 511 /* This happens for unsupported fds, officially, but in my testing,
511 * also randomly happens for supported fds. We fall back to good old 512 * also randomly happens for supported fds. We fall back to good old
512 * poll() here, under the assumption that this is a very rare case. 513 * poll() here, under the assumption that this is a very rare case.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines