Ignore:
Timestamp:
Mar 2, 2021, 1:58:12 PM (8 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
2cd784a
Parents:
6047b00
Message:

Changed io to use ring per kernel threads.

File:
1 edited

Legend:

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

    r6047b00 rdddb3dd0  
    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
     
    8081static void ?{}(processorCtx_t & this) {}
    8182static void ?{}(processorCtx_t & this, processor * proc, current_stack_info_t * info);
    82 static void ?{}(__bin_sem_t & this);
    83 static void ^?{}(__bin_sem_t & this);
    8483
    8584#if defined(__CFA_WITH_VERIFY__)
     
    9190extern void __kernel_alarm_startup(void);
    9291extern void __kernel_alarm_shutdown(void);
    93 extern void __kernel_io_startup (void);
    94 extern void __kernel_io_shutdown(void);
    9592
    9693//-----------------------------------------------------------------------------
     
    104101KERNEL_STORAGE($thread,              mainThread);
    105102KERNEL_STORAGE(__stack_t,            mainThreadCtx);
    106 KERNEL_STORAGE(io_context,           mainIoContext);
    107103KERNEL_STORAGE(__scheduler_RWLock_t, __scheduler_lock);
    108104#if !defined(__CFA_NO_STATISTICS__)
     
    200196
    201197        void ?{}(processor & this) with( this ) {
    202                 ( this.idle ){};
    203198                ( this.terminated ){};
    204199                ( this.runner ){};
     
    228223        __kernel_alarm_startup();
    229224
    230         // Start IO
    231         __kernel_io_startup();
    232 
    233         io_context * mainio = (io_context *)&storage_mainIoContext;
    234         (*mainio){ *mainCluster };
    235 
    236225        // Add the main thread to the ready queue
    237226        // once resume is called on mainProcessor->runner the mainThread needs to be scheduled like any normal thread
     
    255244
    256245static void __kernel_shutdown(void) {
    257         //Before we start shutting things down, wait for systems that need threading to shutdown
    258         io_context * mainio = (io_context *)&storage_mainIoContext;
    259         ^(*mainio){};
    260 
    261246        /* paranoid */ verify( __preemption_enabled() );
    262247        disable_interrupts();
     
    276261        // Disable preemption
    277262        __kernel_alarm_shutdown();
    278 
    279         // Stop IO
    280         __kernel_io_shutdown();
    281263
    282264        // Destroy the main processor and its context in reverse order of construction
     
    479461
    480462        this.io.ctx = 0p;
    481         this.io.lock = false;
     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        }
    482470
    483471        #if !defined(__CFA_NO_STATISTICS__)
     
    521509        // Finally we don't need the read_lock any more
    522510        unregister((__processor_id_t*)&this);
     511
     512        close(this.idle);
    523513}
    524514
    525515void ?{}(processor & this, const char name[], cluster & _cltr) {
    526         ( this.idle ){};
    527516        ( this.terminated ){};
    528517        ( this.runner ){};
     
    726715}
    727716
    728 extern "C" {
    729         char * strerror(int);
    730 }
    731 #define CHECKED(x) { int err = x; if( err != 0 ) abort("KERNEL ERROR: Operation \"" #x "\" return error %d - %s\n", err, strerror(err)); }
    732 
    733 static void ?{}(__bin_sem_t & this) with( this ) {
    734         // Create the mutex with error checking
    735         pthread_mutexattr_t mattr;
    736         pthread_mutexattr_init( &mattr );
    737         pthread_mutexattr_settype( &mattr, PTHREAD_MUTEX_ERRORCHECK_NP);
    738         pthread_mutex_init(&lock, &mattr);
    739 
    740         pthread_cond_init (&cond, (const pthread_condattr_t *)0p);  // workaround trac#208: cast should not be required
    741         val = 0;
    742 }
    743 
    744 static void ^?{}(__bin_sem_t & this) with( this ) {
    745         CHECKED( pthread_mutex_destroy(&lock) );
    746         CHECKED( pthread_cond_destroy (&cond) );
    747 }
    748 
    749 #undef CHECKED
    750 
    751717#if defined(__CFA_WITH_VERIFY__)
    752718static bool verify_fwd_bck_rng(void) {
Note: See TracChangeset for help on using the changeset viewer.