Ignore:
File:
1 edited

Legend:

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

    r1f45c7d re84ab3d  
    110110#endif
    111111
    112 extern $thread * mainThread;
     112extern thread$ * mainThread;
    113113extern processor * mainProcessor;
    114114
    115115//-----------------------------------------------------------------------------
    116116// Kernel Scheduling logic
    117 static $thread * __next_thread(cluster * this);
    118 static $thread * __next_thread_slow(cluster * this);
    119 static inline bool __must_unpark( $thread * thrd ) __attribute((nonnull(1)));
    120 static void __run_thread(processor * this, $thread * dst);
     117static thread$ * __next_thread(cluster * this);
     118static thread$ * __next_thread_slow(cluster * this);
     119static inline bool __must_unpark( thread$ * thrd ) __attribute((nonnull(1)));
     120static void __run_thread(processor * this, thread$ * dst);
    121121static void __wake_one(cluster * cltr);
    122122
     
    181181                __cfadbg_print_safe(runtime_core, "Kernel : core %p started\n", this);
    182182
    183                 $thread * readyThread = 0p;
     183                thread$ * readyThread = 0p;
    184184                MAIN_LOOP:
    185185                for() {
     
    388388// runThread runs a thread by context switching
    389389// from the processor coroutine to the target thread
    390 static void __run_thread(processor * this, $thread * thrd_dst) {
     390static void __run_thread(processor * this, thread$ * thrd_dst) {
    391391        /* paranoid */ verify( ! __preemption_enabled() );
    392392        /* paranoid */ verifyf( thrd_dst->state == Ready || thrd_dst->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", thrd_dst->state, thrd_dst->preempted);
     
    394394        __builtin_prefetch( thrd_dst->context.SP );
    395395
    396         int curr = __kernel_getcpu();
    397         if(thrd_dst->last_cpu != curr) {
    398                 int64_t l = thrd_dst->last_cpu;
    399                 int64_t c = curr;
    400                 int64_t v = (l << 32) | c;
    401                 __push_stat( __tls_stats(), v, false, "Processor", this );
    402         }
    403 
    404         thrd_dst->last_cpu = curr;
    405 
    406396        __cfadbg_print_safe(runtime_core, "Kernel : core %p running thread %p (%s)\n", this, thrd_dst, thrd_dst->self_cor.name);
    407397
    408         $coroutine * proc_cor = get_coroutine(this->runner);
     398        coroutine$ * proc_cor = get_coroutine(this->runner);
    409399
    410400        // set state of processor coroutine to inactive
     
    425415                /* paranoid */ verify( thrd_dst->context.SP );
    426416                /* paranoid */ verify( thrd_dst->state != Halted );
    427                 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor
    428                 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); // add escape condition if we are setting up the processor
     417                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor
     418                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); // add escape condition if we are setting up the processor
    429419                /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary );
    430420
     
    438428
    439429                /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary );
    440                 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too large.\n", thrd_dst );
    441                 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst );
     430                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too large.\n", thrd_dst );
     431                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too small.\n", thrd_dst );
    442432                /* paranoid */ verify( thrd_dst->context.SP );
    443433                /* paranoid */ verify( thrd_dst->curr_cluster == this->cltr );
     
    480470                                #if !defined(__CFA_NO_STATISTICS__)
    481471                                        __tls_stats()->ready.threads.threads++;
     472                                        __push_stat( __tls_stats(), __tls_stats()->ready.threads.threads, false, "Processor", this );
    482473                                #endif
    483474                                // This is case 2, the racy case, someone tried to run this thread before it finished blocking
     
    497488        #if !defined(__CFA_NO_STATISTICS__)
    498489                __tls_stats()->ready.threads.threads--;
     490                __push_stat( __tls_stats(), __tls_stats()->ready.threads.threads, false, "Processor", this );
    499491        #endif
    500492
     
    505497void returnToKernel() {
    506498        /* paranoid */ verify( ! __preemption_enabled() );
    507         $coroutine * proc_cor = get_coroutine(kernelTLS().this_processor->runner);
    508         $thread * thrd_src = kernelTLS().this_thread;
     499        coroutine$ * proc_cor = get_coroutine(kernelTLS().this_processor->runner);
     500        thread$ * thrd_src = kernelTLS().this_thread;
    509501
    510502        __STATS( thrd_src->last_proc = kernelTLS().this_processor; )
     
    534526
    535527        /* paranoid */ verify( ! __preemption_enabled() );
    536         /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ) || thrd_src->corctx_flag, "ERROR : Returning $thread %p has been corrupted.\n StackPointer too small.\n", thrd_src );
    537         /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit) || thrd_src->corctx_flag, "ERROR : Returning $thread %p has been corrupted.\n StackPointer too large.\n", thrd_src );
     528        /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ) || thrd_src->corctx_flag, "ERROR : Returning thread$ %p has been corrupted.\n StackPointer too small.\n", thrd_src );
     529        /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit) || thrd_src->corctx_flag, "ERROR : Returning thread$ %p has been corrupted.\n StackPointer too large.\n", thrd_src );
    538530}
    539531
     
    541533// Scheduler routines
    542534// KERNEL ONLY
    543 static void __schedule_thread( $thread * thrd ) {
     535static void __schedule_thread( thread$ * thrd ) {
    544536        /* paranoid */ verify( ! __preemption_enabled() );
    545537        /* paranoid */ verify( ready_schedule_islocked());
     
    578570                                __tls_stats()->ready.threads.extunpark++;
    579571                        }
     572                        __push_stat( __tls_stats(), __tls_stats()->ready.threads.threads, false, "Processor", kernelTLS().this_processor );
    580573                }
    581574                else {
    582575                        __atomic_fetch_add(&cl->stats->ready.threads.threads, 1, __ATOMIC_RELAXED);
    583576                        __atomic_fetch_add(&cl->stats->ready.threads.extunpark, 1, __ATOMIC_RELAXED);
     577                        __push_stat( cl->stats, cl->stats->ready.threads.threads, true, "Cluster", cl );
    584578                }
    585579        #endif
     
    589583}
    590584
    591 void schedule_thread$( $thread * thrd ) {
     585void schedule_thread$( thread$ * thrd ) {
    592586        ready_schedule_lock();
    593587                __schedule_thread( thrd );
     
    596590
    597591// KERNEL ONLY
    598 static inline $thread * __next_thread(cluster * this) with( *this ) {
     592static inline thread$ * __next_thread(cluster * this) with( *this ) {
    599593        /* paranoid */ verify( ! __preemption_enabled() );
    600594
    601595        ready_schedule_lock();
    602                 $thread * thrd = pop_fast( this );
     596                thread$ * thrd = pop_fast( this );
    603597        ready_schedule_unlock();
    604598
     
    608602
    609603// KERNEL ONLY
    610 static inline $thread * __next_thread_slow(cluster * this) with( *this ) {
     604static inline thread$ * __next_thread_slow(cluster * this) with( *this ) {
    611605        /* paranoid */ verify( ! __preemption_enabled() );
    612606
    613607        ready_schedule_lock();
    614                 $thread * thrd;
     608                thread$ * thrd;
    615609                for(25) {
    616610                        thrd = pop_slow( this );
     
    626620}
    627621
    628 static inline bool __must_unpark( $thread * thrd ) {
     622static inline bool __must_unpark( thread$ * thrd ) {
    629623        int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST);
    630624        switch(old_ticket) {
     
    642636}
    643637
    644 void __kernel_unpark( $thread * thrd ) {
     638void __kernel_unpark( thread$ * thrd ) {
    645639        /* paranoid */ verify( ! __preemption_enabled() );
    646640        /* paranoid */ verify( ready_schedule_islocked());
     
    657651}
    658652
    659 void unpark( $thread * thrd ) {
     653void unpark( thread$ * thrd ) {
    660654        if( !thrd ) return;
    661655
     
    681675        // Should never return
    682676        void __cfactx_thrd_leave() {
    683                 $thread * thrd = active_thread();
    684                 $monitor * this = &thrd->self_mon;
     677                thread$ * thrd = active_thread();
     678                monitor$ * this = &thrd->self_mon;
    685679
    686680                // Lock the monitor now
     
    694688                /* paranoid */ verify( kernelTLS().this_thread == thrd );
    695689                /* paranoid */ verify( thrd->context.SP );
    696                 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) > ((uintptr_t)__get_stack(thrd->curr_cor)->limit), "ERROR : $thread %p has been corrupted.\n StackPointer too large.\n", thrd );
    697                 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) < ((uintptr_t)__get_stack(thrd->curr_cor)->base ), "ERROR : $thread %p has been corrupted.\n StackPointer too small.\n", thrd );
     690                /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) > ((uintptr_t)__get_stack(thrd->curr_cor)->limit), "ERROR : thread$ %p has been corrupted.\n StackPointer too large.\n", thrd );
     691                /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) < ((uintptr_t)__get_stack(thrd->curr_cor)->base ), "ERROR : thread$ %p has been corrupted.\n StackPointer too small.\n", thrd );
    698692
    699693                thrd->state = Halting;
     
    713707bool force_yield( __Preemption_Reason reason ) {
    714708        __disable_interrupts_checked();
    715                 $thread * thrd = kernelTLS().this_thread;
     709                thread$ * thrd = kernelTLS().this_thread;
    716710                /* paranoid */ verify(thrd->state == Active);
    717711
     
    825819//=============================================================================================
    826820void __kernel_abort_msg( char * abort_text, int abort_text_size ) {
    827         $thread * thrd = __cfaabi_tls.this_thread;
     821        thread$ * thrd = __cfaabi_tls.this_thread;
    828822
    829823        if(thrd) {
Note: See TracChangeset for help on using the changeset viewer.