Ignore:
File:
1 edited

Legend:

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

    r8fc652e0 r6a77224  
    118118//-----------------------------------------------------------------------------
    119119// Global state
    120 thread_local struct KernelThreadData __cfaabi_tls __attribute__ ((tls_model ( "initial-exec" ))) @= {
     120thread_local struct KernelThreadData kernelTLS __attribute__ ((tls_model ( "initial-exec" ))) @= {
    121121        NULL,                                                                                           // cannot use 0p
    122         NULL,
    123122        NULL,
    124123        NULL,
     
    156155// Kernel boot procedures
    157156static void __kernel_startup(void) {
    158         /* paranoid */ verify( ! __preemption_enabled() );
     157        verify( ! kernelTLS.preemption_state.enabled );
    159158        __cfadbg_print_safe(runtime_core, "Kernel : Starting\n");
    160159
     
    212211
    213212        //initialize the global state variables
    214         __cfaabi_tls.this_processor = mainProcessor;
    215         __cfaabi_tls.this_proc_id   = (__processor_id_t*)mainProcessor;
    216         __cfaabi_tls.this_thread    = mainThread;
     213        kernelTLS.this_processor = mainProcessor;
     214        kernelTLS.this_thread    = mainThread;
    217215
    218216        #if !defined( __CFA_NO_STATISTICS__ )
    219                 __cfaabi_tls.this_stats = (__stats_t *)& storage_mainProcStats;
    220                 __init_stats( __cfaabi_tls.this_stats );
     217                kernelTLS.this_stats = (__stats_t *)& storage_mainProcStats;
     218                __init_stats( kernelTLS.this_stats );
    221219        #endif
    222220
     
    229227        // Add the main thread to the ready queue
    230228        // once resume is called on mainProcessor->runner the mainThread needs to be scheduled like any normal thread
    231         __schedule_thread(mainThread);
     229        __schedule_thread((__processor_id_t *)mainProcessor, mainThread);
    232230
    233231        // SKULLDUGGERY: Force a context switch to the main processor to set the main thread's context to the current UNIX
    234232        // context. Hence, the main thread does not begin through __cfactx_invoke_thread, like all other threads. The trick here is that
    235233        // mainThread is on the ready queue when this call is made.
    236         __kernel_first_resume( __cfaabi_tls.this_processor );
     234        __kernel_first_resume( kernelTLS.this_processor );
    237235
    238236
     
    251249        __cfadbg_print_safe(runtime_core, "Kernel : Started\n--------------------------------------------------\n\n");
    252250
    253         /* paranoid */ verify( ! __preemption_enabled() );
     251        verify( ! kernelTLS.preemption_state.enabled );
    254252        enable_interrupts( __cfaabi_dbg_ctx );
    255         /* paranoid */ verify( __preemption_enabled() );
    256 
     253        verify( TL_GET( preemption_state.enabled ) );
    257254}
    258255
     
    263260        mainCluster->io.ctxs = 0p;
    264261
    265         /* paranoid */ verify( __preemption_enabled() );
     262        /* paranoid */ verify( TL_GET( preemption_state.enabled ) );
    266263        disable_interrupts();
    267         /* paranoid */ verify( ! __preemption_enabled() );
     264        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    268265
    269266        __cfadbg_print_safe(runtime_core, "\n--------------------------------------------------\nKernel : Shutting down\n");
     
    273270        // which is currently here
    274271        __atomic_store_n(&mainProcessor->do_terminate, true, __ATOMIC_RELEASE);
    275         __kernel_last_resume( __cfaabi_tls.this_processor );
     272        __kernel_last_resume( kernelTLS.this_processor );
    276273        mainThread->self_cor.state = Halted;
    277274
     
    322319                __stats_t local_stats;
    323320                __init_stats( &local_stats );
    324                 __cfaabi_tls.this_stats = &local_stats;
     321                kernelTLS.this_stats = &local_stats;
    325322        #endif
    326323
    327324        processor * proc = (processor *) arg;
    328         __cfaabi_tls.this_processor = proc;
    329         __cfaabi_tls.this_proc_id   = (__processor_id_t*)proc;
    330         __cfaabi_tls.this_thread    = 0p;
    331         __cfaabi_tls.preemption_state.[enabled, disable_count] = [false, 1];
     325        kernelTLS.this_processor = proc;
     326        kernelTLS.this_thread    = 0p;
     327        kernelTLS.preemption_state.[enabled, disable_count] = [false, 1];
    332328        // SKULLDUGGERY: We want to create a context for the processor coroutine
    333329        // which is needed for the 2-step context switch. However, there is no reason
     
    341337
    342338        //Set global state
    343         __cfaabi_tls.this_thread = 0p;
     339        kernelTLS.this_thread = 0p;
    344340
    345341        //We now have a proper context from which to schedule threads
     
    371367        $coroutine * dst = get_coroutine(this->runner);
    372368
    373         /* paranoid */ verify( ! __preemption_enabled() );
    374 
    375         __cfaabi_tls.this_thread->curr_cor = dst;
     369        verify( ! kernelTLS.preemption_state.enabled );
     370
     371        kernelTLS.this_thread->curr_cor = dst;
    376372        __stack_prepare( &dst->stack, 65000 );
    377373        __cfactx_start(main, dst, this->runner, __cfactx_invoke_coroutine);
    378374
    379         /* paranoid */ verify( ! __preemption_enabled() );
     375        verify( ! kernelTLS.preemption_state.enabled );
    380376
    381377        dst->last = &src->self_cor;
     
    395391        /* paranoid */ verify(src->state == Active);
    396392
    397         /* paranoid */ verify( ! __preemption_enabled() );
     393        verify( ! kernelTLS.preemption_state.enabled );
    398394}
    399395
     
    403399        $coroutine * dst = get_coroutine(this->runner);
    404400
    405         /* paranoid */ verify( ! __preemption_enabled() );
    406         /* paranoid */ verify( dst->starter == src );
    407         /* paranoid */ verify( dst->context.SP );
     401        verify( ! kernelTLS.preemption_state.enabled );
     402        verify( dst->starter == src );
     403        verify( dst->context.SP );
    408404
    409405        // SKULLDUGGERY in debug the processors check that the
     
    547543
    548544                P( terminated );
    549                 /* paranoid */ verify( active_processor() != &this);
     545                verify( kernelTLS.this_processor != &this);
    550546        }
    551547
     
    697693#if defined(__CFA_WITH_VERIFY__)
    698694static bool verify_fwd_bck_rng(void) {
    699         __cfaabi_tls.ready_rng.fwd_seed = 25214903917_l64u * (rdtscl() ^ (uintptr_t)&verify_fwd_bck_rng);
     695        kernelTLS.ready_rng.fwd_seed = 25214903917_l64u * (rdtscl() ^ (uintptr_t)&verify_fwd_bck_rng);
    700696
    701697        unsigned values[10];
Note: See TracChangeset for help on using the changeset viewer.