IOW, when the kernel does a context switch it does not save FP registers, but disables the FPU, thus FP register accesses/insns will generate a fault. Threads, which use only integer registers can be scheduled at will -- they will not generate such faults. We have saved gratuitous save/restore of FPU registers.
If a thread attempts to use the FPU, it traps into the kernel. Now there are two cases:
- the FPU contains the registers of that thread, in which case the FPU is simply enabled. We have saved gratuitous save/restore of the FPU state
- the FPU contains the register of some other thread, in which case they are saved into that threads state and the current thread's registers are restored.
~velco
hi ,I browse 2.6.0 source code .It seems the __switch_to functions does save the FP
registers if the FP registers was used by prev_p process.
struct task_struct * __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
{
struct thread_struct *prev = &prev_p->thread,
*next = &next_p->thread;
int cpu = smp_processor_id();
struct tss_struct *tss = init_tss + cpu;
/* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
__unlazy_fpu(prev_p); //look at this
But your idea is more efficient than kernel's implementation,the problem is that a variable is needed to save the process which used FP registers last time.
regards, Bao zhao
_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail
-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/