Changeset 06f81c4 in mainline
- Timestamp:
- 2023-04-16T13:00:39Z (20 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d8581611, f3dbe27
- Parents:
- fbaf6ac
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-03-28 16:21:30)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-04-16 13:00:39)
- Location:
- kernel/generic
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/cpu.h
rfbaf6ac r06f81c4 97 97 cpu_arch_t arch; 98 98 99 #ifdef CONFIG_FPU_LAZY 99 100 IRQ_SPINLOCK_DECLARE(fpu_lock); 100 101 struct thread *fpu_owner; 102 #endif 101 103 102 104 /** -
kernel/generic/include/proc/thread.h
rfbaf6ac r06f81c4 132 132 bool fpu_context_exists; 133 133 134 /*135 * Defined only if thread doesn't run.136 * It means that fpu context is in CPU that last time executes this137 * thread. This disables migration.138 */139 bool fpu_context_engaged;140 141 134 /* The thread will not be migrated if nomigrate is non-zero. */ 142 135 unsigned int nomigrate; -
kernel/generic/src/cpu/cpu.c
rfbaf6ac r06f81c4 84 84 cpus[i].id = i; 85 85 86 #ifdef CONFIG_FPU_LAZY 86 87 irq_spinlock_initialize(&cpus[i].fpu_lock, "cpus[].fpu_lock"); 88 #endif 87 89 irq_spinlock_initialize(&cpus[i].tlb_lock, "cpus[].tlb_lock"); 88 90 -
kernel/generic/src/proc/scheduler.c
rfbaf6ac r06f81c4 84 84 85 85 #ifdef CONFIG_FPU_LAZY 86 irq_spinlock_lock(&CPU->fpu_lock, true); 87 86 88 if (THREAD == CPU->fpu_owner) 87 89 fpu_enable(); 88 90 else 89 91 fpu_disable(); 92 93 irq_spinlock_unlock(&CPU->fpu_lock, true); 90 94 #elif defined CONFIG_FPU 91 95 fpu_enable(); … … 133 137 /* Save old context */ 134 138 if (CPU->fpu_owner != NULL) { 135 irq_spinlock_lock(&CPU->fpu_owner->lock, false);136 139 fpu_context_save(&CPU->fpu_owner->fpu_context); 137 138 /* Don't prevent migration */139 CPU->fpu_owner->fpu_context_engaged = false;140 irq_spinlock_unlock(&CPU->fpu_owner->lock, false);141 140 CPU->fpu_owner = NULL; 142 141 } 143 142 144 irq_spinlock_lock(&THREAD->lock, false);145 143 if (THREAD->fpu_context_exists) { 146 144 fpu_context_restore(&THREAD->fpu_context); … … 151 149 152 150 CPU->fpu_owner = THREAD; 153 THREAD->fpu_context_engaged = true;154 irq_spinlock_unlock(&THREAD->lock, false);155 151 156 152 irq_spinlock_unlock(&CPU->fpu_lock, false); … … 503 499 #ifdef CONFIG_SMP 504 500 501 static inline void fpu_owner_lock(cpu_t *cpu) 502 { 503 #ifdef CONFIG_FPU_LAZY 504 irq_spinlock_lock(&cpu->fpu_lock, false); 505 #endif 506 } 507 508 static inline void fpu_owner_unlock(cpu_t *cpu) 509 { 510 #ifdef CONFIG_FPU_LAZY 511 irq_spinlock_unlock(&cpu->fpu_lock, false); 512 #endif 513 } 514 515 static inline thread_t *fpu_owner(cpu_t *cpu) 516 { 517 #ifdef CONFIG_FPU_LAZY 518 assert(irq_spinlock_locked(&cpu->fpu_lock)); 519 return cpu->fpu_owner; 520 #else 521 return NULL; 522 #endif 523 } 524 505 525 static thread_t *steal_thread_from(cpu_t *old_cpu, int i) 506 526 { … … 508 528 runq_t *new_rq = &CPU->rq[i]; 509 529 510 irq_spinlock_lock(&old_rq->lock, true); 530 ipl_t ipl = interrupts_disable(); 531 532 fpu_owner_lock(old_cpu); 533 irq_spinlock_lock(&old_rq->lock, false); 511 534 512 535 /* Search rq from the back */ … … 521 544 * FPU context is still in the CPU. 522 545 */ 523 if (thread->stolen || thread->nomigrate || thread->fpu_context_engaged) { 546 if (thread->stolen || thread->nomigrate || 547 thread == fpu_owner(old_cpu)) { 524 548 irq_spinlock_unlock(&thread->lock, false); 525 549 continue; 526 550 } 551 552 fpu_owner_unlock(old_cpu); 527 553 528 554 thread->stolen = true; … … 546 572 old_rq->n--; 547 573 list_remove(&thread->rq_link); 548 549 irq_spinlock_pass(&old_rq->lock, &new_rq->lock); 574 irq_spinlock_unlock(&old_rq->lock, false); 550 575 551 576 /* Append thread to local queue. */ 577 irq_spinlock_lock(&new_rq->lock, false); 552 578 list_append(&thread->rq_link, &new_rq->rq); 553 579 new_rq->n++; 554 555 irq_spinlock_unlock(&new_rq->lock, true); 580 irq_spinlock_unlock(&new_rq->lock, false); 556 581 557 582 atomic_dec(&old_cpu->nrdy); 558 583 atomic_inc(&CPU->nrdy); 559 584 interrupts_restore(ipl); 560 585 return thread; 561 586 } 562 587 563 irq_spinlock_unlock(&old_rq->lock, true); 588 irq_spinlock_unlock(&old_rq->lock, false); 589 fpu_owner_unlock(old_cpu); 590 interrupts_restore(ipl); 564 591 return NULL; 565 592 } -
kernel/generic/src/proc/thread.c
rfbaf6ac r06f81c4 355 355 356 356 thread->fpu_context_exists = false; 357 thread->fpu_context_engaged = false;358 357 359 358 odlink_initialize(&thread->lthreads);
Note:
See TracChangeset
for help on using the changeset viewer.