Ignore:
Timestamp:
Jan 9, 2021, 4:27:57 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
561dd26
Parents:
35fd2c4
Message:

Added prints.
Naive implementation of cancel.
Server now shutdown cleanly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/io/setup.cfa

    r35fd2c4 rece0e80  
    169169                // Main loop
    170170                while( iopoll.run ) {
     171                        __cfadbg_print_safe(io_core, "Kernel I/O - epoll : waiting on io_uring contexts\n");
     172
    171173                        // Wait for events
    172174                        int nfds = epoll_pwait( iopoll.epollfd, events, 10, -1, &mask );
     175
     176                        __cfadbg_print_safe(io_core, "Kernel I/O - epoll : %d io contexts events, waking up\n", nfds);
    173177
    174178                        // Check if an error occured
     
    181185                                $io_ctx_thread * io_ctx = ($io_ctx_thread *)(uintptr_t)events[i].data.u64;
    182186                                /* paranoid */ verify( io_ctx );
    183                                 __cfadbg_print_safe(io_core, "Kernel I/O : Unparking io poller %p\n", io_ctx);
     187                                __cfadbg_print_safe(io_core, "Kernel I/O - epoll : Unparking io poller %p\n", io_ctx);
    184188                                #if !defined( __CFA_NO_STATISTICS__ )
    185189                                        __cfaabi_tls.this_stats = io_ctx->self.curr_cluster->stats;
     
    233237                $thread & thrd = this.thrd.self;
    234238                if( cluster_context ) {
     239                        // We are about to do weird things with the threads
     240                        // we don't need interrupts to complicate everything
     241                        disable_interrupts();
     242
     243                        // Get cluster info
    235244                        cluster & cltr = *thrd.curr_cluster;
    236245                        /* paranoid */ verify( cltr.idles.total == 0 || &cltr == mainCluster );
     
    239248                        // We need to adjust the clean-up based on where the thread is
    240249                        if( thrd.state == Ready || thrd.preempted != __NO_PREEMPTION ) {
     250                                // This is the tricky case
     251                                // The thread was preempted or ready to run and now it is on the ready queue
     252                                // but the cluster is shutting down, so there aren't any processors to run the ready queue
     253                                // the solution is to steal the thread from the ready-queue and pretend it was blocked all along
    241254
    242255                                ready_schedule_lock();
    243 
    244                                         // This is the tricky case
    245                                         // The thread was preempted and now it is on the ready queue
     256                                        // The thread should on the list
     257                                        /* paranoid */ verify( thrd.link.next != 0p );
     258
     259                                        // Remove the thread from the ready queue of this cluster
    246260                                        // The thread should be the last on the list
    247                                         /* paranoid */ verify( thrd.link.next != 0p );
    248 
    249                                         // Remove the thread from the ready queue of this cluster
    250261                                        __attribute__((unused)) bool removed = remove_head( &cltr, &thrd );
    251262                                        /* paranoid */ verify( removed );
     
    263274                        }
    264275                        // !!! This is not an else if !!!
     276                        // Ok, now the thread is blocked (whether we cheated to get here or not)
    265277                        if( thrd.state == Blocked ) {
    266 
    267278                                // This is the "easy case"
    268279                                // The thread is parked and can easily be moved to active cluster
     
    274285                        }
    275286                        else {
    276 
    277287                                // The thread is in a weird state
    278288                                // I don't know what to do here
    279289                                abort("io_context poller thread is in unexpected state, cannot clean-up correctly\n");
    280290                        }
     291
     292                        // The weird thread kidnapping stuff is over, restore interrupts.
     293                        enable_interrupts( __cfaabi_dbg_ctx );
    281294                } else {
    282295                        post( this.thrd.sem );
     
    463476
    464477        void __ioctx_prepare_block($io_ctx_thread & ctx, struct epoll_event & ev) {
     478                __cfadbg_print_safe(io_core, "Kernel I/O - epoll : Re-arming io poller %p\n", &ctx);
    465479                int ret = epoll_ctl(iopoll.epollfd, EPOLL_CTL_MOD, ctx.ring->fd, &ev);
    466480                if (ret < 0) {
Note: See TracChangeset for help on using the changeset viewer.