- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel.cfa (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r504a7dc ra7b486b 120 120 static void __run_thread(processor * this, $thread * dst); 121 121 static $thread * __halt(processor * this); 122 static bool __wake_one(cluster * cltr );122 static bool __wake_one(cluster * cltr, bool was_empty); 123 123 static bool __wake_proc(processor *); 124 124 … … 197 197 self_mon.recursion = 1; 198 198 self_mon_p = &self_mon; 199 link.next = 0p; 200 link.prev = 0p; 199 next = 0p; 201 200 202 201 node.next = 0p; … … 224 223 this.name = name; 225 224 this.cltr = &cltr; 226 id = -1u;227 225 terminated{ 0 }; 228 226 destroyer = 0p; … … 262 260 this.preemption_rate = preemption_rate; 263 261 ready_queue{}; 264 ready_ lock{};262 ready_queue_lock{}; 265 263 266 264 #if !defined(__CFA_NO_STATISTICS__) … … 297 295 __cfadbg_print_safe(runtime_core, "Kernel : core %p starting\n", this); 298 296 299 // register the processor unless it's the main thread which is handled in the boot sequence300 if(this != mainProcessor) {301 this->id = doregister2(this->cltr, this);302 ready_queue_grow( this->cltr );303 }304 305 297 doregister(this->cltr, this); 306 298 … … 326 318 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 327 319 /* paranoid */ verifyf( readyThread->state == Ready || readyThread->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", readyThread->state, readyThread->preempted); 328 /* paranoid */ verifyf( readyThread-> link.next == 0p, "Expected null got %p", readyThread->link.next );320 /* paranoid */ verifyf( readyThread->next == 0p, "Expected null got %p", readyThread->next ); 329 321 330 322 // We found a thread run it … … 342 334 V( this->terminated ); 343 335 344 // unregister the processor unless it's the main thread which is handled in the boot sequence345 if(this != mainProcessor) {346 ready_queue_shrink( this->cltr );347 unregister2(this->cltr, this);348 }349 else {350 // HACK : the coroutine context switch expects this_thread to be set351 // and it make sense for it to be set in all other cases except here352 // fake it353 kernelTLS.this_thread = mainThread;354 }355 356 336 __cfadbg_print_safe(runtime_core, "Kernel : core %p terminated\n", this); 357 337 358 stats_tls_tally(this->cltr); 338 // HACK : the coroutine context switch expects this_thread to be set 339 // and it make sense for it to be set in all other cases except here 340 // fake it 341 if( this == mainProcessor ) kernelTLS.this_thread = mainThread; 359 342 } 360 343 … … 608 591 // Scheduler routines 609 592 // KERNEL ONLY 610 void __schedule_thread( $thread * thrd ) { 611 /* paranoid */ verify( thrd ); 612 /* paranoid */ verify( thrd->state != Halted ); 593 void __schedule_thread( $thread * thrd ) with( *thrd->curr_cluster ) { 613 594 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 614 595 /* paranoid */ #if defined( __CFA_WITH_VERIFY__ ) 615 /* paranoid */ if( thrd->state == Blocked || thrd->state == Start ) assertf( thrd->preempted == __NO_PREEMPTION,616 "Error inactive thread marked as preempted, state %d, preemption %d\n", thrd->state, thrd->preempted );617 /* paranoid */ if( thrd->preempted != __NO_PREEMPTION ) assertf(thrd->state == Active || thrd->state == Rerun,618 "Error preempted thread marked as not currently running, state %d, preemption %d\n", thrd->state, thrd->preempted );596 /* paranoid */ if( thrd->state == Blocked || thrd->state == Start ) assertf( thrd->preempted == __NO_PREEMPTION, 597 "Error inactive thread marked as preempted, state %d, preemption %d\n", thrd->state, thrd->preempted ); 598 /* paranoid */ if( thrd->preempted != __NO_PREEMPTION ) assertf(thrd->state == Active || thrd->state == Rerun, 599 "Error preempted thread marked as not currently running, state %d, preemption %d\n", thrd->state, thrd->preempted ); 619 600 /* paranoid */ #endif 620 /* paranoid */ verifyf( thrd-> link.next == 0p, "Expected null got %p", thrd->link.next );601 /* paranoid */ verifyf( thrd->next == 0p, "Expected null got %p", thrd->next ); 621 602 622 603 if (thrd->preempted == __NO_PREEMPTION) thrd->state = Ready; 623 604 624 ready_schedule_lock(thrd->curr_cluster, kernelTLS.this_processor); 625 push( thrd->curr_cluster, thrd ); 626 627 __wake_one(thrd->curr_cluster); 628 ready_schedule_unlock(thrd->curr_cluster, kernelTLS.this_processor); 605 lock ( ready_queue_lock __cfaabi_dbg_ctx2 ); 606 bool was_empty = !(ready_queue != 0); 607 append( ready_queue, thrd ); 608 unlock( ready_queue_lock ); 609 610 __wake_one(thrd->curr_cluster, was_empty); 629 611 630 612 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); … … 635 617 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 636 618 637 ready_schedule_lock(this, kernelTLS.this_processor);638 $thread * head = pop( this);639 ready_schedule_unlock(this, kernelTLS.this_processor);619 lock( ready_queue_lock __cfaabi_dbg_ctx2 ); 620 $thread * head = pop_head( ready_queue ); 621 unlock( ready_queue_lock ); 640 622 641 623 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); … … 721 703 // If that is the case, abandon the preemption. 722 704 bool preempted = false; 723 if(thrd-> link.next == 0p) {705 if(thrd->next == 0p) { 724 706 preempted = true; 725 707 thrd->preempted = reason; … … 781 763 pending_preemption = false; 782 764 kernel_thread = pthread_self(); 783 id = -1u;784 765 785 766 runner{ &this }; … … 791 772 mainProcessor = (processor *)&storage_mainProcessor; 792 773 (*mainProcessor){}; 793 794 mainProcessor->id = doregister2(mainCluster, mainProcessor);795 774 796 775 //initialize the global state variables … … 847 826 kernel_stop_preemption(); 848 827 849 unregister2(mainCluster, mainProcessor);850 851 828 // Destroy the main processor and its context in reverse order of construction 852 829 // These were manually constructed so we need manually destroy them 853 830 void ^?{}(processor & this) with( this ){ 854 831 /* paranoid */ verify( this.do_terminate == true ); 855 __cfaabi_dbg_print_safe("Kernel : destroyed main processor context %p\n", &runner);856 832 } 857 833 … … 859 835 860 836 // Final step, destroy the main thread since it is no longer needed 861 862 837 // Since we provided a stack to this taxk it will not destroy anything 863 838 /* paranoid */ verify(mainThread->self_cor.stack.storage == (__stack_t*)(((uintptr_t)&storage_mainThreadCtx)| 0x1)); … … 912 887 913 888 // Wake a thread from the front if there are any 914 static bool __wake_one(cluster * this) { 889 static bool __wake_one(cluster * this, __attribute__((unused)) bool force) { 890 // if we don't want to force check if we know it's false 891 // if( !this->idles.head && !force ) return false; 892 915 893 // First, lock the cluster idle 916 894 lock( this->idle_lock __cfaabi_dbg_ctx2 );
Note:
See TracChangeset
for help on using the changeset viewer.