- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel.cfa (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r34b2796 r57f70ab 171 171 preemption_scope scope = { this }; 172 172 173 __STATS( unsigned long long last_tally = rdtscl(); )174 175 173 // if we need to run some special setup, now is the time to do it. 176 174 if(this->init.thrd) { … … 184 182 MAIN_LOOP: 185 183 for() { 186 #if 1 184 #define OLD_MAIN 1 185 #if OLD_MAIN 187 186 // Check if there is pending io 188 187 __maybe_io_drain( this ); … … 259 258 if( __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST) ) break MAIN_LOOP; 260 259 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 #endif268 269 260 if(this->io.pending && !this->io.dirty) { 270 261 __cfa_io_flush( this ); … … 272 263 273 264 #else 274 265 #warning new kernel loop 275 266 SEARCH: { 276 267 /* paranoid */ verify( ! __preemption_enabled() ); 277 /* paranoid */ verify( kernelTLS().this_proc_id );278 268 279 269 // First, lock the scheduler since we are searching for a thread … … 288 278 289 279 // Spin a little on I/O, just in case 290 for(25) {280 for(5) { 291 281 __maybe_io_drain( this ); 292 282 readyThread = pop_fast( this->cltr ); … … 295 285 296 286 // no luck, try stealing a few times 297 for(25) {287 for(5) { 298 288 if( __maybe_io_drain( this ) ) { 299 289 readyThread = pop_fast( this->cltr ); … … 333 323 } 334 324 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()); ) 336 326 __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle); 337 327 … … 341 331 // __enable_interrupts_hard(); 342 332 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()); ) 344 334 345 335 // We were woken up, remove self from idle … … 351 341 352 342 RUN_THREAD: 353 /* paranoid */ verify( kernelTLS().this_proc_id );354 343 /* paranoid */ verify( ! __preemption_enabled() ); 355 344 /* paranoid */ verify( readyThread ); … … 363 352 // Are we done? 364 353 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 #endif373 354 374 355 if(this->io.pending && !this->io.dirty) { … … 887 868 unsigned tail = *ctx->cq.tail; 888 869 if(head == tail) return false; 870 #if OLD_MAIN 889 871 ready_schedule_lock(); 890 872 ret = __cfa_io_drain( proc ); 891 873 ready_schedule_unlock(); 874 #else 875 ret = __cfa_io_drain( proc ); 876 #endif 892 877 #endif 893 878 return ret; … … 918 903 } 919 904 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 920 931 void print_stats_now( cluster & this, int flags ) { 932 crawl_cluster_stats( this ); 921 933 __print_stats( this.stats, this.print_stats, "Cluster", this.name, (void*)&this ); 922 934 }
Note:
See TracChangeset
for help on using the changeset viewer.