Changes in src/libcfa/concurrency/kernel.c [01963df:de6319f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
r01963df rde6319f 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 30 18:26:11201813 // Update Count : 2 312 // Last Modified On : Mon Apr 9 16:11:46 2018 13 // Update Count : 24 14 14 // 15 15 … … 25 25 26 26 //CFA Includes 27 #include "time" 27 28 #include "kernel_private.h" 28 29 #include "preemption.h" … … 41 42 KERNEL_STORAGE(cluster, mainCluster); 42 43 KERNEL_STORAGE(processor, mainProcessor); 43 KERNEL_STORAGE(processorCtx_t, mainProcessorCtx);44 44 KERNEL_STORAGE(thread_desc, mainThread); 45 45 KERNEL_STORAGE(machine_context_t, mainThreadCtx); 46 46 47 cluster *mainCluster;48 processor *mainProcessor;47 cluster * mainCluster; 48 processor * mainProcessor; 49 49 thread_desc * mainThread; 50 50 … … 64 64 65 65 //----------------------------------------------------------------------------- 66 // Main thread construction66 // Struct to steal stack 67 67 struct current_stack_info_t { 68 68 machine_context_t ctx; … … 89 89 } 90 90 91 //----------------------------------------------------------------------------- 92 // Main thread construction 91 93 void ?{}( coStack_t & this, current_stack_info_t * info) with( this ) { 92 94 size = info->size; … … 110 112 self_cor{ info }; 111 113 curr_cor = &self_cor; 114 curr_cluster = mainCluster; 112 115 self_mon.owner = &this; 113 116 self_mon.recursion = 1; … … 125 128 //----------------------------------------------------------------------------- 126 129 // Processor coroutine 127 void ?{}(processorCtx_t & this) {} 128 129 // Construct the processor context of the main processor 130 void ?{}(processorCtx_t & this, processor * proc) { 131 (this.__cor){ "Processor" }; 132 this.__cor.starter = NULL; 133 this.proc = proc; 130 void ?{}(processorCtx_t & this) { 131 134 132 } 135 133 … … 140 138 } 141 139 142 void ?{}(processor & this) { 143 this{ mainCluster }; 144 } 145 146 void ?{}(processor & this, cluster * cltr) with( this ) { 147 this.cltr = cltr; 140 void ?{}(processor & this, const char * name, cluster & cltr) with( this ) { 141 this.name = name; 142 this.cltr = &cltr; 148 143 terminated{ 0 }; 149 144 do_terminate = false; … … 153 148 154 149 start( &this ); 155 }156 157 void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) with( this ) {158 this.cltr = cltr;159 terminated{ 0 };160 do_terminate = false;161 preemption_alarm = NULL;162 pending_preemption = false;163 kernel_thread = pthread_self();164 runner.proc = &this;165 166 __cfaabi_dbg_print_safe("Kernel : constructing main processor context %p\n", &runner);167 runner{ &this };168 150 } 169 151 … … 180 162 } 181 163 182 void ?{}(cluster & this) with( this ) { 164 void ?{}(cluster & this, const char * name, Duration preemption_rate) with( this ) { 165 this.name = name; 166 this.preemption_rate = preemption_rate; 183 167 ready_queue{}; 184 168 ready_queue_lock{}; 185 186 preemption_rate = default_preemption();187 169 } 188 170 … … 311 293 TL_SET( this_coroutine, NULL ); 312 294 TL_SET( this_thread, NULL ); 313 TL_GET( preemption_state ).enabled = false; 314 TL_GET( preemption_state ).disable_count = 1; 295 TL_GET( preemption_state ).[enabled, disable_count] = [false, 1]; 315 296 // SKULLDUGGERY: We want to create a context for the processor coroutine 316 297 // which is needed for the 2-step context switch. However, there is no reason … … 401 382 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); 402 383 403 with( * TL_GET( this_processor )->cltr ) {384 with( *thrd->curr_cluster ) { 404 385 lock ( ready_queue_lock __cfaabi_dbg_ctx2 ); 405 386 append( ready_queue, thrd ); … … 429 410 void BlockInternal( __spinlock_t * lock ) { 430 411 disable_interrupts(); 431 TL_GET( this_processor )->finish.action_code = Release; 432 TL_GET( this_processor )->finish.lock = lock; 412 with( *TL_GET( this_processor ) ) { 413 finish.action_code = Release; 414 finish.lock = lock; 415 } 433 416 434 417 verify( ! TL_GET( preemption_state ).enabled ); … … 441 424 void BlockInternal( thread_desc * thrd ) { 442 425 disable_interrupts(); 443 TL_GET( this_processor )->finish.action_code = Schedule; 444 TL_GET( this_processor )->finish.thrd = thrd; 426 with( *TL_GET( this_processor ) ) { 427 finish.action_code = Schedule; 428 finish.thrd = thrd; 429 } 445 430 446 431 verify( ! TL_GET( preemption_state ).enabled ); … … 454 439 assert(thrd); 455 440 disable_interrupts(); 456 TL_GET( this_processor )->finish.action_code = Release_Schedule; 457 TL_GET( this_processor )->finish.lock = lock; 458 TL_GET( this_processor )->finish.thrd = thrd; 441 with( *TL_GET( this_processor ) ) { 442 finish.action_code = Release_Schedule; 443 finish.lock = lock; 444 finish.thrd = thrd; 445 } 459 446 460 447 verify( ! TL_GET( preemption_state ).enabled ); … … 467 454 void BlockInternal(__spinlock_t * locks [], unsigned short count) { 468 455 disable_interrupts(); 469 TL_GET( this_processor )->finish.action_code = Release_Multi; 470 TL_GET( this_processor )->finish.locks = locks; 471 TL_GET( this_processor )->finish.lock_count = count; 456 with( *TL_GET( this_processor ) ) { 457 finish.action_code = Release_Multi; 458 finish.locks = locks; 459 finish.lock_count = count; 460 } 472 461 473 462 verify( ! TL_GET( preemption_state ).enabled ); … … 480 469 void BlockInternal(__spinlock_t * locks [], unsigned short lock_count, thread_desc * thrds [], unsigned short thrd_count) { 481 470 disable_interrupts(); 482 TL_GET( this_processor )->finish.action_code = Release_Multi_Schedule; 483 TL_GET( this_processor )->finish.locks = locks; 484 TL_GET( this_processor )->finish.lock_count = lock_count; 485 TL_GET( this_processor )->finish.thrds = thrds; 486 TL_GET( this_processor )->finish.thrd_count = thrd_count; 471 with( *TL_GET( this_processor ) ) { 472 finish.action_code = Release_Multi_Schedule; 473 finish.locks = locks; 474 finish.lock_count = lock_count; 475 finish.thrds = thrds; 476 finish.thrd_count = thrd_count; 477 } 487 478 488 479 verify( ! TL_GET( preemption_state ).enabled ); … … 495 486 void LeaveThread(__spinlock_t * lock, thread_desc * thrd) { 496 487 verify( ! TL_GET( preemption_state ).enabled ); 497 TL_GET( this_processor )->finish.action_code = thrd ? Release_Schedule : Release; 498 TL_GET( this_processor )->finish.lock = lock; 499 TL_GET( this_processor )->finish.thrd = thrd; 488 with( *TL_GET( this_processor ) ) { 489 finish.action_code = thrd ? Release_Schedule : Release; 490 finish.lock = lock; 491 finish.thrd = thrd; 492 } 500 493 501 494 returnToKernel(); … … 510 503 verify( ! TL_GET( preemption_state ).enabled ); 511 504 __cfaabi_dbg_print_safe("Kernel : Starting\n"); 505 506 // Initialize the main cluster 507 mainCluster = (cluster *)&storage_mainCluster; 508 (*mainCluster){"Main Cluster"}; 509 510 __cfaabi_dbg_print_safe("Kernel : Main cluster ready\n"); 512 511 513 512 // Start by initializing the main thread … … 520 519 __cfaabi_dbg_print_safe("Kernel : Main thread ready\n"); 521 520 522 // Initialize the main cluster 523 mainCluster = (cluster *)&storage_mainCluster; 524 (*mainCluster){}; 525 526 __cfaabi_dbg_print_safe("Kernel : main cluster ready\n"); 521 522 523 // Construct the processor context of the main processor 524 void ?{}(processorCtx_t & this, processor * proc) { 525 (this.__cor){ "Processor" }; 526 this.__cor.starter = NULL; 527 this.proc = proc; 528 } 529 530 void ?{}(processor & this) with( this ) { 531 name = "Main Processor"; 532 cltr = mainCluster; 533 terminated{ 0 }; 534 do_terminate = false; 535 preemption_alarm = NULL; 536 pending_preemption = false; 537 kernel_thread = pthread_self(); 538 539 runner{ &this }; 540 __cfaabi_dbg_print_safe("Kernel : constructed main processor context %p\n", &runner); 541 } 527 542 528 543 // Initialize the main processor and the main processor ctx 529 544 // (the coroutine that contains the processing control flow) 530 545 mainProcessor = (processor *)&storage_mainProcessor; 531 (*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx};546 (*mainProcessor){}; 532 547 533 548 //initialize the global state variables … … 724 739 thrd->dbg_next = NULL; 725 740 } 741 742 void __cfaabi_dbg_record(__spinlock_t & this, const char * prev_name) { 743 this.prev_name = prev_name; 744 this.prev_thrd = TL_GET( this_thread ); 745 } 726 746 ) 727 747 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.