Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 218726
b: refs/heads/master
c: 278d91c
h: refs/heads/master
v: v3
  • Loading branch information
Akira Takeuchi authored and David Howells committed Oct 27, 2010
1 parent 47e3c95 commit 436b852
Show file tree
Hide file tree
Showing 15 changed files with 441 additions and 249 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 965ea4bbb9ae926358273368144ba838c561bc38
refs/heads/master: 278d91c4609d55202c1e63d5fc5f01466cc7bbab
15 changes: 15 additions & 0 deletions trunk/arch/mn10300/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ config FPU
default y
depends on MN10300_PROC_MN103E010

config LAZY_SAVE_FPU
bool "Save FPU state lazily"
default y
depends on FPU && !SMP
help
Enable this to be lazy in the saving of the FPU state to the owning
task's thread struct. This is useful if most tasks on the system
don't use the FPU as only those tasks that use it will pass it
between them, and the state needn't be saved for a task that isn't
using it.

This can't be so easily used on SMP as the process that owns the FPU
state on a CPU may be currently running on another CPU, so for the
moment, it is disabled.

source "arch/mn10300/mm/Kconfig.cache"

config MN10300_TLB_USE_PIDR
Expand Down
2 changes: 0 additions & 2 deletions trunk/arch/mn10300/include/asm/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ typedef struct {
u_int32_t fpcr;
} elf_fpregset_t;

extern int dump_fpu(struct pt_regs *, elf_fpregset_t *);

/*
* This is used to ensure we don't load something for the wrong architecture
*/
Expand Down
1 change: 0 additions & 1 deletion trunk/arch/mn10300/include/asm/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ extern asmlinkage void dtlb_aerror(void);
extern asmlinkage void raw_bus_error(void);
extern asmlinkage void double_fault(void);
extern asmlinkage int system_call(struct pt_regs *);
extern asmlinkage void fpu_exception(struct pt_regs *, enum exception_code);
extern asmlinkage void nmi(struct pt_regs *, enum exception_code);
extern asmlinkage void uninitialised_exception(struct pt_regs *,
enum exception_code);
Expand Down
157 changes: 104 additions & 53 deletions trunk/arch/mn10300/include/asm/fpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,74 +12,125 @@
#ifndef _ASM_FPU_H
#define _ASM_FPU_H

#include <asm/processor.h>
#ifndef __ASSEMBLY__

#include <linux/sched.h>
#include <asm/exceptions.h>
#include <asm/sigcontext.h>
#include <asm/user.h>

#ifdef __KERNEL__

/* the task that owns the FPU state */
extern asmlinkage void fpu_disabled(void);

#ifdef CONFIG_FPU

#ifdef CONFIG_LAZY_SAVE_FPU
/* the task that currently owns the FPU state */
extern struct task_struct *fpu_state_owner;
#endif

#define set_using_fpu(tsk) \
do { \
(tsk)->thread.fpu_flags |= THREAD_USING_FPU; \
} while (0)
#if (THREAD_USING_FPU & ~0xff)
#error THREAD_USING_FPU must be smaller than 0x100.
#endif

#define clear_using_fpu(tsk) \
do { \
(tsk)->thread.fpu_flags &= ~THREAD_USING_FPU; \
} while (0)
static inline void set_using_fpu(struct task_struct *tsk)
{
asm volatile(
"bset %0,(0,%1)"
:
: "i"(THREAD_USING_FPU), "a"(&tsk->thread.fpu_flags)
: "memory", "cc");
}

#define is_using_fpu(tsk) ((tsk)->thread.fpu_flags & THREAD_USING_FPU)
static inline void clear_using_fpu(struct task_struct *tsk)
{
asm volatile(
"bclr %0,(0,%1)"
:
: "i"(THREAD_USING_FPU), "a"(&tsk->thread.fpu_flags)
: "memory", "cc");
}

#define unlazy_fpu(tsk) \
do { \
preempt_disable(); \
if (fpu_state_owner == (tsk)) \
fpu_save(&tsk->thread.fpu_state); \
preempt_enable(); \
} while (0)

