aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/include
diff options
context:
space:
mode:
authorStuart Menefy <stuart.menefy@st.com>2009-09-25 13:25:10 -0400
committerPaul Mundt <lethal@linux-sh.org>2009-11-24 03:45:38 -0500
commitd3ea9fa0a563620fe9f416f94bb8927c64390917 (patch)
tree0aa1278ac7929f936fc4fd8daf235930f6164d18 /arch/sh/include
parent39ac11c1607f1d566e7cf885acd403fa4f07f8a2 (diff)
sh: Minor optimisations to FPU handling
A number of small optimisations to FPU handling, in particular: - move the task USEDFPU flag from the thread_info flags field (which is accessed asynchronously to the thread) to a new status field, which is only accessed by the thread itself. This allows locking to be removed in most cases, or can be reduced to a preempt_lock(). This mimics the i386 behaviour. - move the modification of regs->sr and thread_info->status flags out of save_fpu() to __unlazy_fpu(). This gives the compiler a better chance to optimise things, as well as making save_fpu() symmetrical with restore_fpu() and init_fpu(). - implement prepare_to_copy(), so that when creating a thread, we can unlazy the FPU prior to copying the thread data structures. Also make sure that the FPU is disabled while in the kernel, in particular while booting, and for newly created kernel threads, In a very artificial benchmark, the execution time for 2500000 context switches was reduced from 50 to 45 seconds. Signed-off-by: Stuart Menefy <stuart.menefy@st.com> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'arch/sh/include')
-rw-r--r--arch/sh/include/asm/fpu.h26
-rw-r--r--arch/sh/include/asm/processor_32.h3
-rw-r--r--arch/sh/include/asm/thread_info.h4
3 files changed, 19 insertions, 14 deletions
diff --git a/arch/sh/include/asm/fpu.h b/arch/sh/include/asm/fpu.h
index bfd78e19de1..d7709c06fac 100644
--- a/arch/sh/include/asm/fpu.h
+++ b/arch/sh/include/asm/fpu.h
@@ -18,17 +18,14 @@ static inline void grab_fpu(struct pt_regs *regs)
18 18
19struct task_struct; 19struct task_struct;
20 20
21extern void save_fpu(struct task_struct *__tsk, struct pt_regs *regs); 21extern void save_fpu(struct task_struct *__tsk);
22void fpu_state_restore(struct pt_regs *regs); 22void fpu_state_restore(struct pt_regs *regs);
23#else 23#else
24 24
25#define save_fpu(tsk) do { } while (0)
25#define release_fpu(regs) do { } while (0) 26#define release_fpu(regs) do { } while (0)
26#define grab_fpu(regs) do { } while (0) 27#define grab_fpu(regs) do { } while (0)
27 28
28static inline void save_fpu(struct task_struct *tsk, struct pt_regs *regs)
29{
30 clear_tsk_thread_flag(tsk, TIF_USEDFPU);
31}
32#endif 29#endif
33 30
34struct user_regset; 31struct user_regset;
@@ -40,21 +37,28 @@ extern int fpregs_get(struct task_struct *target,
40 unsigned int pos, unsigned int count, 37 unsigned int pos, unsigned int count,
41 void *kbuf, void __user *ubuf); 38 void *kbuf, void __user *ubuf);
42 39
40static inline void __unlazy_fpu(struct task_struct *tsk, struct pt_regs *regs)
41{
42 if (task_thread_info(tsk)->status & TS_USEDFPU) {
43 task_thread_info(tsk)->status &= ~TS_USEDFPU;
44 save_fpu(tsk);
45 release_fpu(regs);
46 } else
47 tsk->fpu_counter = 0;
48}
49
43static inline void unlazy_fpu(struct task_struct *tsk, struct pt_regs *regs) 50static inline void unlazy_fpu(struct task_struct *tsk, struct pt_regs *regs)
44{ 51{
45 preempt_disable(); 52 preempt_disable();
46 if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) 53 __unlazy_fpu(tsk, regs);
47 save_fpu(tsk, regs);
48 else
49 tsk->fpu_counter = 0;
50 preempt_enable(); 54 preempt_enable();
51} 55}
52 56
53static inline void clear_fpu(struct task_struct *tsk, struct pt_regs *regs) 57static inline void clear_fpu(struct task_struct *tsk, struct pt_regs *regs)
54{ 58{
55 preempt_disable(); 59 preempt_disable();
56 if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) { 60 if (task_thread_info(tsk)->status & TS_USEDFPU) {
57 clear_tsk_thread_flag(tsk, TIF_USEDFPU); 61 task_thread_info(tsk)->status &= ~TS_USEDFPU;
58 release_fpu(regs); 62 release_fpu(regs);
59 } 63 }
60 preempt_enable(); 64 preempt_enable();
diff --git a/arch/sh/include/asm/processor_32.h b/arch/sh/include/asm/processor_32.h
index 9a8714945dc..1f3d6fab660 100644
--- a/arch/sh/include/asm/processor_32.h
+++ b/arch/sh/include/asm/processor_32.h
@@ -56,6 +56,7 @@ asmlinkage void __init sh_cpu_init(void);
56#define SR_DSP 0x00001000 56#define SR_DSP 0x00001000
57#define SR_IMASK 0x000000f0 57#define SR_IMASK 0x000000f0
58#define SR_FD 0x00008000 58#define SR_FD 0x00008000
59#define SR_MD 0x40000000
59 60
60/* 61/*
61 * DSP structure and data 62 * DSP structure and data
@@ -136,7 +137,7 @@ struct mm_struct;
136extern void release_thread(struct task_struct *); 137extern void release_thread(struct task_struct *);
137 138
138/* Prepare to copy thread state - unlazy all lazy status */ 139/* Prepare to copy thread state - unlazy all lazy status */
139#define prepare_to_copy(tsk) do { } while (0) 140void prepare_to_copy(struct task_struct *tsk);
140 141
141/* 142/*
142 * create a kernel thread without removing it from tasklists 143 * create a kernel thread without removing it from tasklists
diff --git a/arch/sh/include/asm/thread_info.h b/arch/sh/include/asm/thread_info.h
index 23eeed89467..1f3d927e226 100644
--- a/arch/sh/include/asm/thread_info.h
+++ b/arch/sh/include/asm/thread_info.h
@@ -51,6 +51,7 @@ struct thread_info {
51 .task = &tsk, \ 51 .task = &tsk, \
52 .exec_domain = &default_exec_domain, \ 52 .exec_domain = &default_exec_domain, \
53 .flags = 0, \ 53 .flags = 0, \
54 .status = 0, \
54 .cpu = 0, \ 55 .cpu = 0, \
55 .preempt_count = INIT_PREEMPT_COUNT, \ 56 .preempt_count = INIT_PREEMPT_COUNT, \
56 .addr_limit = KERNEL_DS, \ 57 .addr_limit = KERNEL_DS, \
@@ -117,7 +118,6 @@ extern void free_thread_info(struct thread_info *ti);
117#define TIF_SECCOMP 6 /* secure computing */ 118#define TIF_SECCOMP 6 /* secure computing */
118#define TIF_NOTIFY_RESUME 7 /* callback before returning to user */ 119#define TIF_NOTIFY_RESUME 7 /* callback before returning to user */
119#define TIF_SYSCALL_TRACEPOINT 8 /* for ftrace syscall instrumentation */ 120#define TIF_SYSCALL_TRACEPOINT 8 /* for ftrace syscall instrumentation */
120#define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
121#define TIF_POLLING_NRFLAG 17 /* true if poll_idle() is polling TIF_NEED_RESCHED */ 121#define TIF_POLLING_NRFLAG 17 /* true if poll_idle() is polling TIF_NEED_RESCHED */
122#define TIF_MEMDIE 18 122#define TIF_MEMDIE 18
123#define TIF_FREEZE 19 /* Freezing for suspend */ 123#define TIF_FREEZE 19 /* Freezing for suspend */
@@ -130,7 +130,6 @@ extern void free_thread_info(struct thread_info *ti);
130#define _TIF_SECCOMP (1 << TIF_SECCOMP) 130#define _TIF_SECCOMP (1 << TIF_SECCOMP)
131#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) 131#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
132#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) 132#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
133#define _TIF_USEDFPU (1 << TIF_USEDFPU)
134#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) 133#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
135#define _TIF_FREEZE (1 << TIF_FREEZE) 134#define _TIF_FREEZE (1 << TIF_FREEZE)
136 135
@@ -163,6 +162,7 @@ extern void free_thread_info(struct thread_info *ti);
163 * have to worry about atomic accesses. 162 * have to worry about atomic accesses.
164 */ 163 */
165#define TS_RESTORE_SIGMASK 0x0001 /* restore signal mask in do_signal() */ 164#define TS_RESTORE_SIGMASK 0x0001 /* restore signal mask in do_signal() */
165#define TS_USEDFPU 0x0002 /* FPU used by this task this quantum */
166 166
167#ifndef __ASSEMBLY__ 167#ifndef __ASSEMBLY__
168#define HAVE_SET_RESTORE_SIGMASK 1 168#define HAVE_SET_RESTORE_SIGMASK 1