Skip to content

Commit 8792468

Browse files
cyrilbur-ibmmpe
authored andcommitted
powerpc: Add the ability to save FPU without giving it up
This patch adds the ability to be able to save the FPU registers to the thread struct without giving up (disabling the facility) next time the process returns to userspace. This patch optimises the thread copy path (as a result of a fork() or clone()) so that the parent thread can return to userspace with hot registers avoiding a possibly pointless reload of FPU register state. Signed-off-by: Cyril Bur <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent de2a20a commit 8792468

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

arch/powerpc/include/asm/switch_to.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ extern void giveup_all(struct task_struct *);
2828
extern void enable_kernel_fp(void);
2929
extern void flush_fp_to_thread(struct task_struct *);
3030
extern void giveup_fpu(struct task_struct *);
31-
extern void __giveup_fpu(struct task_struct *);
31+
extern void save_fpu(struct task_struct *);
3232
static inline void disable_kernel_fp(void)
3333
{
3434
msr_check_and_clear(MSR_FP);
3535
}
3636
#else
3737
static inline void __giveup_fpu(struct task_struct *t) { }
38+
static inline void save_fpu(struct task_struct *t) { }
3839
static inline void flush_fp_to_thread(struct task_struct *t) { }
3940
#endif
4041

arch/powerpc/kernel/fpu.S

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,33 +143,20 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX)
143143
blr
144144

145145
/*
146-
* __giveup_fpu(tsk)
147-
* Disable FP for the task given as the argument,
148-
* and save the floating-point registers in its thread_struct.
146+
* save_fpu(tsk)
147+
* Save the floating-point registers in its thread_struct.
149148
* Enables the FPU for use in the kernel on return.
150149
*/
151-
_GLOBAL(__giveup_fpu)
150+
_GLOBAL(save_fpu)
152151
addi r3,r3,THREAD /* want THREAD of task */
153152
PPC_LL r6,THREAD_FPSAVEAREA(r3)
154153
PPC_LL r5,PT_REGS(r3)
155154
PPC_LCMPI 0,r6,0
156155
bne 2f
157156
addi r6,r3,THREAD_FPSTATE
158-
2: PPC_LCMPI 0,r5,0
159-
SAVE_32FPVSRS(0, R4, R6)
157+
2: SAVE_32FPVSRS(0, R4, R6)
160158
mffs fr0
161159
stfd fr0,FPSTATE_FPSCR(r6)
162-
beq 1f
163-
PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
164-
li r3,MSR_FP|MSR_FE0|MSR_FE1
165-
#ifdef CONFIG_VSX
166-
BEGIN_FTR_SECTION
167-
oris r3,r3,MSR_VSX@h
168-
END_FTR_SECTION_IFSET(CPU_FTR_VSX)
169-
#endif
170-
andc r4,r4,r3 /* disable FP for previous task */
171-
PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
172-
1:
173160
blr
174161

175162
/*

arch/powerpc/kernel/process.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ void __msr_check_and_clear(unsigned long bits)
133133
EXPORT_SYMBOL(__msr_check_and_clear);
134134

135135
#ifdef CONFIG_PPC_FPU
136+
void __giveup_fpu(struct task_struct *tsk)
137+
{
138+
save_fpu(tsk);
139+
tsk->thread.regs->msr &= ~MSR_FP;
140+
#ifdef CONFIG_VSX
141+
if (cpu_has_feature(CPU_FTR_VSX))
142+
tsk->thread.regs->msr &= ~MSR_VSX;
143+
#endif
144+
}
145+
136146
void giveup_fpu(struct task_struct *tsk)
137147
{
138148
check_if_tm_restore_required(tsk);
@@ -459,7 +469,7 @@ void save_all(struct task_struct *tsk)
459469
msr_check_and_set(msr_all_available);
460470

461471
if (usermsr & MSR_FP)
462-
__giveup_fpu(tsk);
472+
save_fpu(tsk);
463473

464474
if (usermsr & MSR_VEC)
465475
__giveup_altivec(tsk);

0 commit comments

Comments
 (0)