- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r1c40091 r7768b8d 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 21 16:46:59201913 // Update Count : 2 712 // Last Modified On : Thu Jun 20 17:21:23 2019 13 // Update Count : 25 14 14 // 15 15 … … 133 133 NULL, 134 134 NULL, 135 { 1, false, false } 135 { 1, false, false }, 136 6u //this should be seeded better but due to a bug calling rdtsc doesn't work 136 137 }; 137 138 … … 209 210 this.name = name; 210 211 this.cltr = &cltr; 212 id = -1u; 211 213 terminated{ 0 }; 212 214 do_terminate = false; … … 238 240 this.preemption_rate = preemption_rate; 239 241 ready_queue{}; 240 ready_queue_lock{}; 241 242 procs{ __get }; 242 ready_lock{}; 243 243 244 idles{ __get }; 244 245 threads{ __get }; … … 260 261 //Main of the processor contexts 261 262 void main(processorCtx_t & runner) { 263 // Because of a bug, we couldn't initialized the seed on construction 264 // Do it here 265 kernelTLS.rand_seed ^= rdtscl(); 266 262 267 processor * this = runner.proc; 263 268 verify(this); … … 265 270 __cfaabi_dbg_print_safe("Kernel : core %p starting\n", this); 266 271 267 doregister(this->cltr, this); 272 // register the processor unless it's the main thread which is handled in the boot sequence 273 if(this != mainProcessor) 274 this->id = doregister(this->cltr, this); 268 275 269 276 { … … 301 308 } 302 309 303 unregister(this->cltr, this);304 305 310 V( this->terminated ); 311 312 // unregister the processor unless it's the main thread which is handled in the boot sequence 313 if(this != mainProcessor) 314 unregister(this->cltr, this); 306 315 307 316 __cfaabi_dbg_print_safe("Kernel : core %p terminated\n", this); … … 500 509 501 510 with( *thrd->curr_cluster ) { 502 lock ( ready_queue_lock __cfaabi_dbg_ctx2 ); 503 bool was_empty = !(ready_queue != 0); 504 append( ready_queue, thrd ); 505 unlock( ready_queue_lock ); 511 ready_schedule_lock(*thrd->curr_cluster, kernelTLS.this_processor); 512 __atomic_acquire(&ready_queue.lock); 513 thrd->ts = rdtscl(); 514 bool was_empty = push( ready_queue, thrd ); 515 __atomic_unlock(&ready_queue.lock); 516 ready_schedule_unlock(*thrd->curr_cluster, kernelTLS.this_processor); 506 517 507 518 if(was_empty) { … … 524 535 thread_desc * nextThread(cluster * this) with( *this ) { 525 536 verify( ! kernelTLS.preemption_state.enabled ); 526 lock( ready_queue_lock __cfaabi_dbg_ctx2 ); 527 thread_desc * head = pop_head( ready_queue ); 528 unlock( ready_queue_lock ); 537 538 ready_schedule_lock(*this, kernelTLS.this_processor); 539 __atomic_acquire(&ready_queue.lock); 540 thread_desc * head; 541 __attribute__((unused)) bool _; 542 [head, _] = pop( ready_queue ); 543 __atomic_unlock(&ready_queue.lock); 544 ready_schedule_unlock(*this, kernelTLS.this_processor); 545 529 546 verify( ! kernelTLS.preemption_state.enabled ); 530 547 return head; … … 688 705 pending_preemption = false; 689 706 kernel_thread = pthread_self(); 707 id = -1u; 690 708 691 709 runner{ &this }; … … 697 715 mainProcessor = (processor *)&storage_mainProcessor; 698 716 (*mainProcessor){}; 717 718 mainProcessor->id = doregister(mainCluster, mainProcessor); 699 719 700 720 //initialize the global state variables … … 743 763 kernel_stop_preemption(); 744 764 765 unregister(mainCluster, mainProcessor); 766 745 767 // Destroy the main processor and its context in reverse order of construction 746 768 // These were manually constructed so we need manually destroy them 747 769 ^(mainProcessor->runner){}; 748 ^( mainProcessor){};770 ^(*mainProcessor){}; 749 771 750 772 // Final step, destroy the main thread since it is no longer needed 751 // Since we provided a stack to this taxk it will not destroy anything 752 ^(mainThread){}; 773 // Since we provided a stack to this task it will not destroy anything 774 ^(*mainThread){}; 775 776 ^(*mainCluster){}; 753 777 754 778 ^(__cfa_dbg_global_clusters.list){}; … … 766 790 with( *cltr ) { 767 791 lock (proc_list_lock __cfaabi_dbg_ctx2); 768 remove (procs, *this);769 792 push_front(idles, *this); 770 793 unlock (proc_list_lock); … … 780 803 lock (proc_list_lock __cfaabi_dbg_ctx2); 781 804 remove (idles, *this); 782 push_front(procs, *this);783 805 unlock (proc_list_lock); 784 806 } … … 819 841 if(thrd) { 820 842 int len = snprintf( abort_text, abort_text_size, "Error occurred while executing thread %.256s (%p)", thrd->self_cor.name, thrd ); 821 __cfaabi_ bits_write( STDERR_FILENO,abort_text, len );843 __cfaabi_dbg_bits_write( abort_text, len ); 822 844 823 845 if ( &thrd->self_cor != thrd->curr_cor ) { 824 846 len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", thrd->curr_cor->name, thrd->curr_cor ); 825 __cfaabi_ bits_write( STDERR_FILENO,abort_text, len );847 __cfaabi_dbg_bits_write( abort_text, len ); 826 848 } 827 849 else { 828 __cfaabi_ bits_write( STDERR_FILENO,".\n", 2 );850 __cfaabi_dbg_bits_write( ".\n", 2 ); 829 851 } 830 852 } 831 853 else { 832 854 int len = snprintf( abort_text, abort_text_size, "Error occurred outside of any thread.\n" ); 833 __cfaabi_ bits_write( STDERR_FILENO,abort_text, len );855 __cfaabi_dbg_bits_write( abort_text, len ); 834 856 } 835 857 } … … 842 864 843 865 extern "C" { 844 void __cfaabi_ bits_acquire() {866 void __cfaabi_dbg_bits_acquire() { 845 867 lock( kernel_debug_lock __cfaabi_dbg_ctx2 ); 846 868 } 847 869 848 void __cfaabi_ bits_release() {870 void __cfaabi_dbg_bits_release() { 849 871 unlock( kernel_debug_lock ); 850 872 } … … 921 943 } 922 944 923 void doregister( cluster * cltr, processor * proc ) {924 lock (cltr->proc_list_lock __cfaabi_dbg_ctx2);925 cltr->nprocessors += 1;926 push_front(cltr->procs, *proc);927 unlock (cltr->proc_list_lock);928 }929 930 void unregister( cluster * cltr, processor * proc ) {931 lock (cltr->proc_list_lock __cfaabi_dbg_ctx2);932 remove(cltr->procs, *proc );933 cltr->nprocessors -= 1;934 unlock(cltr->proc_list_lock);935 }936 937 945 //----------------------------------------------------------------------------- 938 946 // Debug
Note: See TracChangeset
for help on using the changeset viewer.