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/startup.cfa

    ref3c383 rd672350  
    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//-----------------------------------------------------------------------------
     
    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
    226235        register_tls( mainProcessor );
     236        __cfa_io_start( mainProcessor );
    227237
    228238        // Start by initializing the main thread
     
    304314        mainProcessor->local_data = 0p;
    305315
     316        __cfa_io_stop( mainProcessor );
    306317        unregister_tls( mainProcessor );
    307318
     
    355366        register_tls( proc );
    356367
     368        __cfa_io_start( proc );
     369
     370        // used for idle sleep when io_uring is present
     371        io_future_t future;
     372        eventfd_t idle_buf;
     373        proc->idle_wctx.ftr = &future;
     374        proc->idle_wctx.rdbuf = &idle_buf;
     375
     376
    357377        // SKULLDUGGERY: We want to create a context for the processor coroutine
    358378        // which is needed for the 2-step context switch. However, there is no reason
     
    381401        // Main routine of the core returned, the core is now fully terminated
    382402        __cfadbg_print_safe(runtime_core, "Kernel : core %p main ended (%p)\n", proc, &proc->runner);
     403
     404        __cfa_io_stop( proc );
    383405
    384406        #if !defined(__CFA_NO_STATISTICS__)
     
    515537        this.rdq.its = 0;
    516538        this.rdq.itr = 0;
    517         this.rdq.id  = MAX;
     539        this.rdq.id  = 0;
    518540        this.rdq.target = MAX;
    519541        this.rdq.last = MAX;
     
    532554        this.local_data = 0p;
    533555
    534         this.idle_fd = eventfd(0, 0);
    535         if (idle_fd < 0) {
     556        idle_wctx.evfd = eventfd(0, 0);
     557        if (idle_wctx.evfd < 0) {
    536558                abort("KERNEL ERROR: PROCESSOR EVENTFD - %s\n", strerror(errno));
    537559        }
    538560
    539         this.idle_wctx.fd = 0;
     561        idle_wctx.sem = 0;
    540562
    541563        // I'm assuming these two are reserved for standard input and output
    542564        // so I'm using them as sentinels with idle_wctx.
    543         /* paranoid */ verify( this.idle_fd != 0 );
    544         /* paranoid */ verify( this.idle_fd != 1 );
     565        /* paranoid */ verify( idle_wctx.evfd != 0 );
     566        /* paranoid */ verify( idle_wctx.evfd != 1 );
    545567
    546568        #if !defined(__CFA_NO_STATISTICS__)
     
    554576// Not a ctor, it just preps the destruction but should not destroy members
    555577static void deinit(processor & this) {
    556         close(this.idle_fd);
     578        close(this.idle_wctx.evfd);
    557579}
    558580
     
    605627        this.name = name;
    606628        this.preemption_rate = preemption_rate;
    607         ready_queue{};
     629        this.sched.readyQ.data = 0p;
     630        this.sched.readyQ.tscs = 0p;
     631        this.sched.readyQ.count = 0;
     632        this.sched.io.tscs = 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.