Changeset 534d84e for src/libcfa/concurrency/kernel.c
- Timestamp:
- Apr 28, 2018, 10:35:51 AM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- b6dc097
- Parents:
- 9997fee (diff), a0c7d5cc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
r9997fee r534d84e 42 42 KERNEL_STORAGE(cluster, mainCluster); 43 43 KERNEL_STORAGE(processor, mainProcessor); 44 KERNEL_STORAGE(processorCtx_t, mainProcessorCtx);45 44 KERNEL_STORAGE(thread_desc, mainThread); 46 45 KERNEL_STORAGE(machine_context_t, mainThreadCtx); 47 46 48 cluster *mainCluster;49 processor *mainProcessor;47 cluster * mainCluster; 48 processor * mainProcessor; 50 49 thread_desc * mainThread; 51 50 … … 65 64 66 65 //----------------------------------------------------------------------------- 67 // Main thread construction66 // Struct to steal stack 68 67 struct current_stack_info_t { 69 68 machine_context_t ctx; … … 90 89 } 91 90 91 //----------------------------------------------------------------------------- 92 // Main thread construction 92 93 void ?{}( coStack_t & this, current_stack_info_t * info) with( this ) { 93 94 size = info->size; … … 111 112 self_cor{ info }; 112 113 curr_cor = &self_cor; 114 curr_cluster = mainCluster; 113 115 self_mon.owner = &this; 114 116 self_mon.recursion = 1; … … 126 128 //----------------------------------------------------------------------------- 127 129 // Processor coroutine 128 void ?{}(processorCtx_t & this) {} 129 130 // Construct the processor context of the main processor 131 void ?{}(processorCtx_t & this, processor * proc) { 132 (this.__cor){ "Processor" }; 133 this.__cor.starter = NULL; 134 this.proc = proc; 130 void ?{}(processorCtx_t & this) { 131 135 132 } 136 133 … … 141 138 } 142 139 143 void ?{}(processor & this) { 144 this{ mainCluster }; 145 } 146 147 void ?{}(processor & this, cluster * cltr) with( this ) { 148 this.cltr = cltr; 140 void ?{}(processor & this, const char * name, cluster & cltr) with( this ) { 141 this.name = name; 142 this.cltr = &cltr; 149 143 terminated{ 0 }; 150 144 do_terminate = false; … … 154 148 155 149 start( &this ); 156 }157 158 void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) with( this ) {159 this.cltr = cltr;160 terminated{ 0 };161 do_terminate = false;162 preemption_alarm = NULL;163 pending_preemption = false;164 kernel_thread = pthread_self();165 runner.proc = &this;166 167 __cfaabi_dbg_print_safe("Kernel : constructing main processor context %p\n", &runner);168 runner{ &this };169 150 } 170 151 … … 181 162 } 182 163 183 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; 184 167 ready_queue{}; 185 168 ready_queue_lock{}; 186 187 preemption_rate = default_preemption();188 169 } 189 170 … … 312 293 TL_SET( this_coroutine, NULL ); 313 294 TL_SET( this_thread, NULL ); 314 TL_GET( preemption_state ).enabled = false; 315 TL_GET( preemption_state ).disable_count = 1; 295 TL_GET( preemption_state ).[enabled, disable_count] = [false, 1]; 316 296 // SKULLDUGGERY: We want to create a context for the processor coroutine 317 297 // which is needed for the 2-step context switch. However, there is no reason … … 402 382 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); 403 383 404 with( * TL_GET( this_processor )->cltr ) {384 with( *thrd->curr_cluster ) { 405 385 lock ( ready_queue_lock __cfaabi_dbg_ctx2 ); 406 386 append( ready_queue, thrd ); … … 430 410 void BlockInternal( __spinlock_t * lock ) { 431 411 disable_interrupts(); 432 TL_GET( this_processor )->finish.action_code = Release; 433 TL_GET( this_processor )->finish.lock = lock; 412 with( *TL_GET( this_processor ) ) { 413 finish.action_code = Release; 414 finish.lock = lock; 415 } 434 416 435 417 verify( ! TL_GET( preemption_state ).enabled ); … … 442 424 void BlockInternal( thread_desc * thrd ) { 443 425 disable_interrupts(); 444 TL_GET( this_processor )->finish.action_code = Schedule; 445 TL_GET( this_processor )->finish.thrd = thrd; 426 with( *TL_GET( this_processor ) ) { 427 finish.action_code = Schedule; 428 finish.thrd = thrd; 429 } 446 430 447 431 verify( ! TL_GET( preemption_state ).enabled ); … … 455 439 assert(thrd); 456 440 disable_interrupts(); 457 TL_GET( this_processor )->finish.action_code = Release_Schedule; 458 TL_GET( this_processor )->finish.lock = lock; 459 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 } 460 446 461 447 verify( ! TL_GET( preemption_state ).enabled ); … … 468 454 void BlockInternal(__spinlock_t * locks [], unsigned short count) { 469 455 disable_interrupts(); 470 TL_GET( this_processor )->finish.action_code = Release_Multi; 471 TL_GET( this_processor )->finish.locks = locks; 472 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 } 473 461 474 462 verify( ! TL_GET( preemption_state ).enabled ); … … 481 469 void BlockInternal(__spinlock_t * locks [], unsigned short lock_count, thread_desc * thrds [], unsigned short thrd_count) { 482 470 disable_interrupts(); 483 TL_GET( this_processor )->finish.action_code = Release_Multi_Schedule; 484 TL_GET( this_processor )->finish.locks = locks; 485 TL_GET( this_processor )->finish.lock_count = lock_count; 486 TL_GET( this_processor )->finish.thrds = thrds; 487 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 } 488 478 489 479 verify( ! TL_GET( preemption_state ).enabled ); … … 496 486 void LeaveThread(__spinlock_t * lock, thread_desc * thrd) { 497 487 verify( ! TL_GET( preemption_state ).enabled ); 498 TL_GET( this_processor )->finish.action_code = thrd ? Release_Schedule : Release; 499 TL_GET( this_processor )->finish.lock = lock; 500 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 } 501 493 502 494 returnToKernel(); … … 511 503 verify( ! TL_GET( preemption_state ).enabled ); 512 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"); 513 511 514 512 // Start by initializing the main thread … … 521 519 __cfaabi_dbg_print_safe("Kernel : Main thread ready\n"); 522 520 523 // Initialize the main cluster 524 mainCluster = (cluster *)&storage_mainCluster; 525 (*mainCluster){}; 526 527 __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 } 528 542 529 543 // Initialize the main processor and the main processor ctx 530 544 // (the coroutine that contains the processing control flow) 531 545 mainProcessor = (processor *)&storage_mainProcessor; 532 (*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx};546 (*mainProcessor){}; 533 547 534 548 //initialize the global state variables … … 725 739 thrd->dbg_next = NULL; 726 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 } 727 746 ) 728 747 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.