- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r2d8f7b0 r4069faad 15 15 16 16 #define __cforall_thread__ 17 // #define __CFA_DEBUG_PRINT_RUNTIME_CORE__ 17 18 18 19 //C Includes … … 40 41 #include "invoke.h" 41 42 43 42 44 //----------------------------------------------------------------------------- 43 45 // Some assembly required … … 230 232 idle{}; 231 233 232 __cfa abi_dbg_print_safe("Kernel : Starting core %p\n", &this);234 __cfadbg_print_safe(runtime_core, "Kernel : Starting core %p\n", &this); 233 235 234 236 this.stack = __create_pthread( &this.kernel_thread, __invoke_processor, (void *)&this ); 235 237 236 __cfa abi_dbg_print_safe("Kernel : core %p started\n", &this);238 __cfadbg_print_safe(runtime_core, "Kernel : core %p created\n", &this); 237 239 } 238 240 239 241 void ^?{}(processor & this) with( this ){ 240 242 if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) { 241 __cfa abi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);243 __cfadbg_print_safe(runtime_core, "Kernel : core %p signaling termination\n", &this); 242 244 243 245 __atomic_store_n(&do_terminate, true, __ATOMIC_RELAXED); … … 258 260 ready_queue_lock{}; 259 261 262 #if !defined(__CFA_NO_STATISTICS__) 263 print_stats = false; 264 #endif 265 260 266 procs{ __get }; 261 267 idles{ __get }; 262 268 threads{ __get }; 263 269 264 __kernel_io_startup( this );270 __kernel_io_startup( this, &this == mainCluster ); 265 271 266 272 doregister(this); … … 268 274 269 275 void ^?{}(cluster & this) { 270 __kernel_io_shutdown( this );276 __kernel_io_shutdown( this, &this == mainCluster ); 271 277 272 278 unregister(this); … … 285 291 verify(this); 286 292 287 __cfa abi_dbg_print_safe("Kernel : core %p starting\n", this);293 __cfadbg_print_safe(runtime_core, "Kernel : core %p starting\n", this); 288 294 289 295 doregister(this->cltr, this); … … 293 299 preemption_scope scope = { this }; 294 300 295 __cfa abi_dbg_print_safe("Kernel : core %p started\n", this);301 __cfadbg_print_safe(runtime_core, "Kernel : core %p started\n", this); 296 302 297 303 $thread * readyThread = 0p; … … 319 325 } 320 326 321 __cfa abi_dbg_print_safe("Kernel : core %p stopping\n", this);327 __cfadbg_print_safe(runtime_core, "Kernel : core %p stopping\n", this); 322 328 } 323 329 … … 326 332 V( this->terminated ); 327 333 328 __cfa abi_dbg_print_safe("Kernel : core %p terminated\n", this);334 __cfadbg_print_safe(runtime_core, "Kernel : core %p terminated\n", this); 329 335 330 336 // HACK : the coroutine context switch expects this_thread to be set … … 471 477 472 478 //We now have a proper context from which to schedule threads 473 __cfa abi_dbg_print_safe("Kernel : core %p created (%p, %p)\n", proc, &proc->runner, &ctx);479 __cfadbg_print_safe(runtime_core, "Kernel : core %p created (%p, %p)\n", proc, &proc->runner, &ctx); 474 480 475 481 // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't … … 482 488 483 489 // Main routine of the core returned, the core is now fully terminated 484 __cfa abi_dbg_print_safe("Kernel : core %p main ended (%p)\n", proc, &proc->runner);490 __cfadbg_print_safe(runtime_core, "Kernel : core %p main ended (%p)\n", proc, &proc->runner); 485 491 486 492 return 0p; … … 713 719 static void __kernel_startup(void) { 714 720 verify( ! kernelTLS.preemption_state.enabled ); 715 __cfa abi_dbg_print_safe("Kernel : Starting\n");721 __cfadbg_print_safe(runtime_core, "Kernel : Starting\n"); 716 722 717 723 __page_size = sysconf( _SC_PAGESIZE ); … … 724 730 (*mainCluster){"Main Cluster"}; 725 731 726 __cfa abi_dbg_print_safe("Kernel : Main cluster ready\n");732 __cfadbg_print_safe(runtime_core, "Kernel : Main cluster ready\n"); 727 733 728 734 // Start by initializing the main thread … … 734 740 (*mainThread){ &info }; 735 741 736 __cfa abi_dbg_print_safe("Kernel : Main thread ready\n");742 __cfadbg_print_safe(runtime_core, "Kernel : Main thread ready\n"); 737 743 738 744 … … 755 761 756 762 runner{ &this }; 757 __cfa abi_dbg_print_safe("Kernel : constructed main processor context %p\n", &runner);763 __cfadbg_print_safe(runtime_core, "Kernel : constructed main processor context %p\n", &runner); 758 764 } 759 765 … … 780 786 781 787 782 783 788 // THE SYSTEM IS NOW COMPLETELY RUNNING 784 __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n"); 789 790 791 // Now that the system is up, finish creating systems that need threading 792 __kernel_io_finish_start( *mainCluster ); 793 794 795 __cfadbg_print_safe(runtime_core, "Kernel : Started\n--------------------------------------------------\n\n"); 785 796 786 797 verify( ! kernelTLS.preemption_state.enabled ); … … 790 801 791 802 static void __kernel_shutdown(void) { 792 __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n"); 803 //Before we start shutting things down, wait for systems that need threading to shutdown 804 __kernel_io_prepare_stop( *mainCluster ); 793 805 794 806 /* paranoid */ verify( TL_GET( preemption_state.enabled ) ); 795 807 disable_interrupts(); 796 808 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 809 810 __cfadbg_print_safe(runtime_core, "\n--------------------------------------------------\nKernel : Shutting down\n"); 797 811 798 812 // SKULLDUGGERY: Notify the mainProcessor it needs to terminates. … … 822 836 ^(__cfa_dbg_global_clusters.lock){}; 823 837 824 __cfa abi_dbg_print_safe("Kernel : Shutdown complete\n");838 __cfadbg_print_safe(runtime_core, "Kernel : Shutdown complete\n"); 825 839 } 826 840 … … 847 861 848 862 // We are ready to sleep 849 __cfa abi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this);863 __cfadbg_print_safe(runtime_core, "Kernel : Processor %p ready to sleep\n", this); 850 864 wait( idle ); 851 865 852 866 // We have woken up 853 __cfa abi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this);867 __cfadbg_print_safe(runtime_core, "Kernel : Processor %p woke up and ready to run\n", this); 854 868 855 869 // Get ourself off the idle list … … 867 881 static bool __wake_one(cluster * this, __attribute__((unused)) bool force) { 868 882 // if we don't want to force check if we know it's false 869 if( !this->idles.head && !force ) return false;883 // if( !this->idles.head && !force ) return false; 870 884 871 885 // First, lock the cluster idle … … 880 894 881 895 // Wake them up 896 __cfadbg_print_safe(runtime_core, "Kernel : waking Processor %p\n", this->idles.head); 882 897 post( this->idles.head->idle ); 883 898 … … 889 904 // Unconditionnaly wake a thread 890 905 static bool __wake_proc(processor * this) { 906 __cfadbg_print_safe(runtime_core, "Kernel : waking Processor %p\n", this); 891 907 return post( this->idle ); 892 908 } … … 1000 1016 // make new owner 1001 1017 unpark( thrd __cfaabi_dbg_ctx2 ); 1018 1019 return thrd != 0p; 1020 } 1021 1022 bool V(semaphore & this, unsigned diff) with( this ) { 1023 $thread * thrd = 0p; 1024 lock( lock __cfaabi_dbg_ctx2 ); 1025 int release = max(-count, (int)diff); 1026 count += diff; 1027 for(release) { 1028 unpark( pop_head( waiting ) __cfaabi_dbg_ctx2 ); 1029 } 1030 1031 unlock( lock ); 1002 1032 1003 1033 return thrd != 0p;
Note:
See TracChangeset
for help on using the changeset viewer.