- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r8fc652e0 r58688bf 122 122 // Because of a bug, we couldn't initialized the seed on construction 123 123 // Do it here 124 __cfaabi_tls.rand_seed ^= rdtscl();125 __cfaabi_tls.ready_rng.fwd_seed = 25214903917_l64u * (rdtscl() ^ (uintptr_t)&runner);124 kernelTLS.rand_seed ^= rdtscl(); 125 kernelTLS.ready_rng.fwd_seed = 25214903917_l64u * (rdtscl() ^ (uintptr_t)&runner); 126 126 __tls_rand_advance_bck(); 127 127 … … 217 217 // and it make sense for it to be set in all other cases except here 218 218 // fake it 219 __cfaabi_tls.this_thread = mainThread;219 kernelTLS.this_thread = mainThread; 220 220 } 221 221 … … 230 230 // from the processor coroutine to the target thread 231 231 static void __run_thread(processor * this, $thread * thrd_dst) { 232 /* paranoid */ verify( ! __preemption_enabled());232 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 233 233 /* paranoid */ verifyf( thrd_dst->state == Ready || thrd_dst->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", thrd_dst->state, thrd_dst->preempted); 234 234 /* paranoid */ verifyf( thrd_dst->link.next == 0p, "Expected null got %p", thrd_dst->link.next ); … … 247 247 248 248 // Update global state 249 kernelTLS ().this_thread = thrd_dst;250 251 /* paranoid */ verify( ! __preemption_enabled());252 /* paranoid */ verify( kernelTLS ().this_thread == thrd_dst );249 kernelTLS.this_thread = thrd_dst; 250 251 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 252 /* paranoid */ verify( kernelTLS.this_thread == thrd_dst ); 253 253 /* paranoid */ verify( thrd_dst->context.SP ); 254 254 /* paranoid */ verify( thrd_dst->state != Halted ); … … 267 267 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ), "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); 268 268 /* paranoid */ verify( thrd_dst->context.SP ); 269 /* paranoid */ verify( kernelTLS ().this_thread == thrd_dst );270 /* paranoid */ verify( ! __preemption_enabled());269 /* paranoid */ verify( kernelTLS.this_thread == thrd_dst ); 270 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 271 271 272 272 // Reset global state 273 kernelTLS ().this_thread = 0p;273 kernelTLS.this_thread = 0p; 274 274 275 275 // We just finished running a thread, there are a few things that could have happened. … … 315 315 proc_cor->state = Active; 316 316 317 /* paranoid */ verify( ! __preemption_enabled());317 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 318 318 } 319 319 320 320 // KERNEL_ONLY 321 321 void returnToKernel() { 322 /* paranoid */ verify( ! __preemption_enabled());323 $coroutine * proc_cor = get_coroutine(kernelTLS ().this_processor->runner);324 $thread * thrd_src = kernelTLS ().this_thread;322 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 323 $coroutine * proc_cor = get_coroutine(kernelTLS.this_processor->runner); 324 $thread * thrd_src = kernelTLS.this_thread; 325 325 326 326 #if !defined(__CFA_NO_STATISTICS__) 327 struct processor * last_proc = kernelTLS ().this_processor;327 struct processor * last_proc = kernelTLS.this_processor; 328 328 #endif 329 329 … … 345 345 346 346 #if !defined(__CFA_NO_STATISTICS__) 347 if(last_proc != kernelTLS ().this_processor) {347 if(last_proc != kernelTLS.this_processor) { 348 348 __tls_stats()->ready.threads.migration++; 349 349 } 350 350 #endif 351 351 352 /* paranoid */ verify( ! __preemption_enabled());352 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 353 353 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ), "ERROR : Returning $thread %p has been corrupted.\n StackPointer too small.\n", thrd_src ); 354 354 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit), "ERROR : Returning $thread %p has been corrupted.\n StackPointer too large.\n", thrd_src ); … … 359 359 // KERNEL ONLY 360 360 void __schedule_thread( $thread * thrd ) { 361 /* paranoid */ verify( ! __preemption_enabled() );362 361 /* paranoid */ verify( thrd ); 363 362 /* paranoid */ verify( thrd->state != Halted ); 364 /* paranoid */ verify( kernelTLS().this_proc_id ); 363 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 364 /* paranoid */ verify( kernelTLS.this_proc_id ); 365 365 /* paranoid */ #if defined( __CFA_WITH_VERIFY__ ) 366 366 /* paranoid */ if( thrd->state == Blocked || thrd->state == Start ) assertf( thrd->preempted == __NO_PREEMPTION, … … 380 380 ready_schedule_unlock(); 381 381 382 /* paranoid */ verify( ! __preemption_enabled());382 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 383 383 } 384 384 385 385 // KERNEL ONLY 386 386 static inline $thread * __next_thread(cluster * this) with( *this ) { 387 /* paranoid */ verify( ! __preemption_enabled());388 /* paranoid */ verify( kernelTLS().this_proc_id );387 /* paranoid */ verify( kernelTLS.this_proc_id ); 388 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 389 389 390 390 ready_schedule_lock(); … … 392 392 ready_schedule_unlock(); 393 393 394 /* paranoid */ verify( kernelTLS().this_proc_id );395 /* paranoid */ verify( ! __preemption_enabled());394 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 395 /* paranoid */ verify( kernelTLS.this_proc_id ); 396 396 return thrd; 397 397 } … … 399 399 // KERNEL ONLY 400 400 static inline $thread * __next_thread_slow(cluster * this) with( *this ) { 401 /* paranoid */ verify( ! __preemption_enabled());402 /* paranoid */ verify( kernelTLS().this_proc_id );401 /* paranoid */ verify( kernelTLS.this_proc_id ); 402 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 403 403 404 404 ready_schedule_lock(); … … 406 406 ready_schedule_unlock(); 407 407 408 /* paranoid */ verify( kernelTLS().this_proc_id );409 /* paranoid */ verify( ! __preemption_enabled());408 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 409 /* paranoid */ verify( kernelTLS.this_proc_id ); 410 410 return thrd; 411 411 } … … 414 414 if( !thrd ) return; 415 415 416 /* paranoid */ verify( kernelTLS.this_proc_id ); 417 bool full = kernelTLS.this_proc_id->full_proc; 418 if(full) disable_interrupts(); 419 420 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 416 421 int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST); 417 422 switch(old_ticket) { … … 423 428 /* paranoid */ verify( thrd->state == Blocked ); 424 429 425 { 426 /* paranoid */ verify( publicTLS_get(this_proc_id) ); 427 bool full = publicTLS_get(this_proc_id)->full_proc; 428 if(full) disable_interrupts(); 429 430 /* paranoid */ verify( ! __preemption_enabled() ); 431 432 // Wake lost the race, 433 __schedule_thread( thrd ); 434 435 /* paranoid */ verify( ! __preemption_enabled() ); 436 437 if(full) enable_interrupts( __cfaabi_dbg_ctx ); 438 /* paranoid */ verify( publicTLS_get(this_proc_id) ); 439 } 440 430 // Wake lost the race, 431 __schedule_thread( thrd ); 441 432 break; 442 433 default: … … 444 435 abort("Thread %p (%s) has mismatch park/unpark\n", thrd, thrd->self_cor.name); 445 436 } 437 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 438 439 if(full) enable_interrupts( __cfaabi_dbg_ctx ); 440 /* paranoid */ verify( kernelTLS.this_proc_id ); 446 441 } 447 442 448 443 void park( void ) { 449 /* paranoid */ verify( __preemption_enabled());444 /* paranoid */ verify( kernelTLS.preemption_state.enabled ); 450 445 disable_interrupts(); 451 /* paranoid */ verify( ! __preemption_enabled());452 /* paranoid */ verify( kernelTLS ().this_thread->preempted == __NO_PREEMPTION );446 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 447 /* paranoid */ verify( kernelTLS.this_thread->preempted == __NO_PREEMPTION ); 453 448 454 449 returnToKernel(); 455 450 456 /* paranoid */ verify( ! __preemption_enabled());451 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 457 452 enable_interrupts( __cfaabi_dbg_ctx ); 458 /* paranoid */ verify( __preemption_enabled());453 /* paranoid */ verify( kernelTLS.preemption_state.enabled ); 459 454 460 455 } … … 465 460 // Should never return 466 461 void __cfactx_thrd_leave() { 467 $thread * thrd = active_thread();462 $thread * thrd = TL_GET( this_thread ); 468 463 $monitor * this = &thrd->self_mon; 469 464 … … 478 473 479 474 // Leave the thread 480 /* paranoid */ verify( ! __preemption_enabled());475 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 481 476 returnToKernel(); 482 477 abort(); … … 488 483 // KERNEL ONLY 489 484 bool force_yield( __Preemption_Reason reason ) { 490 /* paranoid */ verify( __preemption_enabled());485 /* paranoid */ verify( kernelTLS.preemption_state.enabled ); 491 486 disable_interrupts(); 492 /* paranoid */ verify( ! __preemption_enabled());493 494 $thread * thrd = kernelTLS ().this_thread;487 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 488 489 $thread * thrd = kernelTLS.this_thread; 495 490 /* paranoid */ verify(thrd->state == Active); 496 491 … … 506 501 } 507 502 508 /* paranoid */ verify( ! __preemption_enabled());503 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 509 504 enable_interrupts_noPoll(); 510 /* paranoid */ verify( __preemption_enabled());505 /* paranoid */ verify( kernelTLS.preemption_state.enabled ); 511 506 512 507 return preempted; … … 518 513 // Wake a thread from the front if there are any 519 514 static void __wake_one(cluster * this) { 520 /* paranoid */ verify( ! __preemption_enabled());515 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 521 516 /* paranoid */ verify( ready_schedule_islocked() ); 522 517 … … 538 533 539 534 /* paranoid */ verify( ready_schedule_islocked() ); 540 /* paranoid */ verify( ! __preemption_enabled());535 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 541 536 542 537 return; … … 548 543 549 544 disable_interrupts(); 550 /* paranoid */ verify( ! __preemption_enabled());545 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 551 546 post( this->idle ); 552 547 enable_interrupts( __cfaabi_dbg_ctx ); … … 554 549 555 550 static void push (__cluster_idles & this, processor & proc) { 556 /* paranoid */ verify( ! __preemption_enabled());551 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 557 552 lock( this ); 558 553 this.idle++; … … 561 556 insert_first(this.list, proc); 562 557 unlock( this ); 563 /* paranoid */ verify( ! __preemption_enabled());558 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 564 559 } 565 560 566 561 static void remove(__cluster_idles & this, processor & proc) { 567 /* paranoid */ verify( ! __preemption_enabled());562 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 568 563 lock( this ); 569 564 this.idle--; … … 572 567 remove(proc); 573 568 unlock( this ); 574 /* paranoid */ verify( ! __preemption_enabled());569 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 575 570 } 576 571 … … 616 611 } 617 612 618 return __cfaabi_tls.this_thread;613 return kernelTLS.this_thread; 619 614 } 620 615 … … 641 636 642 637 int kernel_abort_lastframe( void ) __attribute__ ((__nothrow__)) { 643 return get_coroutine(kernelTLS ().this_thread) == get_coroutine(mainThread) ? 4 : 2;638 return get_coroutine(kernelTLS.this_thread) == get_coroutine(mainThread) ? 4 : 2; 644 639 } 645 640 … … 673 668 if ( count < 0 ) { 674 669 // queue current task 675 append( waiting, active_thread());670 append( waiting, kernelTLS.this_thread ); 676 671 677 672 // atomically release spin lock and block … … 723 718 void __cfaabi_dbg_record_lock(__spinlock_t & this, const char prev_name[]) { 724 719 this.prev_name = prev_name; 725 this.prev_thrd = kernelTLS ().this_thread;720 this.prev_thrd = kernelTLS.this_thread; 726 721 } 727 722 }
Note: See TracChangeset
for help on using the changeset viewer.