- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel.cfa (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
rda3963a rdddb3dd0 22 22 #include <signal.h> 23 23 #include <unistd.h> 24 extern "C" { 25 #include <sys/eventfd.h> 26 } 24 27 25 28 //CFA Includes … … 109 112 static void __run_thread(processor * this, $thread * dst); 110 113 static void __wake_one(cluster * cltr); 111 static void wait(__bin_sem_t & this);112 114 113 115 static void push (__cluster_idles & idles, processor & proc); … … 115 117 static [unsigned idle, unsigned total, * processor] query( & __cluster_idles idles ); 116 118 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(); 117 127 118 128 //============================================================================================= … … 130 140 verify(this); 131 141 142 __cfa_io_start( this ); 143 132 144 __cfadbg_print_safe(runtime_core, "Kernel : core %p starting\n", this); 133 145 #if !defined(__CFA_NO_STATISTICS__) … … 151 163 MAIN_LOOP: 152 164 for() { 165 // Check if there is pending io 166 __maybe_io_drain( this ); 167 153 168 // Try to get the next thread 154 169 readyThread = __next_thread( this->cltr ); 155 170 156 171 if( !readyThread ) { 172 __cfa_io_flush( this ); 157 173 readyThread = __next_thread_slow( this->cltr ); 158 174 } … … 190 206 #endif 191 207 192 wait( this->idle ); 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(); 193 214 194 215 #if !defined(__CFA_NO_STATISTICS__) … … 206 227 207 228 /* paranoid */ verify( readyThread ); 229 230 // Reset io dirty bit 231 this->io.dirty = false; 208 232 209 233 // We found a thread run it … … 220 244 } 221 245 #endif 246 247 if(this->io.pending && !this->io.dirty) { 248 __cfa_io_flush( this ); 249 } 222 250 } 223 251 … … 225 253 } 226 254 255 __cfa_io_stop( this ); 256 227 257 post( this->terminated ); 258 228 259 229 260 if(this == mainProcessor) { … … 248 279 /* paranoid */ verifyf( thrd_dst->link.next == 0p, "Expected null got %p", thrd_dst->link.next ); 249 280 __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); 250 283 251 284 $coroutine * proc_cor = get_coroutine(this->runner); … … 330 363 // Just before returning to the processor, set the processor coroutine to active 331 364 proc_cor->state = Active; 365 366 __cfadbg_print_safe(runtime_core, "Kernel : core %p finished running thread %p\n", this, thrd_dst); 332 367 333 368 /* paranoid */ verify( ! __preemption_enabled() ); … … 549 584 // Kernel Idle Sleep 550 585 //============================================================================================= 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 CHECKED581 582 586 // Wake a thread from the front if there are any 583 587 static void __wake_one(cluster * this) { … … 595 599 596 600 // We found a processor, wake it up 597 post( p->idle ); 601 eventfd_t val; 602 val = 1; 603 eventfd_write( p->idle, val ); 598 604 599 605 #if !defined(__CFA_NO_STATISTICS__) … … 613 619 disable_interrupts(); 614 620 /* paranoid */ verify( ! __preemption_enabled() ); 615 post( this->idle ); 621 eventfd_t val; 622 val = 1; 623 eventfd_read( this->idle, &val ); 616 624 enable_interrupts( __cfaabi_dbg_ctx ); 617 625 } … … 696 704 // Kernel Utilities 697 705 //============================================================================================= 706 #if defined(CFA_HAVE_LINUX_IO_URING_H) 707 #include "io/types.hfa" 708 #endif 709 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 queue 715 $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 #endif 720 } 721 698 722 //----------------------------------------------------------------------------- 699 723 // Debug
Note:
See TracChangeset
for help on using the changeset viewer.