Brendan's Multi-tasking Tutorial: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
Brendan (talk | contribs)
Added some stuff for after multi-tasking is working
Brendan (talk | contribs)
m Correction..
Line 952:
==Adding FPU/MMX/SSE/AVX Support (80x86 only)==
 
Originally (for80386, single-CPU) Intel designed theprotected FPUmode so that an OS can avoid saving/loading FPU state during task switches. The general idea was to keep track of an "FPU owner" and use a flag ("TS" in EFLAGS) to indicate when the currently running task isn't the FPU owner. If the CPU executes an instruction that uses FPU but the current task isn't the FPU owner, then the CPU raises an exception (because "TS" is set), and the exception handler saves the FPU state (belonging to a different task) and loads the FPU state for the currently running task. This can (in some cases) improve performance a lot - for example, if you have 100 tasks running where only one uses FPU, you'd never need to save or load FPU state. Intel continued this original idea when newer extensions (MMX, SSE, AVX) where added (although for AVX the implementation is significantly different).
 
However; when almost all tasks are using FPU/MMX/SSE/AVX state, it makes performance worse (due to the extra cost of an inevitable exception); and it doesn't work well for multi-CPU (where the currently running task's FPU state may still be in a completely different CPU).