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