Changeset 8834751 for libcfa/src/concurrency/kernel.cfa
- Timestamp:
- Jun 16, 2020, 12:53:58 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 2073d207
- Parents:
- d29255c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
rd29255c r8834751 130 130 KERNEL_STORAGE(__stack_t, mainThreadCtx); 131 131 KERNEL_STORAGE(__scheduler_RWLock_t, __scheduler_lock); 132 #if !defined(__CFA_NO_STATISTICS__) 133 KERNEL_STORAGE(__stats_t, mainProcStats); 134 #endif 132 135 133 136 cluster * mainCluster; … … 146 149 thread_local struct KernelThreadData kernelTLS __attribute__ ((tls_model ( "initial-exec" ))) = { 147 150 NULL, // cannot use 0p 151 NULL, 148 152 NULL, 149 153 { 1, false, false }, … … 268 272 #if !defined(__CFA_NO_STATISTICS__) 269 273 print_stats = false; 274 stats = alloc(); 275 __init_stats( stats ); 270 276 #endif 271 277 … … 281 287 void ^?{}(cluster & this) { 282 288 __kernel_io_shutdown( this, &this == mainCluster ); 289 290 #if !defined(__CFA_NO_STATISTICS__) 291 if(this.print_stats) { 292 __print_stats( this.stats ); 293 } 294 free( this.stats ); 295 #endif 283 296 284 297 unregister(this); … … 357 370 358 371 __cfadbg_print_safe(runtime_core, "Kernel : core %p terminated\n", this); 359 360 stats_tls_tally(this->cltr);361 372 } 362 373 … … 479 490 // It effectively constructs a coroutine by stealing the pthread stack 480 491 static void * __invoke_processor(void * arg) { 492 #if !defined( __CFA_NO_STATISTICS__ ) 493 __stats_t local_stats; 494 __init_stats( &local_stats ); 495 kernelTLS.this_stats = &local_stats; 496 #endif 497 481 498 processor * proc = (processor *) arg; 482 499 kernelTLS.this_processor = proc; … … 509 526 // Main routine of the core returned, the core is now fully terminated 510 527 __cfadbg_print_safe(runtime_core, "Kernel : core %p main ended (%p)\n", proc, &proc->runner); 528 529 #if !defined(__CFA_NO_STATISTICS__) 530 __tally_stats(proc->cltr->stats, &local_stats); 531 #endif 511 532 512 533 return 0p; … … 794 815 kernelTLS.this_thread = mainThread; 795 816 817 #if !defined( __CFA_NO_STATISTICS__ ) 818 kernelTLS.this_stats = (__stats_t *)& storage_mainProcStats; 819 __init_stats( kernelTLS.this_stats ); 820 #endif 821 796 822 // Enable preemption 797 823 kernel_start_preemption(); … … 874 900 //============================================================================================= 875 901 static $thread * __halt(processor * this) with( *this ) { 876 if( do_terminate ) return 0p;877 878 // First, lock the cluster idle879 lock( cltr->idle_lock __cfaabi_dbg_ctx2 );880 881 // Check if we can find a thread882 if( $thread * found = __next_thread( cltr ) ) {883 unlock( cltr->idle_lock );884 return found;885 }886 887 // Move this processor from the active list to the idle list888 move_to_front(cltr->procs, cltr->idles, *this);889 890 // Unlock the idle lock so we don't go to sleep with a lock891 unlock (cltr->idle_lock);892 893 // We are ready to sleep894 __cfadbg_print_safe(runtime_core, "Kernel : Processor %p ready to sleep\n", this);895 wait( idle );896 897 // We have woken up898 __cfadbg_print_safe(runtime_core, "Kernel : Processor %p woke up and ready to run\n", this);899 900 // Get ourself off the idle list901 with( *cltr ) {902 lock (idle_lock __cfaabi_dbg_ctx2);903 move_to_front(idles, procs, *this);904 unlock(idle_lock);905 }902 // if( do_terminate ) return 0p; 903 904 // // First, lock the cluster idle 905 // lock( cltr->idle_lock __cfaabi_dbg_ctx2 ); 906 907 // // Check if we can find a thread 908 // if( $thread * found = __next_thread( cltr ) ) { 909 // unlock( cltr->idle_lock ); 910 // return found; 911 // } 912 913 // // Move this processor from the active list to the idle list 914 // move_to_front(cltr->procs, cltr->idles, *this); 915 916 // // Unlock the idle lock so we don't go to sleep with a lock 917 // unlock (cltr->idle_lock); 918 919 // // We are ready to sleep 920 // __cfadbg_print_safe(runtime_core, "Kernel : Processor %p ready to sleep\n", this); 921 // wait( idle ); 922 923 // // We have woken up 924 // __cfadbg_print_safe(runtime_core, "Kernel : Processor %p woke up and ready to run\n", this); 925 926 // // Get ourself off the idle list 927 // with( *cltr ) { 928 // lock (idle_lock __cfaabi_dbg_ctx2); 929 // move_to_front(idles, procs, *this); 930 // unlock(idle_lock); 931 // } 906 932 907 933 // Don't check the ready queue again, we may not be in a position to run a thread … … 911 937 // Wake a thread from the front if there are any 912 938 static bool __wake_one(cluster * this) { 913 // First, lock the cluster idle 914 lock( this->idle_lock __cfaabi_dbg_ctx2 ); 915 916 // Check if there is someone to wake up 917 if( !this->idles.head ) { 918 // Nope unlock and return false 919 unlock( this->idle_lock ); 920 return false; 921 } 922 923 // Wake them up 924 __cfadbg_print_safe(runtime_core, "Kernel : waking Processor %p\n", this->idles.head); 925 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 926 post( this->idles.head->idle ); 927 928 // Unlock and return true 929 unlock( this->idle_lock ); 930 return true; 939 // // First, lock the cluster idle 940 // lock( this->idle_lock __cfaabi_dbg_ctx2 ); 941 942 // // Check if there is someone to wake up 943 // if( !this->idles.head ) { 944 // // Nope unlock and return false 945 // unlock( this->idle_lock ); 946 // return false; 947 // } 948 949 // // Wake them up 950 // __cfadbg_print_safe(runtime_core, "Kernel : waking Processor %p\n", this->idles.head); 951 // /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 952 // post( this->idles.head->idle ); 953 954 // // Unlock and return true 955 // unlock( this->idle_lock ); 956 // return true; 957 958 return false; 931 959 } 932 960 933 961 // Unconditionnaly wake a thread 934 962 static bool __wake_proc(processor * this) { 935 __cfadbg_print_safe(runtime_core, "Kernel : waking Processor %p\n", this); 936 937 disable_interrupts(); 938 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 939 bool ret = post( this->idle ); 940 enable_interrupts( __cfaabi_dbg_ctx ); 941 942 return ret; 963 // __cfadbg_print_safe(runtime_core, "Kernel : waking Processor %p\n", this); 964 965 // disable_interrupts(); 966 // /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 967 // bool ret = post( this->idle ); 968 // enable_interrupts( __cfaabi_dbg_ctx ); 969 970 // return ret; 971 972 return false; 943 973 } 944 974
Note: See TracChangeset
for help on using the changeset viewer.