Changes in src/libcfa/concurrency/kernel.c [c40e7c5:b69ea6b]
- File:
-
- 1 edited
-
src/libcfa/concurrency/kernel.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
rc40e7c5 rb69ea6b 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Feb 6 21:51:26201813 // Update Count : 412 // Last Modified On : Thu Feb 8 23:52:19 2018 13 // Update Count : 5 14 14 // 15 15 16 16 //C Includes 17 17 #include <stddef.h> 18 #define ftype `ftype`19 18 extern "C" { 20 19 #include <stdio.h> … … 24 23 #include <unistd.h> 25 24 } 26 #undef ftype27 25 28 26 //CFA Includes … … 58 56 thread_local processor * volatile this_processor; 59 57 60 volatile thread_local bool preemption_in_progress = 0; 61 volatile thread_local bool preemption_enabled = false; 62 volatile thread_local unsigned short disable_preempt_count = 1; 58 // volatile thread_local bool preemption_in_progress = 0; 59 // volatile thread_local bool preemption_enabled = false; 60 // volatile thread_local unsigned short disable_preempt_count = 1; 61 62 volatile thread_local __cfa_kernel_preemption_data_t preemption = { false, false, 1 }; 63 63 64 64 //----------------------------------------------------------------------------- … … 209 209 if(readyThread) 210 210 { 211 verify( !preemption _enabled );211 verify( !preemption.enabled ); 212 212 213 213 runThread(this, readyThread); 214 214 215 verify( !preemption _enabled );215 verify( !preemption.enabled ); 216 216 217 217 //Some actions need to be taken from the kernel … … 262 262 void finishRunning(processor * this) with( this->finish ) { 263 263 if( action_code == Release ) { 264 verify( !preemption _enabled );264 verify( !preemption.enabled ); 265 265 unlock( *lock ); 266 266 } … … 269 269 } 270 270 else if( action_code == Release_Schedule ) { 271 verify( !preemption _enabled );271 verify( !preemption.enabled ); 272 272 unlock( *lock ); 273 273 ScheduleThread( thrd ); 274 274 } 275 275 else if( action_code == Release_Multi ) { 276 verify( !preemption _enabled );276 verify( !preemption.enabled ); 277 277 for(int i = 0; i < lock_count; i++) { 278 278 unlock( *locks[i] ); … … 306 306 this_coroutine = NULL; 307 307 this_thread = NULL; 308 preemption _enabled = false;309 disable_preempt_count = 1;308 preemption.enabled = false; 309 preemption.disable_count = 1; 310 310 // SKULLDUGGERY: We want to create a context for the processor coroutine 311 311 // which is needed for the 2-step context switch. However, there is no reason … … 347 347 } 348 348 349 void kernel_first_resume(processor * this) { 350 coroutine_desc * src = this_coroutine; 351 coroutine_desc * dst = get_coroutine(*this->runner); 352 353 verify( !preemption.enabled ); 354 355 create_stack(&dst->stack, dst->stack.size); 356 CtxStart(this->runner, CtxInvokeCoroutine); 357 358 verify( !preemption.enabled ); 359 360 dst->last = src; 361 dst->starter = dst->starter ? dst->starter : src; 362 363 // set state of current coroutine to inactive 364 src->state = src->state == Halted ? Halted : Inactive; 365 366 // set new coroutine that task is executing 367 this_coroutine = dst; 368 369 // SKULLDUGGERY normally interrupts are enable before leaving a coroutine ctxswitch. 370 // Therefore, when first creating a coroutine, interrupts are enable before calling the main. 371 // This is consistent with thread creation. However, when creating the main processor coroutine, 372 // we wan't interrupts to be disabled. Therefore, we double-disable interrupts here so they will 373 // stay disabled. 374 disable_interrupts(); 375 376 // context switch to specified coroutine 377 assert( src->stack.context ); 378 CtxSwitch( src->stack.context, dst->stack.context ); 379 // when CtxSwitch returns we are back in the src coroutine 380 381 // set state of new coroutine to active 382 src->state = Active; 383 384 verify( !preemption.enabled ); 385 } 386 349 387 //----------------------------------------------------------------------------- 350 388 // Scheduler routines … … 354 392 verify( thrd->self_cor.state != Halted ); 355 393 356 verify( !preemption _enabled );394 verify( !preemption.enabled ); 357 395 358 396 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); … … 364 402 } 365 403 366 verify( !preemption _enabled );404 verify( !preemption.enabled ); 367 405 } 368 406 369 407 thread_desc * nextThread(cluster * this) with( *this ) { 370 verify( !preemption _enabled );408 verify( !preemption.enabled ); 371 409 lock( ready_queue_lock __cfaabi_dbg_ctx2 ); 372 410 thread_desc * head = pop_head( ready_queue ); 373 411 unlock( ready_queue_lock ); 374 verify( !preemption _enabled );412 verify( !preemption.enabled ); 375 413 return head; 376 414 } … … 378 416 void BlockInternal() { 379 417 disable_interrupts(); 380 verify( !preemption _enabled );418 verify( !preemption.enabled ); 381 419 returnToKernel(); 382 verify( !preemption _enabled );420 verify( !preemption.enabled ); 383 421 enable_interrupts( __cfaabi_dbg_ctx ); 384 422 } … … 389 427 this_processor->finish.lock = lock; 390 428 391 verify( !preemption _enabled );429 verify( !preemption.enabled ); 392 430 returnToKernel(); 393 verify( !preemption _enabled );431 verify( !preemption.enabled ); 394 432 395 433 enable_interrupts( __cfaabi_dbg_ctx ); … … 401 439 this_processor->finish.thrd = thrd; 402 440 403 verify( !preemption _enabled );441 verify( !preemption.enabled ); 404 442 returnToKernel(); 405 verify( !preemption _enabled );443 verify( !preemption.enabled ); 406 444 407 445 enable_interrupts( __cfaabi_dbg_ctx ); … … 415 453 this_processor->finish.thrd = thrd; 416 454 417 verify( !preemption _enabled );455 verify( !preemption.enabled ); 418 456 returnToKernel(); 419 verify( !preemption _enabled );457 verify( !preemption.enabled ); 420 458 421 459 enable_interrupts( __cfaabi_dbg_ctx ); … … 428 466 this_processor->finish.lock_count = count; 429 467 430 verify( !preemption _enabled );468 verify( !preemption.enabled ); 431 469 returnToKernel(); 432 verify( !preemption _enabled );470 verify( !preemption.enabled ); 433 471 434 472 enable_interrupts( __cfaabi_dbg_ctx ); … … 443 481 this_processor->finish.thrd_count = thrd_count; 444 482 445 verify( !preemption _enabled );483 verify( !preemption.enabled ); 446 484 returnToKernel(); 447 verify( !preemption _enabled );485 verify( !preemption.enabled ); 448 486 449 487 enable_interrupts( __cfaabi_dbg_ctx ); … … 451 489 452 490 void LeaveThread(__spinlock_t * lock, thread_desc * thrd) { 453 verify( !preemption _enabled );491 verify( !preemption.enabled ); 454 492 this_processor->finish.action_code = thrd ? Release_Schedule : Release; 455 493 this_processor->finish.lock = lock; … … 465 503 // Kernel boot procedures 466 504 void kernel_startup(void) { 505 verify( !preemption.enabled ); 467 506 __cfaabi_dbg_print_safe("Kernel : Starting\n"); 468 507 … … 502 541 // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that 503 542 // mainThread is on the ready queue when this call is made. 504 resume( *mainProcessor->runner );543 kernel_first_resume( this_processor ); 505 544 506 545 … … 509 548 __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n"); 510 549 550 verify( !preemption.enabled ); 511 551 enable_interrupts( __cfaabi_dbg_ctx ); 552 verify( preemption.enabled ); 512 553 } 513 554 … … 515 556 __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n"); 516 557 558 verify( preemption.enabled ); 517 559 disable_interrupts(); 560 verify( !preemption.enabled ); 518 561 519 562 // SKULLDUGGERY: Notify the mainProcessor it needs to terminates.
Note:
See TracChangeset
for help on using the changeset viewer.