#define exit_fpu() \
do { \
struct task_struct *__tsk = current; \
preempt_disable(); \
if (fpu_state_owner == __tsk) \
fpu_state_owner = NULL; \
preempt_enable(); \
} while (0)

#define flush_fpu() \
do { \
struct task_struct *__tsk = current; \
preempt_disable(); \
if (fpu_state_owner == __tsk) { \
fpu_state_owner = NULL; \
__tsk->thread.uregs->epsw &= ~EPSW_FE; \
} \
preempt_enable(); \
clear_using_fpu(__tsk); \
} while (0)
#define is_using_fpu(tsk) ((tsk)->thread.fpu_flags & THREAD_USING_FPU)

extern asmlinkage void fpu_init_state(void);
extern asmlinkage void fpu_kill_state(struct task_struct *);
extern asmlinkage void fpu_disabled(struct pt_regs *, enum exception_code);
extern asmlinkage void fpu_exception(struct pt_regs *, enum exception_code);

#ifdef CONFIG_FPU
extern asmlinkage void fpu_invalid_op(struct pt_regs *, enum exception_code);
extern asmlinkage void fpu_init_state(void);
extern asmlinkage void fpu_save(struct fpu_state_struct *);
extern asmlinkage void fpu_restore(struct fpu_state_struct *);
#else
#define fpu_save(a)
#define fpu_restore(a)
#endif /* CONFIG_FPU */

/*
* signal frame handlers
*/
extern int fpu_setup_sigcontext(struct fpucontext *buf);
extern int fpu_restore_sigcontext(struct fpucontext *buf);

static inline void unlazy_fpu(struct task_struct *tsk)
{
preempt_disable();
#ifndef CONFIG_LAZY_SAVE_FPU
if (tsk->thread.fpu_flags & THREAD_HAS_FPU) {
fpu_save(&tsk->thread.fpu_state);
tsk->thread.fpu_flags &= ~THREAD_HAS_FPU;
tsk->thread.uregs->epsw &= ~EPSW_FE;
}
#else
if (fpu_state_owner == tsk)
fpu_save(&tsk->thread.fpu_state);
#endif
preempt_enable();
}

static inline void exit_fpu(void)
{
#ifdef CONFIG_LAZY_SAVE_FPU
struct task_struct *tsk = current;

preempt_disable();
if (fpu_state_owner == tsk)
fpu_state_owner = NULL;
preempt_enable();
#endif
}

static inline void flush_fpu(void)
{
struct task_struct *tsk = current;

preempt_disable();
#ifndef CONFIG_LAZY_SAVE_FPU
if (tsk->thread.fpu_flags & THREAD_HAS_FPU) {
tsk->thread.fpu_flags &= ~THREAD_HAS_FPU;
tsk->thread.uregs->epsw &= ~EPSW_FE;
}
#else
if (fpu_state_owner == tsk) {
fpu_state_owner = NULL;
tsk->thread.uregs->epsw &= ~EPSW_FE;
}
#endif
preempt_enable();
clear_using_fpu(tsk);
}

#else /* CONFIG_FPU */

extern asmlinkage
void unexpected_fpu_exception(struct pt_regs *, enum exception_code);
#define fpu_invalid_op unexpected_fpu_exception
#define fpu_exception unexpected_fpu_exception

struct task_struct;
struct fpu_state_struct;
static inline bool is_using_fpu(struct task_struct *tsk) { return false; }
static inline void set_using_fpu(struct task_struct *tsk) {}
static inline void clear_using_fpu(struct task_struct *tsk) {}
static inline void fpu_init_state(void) {}
static inline void fpu_save(struct fpu_state_struct *s) {}
static inline void fpu_kill_state(struct task_struct *tsk) {}
static inline void unlazy_fpu(struct task_struct *tsk) {}
static inline void exit_fpu(void) {}
static inline void flush_fpu(void) {}
static inline int fpu_setup_sigcontext(struct fpucontext *buf) { return 0; }
static inline int fpu_restore_sigcontext(struct fpucontext *buf) { return 0; }
#endif /* CONFIG_FPU */

