- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r1f45c7d re84ab3d 110 110 #endif 111 111 112 extern $thread* mainThread;112 extern thread$ * mainThread; 113 113 extern processor * mainProcessor; 114 114 115 115 //----------------------------------------------------------------------------- 116 116 // Kernel Scheduling logic 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);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); 121 121 static void __wake_one(cluster * cltr); 122 122 … … 181 181 __cfadbg_print_safe(runtime_core, "Kernel : core %p started\n", this); 182 182 183 $thread* readyThread = 0p;183 thread$ * readyThread = 0p; 184 184 MAIN_LOOP: 185 185 for() { … … 388 388 // runThread runs a thread by context switching 389 389 // from the processor coroutine to the target thread 390 static void __run_thread(processor * this, $thread* thrd_dst) {390 static void __run_thread(processor * this, thread$ * thrd_dst) { 391 391 /* paranoid */ verify( ! __preemption_enabled() ); 392 392 /* paranoid */ verifyf( thrd_dst->state == Ready || thrd_dst->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", thrd_dst->state, thrd_dst->preempted); … … 394 394 __builtin_prefetch( thrd_dst->context.SP ); 395 395 396 int curr = __kernel_getcpu();397 if(thrd_dst->last_cpu != curr) {398 int64_t l = thrd_dst->last_cpu;399 int64_t c = curr;400 int64_t v = (l << 32) | c;401 __push_stat( __tls_stats(), v, false, "Processor", this );402 }403 404 thrd_dst->last_cpu = curr;405 406 396 __cfadbg_print_safe(runtime_core, "Kernel : core %p running thread %p (%s)\n", this, thrd_dst, thrd_dst->self_cor.name); 407 397 408 $coroutine* proc_cor = get_coroutine(this->runner);398 coroutine$ * proc_cor = get_coroutine(this->runner); 409 399 410 400 // set state of processor coroutine to inactive … … 425 415 /* paranoid */ verify( thrd_dst->context.SP ); 426 416 /* paranoid */ verify( thrd_dst->state != Halted ); 427 /* 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 processor428 /* 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 processor417 /* 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 418 /* 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 429 419 /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary ); 430 420 … … 438 428 439 429 /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary ); 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 );430 /* 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 ); 431 /* 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 ); 442 432 /* paranoid */ verify( thrd_dst->context.SP ); 443 433 /* paranoid */ verify( thrd_dst->curr_cluster == this->cltr ); … … 480 470 #if !defined(__CFA_NO_STATISTICS__) 481 471 __tls_stats()->ready.threads.threads++; 472 __push_stat( __tls_stats(), __tls_stats()->ready.threads.threads, false, "Processor", this ); 482 473 #endif 483 474 // This is case 2, the racy case, someone tried to run this thread before it finished blocking … … 497 488 #if !defined(__CFA_NO_STATISTICS__) 498 489 __tls_stats()->ready.threads.threads--; 490 __push_stat( __tls_stats(), __tls_stats()->ready.threads.threads, false, "Processor", this ); 499 491 #endif 500 492 … … 505 497 void returnToKernel() { 506 498 /* paranoid */ verify( ! __preemption_enabled() ); 507 $coroutine* proc_cor = get_coroutine(kernelTLS().this_processor->runner);508 $thread* thrd_src = kernelTLS().this_thread;499 coroutine$ * proc_cor = get_coroutine(kernelTLS().this_processor->runner); 500 thread$ * thrd_src = kernelTLS().this_thread; 509 501 510 502 __STATS( thrd_src->last_proc = kernelTLS().this_processor; ) … … 534 526 535 527 /* paranoid */ verify( ! __preemption_enabled() ); 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 );528 /* 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 ); 529 /* 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 ); 538 530 } 539 531 … … 541 533 // Scheduler routines 542 534 // KERNEL ONLY 543 static void __schedule_thread( $thread* thrd ) {535 static void __schedule_thread( thread$ * thrd ) { 544 536 /* paranoid */ verify( ! __preemption_enabled() ); 545 537 /* paranoid */ verify( ready_schedule_islocked()); … … 578 570 __tls_stats()->ready.threads.extunpark++; 579 571 } 572 __push_stat( __tls_stats(), __tls_stats()->ready.threads.threads, false, "Processor", kernelTLS().this_processor ); 580 573 } 581 574 else { 582 575 __atomic_fetch_add(&cl->stats->ready.threads.threads, 1, __ATOMIC_RELAXED); 583 576 __atomic_fetch_add(&cl->stats->ready.threads.extunpark, 1, __ATOMIC_RELAXED); 577 __push_stat( cl->stats, cl->stats->ready.threads.threads, true, "Cluster", cl ); 584 578 } 585 579 #endif … … 589 583 } 590 584 591 void schedule_thread$( $thread* thrd ) {585 void schedule_thread$( thread$ * thrd ) { 592 586 ready_schedule_lock(); 593 587 __schedule_thread( thrd ); … … 596 590 597 591 // KERNEL ONLY 598 static inline $thread* __next_thread(cluster * this) with( *this ) {592 static inline thread$ * __next_thread(cluster * this) with( *this ) { 599 593 /* paranoid */ verify( ! __preemption_enabled() ); 600 594 601 595 ready_schedule_lock(); 602 $thread* thrd = pop_fast( this );596 thread$ * thrd = pop_fast( this ); 603 597 ready_schedule_unlock(); 604 598 … … 608 602 609 603 // KERNEL ONLY 610 static inline $thread* __next_thread_slow(cluster * this) with( *this ) {604 static inline thread$ * __next_thread_slow(cluster * this) with( *this ) { 611 605 /* paranoid */ verify( ! __preemption_enabled() ); 612 606 613 607 ready_schedule_lock(); 614 $thread* thrd;608 thread$ * thrd; 615 609 for(25) { 616 610 thrd = pop_slow( this ); … … 626 620 } 627 621 628 static inline bool __must_unpark( $thread* thrd ) {622 static inline bool __must_unpark( thread$ * thrd ) { 629 623 int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST); 630 624 switch(old_ticket) { … … 642 636 } 643 637 644 void __kernel_unpark( $thread* thrd ) {638 void __kernel_unpark( thread$ * thrd ) { 645 639 /* paranoid */ verify( ! __preemption_enabled() ); 646 640 /* paranoid */ verify( ready_schedule_islocked()); … … 657 651 } 658 652 659 void unpark( $thread* thrd ) {653 void unpark( thread$ * thrd ) { 660 654 if( !thrd ) return; 661 655 … … 681 675 // Should never return 682 676 void __cfactx_thrd_leave() { 683 $thread* thrd = active_thread();684 $monitor* this = &thrd->self_mon;677 thread$ * thrd = active_thread(); 678 monitor$ * this = &thrd->self_mon; 685 679 686 680 // Lock the monitor now … … 694 688 /* paranoid */ verify( kernelTLS().this_thread == thrd ); 695 689 /* paranoid */ verify( thrd->context.SP ); 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 );690 /* 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 ); 691 /* 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 ); 698 692 699 693 thrd->state = Halting; … … 713 707 bool force_yield( __Preemption_Reason reason ) { 714 708 __disable_interrupts_checked(); 715 $thread* thrd = kernelTLS().this_thread;709 thread$ * thrd = kernelTLS().this_thread; 716 710 /* paranoid */ verify(thrd->state == Active); 717 711 … … 825 819 //============================================================================================= 826 820 void __kernel_abort_msg( char * abort_text, int abort_text_size ) { 827 $thread* thrd = __cfaabi_tls.this_thread;821 thread$ * thrd = __cfaabi_tls.this_thread; 828 822 829 823 if(thrd) {
Note: See TracChangeset
for help on using the changeset viewer.