question about lazy FPU restore
Hi Suresh,
I have a question about the lazy fpu restore code in switch_fpu_prepare. Specifically, about the case where the old task did not use the FPU, and the new task's FPU state is still in the cpu.
} else {
old->fpu_counter = 0;
old->thread.fpu.last_cpu = ~0;
if (fpu.preload) {
new->fpu_counter++;
if (!use_eager_fpu() && fpu_lazy_restore(new, cpu))
fpu.preload = 0;
else
prefetch(new->thread.fpu.state);
__thread_fpu_begin(new);
}
}In this branch, we call fpu_lazy_restore, which confirms that the CPU still has the new task's state in it.
However, if we are in eager fpu mode, we still end up calling restore_fpu_checking from switch_fpu_finish, even if the new task's FPU state is still resident in the CPU.
Is there a particular reason we do this?
Would it be possible to always set fpu.preload = 0, call clts, and __thread_set_has_fpu if fpu_lazy_restore returns true?
That would allow us to skip the loading of FPU state when re-entering a process that went briefly idle, before getting something else to do, a common occurrance in message passing workloads.