Ignore:
Timestamp:
Jan 25, 2021, 3:45:42 PM (5 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:
c292244
Parents:
b6a8b31 (diff), 7158202 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    rb6a8b31 rd95969a  
    4242        void ^?{}(io_context & this, bool cluster_context) {}
    4343
     44        void register_fixed_files( io_context &, int *, unsigned ) {}
     45        void register_fixed_files( cluster    &, int *, unsigned ) {}
     46
    4447#else
    4548        #include <errno.h>
     
    110113
    111114        static struct {
    112                 pthread_t     thrd;    // pthread handle to io poller thread
    113                 void *        stack;   // pthread stack for io poller thread
    114                 int           epollfd; // file descriptor to the epoll instance
    115                 volatile bool run;     // Whether or not to continue
     115                      pthread_t  thrd;    // pthread handle to io poller thread
     116                      void *     stack;   // pthread stack for io poller thread
     117                      int        epollfd; // file descriptor to the epoll instance
     118                volatile     bool run;     // Whether or not to continue
     119                volatile     bool stopped; // Whether the poller has finished running
     120                volatile uint64_t epoch;   // Epoch used for memory reclamation
    116121        } iopoll;
    117122
     
    126131                __cfadbg_print_safe(io_core, "Kernel : Starting io poller thread\n" );
    127132
    128                 iopoll.run = true;
    129                 iopoll.stack = __create_pthread( &iopoll.thrd, iopoll_loop, 0p );
     133                iopoll.stack   = __create_pthread( &iopoll.thrd, iopoll_loop, 0p );
     134                iopoll.run     = true;
     135                iopoll.stopped = false;
     136                iopoll.epoch   = 0;
    130137        }
    131138
     
    171178                while( iopoll.run ) {
    172179                        __cfadbg_print_safe(io_core, "Kernel I/O - epoll : waiting on io_uring contexts\n");
     180
     181                        // increment the epoch to notify any deleters we are starting a new cycle
     182                        __atomic_fetch_add(&iopoll.epoch, 1, __ATOMIC_SEQ_CST);
    173183
    174184                        // Wait for events
     
    197207                        }
    198208                }
     209
     210                __atomic_store_n(&iopoll.stopped, true, __ATOMIC_SEQ_CST);
    199211
    200212                __cfadbg_print_safe(io_core, "Kernel : IO poller thread stopping\n" );
     
    493505// I/O Context Sleep
    494506//=============================================================================================
    495         #define IOEVENTS EPOLLIN | EPOLLONESHOT
    496 
    497507        static inline void __ioctx_epoll_ctl($io_ctx_thread & ctx, int op, const char * error) {
    498508                struct epoll_event ev;
    499                 ev.events = IOEVENTS;
     509                ev.events = EPOLLIN | EPOLLONESHOT;
    500510                ev.data.u64 = (__u64)&ctx;
    501511                int ret = epoll_ctl(iopoll.epollfd, op, ctx.ring->efd, &ev);
     
    514524        }
    515525
     526        void __ioctx_unregister($io_ctx_thread & ctx) {
     527                // Read the current epoch so we know when to stop
     528                size_t curr = __atomic_load_n(&iopoll.epoch, __ATOMIC_SEQ_CST);
     529
     530                // Remove the fd from the iopoller
     531                __ioctx_epoll_ctl(ctx, EPOLL_CTL_DEL, "REMOVE");
     532
     533                // Notify the io poller thread of the shutdown
     534                iopoll.run = false;
     535                sigval val = { 1 };
     536                pthread_sigqueue( iopoll.thrd, SIGUSR1, val );
     537
     538                // Make sure all this is done
     539                __atomic_thread_fence(__ATOMIC_SEQ_CST);
     540
     541                // Wait for the next epoch
     542                while(curr == iopoll.epoch && !iopoll.stopped) Pause();
     543        }
     544
    516545//=============================================================================================
    517546// I/O Context Misc Setup
     
    520549                int ret = syscall( __NR_io_uring_register, ctx.thrd.ring->fd, IORING_REGISTER_FILES, files, count );
    521550                if( ret < 0 ) {
    522                         abort( "KERNEL ERROR: IO_URING SYSCALL - (%d) %s\n", (int)errno, strerror(errno) );
     551                        abort( "KERNEL ERROR: IO_URING REGISTER - (%d) %s\n", (int)errno, strerror(errno) );
    523552                }
    524553
Note: See TracChangeset for help on using the changeset viewer.