- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel.cfa (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r55d6affb rda3963a 22 22 #include <signal.h> 23 23 #include <unistd.h> 24 extern "C" {25 #include <sys/eventfd.h>26 }27 24 28 25 //CFA Includes … … 112 109 static void __run_thread(processor * this, $thread * dst); 113 110 static void __wake_one(cluster * cltr); 111 static void wait(__bin_sem_t & this); 114 112 115 113 static void push (__cluster_idles & idles, processor & proc); … … 117 115 static [unsigned idle, unsigned total, * processor] query( & __cluster_idles idles ); 118 116 119 extern void __cfa_io_start( processor * );120 extern void __cfa_io_drain( processor * );121 extern void __cfa_io_flush( processor * );122 extern void __cfa_io_stop ( processor * );123 static inline void __maybe_io_drain( processor * );124 125 extern void __disable_interrupts_hard();126 extern void __enable_interrupts_hard();127 117 128 118 //============================================================================================= … … 140 130 verify(this); 141 131 142 __cfa_io_start( this );143 144 132 __cfadbg_print_safe(runtime_core, "Kernel : core %p starting\n", this); 145 133 #if !defined(__CFA_NO_STATISTICS__) … … 163 151 MAIN_LOOP: 164 152 for() { 165 // Check if there is pending io166 __maybe_io_drain( this );167 168 153 // Try to get the next thread 169 154 readyThread = __next_thread( this->cltr ); 170 155 171 156 if( !readyThread ) { 172 __cfa_io_flush( this );173 157 readyThread = __next_thread_slow( this->cltr ); 174 158 } … … 206 190 #endif 207 191 208 __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle); 209 210 __disable_interrupts_hard(); 211 eventfd_t val; 212 eventfd_read( this->idle, &val ); 213 __enable_interrupts_hard(); 192 wait( this->idle ); 214 193 215 194 #if !defined(__CFA_NO_STATISTICS__) … … 227 206 228 207 /* paranoid */ verify( readyThread ); 229 230 // Reset io dirty bit231 this->io.dirty = false;232 208 233 209 // We found a thread run it … … 244 220 } 245 221 #endif 246 247 if(this->io.pending && !this->io.dirty) {248 __cfa_io_flush( this );249 }250 222 } 251 223 … … 253 225 } 254 226 255 __cfa_io_stop( this );256 257 227 post( this->terminated ); 258 259 228 260 229 if(this == mainProcessor) { … … 279 248 /* paranoid */ verifyf( thrd_dst->link.next == 0p, "Expected null got %p", thrd_dst->link.next ); 280 249 __builtin_prefetch( thrd_dst->context.SP ); 281 282 __cfadbg_print_safe(runtime_core, "Kernel : core %p running thread %p (%s)\n", this, thrd_dst, thrd_dst->self_cor.name);283 250 284 251 $coroutine * proc_cor = get_coroutine(this->runner); … … 363 330 // Just before returning to the processor, set the processor coroutine to active 364 331 proc_cor->state = Active; 365 366 __cfadbg_print_safe(runtime_core, "Kernel : core %p finished running thread %p\n", this, thrd_dst);367 332 368 333 /* paranoid */ verify( ! __preemption_enabled() ); … … 584 549 // Kernel Idle Sleep 585 550 //============================================================================================= 551 extern "C" { 552 char * strerror(int); 553 } 554 #define CHECKED(x) { int err = x; if( err != 0 ) abort("KERNEL ERROR: Operation \"" #x "\" return error %d - %s\n", err, strerror(err)); } 555 556 static void wait(__bin_sem_t & this) with( this ) { 557 verify(__cfaabi_dbg_in_kernel()); 558 CHECKED( pthread_mutex_lock(&lock) ); 559 while(val < 1) { 560 pthread_cond_wait(&cond, &lock); 561 } 562 val -= 1; 563 CHECKED( pthread_mutex_unlock(&lock) ); 564 } 565 566 static bool post(__bin_sem_t & this) with( this ) { 567 bool needs_signal = false; 568 569 CHECKED( pthread_mutex_lock(&lock) ); 570 if(val < 1) { 571 val += 1; 572 pthread_cond_signal(&cond); 573 needs_signal = true; 574 } 575 CHECKED( pthread_mutex_unlock(&lock) ); 576 577 return needs_signal; 578 } 579 580 #undef CHECKED 581 586 582 // Wake a thread from the front if there are any 587 583 static void __wake_one(cluster * this) { … … 599 595 600 596 // We found a processor, wake it up 601 eventfd_t val; 602 val = 1; 603 eventfd_write( p->idle, val ); 597 post( p->idle ); 604 598 605 599 #if !defined(__CFA_NO_STATISTICS__) … … 619 613 disable_interrupts(); 620 614 /* paranoid */ verify( ! __preemption_enabled() ); 621 eventfd_t val; 622 val = 1; 623 eventfd_write( this->idle, val ); 615 post( this->idle ); 624 616 enable_interrupts( __cfaabi_dbg_ctx ); 625 617 } … … 704 696 // Kernel Utilities 705 697 //============================================================================================= 706 #if defined(CFA_HAVE_LINUX_IO_URING_H)707 #include "io/types.hfa"708 #endif709 710 static inline void __maybe_io_drain( processor * proc ) {711 #if defined(CFA_HAVE_LINUX_IO_URING_H)712 __cfadbg_print_safe(runtime_core, "Kernel : core %p checking io for ring %d\n", proc, proc->io.ctx->fd);713 714 // Check if we should drain the queue715 $io_context * ctx = proc->io.ctx;716 unsigned head = *ctx->cq.head;717 unsigned tail = *ctx->cq.tail;718 if(head != tail) __cfa_io_drain( proc );719 #endif720 }721 722 698 //----------------------------------------------------------------------------- 723 699 // Debug
Note:
See TracChangeset
for help on using the changeset viewer.