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