Skip to content

Commit 55bc30f

Browse files
author
Ingo Molnar
committed
x86/fpu: Remove the thread::fpu pointer
As suggested by Oleg, remove the thread::fpu pointer, as we can calculate it via x86_task_fpu() at compile-time. This improves code generation a bit: kepler:~/tip> size vmlinux.before vmlinux.after text data bss dec hex filename 26475405 10435342 1740804 38651551 24dc69f vmlinux.before 26475339 10959630 1216516 38651485 24dc65d vmlinux.after Suggested-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Brian Gerst <brgerst@gmail.com> Cc: Chang S. Bae <chang.seok.bae@intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Uros Bizjak <ubizjak@gmail.com> Link: https://lore.kernel.org/r/20250409211127.3544993-5-mingo@kernel.org
1 parent cb7ca40 commit 55bc30f

File tree

5 files changed

+6
-10
lines changed

5 files changed

+6
-10
lines changed

arch/x86/include/asm/processor.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,9 @@ struct thread_struct {
514514

515515
struct thread_shstk shstk;
516516
#endif
517-
518-
/* Floating point and extended processor state */
519-
struct fpu *fpu;
520517
};
521518

522-
#define x86_task_fpu(task) ((task)->thread.fpu)
519+
#define x86_task_fpu(task) ((struct fpu *)((void *)(task) + sizeof(*(task))))
523520

524521
/*
525522
* X86 doesn't need any embedded-FPU-struct quirks:

arch/x86/kernel/fpu/core.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,11 @@ int fpu_clone(struct task_struct *dst, unsigned long clone_flags, bool minimal,
600600
* This is safe because task_struct size is a multiple of cacheline size.
601601
*/
602602
struct fpu *src_fpu = x86_task_fpu(current);
603-
struct fpu *dst_fpu = (void *)dst + sizeof(*dst);
603+
struct fpu *dst_fpu = x86_task_fpu(dst);
604604

605605
BUILD_BUG_ON(sizeof(*dst) % SMP_CACHE_BYTES != 0);
606606
BUG_ON(!src_fpu);
607607

608-
dst->thread.fpu = dst_fpu;
609-
610608
/* The new task's FPU state cannot be valid in the hardware. */
611609
dst_fpu->last_cpu = -1;
612610

arch/x86/kernel/fpu/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ static struct fpu x86_init_fpu __attribute__ ((aligned (64))) __read_mostly;
7676
static void __init fpu__init_system_early_generic(void)
7777
{
7878
fpstate_reset(&x86_init_fpu);
79-
current->thread.fpu = &x86_init_fpu;
8079
set_thread_flag(TIF_NEED_FPU_LOAD);
8180
x86_init_fpu.last_cpu = -1;
8281

arch/x86/kernel/process.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
102102
#ifdef CONFIG_VM86
103103
dst->thread.vm86 = NULL;
104104
#endif
105-
/* Drop the copied pointer to current's fpstate */
106-
dst->thread.fpu = NULL;
107105

108106
return 0;
109107
}

arch/x86/kernel/vmlinux.lds.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ SECTIONS
181181
/* equivalent to task_pt_regs(&init_task) */
182182
__top_init_kernel_stack = __end_init_stack - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE;
183183

184+
__x86_init_fpu_begin = .;
185+
. = __x86_init_fpu_begin + 128*PAGE_SIZE;
186+
__x86_init_fpu_end = .;
187+
184188
#ifdef CONFIG_X86_32
185189
/* 32 bit has nosave before _edata */
186190
NOSAVE_DATA

0 commit comments

Comments
 (0)