Ignore:
Timestamp:
Mar 21, 2022, 1:44:06 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
a76202d
Parents:
ef3c383 (diff), dbe2533 (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/kernel.cfa

    ref3c383 rd672350  
    1919// #define __CFA_DEBUG_PRINT_RUNTIME_CORE__
    2020
     21#pragma GCC diagnostic push
     22#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
     23
    2124//C Includes
    2225#include <errno.h>
     
    2528#include <signal.h>
    2629#include <unistd.h>
     30
    2731extern "C" {
    2832        #include <sys/eventfd.h>
     
    3135
    3236//CFA Includes
    33 #include "kernel_private.hfa"
     37#include "kernel/private.hfa"
    3438#include "preemption.hfa"
    3539#include "strstream.hfa"
     
    4044#define __CFA_INVOKE_PRIVATE__
    4145#include "invoke.h"
     46#pragma GCC diagnostic pop
    4247
    4348#if !defined(__CFA_NO_STATISTICS__)
     
    131136static void mark_awake(__cluster_proc_list & idles, processor & proc);
    132137
    133 extern void __cfa_io_start( processor * );
    134 extern bool __cfa_io_drain( processor * );
     138extern bool __cfa_io_drain( $io_context * );
    135139extern bool __cfa_io_flush( processor *, int min_comp );
    136 extern void __cfa_io_stop ( processor * );
    137140static inline bool __maybe_io_drain( processor * );
    138141
     
    159162        verify(this);
    160163
    161         io_future_t future; // used for idle sleep when io_uring is present
    162         future.self.ptr = 1p;  // mark it as already fulfilled so we know if there is a pending request or not
    163         eventfd_t idle_val;
    164         iovec idle_iovec = { &idle_val, sizeof(idle_val) };
    165 
    166         __cfa_io_start( this );
     164        /* paranoid */ verify( this->idle_wctx.ftr   != 0p );
     165        /* paranoid */ verify( this->idle_wctx.rdbuf != 0p );
     166
     167        // used for idle sleep when io_uring is present
     168        // mark it as already fulfilled so we know if there is a pending request or not
     169        this->idle_wctx.ftr->self.ptr = 1p;
     170        iovec idle_iovec = { this->idle_wctx.rdbuf, sizeof(eventfd_t) };
    167171
    168172        __cfadbg_print_safe(runtime_core, "Kernel : core %p starting\n", this);
     
    231235                                }
    232236
    233                                 idle_sleep( this, future, idle_iovec );
     237                                idle_sleep( this, *this->idle_wctx.ftr, idle_iovec );
    234238
    235239                                // We were woken up, remove self from idle
     
    251255                        if( __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST) ) break MAIN_LOOP;
    252256
    253                         if(this->io.pending && !this->io.dirty) {
     257                        if(__atomic_load_n(&this->io.pending, __ATOMIC_RELAXED) && !__atomic_load_n(&this->io.dirty, __ATOMIC_RELAXED)) {
    254258                                __IO_STATS__(true, io.flush.dirty++; )
    255259                                __cfa_io_flush( this, 0 );
     
    259263                __cfadbg_print_safe(runtime_core, "Kernel : core %p stopping\n", this);
    260264        }
    261 
    262         for(int i = 0; !available(future); i++) {
    263                 if(i > 1000) __cfaabi_dbg_write( "ERROR: kernel has bin spinning on a flush after exit loop.\n", 60);
    264                 __cfa_io_flush( this, 1 );
    265         }
    266 
    267         __cfa_io_stop( this );
    268265
    269266        post( this->terminated );
     
    634631
    635632        int fd = 1;
    636         if( __atomic_load_n(&fdp->fd, __ATOMIC_SEQ_CST) != 1 ) {
    637                 fd = __atomic_exchange_n(&fdp->fd, 1, __ATOMIC_RELAXED);
     633        if( __atomic_load_n(&fdp->sem, __ATOMIC_SEQ_CST) != 1 ) {
     634                fd = __atomic_exchange_n(&fdp->sem, 1, __ATOMIC_RELAXED);
    638635        }
    639636
     
    677674        __cfadbg_print_safe(runtime_core, "Kernel : waking Processor %p\n", this);
    678675
    679         this->idle_wctx.fd = 1;
     676        this->idle_wctx.sem = 1;
    680677
    681678        eventfd_t val;
    682679        val = 1;
    683         eventfd_write( this->idle_fd, val );
     680        eventfd_write( this->idle_wctx.evfd, val );
    684681
    685682        /* paranoid */ verify( ! __preemption_enabled() );
     
    689686        // Tell everyone we are ready to go do sleep
    690687        for() {
    691                 int expected = this->idle_wctx.fd;
     688                int expected = this->idle_wctx.sem;
    692689
    693690                // Someone already told us to wake-up! No time for a nap.
     
    695692
    696693                // Try to mark that we are going to sleep
    697                 if(__atomic_compare_exchange_n(&this->idle_wctx.fd, &expected, this->idle_fd, false,  __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ) {
     694                if(__atomic_compare_exchange_n(&this->idle_wctx.sem, &expected, this->idle_wctx.evfd, false,  __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ) {
    698695                        // Every one agreed, taking a nap
    699696                        break;
     
    713710                {
    714711                        eventfd_t val;
    715                         ssize_t ret = read( this->idle_fd, &val, sizeof(val) );
     712                        ssize_t ret = read( this->idle_wctx.evfd, &val, sizeof(val) );
    716713                        if(ret < 0) {
    717714                                switch((int)errno) {
     
    740737                        reset(future);
    741738
    742                         __kernel_read(this, future, iov, this->idle_fd );
     739                        __kernel_read(this, future, iov, this->idle_wctx.evfd );
    743740                }
    744741
     
    750747        __STATS__(true, ready.sleep.halts++; )
    751748
    752         proc.idle_wctx.fd = 0;
     749        proc.idle_wctx.sem = 0;
    753750
    754751        /* paranoid */ verify( ! __preemption_enabled() );
     
    842839                if(head == tail) return false;
    843840                ready_schedule_lock();
    844                 ret = __cfa_io_drain( proc );
     841                ret = __cfa_io_drain( ctx );
    845842                ready_schedule_unlock();
    846843        #endif
Note: See TracChangeset for help on using the changeset viewer.