x86/fpu: Optimize fpu__save()
authorIngo Molnar <mingo@kernel.org>
Mon, 27 Apr 2015 07:45:12 +0000 (09:45 +0200)
committerIngo Molnar <mingo@kernel.org>
Tue, 19 May 2015 13:47:53 +0000 (15:47 +0200)
So fpu__save() does this currently:

copy_fpregs_to_fpstate(fpu);
if (!use_eager_fpu())
fpregs_deactivate(fpu);

... which deactivates the FPU on lazy switching systems unconditionally.

Both usecases of fpu__save() use this function to save the
FPU state into a fpstate: fork()/clone() and math error signal handling.

The unconditional disabling of FPU registers in the lazy switching
case is probably a mistaken conversion of old FNSAVE code (that had
to disable FPU registers).

So speed up this code by only disabling FPU registers when absolutely
necessary: when indicated by the copy_fpregs_to_fpstate() return
code:

if (!copy_fpregs_to_fpstate(fpu))
fpregs_deactivate(fpu);

Reviewed-by: Borislav Petkov <bp@alien8.de>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/kernel/fpu/core.c

index a0b2221b686d23ad7376fefc430d996c525d3713..b1fbbb8eb934ca75e580ac036d84786b6fd30424 100644 (file)
@@ -170,7 +170,7 @@ void irq_ts_restore(int TS_state)
 EXPORT_SYMBOL_GPL(irq_ts_restore);
 
 /*
- * Save the FPU state (initialize it if necessary):
+ * Save the FPU state (mark it for reload if necessary):
  *
  * This only ever gets called for the current task.
  */
@@ -180,8 +180,7 @@ void fpu__save(struct fpu *fpu)
 
        preempt_disable();
        if (fpu->fpregs_active) {
-               copy_fpregs_to_fpstate(fpu);
-               if (!use_eager_fpu())
+               if (!copy_fpregs_to_fpstate(fpu))
                        fpregs_deactivate(fpu);
        }
        preempt_enable();