Ignore:
Timestamp:
Mar 4, 2021, 7:40:25 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:
77d601f
Parents:
342af53 (diff), a5040fe (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

    r342af53 r8e4aa05  
    2222extern "C" {
    2323      #include <limits.h>       // PTHREAD_STACK_MIN
     24        #include <sys/eventfd.h>  // eventfd
    2425      #include <sys/mman.h>     // mprotect
    2526      #include <sys/resource.h> // getrlimit
     
    8990extern void __kernel_alarm_startup(void);
    9091extern void __kernel_alarm_shutdown(void);
    91 extern void __kernel_io_startup (void);
    92 extern void __kernel_io_shutdown(void);
    9392
    9493//-----------------------------------------------------------------------------
     
    102101KERNEL_STORAGE($thread,              mainThread);
    103102KERNEL_STORAGE(__stack_t,            mainThreadCtx);
    104 KERNEL_STORAGE(io_context,           mainPollerThread);
    105103KERNEL_STORAGE(__scheduler_RWLock_t, __scheduler_lock);
    106104#if !defined(__CFA_NO_STATISTICS__)
     
    198196
    199197        void ?{}(processor & this) with( this ) {
    200                 ( this.idle ){};
    201                 ( this.terminated ){ 0 };
     198                ( this.terminated ){};
    202199                ( this.runner ){};
    203200                init( this, "Main Processor", *mainCluster );
     
    226223        __kernel_alarm_startup();
    227224
    228         // Start IO
    229         __kernel_io_startup();
    230 
    231225        // Add the main thread to the ready queue
    232226        // once resume is called on mainProcessor->runner the mainThread needs to be scheduled like any normal thread
     
    241235        // THE SYSTEM IS NOW COMPLETELY RUNNING
    242236
    243 
    244         // SKULLDUGGERY: The constructor for the mainCluster will call alloc with a dimension of 0
    245         // malloc *can* return a non-null value, we should free it if that is the case
    246         free( mainCluster->io.ctxs );
    247 
    248         // Now that the system is up, finish creating systems that need threading
    249         mainCluster->io.ctxs = (io_context *)&storage_mainPollerThread;
    250         mainCluster->io.cnt  = 1;
    251         (*mainCluster->io.ctxs){ *mainCluster };
    252 
    253237        __cfadbg_print_safe(runtime_core, "Kernel : Started\n--------------------------------------------------\n\n");
    254238
     
    260244
    261245static void __kernel_shutdown(void) {
    262         //Before we start shutting things down, wait for systems that need threading to shutdown
    263         ^(*mainCluster->io.ctxs){};
    264         mainCluster->io.cnt  = 0;
    265         mainCluster->io.ctxs = 0p;
    266 
    267246        /* paranoid */ verify( __preemption_enabled() );
    268247        disable_interrupts();
     
    282261        // Disable preemption
    283262        __kernel_alarm_shutdown();
    284 
    285         // Stop IO
    286         __kernel_io_shutdown();
    287263
    288264        // Destroy the main processor and its context in reverse order of construction
     
    484460        pending_preemption = false;
    485461
     462        this.io.ctx = 0p;
     463        this.io.pending = false;
     464        this.io.dirty   = false;
     465
     466        this.idle = eventfd(0, 0);
     467        if (idle < 0) {
     468                abort("KERNEL ERROR: PROCESSOR EVENTFD - %s\n", strerror(errno));
     469        }
     470
    486471        #if !defined(__CFA_NO_STATISTICS__)
    487472                print_stats = 0;
     
    524509        // Finally we don't need the read_lock any more
    525510        unregister((__processor_id_t*)&this);
     511
     512        close(this.idle);
    526513}
    527514
    528515void ?{}(processor & this, const char name[], cluster & _cltr) {
    529         ( this.idle ){};
    530         ( this.terminated ){ 0 };
     516        ( this.terminated ){};
    531517        ( this.runner ){};
    532518
     
    549535                __wake_proc( &this );
    550536
    551                 P( terminated );
     537                wait( terminated );
    552538                /* paranoid */ verify( active_processor() != &this);
    553539        }
     
    582568        threads{ __get };
    583569
     570        io.arbiter = create();
     571        io.params = io_params;
     572
    584573        doregister(this);
    585574
     
    594583        ready_mutate_unlock( last_size );
    595584        enable_interrupts_noPoll(); // Don't poll, could be in main cluster
    596 
    597 
    598         this.io.cnt  = num_io;
    599         this.io.ctxs = aalloc(num_io);
    600         for(i; this.io.cnt) {
    601                 (this.io.ctxs[i]){ this, io_params };
    602         }
    603585}
    604586
    605587void ^?{}(cluster & this) {
    606         for(i; this.io.cnt) {
    607                 ^(this.io.ctxs[i]){ true };
    608         }
    609         free(this.io.ctxs);
     588        destroy(this.io.arbiter);
    610589
    611590        // Lock the RWlock so no-one pushes/pops while we are changing the queue
     
    736715}
    737716
    738 
    739717#if defined(__CFA_WITH_VERIFY__)
    740718static bool verify_fwd_bck_rng(void) {
Note: See TracChangeset for help on using the changeset viewer.