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