Ignore:
File:
1 edited

Legend:

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

    r57f70ab r34b2796  
    171171                preemption_scope scope = { this };
    172172
     173                __STATS( unsigned long long last_tally = rdtscl(); )
     174
    173175                // if we need to run some special setup, now is the time to do it.
    174176                if(this->init.thrd) {
     
    182184                MAIN_LOOP:
    183185                for() {
    184                         #define OLD_MAIN 1
    185                         #if OLD_MAIN
     186                        #if 1
    186187                        // Check if there is pending io
    187188                        __maybe_io_drain( this );
     
    258259                        if( __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST) ) break MAIN_LOOP;
    259260
     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
    260269                        if(this->io.pending && !this->io.dirty) {
    261270                                __cfa_io_flush( this );
     
    263272
    264273                        #else
    265                                 #warning new kernel loop
     274
    266275                        SEARCH: {
    267276                                /* paranoid */ verify( ! __preemption_enabled() );
     277                                /* paranoid */ verify( kernelTLS().this_proc_id );
    268278
    269279                                // First, lock the scheduler since we are searching for a thread
     
    278288
    279289                                // Spin a little on I/O, just in case
    280                                         for(5) {
     290                                for(25) {
    281291                                        __maybe_io_drain( this );
    282292                                        readyThread = pop_fast( this->cltr );
     
    285295
    286296                                // no luck, try stealing a few times
    287                                         for(5) {
     297                                for(25) {
    288298                                        if( __maybe_io_drain( this ) ) {
    289299                                                readyThread = pop_fast( this->cltr );
     
    323333                                }
    324334
    325                                         __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl()); )
     335                                __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->id, rdtscl()); )
    326336                                __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle);
    327337
     
    331341                                // __enable_interrupts_hard();
    332342
    333                                         __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->unique_id, rdtscl()); )
     343                                __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->id, rdtscl()); )
    334344
    335345                                // We were woken up, remove self from idle
     
    341351
    342352                RUN_THREAD:
     353                        /* paranoid */ verify( kernelTLS().this_proc_id );
    343354                        /* paranoid */ verify( ! __preemption_enabled() );
    344355                        /* paranoid */ verify( readyThread );
     
    352363                        // Are we done?
    353364                        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
    354373
    355374                        if(this->io.pending && !this->io.dirty) {
     
    868887                unsigned tail = *ctx->cq.tail;
    869888                if(head == tail) return false;
    870                 #if OLD_MAIN
    871889                ready_schedule_lock();
    872890                ret = __cfa_io_drain( proc );
    873891                ready_schedule_unlock();
    874                 #else
    875                         ret = __cfa_io_drain( proc );
    876         #endif
    877892        #endif
    878893        return ret;
     
    903918        }
    904919
    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 
    931920        void print_stats_now( cluster & this, int flags ) {
    932                 crawl_cluster_stats( this );
    933921                __print_stats( this.stats, this.print_stats, "Cluster", this.name, (void*)&this );
    934922        }
Note: See TracChangeset for help on using the changeset viewer.