Skip to content

Commit c375f15

Browse files
Vineet Guptatorvalds
authored andcommitted
x86: move fpu_counter into ARCH specific thread_struct
Only a couple of arches (sh/x86) use fpu_counter in task_struct so it can be moved out into ARCH specific thread_struct, reducing the size of task_struct for other arches. Compile tested i386_defconfig + gcc 4.7.3 Signed-off-by: Vineet Gupta <vgupta@synopsys.com> Acked-by: Ingo Molnar <mingo@kernel.org> Cc: Paul Mundt <paul.mundt@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 616c05d commit c375f15

6 files changed

Lines changed: 19 additions & 10 deletions

File tree

‎arch/x86/include/asm/fpu-internal.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static inline void drop_fpu(struct task_struct *tsk)
365365
* Forget coprocessor state..
366366
*/
367367
preempt_disable();
368-
tsk->fpu_counter = 0;
368+
tsk->thread.fpu_counter = 0;
369369
__drop_fpu(tsk);
370370
clear_used_math();
371371
preempt_enable();
@@ -424,7 +424,7 @@ static inline fpu_switch_t switch_fpu_prepare(struct task_struct *old, struct ta
424424
* or if the past 5 consecutive context-switches used math.
425425
*/
426426
fpu.preload = tsk_used_math(new) && (use_eager_fpu() ||
427-
new->fpu_counter > 5);
427+
new->thread.fpu_counter > 5);
428428
if (__thread_has_fpu(old)) {
429429
if (!__save_init_fpu(old))
430430
cpu = ~0;
@@ -433,16 +433,16 @@ static inline fpu_switch_t switch_fpu_prepare(struct task_struct *old, struct ta
433433

434434
/* Don't change CR0.TS if we just switch! */
435435
if (fpu.preload) {
436-
new->fpu_counter++;
436+
new->thread.fpu_counter++;
437437
__thread_set_has_fpu(new);
438438
prefetch(new->thread.fpu.state);
439439
} else if (!use_eager_fpu())
440440
stts();
441441
} else {
442-
old->fpu_counter = 0;
442+
old->thread.fpu_counter = 0;
443443
old->thread.fpu.last_cpu = ~0;
444444
if (fpu.preload) {
445-
new->fpu_counter++;
445+
new->thread.fpu_counter++;
446446
if (!use_eager_fpu() && fpu_lazy_restore(new, cpu))
447447
fpu.preload = 0;
448448
else

‎arch/x86/include/asm/processor.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,15 @@ struct thread_struct {
488488
unsigned long iopl;
489489
/* Max allowed port in the bitmap, in bytes: */
490490
unsigned io_bitmap_max;
491+
/*
492+
* fpu_counter contains the number of consecutive context switches
493+
* that the FPU is used. If this is over a threshold, the lazy fpu
494+
* saving becomes unlazy to save the trap. This is an unsigned char
495+
* so that after 256 times the counter wraps and the behavior turns
496+
* lazy again; this to deal with bursty apps that only use FPU for
497+
* a short time
498+
*/
499+
unsigned char fpu_counter;
491500
};
492501

493502
/*

‎arch/x86/kernel/i387.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void unlazy_fpu(struct task_struct *tsk)
100100
__save_init_fpu(tsk);
101101
__thread_fpu_end(tsk);
102102
} else
103-
tsk->fpu_counter = 0;
103+
tsk->thread.fpu_counter = 0;
104104
preempt_enable();
105105
}
106106
EXPORT_SYMBOL(unlazy_fpu);

‎arch/x86/kernel/process_32.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
153153
childregs->orig_ax = -1;
154154
childregs->cs = __KERNEL_CS | get_kernel_rpl();
155155
childregs->flags = X86_EFLAGS_IF | X86_EFLAGS_FIXED;
156-
p->fpu_counter = 0;
156+
p->thread.fpu_counter = 0;
157157
p->thread.io_bitmap_ptr = NULL;
158158
memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
159159
return 0;
@@ -166,7 +166,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
166166
p->thread.ip = (unsigned long) ret_from_fork;
167167
task_user_gs(p) = get_user_gs(current_pt_regs());
168168

169-
p->fpu_counter = 0;
169+
p->thread.fpu_counter = 0;
170170
p->thread.io_bitmap_ptr = NULL;
171171
tsk = current;
172172
err = -ENOMEM;

‎arch/x86/kernel/process_64.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
163163
p->thread.sp = (unsigned long) childregs;
164164
p->thread.usersp = me->thread.usersp;
165165
set_tsk_thread_flag(p, TIF_FORK);
166-
p->fpu_counter = 0;
166+
p->thread.fpu_counter = 0;
167167
p->thread.io_bitmap_ptr = NULL;
168168

169169
savesegment(gs, p->thread.gsindex);

‎arch/x86/kernel/traps.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ void math_state_restore(void)
653653
return;
654654
}
655655

656-
tsk->fpu_counter++;
656+
tsk->thread.fpu_counter++;
657657
}
658658
EXPORT_SYMBOL_GPL(math_state_restore);
659659

0 commit comments

Comments
 (0)