Duncan Coutts pushed to branch wip/io-manager-deadlock-detection at Glasgow Haskell Compiler / GHC

Commits:

1 changed file:

Changes:

  • rts/posix/Poll.c
    ... ... @@ -38,6 +38,10 @@
    38 38
     #include <signal.h>
    
    39 39
     #include <poll.h>
    
    40 40
     #endif
    
    41
    +#if defined(HAVE_UNISTD_H)
    
    42
    +#include <unistd.h>
    
    43
    +#endif
    
    44
    +
    
    41 45
     
    
    42 46
     #include "IOManagerInternals.h"
    
    43 47
     #include "Timeout.h"
    
    ... ... @@ -424,13 +428,13 @@ void pollCompletedTimeoutsOrIOPoll(CapIOManager *iomgr)
    424 428
             int res = ppoll(poll_table, nfds, &tv, NULL);
    
    425 429
     
    
    426 430
             debugTrace(DEBUG_iomanager,
    
    427
    -                   "ppoll(nfds = %d, timeout.sec = 0, timeout.nsec = 0) = %d",
    
    431
    +                   "ppoll(nfds = %lu, timeout.sec = 0, timeout.nsec = 0) = %d",
    
    428 432
                        nfds, res);
    
    429 433
     #else
    
    430 434
             int res = poll(poll_table, nfds, 0);
    
    431 435
     
    
    432 436
             debugTrace(DEBUG_iomanager,
    
    433
    -                   "poll(nfds = %d, timeout_ms = 0) = %d",
    
    437
    +                   "poll(nfds = %lu, timeout_ms = 0) = %d",
    
    434 438
                        nfds, res);
    
    435 439
     #endif
    
    436 440
             if (res == 0) {
    
    ... ... @@ -510,15 +514,30 @@ bool awaitCompletedTimeoutsOrIOPoll(CapIOManager *iomgr)
    510 514
             int res = ppoll(poll_table, nfds, timeout_ns, NULL);
    
    511 515
     
    
    512 516
             debugTrace(DEBUG_iomanager,
    
    513
    -                   "ppoll(nfds = %d, timeout.sec = %d, timeout.nsec = %d) = %d",
    
    517
    +                   "ppoll(nfds = %lu, timeout.sec = %d, timeout.nsec = %d) = %d",
    
    514 518
                        nfds, timeout_ns == NULL ? -1 : timeout_ns->tv_sec,
    
    515 519
                              timeout_ns == NULL ?  0 : timeout_ns->tv_nsec,
    
    516 520
                        res);
    
    521
    +#elif defined(wasm32_HOST_ARCH)
    
    522
    +        /* Debug hack: on wasm CI we observe failures like
    
    523
    +         * T5866: poll res = -1: Not supported
    
    524
    +         * We want to get more detail.
    
    525
    +         */
    
    526
    +        int res = poll(poll_table, nfds, timeout_ms);
    
    527
    +        if (res < 0) {
    
    528
    +            if (errno == ENOTSUP && nfds == 0 && timeout_ms == -1) {
    
    529
    +                pause();
    
    530
    +            } else {
    
    531
    +                sysErrorBelch("poll res = %d, errno = %d (ENOTSUP == %d), nfds = %lu, timeout_ms = %d",
    
    532
    +                              res, errno, ENOTSUP, nfds, timeout_ms);
    
    533
    +                stg_exit(EXIT_FAILURE);
    
    534
    +            }
    
    535
    +        }
    
    517 536
     #else
    
    518 537
             int res = poll(poll_table, nfds, timeout_ms);
    
    519 538
     
    
    520 539
             debugTrace(DEBUG_iomanager,
    
    521
    -                   "poll(nfds = %d, timeout_ms = %d) = %d",
    
    540
    +                   "poll(nfds = %lu, timeout_ms = %d) = %d",
    
    522 541
                        nfds, timeout_ms, res);
    
    523 542
     #endif
    
    524 543
     
    
    ... ... @@ -579,7 +598,8 @@ static void reportPollError(int res, nfds_t nfds)
    579 598
             // as soon as we get thread submitting an operation that would exceed
    
    580 599
             // the limit.
    
    581 600
         } else {
    
    582
    -        sysErrorBelch("poll res = %d", res);
    
    601
    +        sysErrorBelch("poll res = %d, errno = %d, nfds = %lu ",
    
    602
    +                      res, errno, (unsigned long) nfds);
    
    583 603
             stg_exit(EXIT_FAILURE);
    
    584 604
         }
    
    585 605
     }