Ignore:
File:
1 edited

Legend:

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

    r58688bf r8fc652e0  
    122122        // Because of a bug, we couldn't initialized the seed on construction
    123123        // Do it here
    124         kernelTLS.rand_seed ^= rdtscl();
    125         kernelTLS.ready_rng.fwd_seed = 25214903917_l64u * (rdtscl() ^ (uintptr_t)&runner);
     124        __cfaabi_tls.rand_seed ^= rdtscl();
     125        __cfaabi_tls.ready_rng.fwd_seed = 25214903917_l64u * (rdtscl() ^ (uintptr_t)&runner);
    126126        __tls_rand_advance_bck();
    127127
     
    217217                // and it make sense for it to be set in all other cases except here
    218218                // fake it
    219                 kernelTLS.this_thread = mainThread;
     219                __cfaabi_tls.this_thread = mainThread;
    220220        }
    221221
     
    230230// from the processor coroutine to the target thread
    231231static void __run_thread(processor * this, $thread * thrd_dst) {
    232         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     232        /* paranoid */ verify( ! __preemption_enabled() );
    233233        /* paranoid */ verifyf( thrd_dst->state == Ready || thrd_dst->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", thrd_dst->state, thrd_dst->preempted);
    234234        /* paranoid */ verifyf( thrd_dst->link.next == 0p, "Expected null got %p", thrd_dst->link.next );
     
    247247
    248248                // Update global state
    249                 kernelTLS.this_thread = thrd_dst;
    250 
    251                 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    252                 /* paranoid */ verify( kernelTLS.this_thread == thrd_dst );
     249                kernelTLS().this_thread = thrd_dst;
     250
     251                /* paranoid */ verify( ! __preemption_enabled() );
     252                /* paranoid */ verify( kernelTLS().this_thread == thrd_dst );
    253253                /* paranoid */ verify( thrd_dst->context.SP );
    254254                /* paranoid */ verify( thrd_dst->state != Halted );
     
    267267                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ), "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst );
    268268                /* paranoid */ verify( thrd_dst->context.SP );
    269                 /* paranoid */ verify( kernelTLS.this_thread == thrd_dst );
    270                 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     269                /* paranoid */ verify( kernelTLS().this_thread == thrd_dst );
     270                /* paranoid */ verify( ! __preemption_enabled() );
    271271
    272272                // Reset global state
    273                 kernelTLS.this_thread = 0p;
     273                kernelTLS().this_thread = 0p;
    274274
    275275                // We just finished running a thread, there are a few things that could have happened.
     
    315315        proc_cor->state = Active;
    316316
    317         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     317        /* paranoid */ verify( ! __preemption_enabled() );
    318318}
    319319
    320320// KERNEL_ONLY
    321321void returnToKernel() {
    322         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    323         $coroutine * proc_cor = get_coroutine(kernelTLS.this_processor->runner);
    324         $thread * thrd_src = kernelTLS.this_thread;
     322        /* paranoid */ verify( ! __preemption_enabled() );
     323        $coroutine * proc_cor = get_coroutine(kernelTLS().this_processor->runner);
     324        $thread * thrd_src = kernelTLS().this_thread;
    325325
    326326        #if !defined(__CFA_NO_STATISTICS__)
    327                 struct processor * last_proc = kernelTLS.this_processor;
     327                struct processor * last_proc = kernelTLS().this_processor;
    328328        #endif
    329329
     
    345345
    346346        #if !defined(__CFA_NO_STATISTICS__)
    347                 if(last_proc != kernelTLS.this_processor) {
     347                if(last_proc != kernelTLS().this_processor) {
    348348                        __tls_stats()->ready.threads.migration++;
    349349                }
    350350        #endif
    351351
    352         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     352        /* paranoid */ verify( ! __preemption_enabled() );
    353353        /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ), "ERROR : Returning $thread %p has been corrupted.\n StackPointer too small.\n", thrd_src );
    354354        /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit), "ERROR : Returning $thread %p has been corrupted.\n StackPointer too large.\n", thrd_src );
     
    359359// KERNEL ONLY
    360360void __schedule_thread( $thread * thrd ) {
     361        /* paranoid */ verify( ! __preemption_enabled() );
    361362        /* paranoid */ verify( thrd );
    362363        /* paranoid */ verify( thrd->state != Halted );
    363         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    364         /* paranoid */ verify( kernelTLS.this_proc_id );
     364        /* paranoid */ verify( kernelTLS().this_proc_id );
    365365        /* paranoid */ #if defined( __CFA_WITH_VERIFY__ )
    366366        /* paranoid */  if( thrd->state == Blocked || thrd->state == Start ) assertf( thrd->preempted == __NO_PREEMPTION,
     
    380380        ready_schedule_unlock();
    381381
    382         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     382        /* paranoid */ verify( ! __preemption_enabled() );
    383383}
    384384
    385385// KERNEL ONLY
    386386static inline $thread * __next_thread(cluster * this) with( *this ) {
    387         /* paranoid */ verify( kernelTLS.this_proc_id );
    388         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     387        /* paranoid */ verify( ! __preemption_enabled() );
     388        /* paranoid */ verify( kernelTLS().this_proc_id );
    389389
    390390        ready_schedule_lock();
     
    392392        ready_schedule_unlock();
    393393
    394         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    395         /* paranoid */ verify( kernelTLS.this_proc_id );
     394        /* paranoid */ verify( kernelTLS().this_proc_id );
     395        /* paranoid */ verify( ! __preemption_enabled() );
    396396        return thrd;
    397397}
     
    399399// KERNEL ONLY
    400400static inline $thread * __next_thread_slow(cluster * this) with( *this ) {
    401         /* paranoid */ verify( kernelTLS.this_proc_id );
    402         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     401        /* paranoid */ verify( ! __preemption_enabled() );
     402        /* paranoid */ verify( kernelTLS().this_proc_id );
    403403
    404404        ready_schedule_lock();
     
    406406        ready_schedule_unlock();
    407407
    408         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    409         /* paranoid */ verify( kernelTLS.this_proc_id );
     408        /* paranoid */ verify( kernelTLS().this_proc_id );
     409        /* paranoid */ verify( ! __preemption_enabled() );
    410410        return thrd;
    411411}
     
    414414        if( !thrd ) return;
    415415
    416         /* paranoid */ verify( kernelTLS.this_proc_id );
    417         bool full = kernelTLS.this_proc_id->full_proc;
    418         if(full) disable_interrupts();
    419 
    420         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    421416        int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST);
    422417        switch(old_ticket) {
     
    428423                        /* paranoid */ verify( thrd->state == Blocked );
    429424
    430                         // Wake lost the race,
    431                         __schedule_thread( thrd );
     425                        {
     426                                /* paranoid */ verify( publicTLS_get(this_proc_id) );
     427                                bool full = publicTLS_get(this_proc_id)->full_proc;
     428                                if(full) disable_interrupts();
     429
     430                                /* paranoid */ verify( ! __preemption_enabled() );
     431
     432                                // Wake lost the race,
     433                                __schedule_thread( thrd );
     434
     435                                /* paranoid */ verify( ! __preemption_enabled() );
     436
     437                                if(full) enable_interrupts( __cfaabi_dbg_ctx );
     438                                /* paranoid */ verify( publicTLS_get(this_proc_id) );
     439                        }
     440
    432441                        break;
    433442                default:
     
    435444                        abort("Thread %p (%s) has mismatch park/unpark\n", thrd, thrd->self_cor.name);
    436445        }
    437         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    438 
    439         if(full) enable_interrupts( __cfaabi_dbg_ctx );
    440         /* paranoid */ verify( kernelTLS.this_proc_id );
    441446}
    442447
    443448void park( void ) {
    444         /* paranoid */ verify( kernelTLS.preemption_state.enabled );
     449        /* paranoid */ verify( __preemption_enabled() );
    445450        disable_interrupts();
    446         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    447         /* paranoid */ verify( kernelTLS.this_thread->preempted == __NO_PREEMPTION );
     451        /* paranoid */ verify( ! __preemption_enabled() );
     452        /* paranoid */ verify( kernelTLS().this_thread->preempted == __NO_PREEMPTION );
    448453
    449454        returnToKernel();
    450455
    451         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     456        /* paranoid */ verify( ! __preemption_enabled() );
    452457        enable_interrupts( __cfaabi_dbg_ctx );
    453         /* paranoid */ verify( kernelTLS.preemption_state.enabled );
     458        /* paranoid */ verify( __preemption_enabled() );
    454459
    455460}
     
    460465        // Should never return
    461466        void __cfactx_thrd_leave() {
    462                 $thread * thrd = TL_GET( this_thread );
     467                $thread * thrd = active_thread();
    463468                $monitor * this = &thrd->self_mon;
    464469
     
    473478
    474479                // Leave the thread
    475                 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     480                /* paranoid */ verify( ! __preemption_enabled() );
    476481                returnToKernel();
    477482                abort();
     
    483488// KERNEL ONLY
    484489bool force_yield( __Preemption_Reason reason ) {
    485         /* paranoid */ verify( kernelTLS.preemption_state.enabled );
     490        /* paranoid */ verify( __preemption_enabled() );
    486491        disable_interrupts();
    487         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    488 
    489         $thread * thrd = kernelTLS.this_thread;
     492        /* paranoid */ verify( ! __preemption_enabled() );
     493
     494        $thread * thrd = kernelTLS().this_thread;
    490495        /* paranoid */ verify(thrd->state == Active);
    491496
     
    501506        }
    502507
    503         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     508        /* paranoid */ verify( ! __preemption_enabled() );
    504509        enable_interrupts_noPoll();
    505         /* paranoid */ verify( kernelTLS.preemption_state.enabled );
     510        /* paranoid */ verify( __preemption_enabled() );
    506511
    507512        return preempted;
     
    513518// Wake a thread from the front if there are any
    514519static void __wake_one(cluster * this) {
    515         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     520        /* paranoid */ verify( ! __preemption_enabled() );
    516521        /* paranoid */ verify( ready_schedule_islocked() );
    517522
     
    533538
    534539        /* paranoid */ verify( ready_schedule_islocked() );
    535         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     540        /* paranoid */ verify( ! __preemption_enabled() );
    536541
    537542        return;
     
    543548
    544549        disable_interrupts();
    545                 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     550                /* paranoid */ verify( ! __preemption_enabled() );
    546551                post( this->idle );
    547552        enable_interrupts( __cfaabi_dbg_ctx );
     
    549554
    550555static void push  (__cluster_idles & this, processor & proc) {
    551         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     556        /* paranoid */ verify( ! __preemption_enabled() );
    552557        lock( this );
    553558                this.idle++;
     
    556561                insert_first(this.list, proc);
    557562        unlock( this );
    558         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     563        /* paranoid */ verify( ! __preemption_enabled() );
    559564}
    560565
    561566static void remove(__cluster_idles & this, processor & proc) {
    562         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     567        /* paranoid */ verify( ! __preemption_enabled() );
    563568        lock( this );
    564569                this.idle--;
     
    567572                remove(proc);
    568573        unlock( this );
    569         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     574        /* paranoid */ verify( ! __preemption_enabled() );
    570575}
    571576
     
    611616        }
    612617
    613         return kernelTLS.this_thread;
     618        return __cfaabi_tls.this_thread;
    614619}
    615620
     
    636641
    637642int kernel_abort_lastframe( void ) __attribute__ ((__nothrow__)) {
    638         return get_coroutine(kernelTLS.this_thread) == get_coroutine(mainThread) ? 4 : 2;
     643        return get_coroutine(kernelTLS().this_thread) == get_coroutine(mainThread) ? 4 : 2;
    639644}
    640645
     
    668673        if ( count < 0 ) {
    669674                // queue current task
    670                 append( waiting, kernelTLS.this_thread );
     675                append( waiting, active_thread() );
    671676
    672677                // atomically release spin lock and block
     
    718723                void __cfaabi_dbg_record_lock(__spinlock_t & this, const char prev_name[]) {
    719724                        this.prev_name = prev_name;
    720                         this.prev_thrd = kernelTLS.this_thread;
     725                        this.prev_thrd = kernelTLS().this_thread;
    721726                }
    722727        }
Note: See TracChangeset for help on using the changeset viewer.