Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/fpu: Default eagerfpu=on on all CPUs

We have eager and lazy FPU modes, introduced in:

304bceda6a18 ("x86, fpu: use non-lazy fpu restore for processors supporting xsave")

The result is rather messy. There are two code paths in almost all
of the FPU code, and only one of them (the eager case) is tested
frequently, since most kernel developers have new enough hardware
that we use eagerfpu.

It seems that, on any remotely recent hardware, eagerfpu is a win:
glibc uses SSE2, so laziness is probably overoptimistic, and, in any
case, manipulating TS is far slower that saving and restoring the
full state. (Stores to CR0.TS are serializing and are poorly
optimized.)

To try to shake out any latent issues on old hardware, this changes
the default to eager on all CPUs. If no performance or functionality
problems show up, a subsequent patch could remove lazy mode entirely.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
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: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: yu-cheng yu <yu-cheng.yu@intel.com>
Link: http://lkml.kernel.org/r/ac290de61bf08d9cfc2664a4f5080257ffc1075a.1453675014.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Andy Lutomirski and committed by
Ingo Molnar
58122bf1 c6ab109f

+5 -8
+5 -8
arch/x86/kernel/fpu/init.c
··· 260 260 * not only saved the restores along the way, but we also have the 261 261 * FPU ready to be used for the original task. 262 262 * 263 - * 'eager' switching is used on modern CPUs, there we switch the FPU 263 + * 'lazy' is deprecated because it's almost never a performance win 264 + * and it's much more complicated than 'eager'. 265 + * 266 + * 'eager' switching is by default on all CPUs, there we switch the FPU 264 267 * state during every context switch, regardless of whether the task 265 268 * has used FPU instructions in that time slice or not. This is done 266 269 * because modern FPU context saving instructions are able to optimize ··· 274 271 * to use 'eager' restores, if we detect that a task is using the FPU 275 272 * frequently. See the fpu->counter logic in fpu/internal.h for that. ] 276 273 */ 277 - static enum { AUTO, ENABLE, DISABLE } eagerfpu = AUTO; 274 + static enum { ENABLE, DISABLE } eagerfpu = ENABLE; 278 275 279 276 /* 280 277 * Find supported xfeatures based on cpu features and command-line input. ··· 351 348 */ 352 349 static void __init fpu__init_parse_early_param(void) 353 350 { 354 - /* 355 - * No need to check "eagerfpu=auto" again, since it is the 356 - * initial default. 357 - */ 358 351 if (cmdline_find_option_bool(boot_command_line, "eagerfpu=off")) { 359 352 eagerfpu = DISABLE; 360 353 fpu__clear_eager_fpu_features(); 361 - } else if (cmdline_find_option_bool(boot_command_line, "eagerfpu=on")) { 362 - eagerfpu = ENABLE; 363 354 } 364 355 365 356 if (cmdline_find_option_bool(boot_command_line, "no387"))