- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel.cfa (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r445f984 r1f45c7d 22 22 #include <errno.h> 23 23 #include <stdio.h> 24 #include <string.h>25 24 #include <signal.h> 26 25 #include <unistd.h> … … 32 31 #include "kernel_private.hfa" 33 32 #include "preemption.hfa" 34 #include "strstream.hfa"35 #include "device/cpu.hfa"36 33 37 34 //Private includes … … 113 110 #endif 114 111 115 extern thread$* mainThread;112 extern $thread * mainThread; 116 113 extern processor * mainProcessor; 117 114 118 115 //----------------------------------------------------------------------------- 119 116 // Kernel Scheduling logic 120 static thread$* __next_thread(cluster * this);121 static thread$* __next_thread_slow(cluster * this);122 static inline bool __must_unpark( thread$* thrd ) __attribute((nonnull(1)));123 static void __run_thread(processor * this, thread$* dst);117 static $thread * __next_thread(cluster * this); 118 static $thread * __next_thread_slow(cluster * this); 119 static inline bool __must_unpark( $thread * thrd ) __attribute((nonnull(1))); 120 static void __run_thread(processor * this, $thread * dst); 124 121 static void __wake_one(cluster * cltr); 125 122 … … 184 181 __cfadbg_print_safe(runtime_core, "Kernel : core %p started\n", this); 185 182 186 thread$* readyThread = 0p;183 $thread * readyThread = 0p; 187 184 MAIN_LOOP: 188 185 for() { … … 234 231 __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle); 235 232 236 { 237 eventfd_t val; 238 ssize_t ret = read( this->idle, &val, sizeof(val) ); 239 if(ret < 0) { 240 switch((int)errno) { 241 case EAGAIN: 242 #if EAGAIN != EWOULDBLOCK 243 case EWOULDBLOCK: 244 #endif 245 case EINTR: 246 // No need to do anything special here, just assume it's a legitimate wake-up 247 break; 248 default: 249 abort( "KERNEL : internal error, read failure on idle eventfd, error(%d) %s.", (int)errno, strerror( (int)errno ) ); 250 } 251 } 252 } 233 __disable_interrupts_hard(); 234 eventfd_t val; 235 eventfd_read( this->idle, &val ); 236 __enable_interrupts_hard(); 253 237 254 238 #if !defined(__CFA_NO_STATISTICS__) … … 404 388 // runThread runs a thread by context switching 405 389 // from the processor coroutine to the target thread 406 static void __run_thread(processor * this, thread$* thrd_dst) {390 static void __run_thread(processor * this, $thread * thrd_dst) { 407 391 /* paranoid */ verify( ! __preemption_enabled() ); 408 392 /* paranoid */ verifyf( thrd_dst->state == Ready || thrd_dst->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", thrd_dst->state, thrd_dst->preempted); … … 422 406 __cfadbg_print_safe(runtime_core, "Kernel : core %p running thread %p (%s)\n", this, thrd_dst, thrd_dst->self_cor.name); 423 407 424 coroutine$* proc_cor = get_coroutine(this->runner);408 $coroutine * proc_cor = get_coroutine(this->runner); 425 409 426 410 // set state of processor coroutine to inactive … … 441 425 /* paranoid */ verify( thrd_dst->context.SP ); 442 426 /* paranoid */ verify( thrd_dst->state != Halted ); 443 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination thread$%p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor444 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination thread$%p has been corrupted.\n StackPointer too large.\n", thrd_dst ); // add escape condition if we are setting up the processor427 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor 428 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); // add escape condition if we are setting up the processor 445 429 /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary ); 446 430 … … 454 438 455 439 /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary ); 456 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->corctx_flag, "ERROR : Destination thread$%p has been corrupted.\n StackPointer too large.\n", thrd_dst );457 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->corctx_flag, "ERROR : Destination thread$%p has been corrupted.\n StackPointer too small.\n", thrd_dst );440 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); 441 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); 458 442 /* paranoid */ verify( thrd_dst->context.SP ); 459 443 /* paranoid */ verify( thrd_dst->curr_cluster == this->cltr ); … … 521 505 void returnToKernel() { 522 506 /* paranoid */ verify( ! __preemption_enabled() ); 523 coroutine$* proc_cor = get_coroutine(kernelTLS().this_processor->runner);524 thread$* thrd_src = kernelTLS().this_thread;507 $coroutine * proc_cor = get_coroutine(kernelTLS().this_processor->runner); 508 $thread * thrd_src = kernelTLS().this_thread; 525 509 526 510 __STATS( thrd_src->last_proc = kernelTLS().this_processor; ) … … 550 534 551 535 /* paranoid */ verify( ! __preemption_enabled() ); 552 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ) || thrd_src->corctx_flag, "ERROR : Returning thread$%p has been corrupted.\n StackPointer too small.\n", thrd_src );553 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit) || thrd_src->corctx_flag, "ERROR : Returning thread$%p has been corrupted.\n StackPointer too large.\n", thrd_src );536 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ) || thrd_src->corctx_flag, "ERROR : Returning $thread %p has been corrupted.\n StackPointer too small.\n", thrd_src ); 537 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit) || thrd_src->corctx_flag, "ERROR : Returning $thread %p has been corrupted.\n StackPointer too large.\n", thrd_src ); 554 538 } 555 539 … … 557 541 // Scheduler routines 558 542 // KERNEL ONLY 559 static void __schedule_thread( thread$* thrd ) {543 static void __schedule_thread( $thread * thrd ) { 560 544 /* paranoid */ verify( ! __preemption_enabled() ); 561 545 /* paranoid */ verify( ready_schedule_islocked()); … … 605 589 } 606 590 607 void schedule_thread$( thread$* thrd ) {591 void schedule_thread$( $thread * thrd ) { 608 592 ready_schedule_lock(); 609 593 __schedule_thread( thrd ); … … 612 596 613 597 // KERNEL ONLY 614 static inline thread$* __next_thread(cluster * this) with( *this ) {598 static inline $thread * __next_thread(cluster * this) with( *this ) { 615 599 /* paranoid */ verify( ! __preemption_enabled() ); 616 600 617 601 ready_schedule_lock(); 618 thread$* thrd = pop_fast( this );602 $thread * thrd = pop_fast( this ); 619 603 ready_schedule_unlock(); 620 604 … … 624 608 625 609 // KERNEL ONLY 626 static inline thread$* __next_thread_slow(cluster * this) with( *this ) {610 static inline $thread * __next_thread_slow(cluster * this) with( *this ) { 627 611 /* paranoid */ verify( ! __preemption_enabled() ); 628 612 629 613 ready_schedule_lock(); 630 thread$* thrd;614 $thread * thrd; 631 615 for(25) { 632 616 thrd = pop_slow( this ); … … 642 626 } 643 627 644 static inline bool __must_unpark( thread$* thrd ) {628 static inline bool __must_unpark( $thread * thrd ) { 645 629 int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST); 646 630 switch(old_ticket) { … … 658 642 } 659 643 660 void __kernel_unpark( thread$* thrd ) {644 void __kernel_unpark( $thread * thrd ) { 661 645 /* paranoid */ verify( ! __preemption_enabled() ); 662 646 /* paranoid */ verify( ready_schedule_islocked()); … … 673 657 } 674 658 675 void unpark( thread$* thrd ) {659 void unpark( $thread * thrd ) { 676 660 if( !thrd ) return; 677 661 … … 697 681 // Should never return 698 682 void __cfactx_thrd_leave() { 699 thread$* thrd = active_thread();700 monitor$* this = &thrd->self_mon;683 $thread * thrd = active_thread(); 684 $monitor * this = &thrd->self_mon; 701 685 702 686 // Lock the monitor now … … 710 694 /* paranoid */ verify( kernelTLS().this_thread == thrd ); 711 695 /* paranoid */ verify( thrd->context.SP ); 712 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) > ((uintptr_t)__get_stack(thrd->curr_cor)->limit), "ERROR : thread$%p has been corrupted.\n StackPointer too large.\n", thrd );713 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) < ((uintptr_t)__get_stack(thrd->curr_cor)->base ), "ERROR : thread$%p has been corrupted.\n StackPointer too small.\n", thrd );696 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) > ((uintptr_t)__get_stack(thrd->curr_cor)->limit), "ERROR : $thread %p has been corrupted.\n StackPointer too large.\n", thrd ); 697 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) < ((uintptr_t)__get_stack(thrd->curr_cor)->base ), "ERROR : $thread %p has been corrupted.\n StackPointer too small.\n", thrd ); 714 698 715 699 thrd->state = Halting; … … 729 713 bool force_yield( __Preemption_Reason reason ) { 730 714 __disable_interrupts_checked(); 731 thread$* thrd = kernelTLS().this_thread;715 $thread * thrd = kernelTLS().this_thread; 732 716 /* paranoid */ verify(thrd->state == Active); 733 717 … … 841 825 //============================================================================================= 842 826 void __kernel_abort_msg( char * abort_text, int abort_text_size ) { 843 thread$* thrd = __cfaabi_tls.this_thread;827 $thread * thrd = __cfaabi_tls.this_thread; 844 828 845 829 if(thrd) {
Note:
See TracChangeset
for help on using the changeset viewer.