- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel.cfa (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
rc84b4be re3fea42 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Dec 5 16:25:52 201913 // Update Count : 5 212 // Last Modified On : Tue Feb 4 13:03:15 2020 13 // Update Count : 58 14 14 // 15 15 … … 187 187 self_mon.recursion = 1; 188 188 self_mon_p = &self_mon; 189 link.next = 0p; 190 link.prev = 0p; 189 next = 0p; 191 190 192 191 node.next = 0p; … … 210 209 211 210 static void start(processor * this); 212 void ?{}(processor & this, const char * name, cluster & cltr) with( this ) {211 void ?{}(processor & this, const char name[], cluster & cltr) with( this ) { 213 212 this.name = name; 214 213 this.cltr = &cltr; 215 id = -1u;216 214 terminated{ 0 }; 217 215 do_terminate = false; … … 240 238 } 241 239 242 void ?{}(cluster & this, const char * name, Duration preemption_rate) with( this ) {240 void ?{}(cluster & this, const char name[], Duration preemption_rate) with( this ) { 243 241 this.name = name; 244 242 this.preemption_rate = preemption_rate; 245 243 ready_queue{}; 246 ready_lock{}; 247 244 ready_queue_lock{}; 245 246 procs{ __get }; 248 247 idles{ __get }; 249 248 threads{ __get }; … … 274 273 __cfaabi_dbg_print_safe("Kernel : core %p starting\n", this); 275 274 276 // register the processor unless it's the main thread which is handled in the boot sequence 277 if(this != mainProcessor) { 278 this->id = doregister(this->cltr, this); 279 ready_queue_grow( this->cltr ); 280 } 281 275 doregister(this->cltr, this); 282 276 283 277 { … … 311 305 } 312 306 307 unregister(this->cltr, this); 308 313 309 V( this->terminated ); 314 310 315 316 // unregister the processor unless it's the main thread which is handled in the boot sequence317 if(this != mainProcessor) {318 ready_queue_shrink( this->cltr );319 unregister(this->cltr, this);320 }321 322 311 __cfaabi_dbg_print_safe("Kernel : core %p terminated\n", this); 323 324 stats_tls_tally(this->cltr);325 312 } 326 313 … … 454 441 } 455 442 456 static void Abort( int ret, const char * func) {443 static void Abort( int ret, const char func[] ) { 457 444 if ( ret ) { // pthread routines return errno values 458 445 abort( "%s : internal error, error(%d) %s.", func, ret, strerror( ret ) ); … … 482 469 ); 483 470 484 Abort( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" ); 471 Abort( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" ); 485 472 486 473 Abort( pthread_create( pthread, &attr, start, arg ), "pthread_create" ); … … 548 535 verify( ! kernelTLS.preemption_state.enabled ); 549 536 550 verifyf( thrd->link.next == 0p, "Expected null got %p", thrd->link.next ); 551 552 553 ready_schedule_lock(thrd->curr_cluster, kernelTLS.this_processor); 554 bool was_empty = push( thrd->curr_cluster, thrd ); 555 ready_schedule_unlock(thrd->curr_cluster, kernelTLS.this_processor); 537 verifyf( thrd->next == 0p, "Expected null got %p", thrd->next ); 556 538 557 539 with( *thrd->curr_cluster ) { 558 // if(was_empty) { 559 // lock (proc_list_lock __cfaabi_dbg_ctx2); 560 // if(idles) { 561 // wake_fast(idles.head); 562 // } 563 // unlock (proc_list_lock); 564 // } 565 // else if( struct processor * idle = idles.head ) { 566 // wake_fast(idle); 567 // } 540 lock ( ready_queue_lock __cfaabi_dbg_ctx2 ); 541 bool was_empty = !(ready_queue != 0); 542 append( ready_queue, thrd ); 543 unlock( ready_queue_lock ); 544 545 if(was_empty) { 546 lock (proc_list_lock __cfaabi_dbg_ctx2); 547 if(idles) { 548 wake_fast(idles.head); 549 } 550 unlock (proc_list_lock); 551 } 552 else if( struct processor * idle = idles.head ) { 553 wake_fast(idle); 554 } 555 568 556 } 569 557 … … 574 562 thread_desc * nextThread(cluster * this) with( *this ) { 575 563 verify( ! kernelTLS.preemption_state.enabled ); 576 577 ready_schedule_lock(this, kernelTLS.this_processor); 578 thread_desc * head = pop( this ); 579 ready_schedule_unlock(this, kernelTLS.this_processor); 580 564 lock( ready_queue_lock __cfaabi_dbg_ctx2 ); 565 thread_desc * head = pop_head( ready_queue ); 566 unlock( ready_queue_lock ); 581 567 verify( ! kernelTLS.preemption_state.enabled ); 582 568 return head; … … 740 726 pending_preemption = false; 741 727 kernel_thread = pthread_self(); 742 id = -1u;743 728 744 729 runner{ &this }; … … 750 735 mainProcessor = (processor *)&storage_mainProcessor; 751 736 (*mainProcessor){}; 752 753 mainProcessor->id = doregister(mainCluster, mainProcessor);754 737 755 738 //initialize the global state variables … … 798 781 kernel_stop_preemption(); 799 782 800 unregister(mainCluster, mainProcessor);801 802 783 // Destroy the main processor and its context in reverse order of construction 803 784 // These were manually constructed so we need manually destroy them 804 void ^?{}(processor & this) with( this ) { 805 //don't join the main thread here, that wouldn't make any sense 806 __cfaabi_dbg_print_safe("Kernel : destroyed main processor context %p\n", &runner); 807 } 808 809 ^(*mainProcessor){}; 785 ^(mainProcessor->runner){}; 786 ^(mainProcessor){}; 810 787 811 788 // Final step, destroy the main thread since it is no longer needed 812 // Since we provided a stack to this task it will not destroy anything 813 ^(*mainThread){}; 814 815 ^(*mainCluster){}; 789 // Since we provided a stack to this taxk it will not destroy anything 790 ^(mainThread){}; 816 791 817 792 ^(__cfa_dbg_global_clusters.list){}; … … 825 800 //============================================================================================= 826 801 static void halt(processor * this) with( *this ) { 827 // // verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) ); 828 829 // with( *cltr ) { 830 // lock (proc_list_lock __cfaabi_dbg_ctx2); 831 // push_front(idles, *this); 832 // unlock (proc_list_lock); 833 // } 834 835 // __cfaabi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this); 836 837 // wait( idleLock ); 838 839 // __cfaabi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this); 840 841 // with( *cltr ) { 842 // lock (proc_list_lock __cfaabi_dbg_ctx2); 843 // remove (idles, *this); 844 // unlock (proc_list_lock); 845 // } 802 // verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) ); 803 804 with( *cltr ) { 805 lock (proc_list_lock __cfaabi_dbg_ctx2); 806 remove (procs, *this); 807 push_front(idles, *this); 808 unlock (proc_list_lock); 809 } 810 811 __cfaabi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this); 812 813 wait( idleLock ); 814 815 __cfaabi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this); 816 817 with( *cltr ) { 818 lock (proc_list_lock __cfaabi_dbg_ctx2); 819 remove (idles, *this); 820 push_front(procs, *this); 821 unlock (proc_list_lock); 822 } 846 823 } 847 824 … … 864 841 sigemptyset( &mask ); 865 842 sigaddset( &mask, SIGALRM ); // block SIGALRM signals 866 sigsuspend( &mask ); // block the processor to prevent further damage during abort 867 _exit( EXIT_FAILURE ); // if processor unblocks before it is killed, terminate it 843 sigaddset( &mask, SIGUSR1 ); // block SIGALRM signals 844 sigsuspend( &mask ); // block the processor to prevent further damage during abort 845 _exit( EXIT_FAILURE ); // if processor unblocks before it is killed, terminate it 868 846 } 869 847 else { … … 982 960 } 983 961 962 void doregister( cluster * cltr, processor * proc ) { 963 lock (cltr->proc_list_lock __cfaabi_dbg_ctx2); 964 cltr->nprocessors += 1; 965 push_front(cltr->procs, *proc); 966 unlock (cltr->proc_list_lock); 967 } 968 969 void unregister( cluster * cltr, processor * proc ) { 970 lock (cltr->proc_list_lock __cfaabi_dbg_ctx2); 971 remove(cltr->procs, *proc ); 972 cltr->nprocessors -= 1; 973 unlock(cltr->proc_list_lock); 974 } 975 984 976 //----------------------------------------------------------------------------- 985 977 // Debug 986 978 __cfaabi_dbg_debug_do( 987 979 extern "C" { 988 void __cfaabi_dbg_record(__spinlock_t & this, const char * prev_name) {980 void __cfaabi_dbg_record(__spinlock_t & this, const char prev_name[]) { 989 981 this.prev_name = prev_name; 990 982 this.prev_thrd = kernelTLS.this_thread;
Note:
See TracChangeset
for help on using the changeset viewer.