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