Ignore:
Timestamp:
Mar 30, 2022, 10:44:10 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
f870e257
Parents:
ee3da78 (diff), bdfd0bd (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

Location:
libcfa/src/concurrency
Files:
4 edited

Legend:

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

    ree3da78 r13cdc8c  
    9696        static void ioring_syscsll( struct $io_context & ctx, unsigned int min_comp, unsigned int flags ) {
    9797                __STATS__( true, io.calls.flush++; )
    98                 int ret = syscall( __NR_io_uring_enter, ctx.fd, ctx.sq.to_submit, min_comp, flags, (sigset_t *)0p, _NSIG / 8);
    99                 if( ret < 0 ) {
    100                         switch((int)errno) {
    101                         case EAGAIN:
    102                         case EINTR:
    103                         case EBUSY:
    104                                 // Update statistics
    105                                 __STATS__( false, io.calls.errors.busy ++; )
    106                                 return false;
    107                         default:
    108                                 abort( "KERNEL ERROR: IO_URING SYSCALL - (%d) %s\n", (int)errno, strerror(errno) );
     98                int ret;
     99                for() {
     100                        ret = syscall( __NR_io_uring_enter, ctx.fd, ctx.sq.to_submit, min_comp, flags, (sigset_t *)0p, _NSIG / 8);
     101                        if( ret < 0 ) {
     102                                switch((int)errno) {
     103                                case EINTR:
     104                                        continue;
     105                                case EAGAIN:
     106                                case EBUSY:
     107                                        // Update statistics
     108                                        __STATS__( false, io.calls.errors.busy ++; )
     109                                        return false;
     110                                default:
     111                                        abort( "KERNEL ERROR: IO_URING SYSCALL - (%d) %s\n", (int)errno, strerror(errno) );
     112                                }
    109113                        }
     114                        break;
    110115                }
    111116
     
    179184                // Ensure that the kernel only sees the new value of the head index after the CQEs have been read.
    180185                __atomic_store_n( ctx->cq.head, head + count, __ATOMIC_SEQ_CST );
     186                ctx->proc->idle_wctx.drain_time = ts_next;
    181187
    182188                __cfadbg_print_safe(io, "Kernel I/O : %u completed age %llu\n", count, ts_next);
     
    230236                                        const unsigned long long cutoff = calc_cutoff(ctsc, ctx->cq.id, ctxs_count, io.data, io.tscs, __shard_factor.io);
    231237                                        const unsigned long long age = moving_average(ctsc, io.tscs[target].tv, io.tscs[target].ma);
    232                                         __cfadbg_print_safe(io, "Kernel I/O: Help attempt on %u from %u, age %'llu vs cutoff %'llu, %s\n", target, this, age, cutoff, age > cutoff ? "yes" : "no");
     238                                        __cfadbg_print_safe(io, "Kernel I/O: Help attempt on %u from %u, age %'llu vs cutoff %'llu, %s\n", target, ctx->cq.id, age, cutoff, age > cutoff ? "yes" : "no");
    233239                                        if(age <= cutoff) break HELP;
    234240
     
    635641
    636642                        // We can proceed to the fast path
    637                         if( !__alloc(ctx, &idx, 1) ) return false;
     643                        if( !__alloc(ctx, &idx, 1) ) {
     644                                /* paranoid */ verify( false ); // for now check if this happens, next time just abort the sleep.
     645                                return false;
     646                        }
    638647
    639648                        // Allocation was successful
     
    665674
    666675                        /* paranoid */ verify( sqe->user_data == (uintptr_t)&future );
    667                         __submit( ctx, &idx, 1, true );
     676                        __submit_only( ctx, &idx, 1 );
    668677
    669678                        /* paranoid */ verify( proc == __cfaabi_tls.this_processor );
     
    676685                        iovec iov;
    677686                        __atomic_acquire( &proc->io.ctx->cq.lock );
     687
     688                        __attribute__((used)) volatile bool was_reset = false;
    678689
    679690                        with( proc->idle_wctx) {
     
    687698                                        iov.iov_len  = sizeof(eventfd_t);
    688699                                        __kernel_read(proc, *ftr, iov, evfd );
     700                                        ftr->result = 0xDEADDEAD;
     701                                        *((eventfd_t *)rdbuf) = 0xDEADDEADDEADDEAD;
     702                                        was_reset = true;
    689703                                }
    690704                        }
    691705
    692                         __ioarbiter_flush( *proc->io.ctx );
    693                         ioring_syscsll( *proc->io.ctx, 1, IORING_ENTER_GETEVENTS);
     706                        if( !__atomic_load_n( &proc->do_terminate, __ATOMIC_SEQ_CST ) ) {
     707                                __ioarbiter_flush( *proc->io.ctx );
     708                                proc->idle_wctx.sleep_time = rdtscl();
     709                                ioring_syscsll( *proc->io.ctx, 1, IORING_ENTER_GETEVENTS);
     710                        }
    694711
    695712                        ready_schedule_lock();
    696713                        __cfa_do_drain( proc->io.ctx, proc->cltr );
    697714                        ready_schedule_unlock();
     715
     716                        asm volatile ("" :: "m" (was_reset));
    698717                }
    699718        #endif
  • libcfa/src/concurrency/kernel.cfa

    ree3da78 r13cdc8c  
    642642
    643643        switch(fd) {
     644                __attribute__((unused)) int ret;
    644645        case 0:
    645646                // If the processor isn't ready to sleep then the exchange will already wake it up
     
    659660                // If the processor was ready to sleep, we need to wake it up with an actual write
    660661                val = 1;
    661                 eventfd_write( fd, val );
     662                ret = eventfd_write( fd, val );
     663                /* paranoid */ verifyf( ret == 0, "Expected return to be 0, was %d\n", ret );
    662664
    663665                #if !defined(__CFA_NO_STATISTICS__)
     
    682684        this->idle_wctx.sem = 1;
    683685
     686        this->idle_wctx.wake__time = rdtscl();
     687
    684688        eventfd_t val;
    685689        val = 1;
    686         eventfd_write( this->idle_wctx.evfd, val );
    687 
     690        __attribute__((unused)) int ret = eventfd_write( this->idle_wctx.evfd, val );
     691
     692        /* paranoid */ verifyf( ret == 0, "Expected return to be 0, was %d\n", ret );
    688693        /* paranoid */ verify( ! __preemption_enabled() );
    689694}
  • libcfa/src/concurrency/kernel.hfa

    ree3da78 r13cdc8c  
    7474        // unused if not using io_uring for idle sleep
    7575        io_future_t * ftr;
     76
     77        volatile unsigned long long wake__time;
     78        volatile unsigned long long sleep_time;
     79        volatile unsigned long long drain_time;
    7680};
    7781
  • libcfa/src/concurrency/kernel/startup.cfa

    ree3da78 r13cdc8c  
    558558
    559559        idle_wctx.sem = 0;
     560        idle_wctx.wake__time = 0;
    560561
    561562        // I'm assuming these two are reserved for standard input and output
Note: See TracChangeset for help on using the changeset viewer.