Duncan Coutts pushed to branch wip/dcoutts/io-manager-tidy at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • rts/IOManagerInternals.h
    ... ... @@ -47,9 +47,11 @@ struct _CapIOManager {
    47 47
     #endif
    
    48 48
     
    
    49 49
     #if defined(IOMGR_ENABLED_SELECT) || defined(IOMGR_ENABLED_POLL)
    
    50
    +#if defined(HAVE_PREEMPTION)
    
    50 51
         /* FDs for waking up the I/O manager when it is blocked waiting */
    
    51 52
         int interrupt_fd_r, interrupt_fd_w;
    
    52 53
     #endif
    
    54
    +#endif
    
    53 55
     
    
    54 56
     #if defined(IOMGR_ENABLED_POLL)
    
    55 57
         /* AIOP and timeout collections shared by several I/O manager impls */
    

  • rts/posix/FdWakeup.h
    ... ... @@ -29,12 +29,14 @@
    29 29
     
    
    30 30
     #include "BeginPrivate.h"
    
    31 31
     
    
    32
    +#if defined(HAVE_PREEMPTION)
    
    32 33
     void newFdWakeup(int *fd_r, int *fd_w);
    
    33 34
     void closeFdWakeup(int fd_r, int fd_w);
    
    34 35
     
    
    35 36
     /* This is safe to use from a signal handler */
    
    36 37
     void sendFdWakeup(int fd_w);
    
    37 38
     void collectFdWakeup(int fd_r);
    
    39
    +#endif
    
    38 40
     
    
    39 41
     #include "EndPrivate.h"
    
    40 42
     

  • rts/posix/Poll.c
    ... ... @@ -142,13 +142,20 @@ void initCapabilityIOManagerPoll(CapIOManager *iomgr)
    142 142
         initClosureTable(&iomgr->aiop_table, ClosureTableCompact);
    
    143 143
         iomgr->timeout_queue = emptyTimeoutQueue();
    
    144 144
     
    
    145
    +#if defined(HAVE_PREEMPTION)
    
    145 146
         newFdWakeup(&iomgr->interrupt_fd_r, &iomgr->interrupt_fd_w);
    
    147
    +#endif
    
    146 148
     
    
    147 149
         iomgr->full_poll_table = stgMallocBytes(sizeof(struct pollfd) /* size 1 */,
    
    148 150
                                                 "initCapabilityIOManagerPoll");
    
    149 151
         iomgr->full_poll_table[0] = (struct pollfd) {
    
    152
    +#if defined(HAVE_PREEMPTION)
    
    150 153
                                       .fd      = iomgr->interrupt_fd_r,
    
    151 154
                                       .events  = POLLIN,
    
    155
    +#else
    
    156
    +                                  .fd      = -1, // unused
    
    157
    +                                  .events  = 0,  // unused
    
    158
    +#endif
    
    152 159
                                       .revents = 0
    
    153 160
                                     };
    
    154 161
         iomgr->aiop_poll_table = iomgr->full_poll_table+1; /* hence empty */
    
    ... ... @@ -158,7 +165,9 @@ void initCapabilityIOManagerPoll(CapIOManager *iomgr)
    158 165
     void freeCapabilityIOManagerPoll(CapIOManager *iomgr)
    
    159 166
     {
    
    160 167
         stgFree(iomgr->full_poll_table);
    
    168
    +#if defined(HAVE_PREEMPTION)
    
    161 169
         closeFdWakeup(iomgr->interrupt_fd_r, iomgr->interrupt_fd_w);
    
    170
    +#endif
    
    162 171
     }
    
    163 172
     
    
    164 173
     
    
    ... ... @@ -326,7 +335,8 @@ static bool processIOCompletions(CapIOManager *iomgr, int ncompletions)
    326 335
         debugTrace(DEBUG_iomanager, "processIOCompletions(ncompletions = %d)",
    
    327 336
                                     ncompletions);
    
    328 337
     
    
    329
    -    bool interrupt;
    
    338
    +    bool interrupt = false;
    
    339
    +#if defined(HAVE_PREEMPTION)
    
    330 340
         /* If the interrupt_fd_r is ready, collect it */
    
    331 341
         if (iomgr->full_poll_table[0].revents) {
    
    332 342
             ASSERT(iomgr->full_poll_table[0].fd == iomgr->interrupt_fd_r);
    
    ... ... @@ -334,9 +344,8 @@ static bool processIOCompletions(CapIOManager *iomgr, int ncompletions)
    334 344
             ncompletions--;
    
    335 345
             interrupt = true;
    
    336 346
             debugTrace(DEBUG_iomanager, "Received interrupt in poll I/O manager");
    
    337
    -    } else {
    
    338
    -        interrupt = false;
    
    339 347
         }
    
    348
    +#endif
    
    340 349
     
    
    341 350
         struct pollfd *aiop_poll_table = iomgr->aiop_poll_table;
    
    342 351
         int n = ncompletions;
    
    ... ... @@ -407,18 +416,26 @@ void pollCompletedTimeoutsOrIOPoll(CapIOManager *iomgr)
    407 416
     
    
    408 417
             nfds_t nfds = sizeClosureTable(&iomgr->aiop_table) + 1;
    
    409 418
     
    
    419
    +#if defined(HAVE_PREEMPTION)
    
    420
    +        /* the full_poll_table includes interrupt_fd_r */
    
    421
    +        struct pollfd *poll_table = iomgr->full_poll_table;
    
    422
    +#else
    
    423
    +        /* the aiop_poll_table does not include interrupt_fd_r */
    
    424
    +        struct pollfd *poll_table = iomgr->aiop_poll_table;
    
    425
    +#endif
    
    426
    +
    
    410 427
             /* Poll for I/O readiness, without waiting. */
    
    411 428
     #if defined(HAVE_DECL_PPOLL) && HAVE_DECL_PPOLL == 1
    
    412 429
             /* We could use poll here, since we use no timeout, but for
    
    413 430
                consistency we use the same syscall as at the other call site. */
    
    414 431
             struct timespec tv = (struct timespec) { .tv_sec = 0, .tv_nsec = 0 };
    
    415
    -        int res = ppoll(iomgr->full_poll_table, nfds, &tv, NULL);
    
    432
    +        int res = ppoll(poll_table, nfds, &tv, NULL);
    
    416 433
     
    
    417 434
             debugTrace(DEBUG_iomanager,
    
    418 435
                        "ppoll(nfds = %d, timeout.sec = 0, timeout.nsec = 0) = %d",
    
    419 436
                        nfds, res);
    
    420 437
     #else
    
    421
    -        int res = poll(iomgr->full_poll_table, nfds, 0);
    
    438
    +        int res = poll(poll_table, nfds, 0);
    
    422 439
     
    
    423 440
             debugTrace(DEBUG_iomanager,
    
    424 441
                        "poll(nfds = %d, timeout_ms = 0) = %d",
    
    ... ... @@ -471,6 +488,14 @@ bool awaitCompletedTimeoutsOrIOPoll(CapIOManager *iomgr)
    471 488
              */
    
    472 489
             bool wait = emptyRunQueue(iomgr->cap);
    
    473 490
     
    
    491
    +#if defined(HAVE_PREEMPTION)
    
    492
    +        /* the full_poll_table includes interrupt_fd_r */
    
    493
    +        struct pollfd *poll_table = iomgr->full_poll_table;
    
    494
    +#else
    
    495
    +        /* the aiop_poll_table does not include interrupt_fd_r */
    
    496
    +        struct pollfd *poll_table = iomgr->aiop_poll_table;
    
    497
    +#endif
    
    498
    +
    
    474 499
             /* Decide if we are going to wait if no I/O is ready, either:
    
    475 500
              * poll only, wait indefinitely, or wait until a timeout.
    
    476 501
              */
    
    ... ... @@ -484,7 +509,7 @@ bool awaitCompletedTimeoutsOrIOPoll(CapIOManager *iomgr)
    484 509
             /* Check for I/O readiness, possibly waiting. */
    
    485 510
             nfds_t nfds = sizeClosureTable(&iomgr->aiop_table) + 1;
    
    486 511
     #if defined(HAVE_DECL_PPOLL) && HAVE_DECL_PPOLL == 1
    
    487
    -        int res = ppoll(iomgr->full_poll_table, nfds, timeout_ns, NULL);
    
    512
    +        int res = ppoll(poll_table, nfds, timeout_ns, NULL);
    
    488 513
     
    
    489 514
             debugTrace(DEBUG_iomanager,
    
    490 515
                        "ppoll(nfds = %d, timeout.sec = %d, timeout.nsec = %d) = %d",
    
    ... ... @@ -492,7 +517,7 @@ bool awaitCompletedTimeoutsOrIOPoll(CapIOManager *iomgr)
    492 517
                              timeout_ns == NULL ?  0 : timeout_ns->tv_nsec,
    
    493 518
                        res);
    
    494 519
     #else
    
    495
    -        int res = poll(iomgr->full_poll_table, nfds, timeout_ms);
    
    520
    +        int res = poll(poll_table, nfds, timeout_ms);
    
    496 521
     
    
    497 522
             debugTrace(DEBUG_iomanager,
    
    498 523
                        "poll(nfds = %d, timeout_ms = %d) = %d",
    
    ... ... @@ -565,7 +590,9 @@ static void reportPollError(int res, nfds_t nfds)
    565 590
     
    
    566 591
     void interruptIOManagerPoll(CapIOManager *iomgr)
    
    567 592
     {
    
    593
    +#if defined(HAVE_PREEMPTION)
    
    568 594
         sendFdWakeup(iomgr->interrupt_fd_w);
    
    595
    +#endif
    
    569 596
     }
    
    570 597
     
    
    571 598