Changeset b69ea6b for src/libcfa/concurrency/kernel.c
- Timestamp:
- Feb 15, 2018, 10:52:35 AM (7 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, resolv-new, with_gc
- Children:
- d27e340
- Parents:
- ff2d1139
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
rff2d1139 rb69ea6b 56 56 thread_local processor * volatile this_processor; 57 57 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; 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 }; 61 63 62 64 //----------------------------------------------------------------------------- … … 207 209 if(readyThread) 208 210 { 209 verify( !preemption _enabled );211 verify( !preemption.enabled ); 210 212 211 213 runThread(this, readyThread); 212 214 213 verify( !preemption _enabled );215 verify( !preemption.enabled ); 214 216 215 217 //Some actions need to be taken from the kernel … … 260 262 void finishRunning(processor * this) with( this->finish ) { 261 263 if( action_code == Release ) { 262 verify( !preemption _enabled );264 verify( !preemption.enabled ); 263 265 unlock( *lock ); 264 266 } … … 267 269 } 268 270 else if( action_code == Release_Schedule ) { 269 verify( !preemption _enabled );271 verify( !preemption.enabled ); 270 272 unlock( *lock ); 271 273 ScheduleThread( thrd ); 272 274 } 273 275 else if( action_code == Release_Multi ) { 274 verify( !preemption _enabled );276 verify( !preemption.enabled ); 275 277 for(int i = 0; i < lock_count; i++) { 276 278 unlock( *locks[i] ); … … 304 306 this_coroutine = NULL; 305 307 this_thread = NULL; 306 preemption _enabled = false;307 disable_preempt_count = 1;308 preemption.enabled = false; 309 preemption.disable_count = 1; 308 310 // SKULLDUGGERY: We want to create a context for the processor coroutine 309 311 // which is needed for the 2-step context switch. However, there is no reason … … 345 347 } 346 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 347 387 //----------------------------------------------------------------------------- 348 388 // Scheduler routines … … 352 392 verify( thrd->self_cor.state != Halted ); 353 393 354 verify( !preemption _enabled );394 verify( !preemption.enabled ); 355 395 356 396 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); … … 362 402 } 363 403 364 verify( !preemption _enabled );404 verify( !preemption.enabled ); 365 405 } 366 406 367 407 thread_desc * nextThread(cluster * this) with( *this ) { 368 verify( !preemption _enabled );408 verify( !preemption.enabled ); 369 409 lock( ready_queue_lock __cfaabi_dbg_ctx2 ); 370 410 thread_desc * head = pop_head( ready_queue ); 371 411 unlock( ready_queue_lock ); 372 verify( !preemption _enabled );412 verify( !preemption.enabled ); 373 413 return head; 374 414 } … … 376 416 void BlockInternal() { 377 417 disable_interrupts(); 378 verify( !preemption _enabled );418 verify( !preemption.enabled ); 379 419 returnToKernel(); 380 verify( !preemption _enabled );420 verify( !preemption.enabled ); 381 421 enable_interrupts( __cfaabi_dbg_ctx ); 382 422 } … … 387 427 this_processor->finish.lock = lock; 388 428 389 verify( !preemption _enabled );429 verify( !preemption.enabled ); 390 430 returnToKernel(); 391 verify( !preemption _enabled );431 verify( !preemption.enabled ); 392 432 393 433 enable_interrupts( __cfaabi_dbg_ctx ); … … 399 439 this_processor->finish.thrd = thrd; 400 440 401 verify( !preemption _enabled );441 verify( !preemption.enabled ); 402 442 returnToKernel(); 403 verify( !preemption _enabled );443 verify( !preemption.enabled ); 404 444 405 445 enable_interrupts( __cfaabi_dbg_ctx ); … … 413 453 this_processor->finish.thrd = thrd; 414 454 415 verify( !preemption _enabled );455 verify( !preemption.enabled ); 416 456 returnToKernel(); 417 verify( !preemption _enabled );457 verify( !preemption.enabled ); 418 458 419 459 enable_interrupts( __cfaabi_dbg_ctx ); … … 426 466 this_processor->finish.lock_count = count; 427 467 428 verify( !preemption _enabled );468 verify( !preemption.enabled ); 429 469 returnToKernel(); 430 verify( !preemption _enabled );470 verify( !preemption.enabled ); 431 471 432 472 enable_interrupts( __cfaabi_dbg_ctx ); … … 441 481 this_processor->finish.thrd_count = thrd_count; 442 482 443 verify( !preemption _enabled );483 verify( !preemption.enabled ); 444 484 returnToKernel(); 445 verify( !preemption _enabled );485 verify( !preemption.enabled ); 446 486 447 487 enable_interrupts( __cfaabi_dbg_ctx ); … … 449 489 450 490 void LeaveThread(__spinlock_t * lock, thread_desc * thrd) { 451 verify( !preemption _enabled );491 verify( !preemption.enabled ); 452 492 this_processor->finish.action_code = thrd ? Release_Schedule : Release; 453 493 this_processor->finish.lock = lock; … … 463 503 // Kernel boot procedures 464 504 void kernel_startup(void) { 505 verify( !preemption.enabled ); 465 506 __cfaabi_dbg_print_safe("Kernel : Starting\n"); 466 507 … … 500 541 // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that 501 542 // mainThread is on the ready queue when this call is made. 502 resume( *mainProcessor->runner );543 kernel_first_resume( this_processor ); 503 544 504 545 … … 507 548 __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n"); 508 549 550 verify( !preemption.enabled ); 509 551 enable_interrupts( __cfaabi_dbg_ctx ); 552 verify( preemption.enabled ); 510 553 } 511 554 … … 513 556 __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n"); 514 557 558 verify( preemption.enabled ); 515 559 disable_interrupts(); 560 verify( !preemption.enabled ); 516 561 517 562 // SKULLDUGGERY: Notify the mainProcessor it needs to terminates.
Note: See TracChangeset
for help on using the changeset viewer.