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

x86/fpu: Factor out fpu__flush_thread() from flush_thread()

flush_thread() open codes a lot of FPU internals - create a separate
function for it in fpu/core.c.

Turns out that this does not hurt performance:

text data bss dec hex filename
11843039 1884440 1130496 14857975 e2b6f7 vmlinux.before
11843039 1884440 1130496 14857975 e2b6f7 vmlinux.after

and since this is a slowpath clarity comes first anyway.

We can reconsider inlining decisions after the FPU code has been cleaned up.

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>

+19 -13
+1
arch/x86/include/asm/i387.h
··· 20 20 21 21 extern int fpstate_alloc_init(struct task_struct *curr); 22 22 extern void fpstate_init(struct fpu *fpu); 23 + extern void fpu__flush_thread(struct task_struct *tsk); 23 24 24 25 extern int dump_fpu(struct pt_regs *, struct user_i387_struct *); 25 26 extern void math_state_restore(void);
+17
arch/x86/kernel/fpu/core.c
··· 227 227 return 0; 228 228 } 229 229 230 + void fpu__flush_thread(struct task_struct *tsk) 231 + { 232 + if (!use_eager_fpu()) { 233 + /* FPU state will be reallocated lazily at the first use. */ 234 + drop_fpu(tsk); 235 + fpstate_free(&tsk->thread.fpu); 236 + } else { 237 + if (!tsk_used_math(tsk)) { 238 + /* kthread execs. TODO: cleanup this horror. */ 239 + if (WARN_ON(fpstate_alloc_init(tsk))) 240 + force_sig(SIGKILL, tsk); 241 + user_fpu_begin(); 242 + } 243 + restore_init_xstate(); 244 + } 245 + } 246 + 230 247 /* 231 248 * The xstateregs_active() routine is the same as the fpregs_active() routine, 232 249 * as the "regset->n" for the xstate regset will be updated based on the feature
+1 -13
arch/x86/kernel/process.c
··· 146 146 flush_ptrace_hw_breakpoint(tsk); 147 147 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array)); 148 148 149 - if (!use_eager_fpu()) { 150 - /* FPU state will be reallocated lazily at the first use. */ 151 - drop_fpu(tsk); 152 - fpstate_free(&tsk->thread.fpu); 153 - } else { 154 - if (!tsk_used_math(tsk)) { 155 - /* kthread execs. TODO: cleanup this horror. */ 156 - if (WARN_ON(fpstate_alloc_init(tsk))) 157 - force_sig(SIGKILL, tsk); 158 - user_fpu_begin(); 159 - } 160 - restore_init_xstate(); 161 - } 149 + fpu__flush_thread(tsk); 162 150 } 163 151 164 152 static void hard_disable_TSC(void)