#endif /* __KERNEL__ */
#endif /* !__ASSEMBLY__ */
#endif /* _ASM_FPU_H */
1 change: 1 addition & 0 deletions trunk/arch/mn10300/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct thread_struct {
struct pt_regs *__frame;
unsigned long fpu_flags;
#define THREAD_USING_FPU 0x00000001 /* T if this task is using the FPU */
#define THREAD_HAS_FPU 0x00000002 /* T if this task owns the FPU right now */
struct fpu_state_struct fpu_state;
};

Expand Down
16 changes: 16 additions & 0 deletions trunk/arch/mn10300/include/asm/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
#include <linux/kernel.h>
#include <linux/irqflags.h>

#if !defined(CONFIG_LAZY_SAVE_FPU)
struct fpu_state_struct;
extern asmlinkage void fpu_save(struct fpu_state_struct *);
#define switch_fpu(prev, next) \
do { \
if ((prev)->thread.fpu_flags & THREAD_HAS_FPU) { \
(prev)->thread.fpu_flags &= ~THREAD_HAS_FPU; \
(prev)->thread.uregs->epsw &= ~EPSW_FE; \
fpu_save(&(prev)->thread.fpu_state); \
} \
} while (0)
#else
#define switch_fpu(prev, next) do {} while (0)
#endif

struct task_struct;
struct thread_struct;

Expand All @@ -30,6 +45,7 @@ struct task_struct *__switch_to(struct thread_struct *prev,
/* context switching is now performed out-of-line in switch_to.S */
#define switch_to(prev, next, last) \
do { \
switch_fpu(prev, next); \
current->thread.wchan = (u_long) __builtin_return_address(0); \
(last) = __switch_to(&(prev)->thread, &(next)->thread, (prev)); \
mb(); \
Expand Down
8 changes: 5 additions & 3 deletions trunk/arch/mn10300/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#
extra-y := head.o init_task.o vmlinux.lds

obj-y := process.o signal.o entry.o fpu.o traps.o irq.o \
fpu-obj-y := fpu-nofpu.o fpu-nofpu-low.o
fpu-obj-$(CONFIG_FPU) := fpu.o fpu-low.o

obj-y := process.o signal.o entry.o traps.o irq.o \
ptrace.o setup.o time.o sys_mn10300.o io.o kthread.o \
switch_to.o mn10300_ksyms.o kernel_execve.o
switch_to.o mn10300_ksyms.o kernel_execve.o $(fpu-obj-y)

obj-$(CONFIG_MN10300_WD_TIMER) += mn10300-watchdog.o mn10300-watchdog-low.o

obj-$(CONFIG_FPU) += fpu-low.o

obj-$(CONFIG_MN10300_TTYSM) += mn10300-serial.o mn10300-serial-low.o \
mn10300-debug.o
Expand Down
9 changes: 9 additions & 0 deletions trunk/arch/mn10300/kernel/asm-offsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ void foo(void)
OFFSET(THREAD_A3, thread_struct, a3);
OFFSET(THREAD_USP, thread_struct, usp);
OFFSET(THREAD_FRAME, thread_struct, __frame);
#ifdef CONFIG_FPU
OFFSET(THREAD_FPU_FLAGS, thread_struct, fpu_flags);
OFFSET(THREAD_FPU_STATE, thread_struct, fpu_state);
DEFINE(__THREAD_USING_FPU, THREAD_USING_FPU);
DEFINE(__THREAD_HAS_FPU, THREAD_HAS_FPU);
#endif /* CONFIG_FPU */
BLANK();

OFFSET(TASK_THREAD, task_struct, thread);
BLANK();

DEFINE(CLONE_VM_asm, CLONE_VM);
Expand Down
Loading

0 comments on commit 436b852

Please sign in to comment.