Ignore:
File:
1 edited

Legend:

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

    r34b2796 r57f70ab  
    171171                preemption_scope scope = { this };
    172172
    173                 __STATS( unsigned long long last_tally = rdtscl(); )
    174 
    175173                // if we need to run some special setup, now is the time to do it.
    176174                if(this->init.thrd) {
     
    184182                MAIN_LOOP:
    185183                for() {
    186                         #if 1
     184                        #define OLD_MAIN 1
     185                        #if OLD_MAIN
    187186                        // Check if there is pending io
    188187                        __maybe_io_drain( this );
     
    259258                        if( __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST) ) break MAIN_LOOP;
    260259
    261                         #if !defined(__CFA_NO_STATISTICS__)
    262                                 unsigned long long curr = rdtscl();
    263                                 if(curr > (last_tally + 500000000)) {
    264                                         __tally_stats(this->cltr->stats, __cfaabi_tls.this_stats);
    265                                         last_tally = curr;
    266                                 }
    267                         #endif
    268 
    269260                        if(this->io.pending && !this->io.dirty) {
    270261                                __cfa_io_flush( this );
     
    272263
    273264                        #else
    274 
     265                                #warning new kernel loop
    275266                        SEARCH: {
    276267                                /* paranoid */ verify( ! __preemption_enabled() );
    277                                 /* paranoid */ verify( kernelTLS().this_proc_id );
    278268
    279269                                // First, lock the scheduler since we are searching for a thread
     
    288278
    289279                                // Spin a little on I/O, just in case
    290                                 for(25) {
     280                                        for(5) {
    291281                                        __maybe_io_drain( this );
    292282                                        readyThread = pop_fast( this->cltr );
     
    295285
    296286                                // no luck, try stealing a few times
    297                                 for(25) {
     287                                        for(5) {
    298288                                        if( __maybe_io_drain( this ) ) {
    299289                                                readyThread = pop_fast( this->cltr );
     
    333323                                }
    334324
    335                                 __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->id, rdtscl()); )
     325                                        __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl()); )
    336326                                __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle);
    337327
     
    341331                                // __enable_interrupts_hard();
    342332
    343                                 __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->id, rdtscl()); )
     333                                        __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->unique_id, rdtscl()); )
    344334
    345335                                // We were woken up, remove self from idle
     
    351341
    352342                RUN_THREAD:
    353                         /* paranoid */ verify( kernelTLS().this_proc_id );
    354343                        /* paranoid */ verify( ! __preemption_enabled() );
    355344                        /* paranoid */ verify( readyThread );
     
    363352                        // Are we done?
    364353                        if( __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST) ) break MAIN_LOOP;
    365 
    366                         #if !defined(__CFA_NO_STATISTICS__)
    367                                 unsigned long long curr = rdtscl();
    368                                 if(curr > (last_tally + 500000000)) {
    369                                         __tally_stats(this->cltr->stats, __cfaabi_tls.this_stats);
    370                                         last_tally = curr;
    371                                 }
    372                         #endif
    373354
    374355                        if(this->io.pending && !this->io.dirty) {
     
    887868                unsigned tail = *ctx->cq.tail;
    888869                if(head == tail) return false;
     870                #if OLD_MAIN
    889871                ready_schedule_lock();
    890872                ret = __cfa_io_drain( proc );
    891873                ready_schedule_unlock();
     874                #else
     875                        ret = __cfa_io_drain( proc );
     876        #endif
    892877        #endif
    893878        return ret;
     
    918903        }
    919904
     905        static void crawl_list( cluster * cltr, dlist(processor, processor) & list, unsigned count ) {
     906                /* paranoid */ verify( cltr->stats );
     907
     908                processor * it = &list`first;
     909                for(unsigned i = 0; i < count; i++) {
     910                        /* paranoid */ verifyf( it, "Unexpected null iterator, at index %u of %u\n", i, count);
     911                        /* paranoid */ verify( it->local_data->this_stats );
     912                        __tally_stats( cltr->stats, it->local_data->this_stats );
     913                        it = &(*it)`next;
     914                }
     915        }
     916
     917        void crawl_cluster_stats( cluster & this ) {
     918                // Stop the world, otherwise stats could get really messed-up
     919                // this doesn't solve all problems but does solve many
     920                // so it's probably good enough
     921                uint_fast32_t last_size = ready_mutate_lock();
     922
     923                        crawl_list(&this, this.procs.actives, this.procs.total - this.procs.idle);
     924                        crawl_list(&this, this.procs.idles  , this.procs.idle );
     925
     926                // Unlock the RWlock
     927                ready_mutate_unlock( last_size );
     928        }
     929
     930
    920931        void print_stats_now( cluster & this, int flags ) {
     932                crawl_cluster_stats( this );
    921933                __print_stats( this.stats, this.print_stats, "Cluster", this.name, (void*)&this );
    922934        }
Note: See TracChangeset for help on using the changeset viewer.