i386: inline restore_fpu
Quoted 8 lines
Since fxsave leaves the FPU state intact, there ought to be a better way to do this but it gets tricky. Maybe using the TSC to put a timestamp in every thread save area?
when saving FPU state:
put cpu# and timestamp in thread state info also store timestamp in per-cpu data
Quoted 8 lines
on task switch:
compare cpu# and timestamps for next task
if equal, clear TS and setTS_USEDFPUwhen state becomes invalid for some reason:
zero cpu's timestampBut the extra overhead might be too much in many cases.
Simpler:
- Thread has "CPU that I last used FPU on" pointer. Never NULL.
- Each CPU has "thread whose FPU state I hold" pointer. May be NULL.
When *loading* FPU state:
- Set up both pointers.
On task switch:
- If the pointers point to each other, then clear TS and skip restore. ("Preloaded")
When state becomes invalid (kernel MMX use, or whatever)
- Set CPU's pointer to NULL.
On thread creation:
- If current CPU's thread pointer points to the newly allocated thread, clear it to NULL.
- Set thread's CPU pointer to current CPU.
The UP case just omits the per-thread CPU pointer. (Well, stores it in zero bits.)
An alternative SMP thread-creation case would be to have a NULL value for the thread-to-CPU pointer and initialize the thread's CPU pointer to that, but that then complicates the UP case.