Ignore:
File:
1 edited

Legend:

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

    r3e1a705 r89eff25  
    7777static void doregister( struct cluster & cltr );
    7878static void unregister( struct cluster & cltr );
    79 static void register_tls( processor * this );
    80 static void unregister_tls( processor * this );
    8179static void ?{}( $coroutine & this, current_stack_info_t * info);
    8280static void ?{}( $thread & this, current_stack_info_t * info);
     
    125123        NULL,                                                                                           // cannot use 0p
    126124        NULL,
    127         false,
     125        NULL,
     126        NULL,
    128127        { 1, false, false },
    129         0,
    130         { 0, 0 },
    131         NULL,
    132         #ifdef __CFA_WITH_VERIFY__
    133                 false,
    134                 0,
    135         #endif
    136128};
    137129
     
    218210        (*mainProcessor){};
    219211
    220         register_tls( mainProcessor );
    221 
    222212        //initialize the global state variables
    223213        __cfaabi_tls.this_processor = mainProcessor;
     214        __cfaabi_tls.this_proc_id   = (__processor_id_t*)mainProcessor;
    224215        __cfaabi_tls.this_thread    = mainThread;
    225216
     
    228219                __init_stats( __cfaabi_tls.this_stats );
    229220        #endif
    230         mainProcessor->local_data = &__cfaabi_tls;
    231221
    232222        // Enable preemption
     
    235225        // Add the main thread to the ready queue
    236226        // once resume is called on mainProcessor->runner the mainThread needs to be scheduled like any normal thread
    237         schedule_thread$(mainThread);
     227        __schedule_thread(mainThread);
    238228
    239229        // SKULLDUGGERY: Force a context switch to the main processor to set the main thread's context to the current UNIX
     
    248238
    249239        /* paranoid */ verify( ! __preemption_enabled() );
    250         enable_interrupts();
     240        enable_interrupts( __cfaabi_dbg_ctx );
    251241        /* paranoid */ verify( __preemption_enabled() );
    252242
     
    283273        #endif
    284274
    285         mainProcessor->local_data = 0p;
    286 
    287         unregister_tls( mainProcessor );
    288 
    289275        // Destroy the main processor and its context in reverse order of construction
    290276        // These were manually constructed so we need manually destroy them
     
    330316        processor * proc = (processor *) arg;
    331317        __cfaabi_tls.this_processor = proc;
     318        __cfaabi_tls.this_proc_id   = (__processor_id_t*)proc;
    332319        __cfaabi_tls.this_thread    = 0p;
    333320        __cfaabi_tls.preemption_state.[enabled, disable_count] = [false, 1];
    334         proc->local_data = &__cfaabi_tls;
    335 
    336         register_tls( proc );
    337 
    338321        // SKULLDUGGERY: We want to create a context for the processor coroutine
    339322        // which is needed for the 2-step context switch. However, there is no reason
     
    372355                #endif
    373356        #endif
    374 
    375         proc->local_data = 0p;
    376 
    377         unregister_tls( proc );
    378357
    379358        return 0p;
     
    467446        self_mon_p = &self_mon;
    468447        link.next = 0p;
    469         link.ts   = 0;
    470         preferred = -1u;
     448        link.prev = 0p;
     449        link.preferred = -1u;
    471450        last_proc = 0p;
    472451        #if defined( __CFA_WITH_VERIFY__ )
     
    496475        this.rdq.id  = -1u;
    497476        this.rdq.target = -1u;
    498         this.rdq.cutoff = 0ull;
     477        this.rdq.cutoff = -1ull;
    499478        do_terminate = false;
    500479        preemption_alarm = 0p;
     
    506485
    507486        this.init.thrd = initT;
    508 
    509         this.local_data = 0p;
    510487
    511488        this.idle = eventfd(0, 0);
     
    519496        #endif
    520497
     498        // Register and Lock the RWlock so no-one pushes/pops while we are changing the queue
     499        uint_fast32_t last_size = ready_mutate_register((__processor_id_t*)&this);
     500                this.cltr->procs.total += 1u;
     501                insert_last(this.cltr->procs.actives, this);
     502
     503                // Adjust the ready queue size
     504                ready_queue_grow( cltr );
     505
     506        // Unlock the RWlock
     507        ready_mutate_unlock( last_size );
     508
    521509        __cfadbg_print_safe(runtime_core, "Kernel : core %p created\n", &this);
    522510}
     
    524512// Not a ctor, it just preps the destruction but should not destroy members
    525513static void deinit(processor & this) {
     514        // Lock the RWlock so no-one pushes/pops while we are changing the queue
     515        uint_fast32_t last_size = ready_mutate_lock();
     516                this.cltr->procs.total -= 1u;
     517                remove(this);
     518
     519                // Adjust the ready queue size
     520                ready_queue_shrink( this.cltr );
     521
     522        // Unlock the RWlock and unregister: we don't need the read_lock any more
     523        ready_mutate_unregister((__processor_id_t*)&this, last_size );
     524
    526525        close(this.idle);
    527526}
     
    533532        disable_interrupts();
    534533                init( this, name, _cltr, initT );
    535         enable_interrupts();
     534        enable_interrupts( __cfaabi_dbg_ctx );
    536535
    537536        __cfadbg_print_safe(runtime_core, "Kernel : Starting core %p\n", &this);
     
    560559        disable_interrupts();
    561560                deinit( this );
    562         enable_interrupts();
     561        enable_interrupts( __cfaabi_dbg_ctx );
    563562}
    564563
     
    598597        // Unlock the RWlock
    599598        ready_mutate_unlock( last_size );
    600         enable_interrupts( false ); // Don't poll, could be in main cluster
     599        enable_interrupts_noPoll(); // Don't poll, could be in main cluster
    601600}
    602601
     
    613612        // Unlock the RWlock
    614613        ready_mutate_unlock( last_size );
    615         enable_interrupts( false ); // Don't poll, could be in main cluster
     614        enable_interrupts_noPoll(); // Don't poll, could be in main cluster
    616615
    617616        #if !defined(__CFA_NO_STATISTICS__)
     
    657656        cltr->nthreads -= 1;
    658657        unlock(cltr->thread_list_lock);
    659 }
    660 
    661 static void register_tls( processor * this ) {
    662         // Register and Lock the RWlock so no-one pushes/pops while we are changing the queue
    663         uint_fast32_t last_size;
    664         [this->unique_id, last_size] = ready_mutate_register();
    665 
    666                 this->cltr->procs.total += 1u;
    667                 insert_last(this->cltr->procs.actives, *this);
    668 
    669                 // Adjust the ready queue size
    670                 ready_queue_grow( this->cltr );
    671 
    672         // Unlock the RWlock
    673         ready_mutate_unlock( last_size );
    674 }
    675 
    676 
    677 static void unregister_tls( processor * this ) {
    678         // Lock the RWlock so no-one pushes/pops while we are changing the queue
    679         uint_fast32_t last_size = ready_mutate_lock();
    680                 this->cltr->procs.total -= 1u;
    681                 remove(*this);
    682 
    683                 // clear the cluster so nothing gets pushed to local queues
    684                 cluster * cltr = this->cltr;
    685                 this->cltr = 0p;
    686 
    687                 // Adjust the ready queue size
    688                 ready_queue_shrink( cltr );
    689 
    690         // Unlock the RWlock and unregister: we don't need the read_lock any more
    691         ready_mutate_unregister( this->unique_id, last_size );
    692658}
    693659
Note: See TracChangeset for help on using the changeset viewer.