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