Ignore:
Timestamp:
Apr 10, 2022, 2:53:18 PM (4 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
d8e2a09
Parents:
4559b34 (diff), 6256891 (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:

Resolve conflict

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel/startup.cfa

    r4559b34 r92538ab  
    1818
    1919// C Includes
    20 #include <errno.h>              // errno
     20#include <errno.h>                                      // errno
    2121#include <signal.h>
    22 #include <string.h>             // strerror
    23 #include <unistd.h>             // sysconf
     22#include <string.h>                                     // strerror
     23#include <unistd.h>                                     // sysconf
    2424
    2525extern "C" {
    26       #include <limits.h>       // PTHREAD_STACK_MIN
    27         #include <unistd.h>       // syscall
    28         #include <sys/eventfd.h>  // eventfd
    29       #include <sys/mman.h>     // mprotect
    30       #include <sys/resource.h> // getrlimit
     26        #include <limits.h>                             // PTHREAD_STACK_MIN
     27        #include <unistd.h>                             // syscall
     28        #include <sys/eventfd.h>                        // eventfd
     29        #include <sys/mman.h>                           // mprotect
     30        #include <sys/resource.h>                       // getrlimit
    3131}
    3232
    3333// CFA Includes
    34 #include "kernel_private.hfa"
    35 #include "startup.hfa"          // STARTUP_PRIORITY_XXX
     34#include "kernel/private.hfa"
     35#include "iofwd.hfa"
     36#include "startup.hfa"                                  // STARTUP_PRIORITY_XXX
    3637#include "limits.hfa"
    3738#include "math.hfa"
     
    9798extern void __kernel_alarm_startup(void);
    9899extern void __kernel_alarm_shutdown(void);
     100extern void __cfa_io_start( processor * );
     101extern void __cfa_io_stop ( processor * );
    99102
    100103//-----------------------------------------------------------------------------
     
    102105extern void __wake_proc(processor *);
    103106extern int cfa_main_returned;                                                   // from interpose.cfa
    104 extern uint32_t __global_random_seed;
     107uint32_t __global_random_prime = 4_294_967_291u, __global_random_mask = false;
    105108
    106109//-----------------------------------------------------------------------------
     
    111114KERNEL_STORAGE(__stack_t,            mainThreadCtx);
    112115KERNEL_STORAGE(__scheduler_RWLock_t, __scheduler_lock);
     116KERNEL_STORAGE(eventfd_t,            mainIdleEventFd);
     117KERNEL_STORAGE(io_future_t,          mainIdleFuture);
    113118#if !defined(__CFA_NO_STATISTICS__)
    114119KERNEL_STORAGE(__stats_t, mainProcStats);
     
    224229        (*mainProcessor){};
    225230
     231        mainProcessor->idle_wctx.rdbuf = &storage_mainIdleEventFd;
     232        mainProcessor->idle_wctx.ftr   = (io_future_t*)&storage_mainIdleFuture;
     233        /* paranoid */ verify( sizeof(storage_mainIdleEventFd) == sizeof(eventfd_t) );
     234
     235        __cfa_io_start( mainProcessor );
    226236        register_tls( mainProcessor );
    227237
     
    305315
    306316        unregister_tls( mainProcessor );
     317        __cfa_io_stop( mainProcessor );
    307318
    308319        // Destroy the main processor and its context in reverse order of construction
     
    353364        proc->local_data = &__cfaabi_tls;
    354365
     366        __cfa_io_start( proc );
    355367        register_tls( proc );
     368
     369        // used for idle sleep when io_uring is present
     370        io_future_t future;
     371        eventfd_t idle_buf;
     372        proc->idle_wctx.ftr = &future;
     373        proc->idle_wctx.rdbuf = &idle_buf;
     374
    356375
    357376        // SKULLDUGGERY: We want to create a context for the processor coroutine
     
    395414
    396415        unregister_tls( proc );
     416        __cfa_io_stop( proc );
    397417
    398418        return 0p;
     
    490510        preferred = ready_queue_new_preferred();
    491511        last_proc = 0p;
    492         random_state = __global_random_seed;
     512        random_state = __global_random_mask ? __global_random_prime : __global_random_prime ^ rdtscl();
    493513        #if defined( __CFA_WITH_VERIFY__ )
    494514                canary = 0x0D15EA5E0D15EA5Ep;
     
    515535        this.rdq.its = 0;
    516536        this.rdq.itr = 0;
    517         this.rdq.id  = MAX;
     537        this.rdq.id  = 0;
    518538        this.rdq.target = MAX;
    519539        this.rdq.last = MAX;
     
    532552        this.local_data = 0p;
    533553
    534         this.idle_fd = eventfd(0, 0);
    535         if (idle_fd < 0) {
     554        idle_wctx.evfd = eventfd(0, 0);
     555        if (idle_wctx.evfd < 0) {
    536556                abort("KERNEL ERROR: PROCESSOR EVENTFD - %s\n", strerror(errno));
    537557        }
    538558
    539         this.idle_wctx.fd = 0;
     559        idle_wctx.sem = 0;
     560        idle_wctx.wake__time = 0;
    540561
    541562        // I'm assuming these two are reserved for standard input and output
    542563        // so I'm using them as sentinels with idle_wctx.
    543         /* paranoid */ verify( this.idle_fd != 0 );
    544         /* paranoid */ verify( this.idle_fd != 1 );
     564        /* paranoid */ verify( idle_wctx.evfd != 0 );
     565        /* paranoid */ verify( idle_wctx.evfd != 1 );
    545566
    546567        #if !defined(__CFA_NO_STATISTICS__)
     
    554575// Not a ctor, it just preps the destruction but should not destroy members
    555576static void deinit(processor & this) {
    556         close(this.idle_fd);
     577        close(this.idle_wctx.evfd);
    557578}
    558579
     
    605626        this.name = name;
    606627        this.preemption_rate = preemption_rate;
    607         ready_queue{};
     628        this.sched.readyQ.data = 0p;
     629        this.sched.readyQ.tscs = 0p;
     630        this.sched.readyQ.count = 0;
     631        this.sched.io.tscs = 0p;
     632        this.sched.io.data = 0p;
     633        this.sched.caches = 0p;
    608634
    609635        #if !defined(__CFA_NO_STATISTICS__)
     
    644670        // Unlock the RWlock
    645671        ready_mutate_unlock( last_size );
     672
     673        ready_queue_close( &this );
     674        /* paranoid */ verify( this.sched.readyQ.data == 0p );
     675        /* paranoid */ verify( this.sched.readyQ.tscs == 0p );
     676        /* paranoid */ verify( this.sched.readyQ.count == 0 );
     677        /* paranoid */ verify( this.sched.io.tscs == 0p );
     678        /* paranoid */ verify( this.sched.caches == 0p );
     679
    646680        enable_interrupts( false ); // Don't poll, could be in main cluster
     681
    647682
    648683        #if !defined(__CFA_NO_STATISTICS__)
     
    736771        check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
    737772
    738         size_t stacksize = DEFAULT_STACK_SIZE;
     773        size_t stacksize = max( PTHREAD_STACK_MIN, DEFAULT_STACK_SIZE );
    739774
    740775        void * stack;
Note: See TracChangeset for help on using the changeset viewer.