Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH 0/7] Clean up signal code
@ 2007-01-23 14:18 Franck Bui-Huu
  2007-01-23 14:18 ` [PATCH 1/7] signals: reduce {setup,restore}_sigcontext sizes Franck Bui-Huu
                   ` (7 more replies)
  0 siblings, 8 replies; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-23 14:18 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips

Hi,

This patchset cleans up signal related code by factorizing code
shared by all signal sources. The consequence is that the signal
code is decreased a lot.

This patchset has been splitted out into 7 differents patches
to ease code review.

Two questions are still open: 

    (a) It seems that the status register is not saved by
        setup_sigcontext() and therefore not restored by
        restore_sigcontext(). Is it a bug ?

    (b) Status register is saved by setup_sigcontext32() but
        not restored by restore_sigcontext(). Is it a bug ?

Unfortunately I do not have any 64 bits cross compiler setup
and no adequate plateforms to test the changes introduced by
this patchset in signal32.c and signal_n32.c. If someone
could give it a try, that would be nice.

Please, consider.

		Franck
---
 arch/mips/kernel/signal-common.h |  194 +++++------------------
 arch/mips/kernel/signal.c        |  216 ++++++++++++++++++++------
 arch/mips/kernel/signal32.c      |  326 +++++++++++++++-----------------------
 arch/mips/kernel/signal_n32.c    |   26 ++--
 4 files changed, 354 insertions(+), 408 deletions(-)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/7] signals: reduce {setup,restore}_sigcontext sizes
  2007-01-23 14:18 [PATCH 0/7] Clean up signal code Franck Bui-Huu
@ 2007-01-23 14:18 ` Franck Bui-Huu
  2007-01-23 14:38   ` Ralf Baechle
  2007-01-23 14:18 ` [PATCH 2/7] signal: do not inline functions in signal-common.h Franck Bui-Huu
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-23 14:18 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips, Franck Bui-Huu

From: Franck Bui-Huu <fbuihuu@gmail.com>

This trivial change reduces considerably code size of these
2 functions callers. For instance, here is the figures for
arch/kernel/signal.o objects:

   text    data     bss     dec     hex filename
  11972       0       0   11972    2ec4 arch/mips/kernel/signal.o~old
   5380       0       0    5380    1504 arch/mips/kernel/signal.o~new

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/kernel/signal-common.h |   35 +++++++----------------------------
 1 files changed, 7 insertions(+), 28 deletions(-)

diff --git a/arch/mips/kernel/signal-common.h b/arch/mips/kernel/signal-common.h
index b1f09d5..d56897e 100644
--- a/arch/mips/kernel/signal-common.h
+++ b/arch/mips/kernel/signal-common.h
@@ -13,22 +13,13 @@ static inline int
 setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
 {
 	int err = 0;
+	int i;
 
 	err |= __put_user(regs->cp0_epc, &sc->sc_pc);
 
-#define save_gp_reg(i) do {						\
-	err |= __put_user(regs->regs[i], &sc->sc_regs[i]);		\
-} while(0)
-	__put_user(0, &sc->sc_regs[0]); save_gp_reg(1); save_gp_reg(2);
-	save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6);
-	save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10);
-	save_gp_reg(11); save_gp_reg(12); save_gp_reg(13); save_gp_reg(14);
-	save_gp_reg(15); save_gp_reg(16); save_gp_reg(17); save_gp_reg(18);
-	save_gp_reg(19); save_gp_reg(20); save_gp_reg(21); save_gp_reg(22);
-	save_gp_reg(23); save_gp_reg(24); save_gp_reg(25); save_gp_reg(26);
-	save_gp_reg(27); save_gp_reg(28); save_gp_reg(29); save_gp_reg(30);
-	save_gp_reg(31);
-#undef save_gp_reg
+	err |= __put_user(0, &sc->sc_regs[0]);
+	for (i = 1; i < 32; i++)
+		err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
 
 	err |= __put_user(regs->hi, &sc->sc_mdhi);
 	err |= __put_user(regs->lo, &sc->sc_mdlo);
@@ -71,6 +62,7 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
 	unsigned int used_math;
 	unsigned long treg;
 	int err = 0;
+	int i;
 
 	/* Always make any pending restarted system calls return -EINTR */
 	current_thread_info()->restart_block.fn = do_no_restart_syscall;
@@ -88,21 +80,8 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
 		err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
 	}
 
-#define restore_gp_reg(i) do {						\
-	err |= __get_user(regs->regs[i], &sc->sc_regs[i]);		\
-} while(0)
-	restore_gp_reg( 1); restore_gp_reg( 2); restore_gp_reg( 3);
-	restore_gp_reg( 4); restore_gp_reg( 5); restore_gp_reg( 6);
-	restore_gp_reg( 7); restore_gp_reg( 8); restore_gp_reg( 9);
-	restore_gp_reg(10); restore_gp_reg(11); restore_gp_reg(12);
-	restore_gp_reg(13); restore_gp_reg(14); restore_gp_reg(15);
-	restore_gp_reg(16); restore_gp_reg(17); restore_gp_reg(18);
-	restore_gp_reg(19); restore_gp_reg(20); restore_gp_reg(21);
-	restore_gp_reg(22); restore_gp_reg(23); restore_gp_reg(24);
-	restore_gp_reg(25); restore_gp_reg(26); restore_gp_reg(27);
-	restore_gp_reg(28); restore_gp_reg(29); restore_gp_reg(30);
-	restore_gp_reg(31);
-#undef restore_gp_reg
+	for (i = 1; i < 32; i++)
+		err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
 
 	err |= __get_user(used_math, &sc->sc_used_math);
 	conditional_used_math(used_math);
-- 
1.4.4.3.ge6d4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/7] signal: do not inline functions in signal-common.h
  2007-01-23 14:18 [PATCH 0/7] Clean up signal code Franck Bui-Huu
  2007-01-23 14:18 ` [PATCH 1/7] signals: reduce {setup,restore}_sigcontext sizes Franck Bui-Huu
@ 2007-01-23 14:18 ` Franck Bui-Huu
  2007-01-23 14:18 ` [PATCH 3/7] signal: clean up sigframe structure Franck Bui-Huu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-23 14:18 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips, Franck Bui-Huu

From: Franck Bui-Huu <fbuihuu@gmail.com>

These functions are quite big and there are no points to make
them inlined. So this patch moves the functions implementation
in signal.c and make them available for others source files
which need them.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/kernel/signal-common.h |  153 ++++----------------------------------
 arch/mips/kernel/signal.c        |  142 +++++++++++++++++++++++++++++++++++
 2 files changed, 156 insertions(+), 139 deletions(-)

diff --git a/arch/mips/kernel/signal-common.h b/arch/mips/kernel/signal-common.h
index d56897e..03d2b60 100644
--- a/arch/mips/kernel/signal-common.h
+++ b/arch/mips/kernel/signal-common.h
@@ -8,148 +8,23 @@
  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  */
 
+#ifndef __SIGNAL_COMMON_H
+#define __SIGNAL_COMMON_H
 
-static inline int
-setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
-{
-	int err = 0;
-	int i;
-
-	err |= __put_user(regs->cp0_epc, &sc->sc_pc);
-
-	err |= __put_user(0, &sc->sc_regs[0]);
-	for (i = 1; i < 32; i++)
-		err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
-
-	err |= __put_user(regs->hi, &sc->sc_mdhi);
-	err |= __put_user(regs->lo, &sc->sc_mdlo);
-	if (cpu_has_dsp) {
-		err |= __put_user(mfhi1(), &sc->sc_hi1);
-		err |= __put_user(mflo1(), &sc->sc_lo1);
-		err |= __put_user(mfhi2(), &sc->sc_hi2);
-		err |= __put_user(mflo2(), &sc->sc_lo2);
-		err |= __put_user(mfhi3(), &sc->sc_hi3);
-		err |= __put_user(mflo3(), &sc->sc_lo3);
-		err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
-	}
-
-	err |= __put_user(!!used_math(), &sc->sc_used_math);
-
-	if (!used_math())
-		goto out;
-
-	/*
-	 * Save FPU state to signal context.  Signal handler will "inherit"
-	 * current FPU state.
-	 */
-	preempt_disable();
-
-	if (!is_fpu_owner()) {
-		own_fpu();
-		restore_fp(current);
-	}
-	err |= save_fp_context(sc);
-
-	preempt_enable();
-
-out:
-	return err;
-}
-
-static inline int
-restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
-{
-	unsigned int used_math;
-	unsigned long treg;
-	int err = 0;
-	int i;
-
-	/* Always make any pending restarted system calls return -EINTR */
-	current_thread_info()->restart_block.fn = do_no_restart_syscall;
-
-	err |= __get_user(regs->cp0_epc, &sc->sc_pc);
-	err |= __get_user(regs->hi, &sc->sc_mdhi);
-	err |= __get_user(regs->lo, &sc->sc_mdlo);
-	if (cpu_has_dsp) {
-		err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
-		err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
-		err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
-		err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
-		err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
-		err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
-		err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
-	}
-
-	for (i = 1; i < 32; i++)
-		err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
-
-	err |= __get_user(used_math, &sc->sc_used_math);
-	conditional_used_math(used_math);
-
-	preempt_disable();
-
-	if (used_math()) {
-		/* restore fpu context if we have used it before */
-		own_fpu();
-		err |= restore_fp_context(sc);
-	} else {
-		/* signal handler may have used FPU.  Give it up. */
-		lose_fpu();
-	}
-
-	preempt_enable();
-
-	return err;
-}
+/*
+ * handle hardware context
+ */
+extern int setup_sigcontext(struct pt_regs *, struct sigcontext __user *);
+extern int restore_sigcontext(struct pt_regs *, struct sigcontext __user *);
 
 /*
  * Determine which stack to use..
  */
-static inline void __user *
-get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
-{
-	unsigned long sp;
-
-	/* Default to using normal stack */
-	sp = regs->regs[29];
-
-	/*
-	 * FPU emulator may have it's own trampoline active just
-	 * above the user stack, 16-bytes before the next lowest
-	 * 16 byte boundary.  Try to avoid trashing it.
-	 */
-	sp -= 32;
-
-	/* This is the X/Open sanctioned signal stack switching.  */
-	if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
-		sp = current->sas_ss_sp + current->sas_ss_size;
-
-	return (void __user *)((sp - frame_size) & (ICACHE_REFILLS_WORKAROUND_WAR ? ~(cpu_icache_line_size()-1) : ALMASK));
-}
-
-static inline int install_sigtramp(unsigned int __user *tramp,
-	unsigned int syscall)
-{
-	int err;
-
-	/*
-	 * Set up the return code ...
-	 *
-	 *         li      v0, __NR__foo_sigreturn
-	 *         syscall
-	 */
-
-	err = __put_user(0x24020000 + syscall, tramp + 0);
-	err |= __put_user(0x0000000c          , tramp + 1);
-	if (ICACHE_REFILLS_WORKAROUND_WAR) {
-		err |= __put_user(0, tramp + 2);
-		err |= __put_user(0, tramp + 3);
-		err |= __put_user(0, tramp + 4);
-		err |= __put_user(0, tramp + 5);
-		err |= __put_user(0, tramp + 6);
-		err |= __put_user(0, tramp + 7);
-	}
-	flush_cache_sigtramp((unsigned long) tramp);
+extern void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
+				 size_t frame_size);
+/*
+ * install trampoline code to get back from the sig handler
+ */
+extern int install_sigtramp(unsigned int __user *tramp, unsigned int syscall);
 
-	return err;
-}
+#endif	/* __SIGNAL_COMMON_H */
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index b9d358e..50b9191 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -39,6 +39,148 @@
 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
 
 /*
+ * Helper routines
+ */
+int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
+{
+	int err = 0;
+	int i;
+
+	err |= __put_user(regs->cp0_epc, &sc->sc_pc);
+
+	err |= __put_user(0, &sc->sc_regs[0]);
+	for (i = 1; i < 32; i++)
+		err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
+
+	err |= __put_user(regs->hi, &sc->sc_mdhi);
+	err |= __put_user(regs->lo, &sc->sc_mdlo);
+	if (cpu_has_dsp) {
+		err |= __put_user(mfhi1(), &sc->sc_hi1);
+		err |= __put_user(mflo1(), &sc->sc_lo1);
+		err |= __put_user(mfhi2(), &sc->sc_hi2);
+		err |= __put_user(mflo2(), &sc->sc_lo2);
+		err |= __put_user(mfhi3(), &sc->sc_hi3);
+		err |= __put_user(mflo3(), &sc->sc_lo3);
+		err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
+	}
+
+	err |= __put_user(!!used_math(), &sc->sc_used_math);
+
+	if (!used_math())
+		goto out;
+
+	/*
+	 * Save FPU state to signal context.  Signal handler will "inherit"
+	 * current FPU state.
+	 */
+	preempt_disable();
+
+	if (!is_fpu_owner()) {
+		own_fpu();
+		restore_fp(current);
+	}
+	err |= save_fp_context(sc);
+
+	preempt_enable();
+
+out:
+	return err;
+}
+
+int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
+{
+	unsigned int used_math;
+	unsigned long treg;
+	int err = 0;
+	int i;
+
+	/* Always make any pending restarted system calls return -EINTR */
+	current_thread_info()->restart_block.fn = do_no_restart_syscall;
+
+	err |= __get_user(regs->cp0_epc, &sc->sc_pc);
+	err |= __get_user(regs->hi, &sc->sc_mdhi);
+	err |= __get_user(regs->lo, &sc->sc_mdlo);
+	if (cpu_has_dsp) {
+		err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
+		err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
+		err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
+		err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
+		err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
+		err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
+		err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
+	}
+
+	for (i = 1; i < 32; i++)
+		err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
+
+	err |= __get_user(used_math, &sc->sc_used_math);
+	conditional_used_math(used_math);
+
+	preempt_disable();
+
+	if (used_math()) {
+		/* restore fpu context if we have used it before */
+		own_fpu();
+		err |= restore_fp_context(sc);
+	} else {
+		/* signal handler may have used FPU.  Give it up. */
+		lose_fpu();
+	}
+
+	preempt_enable();
+
+	return err;
+}
+
+void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
+			  size_t frame_size)
+{
+	unsigned long sp;
+
+	/* Default to using normal stack */
+	sp = regs->regs[29];
+
+	/*
+	 * FPU emulator may have it's own trampoline active just
+	 * above the user stack, 16-bytes before the next lowest
+	 * 16 byte boundary.  Try to avoid trashing it.
+	 */
+	sp -= 32;
+
+	/* This is the X/Open sanctioned signal stack switching.  */
+	if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
+		sp = current->sas_ss_sp + current->sas_ss_size;
+
+	return (void __user *)((sp - frame_size) & (ICACHE_REFILLS_WORKAROUND_WAR ? ~(cpu_icache_line_size()-1) : ALMASK));
+}
+
+int install_sigtramp(unsigned int __user *tramp, unsigned int syscall)
+{
+	int err;
+
+	/*
+	 * Set up the return code ...
+	 *
+	 *         li      v0, __NR__foo_sigreturn
+	 *         syscall
+	 */
+
+	err = __put_user(0x24020000 + syscall, tramp + 0);
+	err |= __put_user(0x0000000c          , tramp + 1);
+	if (ICACHE_REFILLS_WORKAROUND_WAR) {
+		err |= __put_user(0, tramp + 2);
+		err |= __put_user(0, tramp + 3);
+		err |= __put_user(0, tramp + 4);
+		err |= __put_user(0, tramp + 5);
+		err |= __put_user(0, tramp + 6);
+		err |= __put_user(0, tramp + 7);
+	}
+	flush_cache_sigtramp((unsigned long) tramp);
+
+	return err;
+}
+
+/*
  * Atomically swap in the new signal mask, and wait for a signal.
  */
 
-- 
1.4.4.3.ge6d4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 3/7] signal: clean up sigframe structure
  2007-01-23 14:18 [PATCH 0/7] Clean up signal code Franck Bui-Huu
  2007-01-23 14:18 ` [PATCH 1/7] signals: reduce {setup,restore}_sigcontext sizes Franck Bui-Huu
  2007-01-23 14:18 ` [PATCH 2/7] signal: do not inline functions in signal-common.h Franck Bui-Huu
@ 2007-01-23 14:18 ` Franck Bui-Huu
  2007-01-23 14:35   ` Ralf Baechle
  2007-01-23 14:18 ` [PATCH 4/7] signal32: remove code duplication Franck Bui-Huu
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-23 14:18 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips, Franck Bui-Huu

From: Franck Bui-Huu <fbuihuu@gmail.com>

This patch makes 'struct sigframe' declaration avalaible for all signals
code. It allows signal32 to not have its own declaration.

This patch also removes all ICACHE_REFILLS_WORKAROUND_WAR tests in
structure declaration and hopefully make them more readable.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/kernel/signal-common.h |   26 +++++++++++++++++
 arch/mips/kernel/signal.c        |   56 ++++++++++++++-----------------------
 arch/mips/kernel/signal32.c      |   49 ++++++++++++++-------------------
 arch/mips/kernel/signal_n32.c    |   19 +++++++++----
 4 files changed, 81 insertions(+), 69 deletions(-)

diff --git a/arch/mips/kernel/signal-common.h b/arch/mips/kernel/signal-common.h
index 03d2b60..5838f6d 100644
--- a/arch/mips/kernel/signal-common.h
+++ b/arch/mips/kernel/signal-common.h
@@ -12,6 +12,32 @@
 #define __SIGNAL_COMMON_H
 
 /*
+ * Horribly complicated - with the bloody RM9000 workarounds enabled
+ * the signal trampolines is moving to the end of the structure so we can
+ * increase the alignment without breaking software compatibility.
+ */
+#ifndef ICACHE_REFILLS_WORKAROUND_WAR
+
+struct sigframe {
+	u32 sf_ass[4];		/* argument save space for o32 */
+	u32 sf_code[2];		/* signal trampoline */
+	struct sigcontext sf_sc;
+	sigset_t sf_mask;
+};
+
+#else  /* ICACHE_REFILLS_WORKAROUND_WAR */
+
+struct sigframe {
+	u32 sf_ass[4];			/* argument save space for o32 */
+	u32 sf_pad[2];
+	struct sigcontext sf_sc;	/* hw context */
+	sigset_t sf_mask;
+	u32 sf_code[8] ____cacheline_aligned;	/* signal trampoline */
+};
+
+#endif	/* !ICACHE_REFILLS_WORKAROUND_WAR */
+
+/*
  * handle hardware context
  */
 extern int setup_sigcontext(struct pt_regs *, struct sigcontext __user *);
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 50b9191..468c74d 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -38,6 +38,27 @@
 
 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
 
+#ifndef ICACHE_REFILLS_WORKAROUND_WAR
+
+struct rt_sigframe {
+	u32 rs_ass[4];		/* argument save space for o32 */
+	u32 rs_code[2];		/* signal trampoline */
+	struct siginfo rs_info;
+	struct ucontext rs_uc;
+};
+
+#else
+
+struct rt_sigframe {
+	u32 rs_ass[4];			/* argument save space for o32 */
+	u32 rs_pad[2];
+	struct siginfo rs_info;
+	struct ucontext rs_uc;
+	u32 rs_code[8] ____cacheline_aligned;	/* signal trampoline */
+};
+
+#endif
+
 /*
  * Helper routines
  */
@@ -290,41 +311,6 @@ asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs)
 	return do_sigaltstack(uss, uoss, usp);
 }
 
-/*
- * Horribly complicated - with the bloody RM9000 workarounds enabled
- * the signal trampolines is moving to the end of the structure so we can
- * increase the alignment without breaking software compatibility.
- */
-#ifdef CONFIG_TRAD_SIGNALS
-struct sigframe {
-	u32 sf_ass[4];			/* argument save space for o32 */
-#if ICACHE_REFILLS_WORKAROUND_WAR
-	u32 sf_pad[2];
-#else
-	u32 sf_code[2];			/* signal trampoline */
-#endif
-	struct sigcontext sf_sc;
-	sigset_t sf_mask;
-#if ICACHE_REFILLS_WORKAROUND_WAR
-	u32 sf_code[8] ____cacheline_aligned;	/* signal trampoline */
-#endif
-};
-#endif
-
-struct rt_sigframe {
-	u32 rs_ass[4];			/* argument save space for o32 */
-#if ICACHE_REFILLS_WORKAROUND_WAR
-	u32 rs_pad[2];
-#else
-	u32 rs_code[2];			/* signal trampoline */
-#endif
-	struct siginfo rs_info;
-	struct ucontext rs_uc;
-#if ICACHE_REFILLS_WORKAROUND_WAR
-	u32 rs_code[8] ____cacheline_aligned;	/* signal trampoline */
-#endif
-};
-
 #ifdef CONFIG_TRAD_SIGNALS
 save_static_function(sys_sigreturn);
 __attribute_used__ noinline static void
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index c86a5dd..e5125ad 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -139,6 +139,27 @@ struct ucontext32 {
 	sigset_t32          uc_sigmask;   /* mask last for extensibility */
 };
 
+#ifndef ICACHE_REFILLS_WORKAROUND_WAR
+
+struct rt_sigframe32 {
+	u32 rs_ass[4];			/* argument save space for o32 */
+	u32 rs_code[2];			/* signal trampoline */
+	compat_siginfo_t rs_info;
+	struct ucontext32 rs_uc;
+};
+
+#else  /* ICACHE_REFILLS_WORKAROUND_WAR */
+
+struct rt_sigframe32 {
+	u32 rs_ass[4];			/* argument save space for o32 */
+	u32 rs_pad[2];
+	compat_siginfo_t rs_info;
+	struct ucontext32 rs_uc;
+	u32 rs_code[8] __attribute__((aligned(32)));	/* signal trampoline */
+};
+
+#endif	/* !ICACHE_REFILLS_WORKAROUND_WAR */
+
 extern void __put_sigset_unknown_nsig(void);
 extern void __get_sigset_unknown_nsig(void);
 
@@ -383,34 +404,6 @@ static int restore_sigcontext32(struct pt_regs *regs, struct sigcontext32 __user
 	return err;
 }
 
-struct sigframe {
-	u32 sf_ass[4];			/* argument save space for o32 */
-#if ICACHE_REFILLS_WORKAROUND_WAR
-	u32 sf_pad[2];
-#else
-	u32 sf_code[2];			/* signal trampoline */
-#endif
-	struct sigcontext32 sf_sc;
-	sigset_t sf_mask;
-#if ICACHE_REFILLS_WORKAROUND_WAR
-	u32 sf_code[8] ____cacheline_aligned;	/* signal trampoline */
-#endif
-};
-
-struct rt_sigframe32 {
-	u32 rs_ass[4];			/* argument save space for o32 */
-#if ICACHE_REFILLS_WORKAROUND_WAR
-	u32 rs_pad[2];
-#else
-	u32 rs_code[2];			/* signal trampoline */
-#endif
-	compat_siginfo_t rs_info;
-	struct ucontext32 rs_uc;
-#if ICACHE_REFILLS_WORKAROUND_WAR
-	u32 rs_code[8] __attribute__((aligned(32)));	/* signal trampoline */
-#endif
-};
-
 int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
 {
 	int err;
diff --git a/arch/mips/kernel/signal_n32.c b/arch/mips/kernel/signal_n32.c
index a67c185..3830757 100644
--- a/arch/mips/kernel/signal_n32.c
+++ b/arch/mips/kernel/signal_n32.c
@@ -66,20 +66,27 @@ struct ucontextn32 {
 	sigset_t            uc_sigmask;   /* mask last for extensibility */
 };
 
+#ifndef ICACHE_REFILLS_WORKAROUND_WAR
+
 struct rt_sigframe_n32 {
 	u32 rs_ass[4];			/* argument save space for o32 */
-#if ICACHE_REFILLS_WORKAROUND_WAR
-	u32 rs_pad[2];
-#else
 	u32 rs_code[2];			/* signal trampoline */
-#endif
 	struct siginfo rs_info;
 	struct ucontextn32 rs_uc;
-#if ICACHE_REFILLS_WORKAROUND_WAR
+};
+
+#else  /* ICACHE_REFILLS_WORKAROUND_WAR */
+
+struct rt_sigframe_n32 {
+	u32 rs_ass[4];			/* argument save space for o32 */
+	u32 rs_pad[2];
+	struct siginfo rs_info;
+	struct ucontextn32 rs_uc;
 	u32 rs_code[8] ____cacheline_aligned;		/* signal trampoline */
-#endif
 };
 
+#endif	/* !ICACHE_REFILLS_WORKAROUND_WAR */
+
 extern void sigset_from_compat (sigset_t *set, compat_sigset_t *compat);
 
 save_static_function(sysn32_rt_sigsuspend);
-- 
1.4.4.3.ge6d4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 4/7] signal32: remove code duplication
  2007-01-23 14:18 [PATCH 0/7] Clean up signal code Franck Bui-Huu
                   ` (2 preceding siblings ...)
  2007-01-23 14:18 ` [PATCH 3/7] signal: clean up sigframe structure Franck Bui-Huu
@ 2007-01-23 14:18 ` Franck Bui-Huu
  2007-01-23 14:18 ` [PATCH 5/7] signal: test return value of install_sigtramp() Franck Bui-Huu
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-23 14:18 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips, Franck Bui-Huu

From: Franck Bui-Huu <fbuihuu@gmail.com>

There's no point for signal32.c to redefine get_sigframe().
It should use the one define in signal.c instead.

The same stands for install_sigtramp().

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/kernel/signal32.c |   50 +++---------------------------------------
 1 files changed, 4 insertions(+), 46 deletions(-)

diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index e5125ad..d83002e 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -33,6 +33,8 @@
 #include <asm/fpu.h>
 #include <asm/war.h>
 
+#include "signal-common.h"
+
 #define SI_PAD_SIZE32   ((SI_MAX_SIZE/sizeof(int)) - 3)
 
 typedef struct compat_siginfo {
@@ -604,32 +606,6 @@ out:
 	return err;
 }
 
-/*
- * Determine which stack to use..
- */
-static inline void __user *get_sigframe(struct k_sigaction *ka,
-					struct pt_regs *regs,
-					size_t frame_size)
-{
-	unsigned long sp;
-
-	/* Default to using normal stack */
-	sp = regs->regs[29];
-
-	/*
-	 * FPU emulator may have it's own trampoline active just
-	 * above the user stack, 16-bytes before the next lowest
-	 * 16 byte boundary.  Try to avoid trashing it.
-	 */
-	sp -= 32;
-
-	/* This is the X/Open sanctioned signal stack switching.  */
-	if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
-		sp = current->sas_ss_sp + current->sas_ss_size;
-
-	return (void __user *)((sp - frame_size) & ALMASK);
-}
-
 int setup_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
 	int signr, sigset_t *set)
 {
@@ -640,15 +616,7 @@ int setup_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
 	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
 		goto give_sigsegv;
 
-	/*
-	 * Set up the return code ...
-	 *
-	 *         li      v0, __NR_O32_sigreturn
-	 *         syscall
-	 */
-	err |= __put_user(0x24020000 + __NR_O32_sigreturn, frame->sf_code + 0);
-	err |= __put_user(0x0000000c                     , frame->sf_code + 1);
-	flush_cache_sigtramp((unsigned long) frame->sf_code);
+	err |= install_sigtramp(frame->sf_code, __NR_O32_sigreturn);
 
 	err |= setup_sigcontext32(regs, &frame->sf_sc);
 	err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
@@ -695,17 +663,7 @@ int setup_rt_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
 	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
 		goto give_sigsegv;
 
-	/* Set up to return from userspace.  If provided, use a stub already
-	   in userspace.  */
-	/*
-	 * Set up the return code ...
-	 *
-	 *         li      v0, __NR_O32_rt_sigreturn
-	 *         syscall
-	 */
-	err |= __put_user(0x24020000 + __NR_O32_rt_sigreturn, frame->rs_code + 0);
-	err |= __put_user(0x0000000c                      , frame->rs_code + 1);
-	flush_cache_sigtramp((unsigned long) frame->rs_code);
+	err |= install_sigtramp(frame->rs_code, __NR_O32_rt_sigreturn);
 
 	/* Convert (siginfo_t -> compat_siginfo_t) and copy to user. */
 	err |= copy_siginfo_to_user32(&frame->rs_info, info);
-- 
1.4.4.3.ge6d4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 5/7] signal: test return value of install_sigtramp()
  2007-01-23 14:18 [PATCH 0/7] Clean up signal code Franck Bui-Huu
                   ` (3 preceding siblings ...)
  2007-01-23 14:18 ` [PATCH 4/7] signal32: remove code duplication Franck Bui-Huu
@ 2007-01-23 14:18 ` Franck Bui-Huu
  2007-01-23 14:18 ` [PATCH 6/7] signal: factorize debug code Franck Bui-Huu
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-23 14:18 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips, Franck Bui-Huu

From: Franck Bui-Huu <fbuihuu@gmail.com>

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/kernel/signal.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 468c74d..133ef74 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -187,7 +187,7 @@ int install_sigtramp(unsigned int __user *tramp, unsigned int syscall)
 	 */
 
 	err = __put_user(0x24020000 + syscall, tramp + 0);
-	err |= __put_user(0x0000000c          , tramp + 1);
+	err |= __put_user(0x0000000c         , tramp + 1);
 	if (ICACHE_REFILLS_WORKAROUND_WAR) {
 		err |= __put_user(0, tramp + 2);
 		err |= __put_user(0, tramp + 3);
@@ -403,7 +403,7 @@ int setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
 	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
 		goto give_sigsegv;
 
-	install_sigtramp(frame->sf_code, __NR_sigreturn);
+	err |= install_sigtramp(frame->sf_code, __NR_sigreturn);
 
 	err |= setup_sigcontext(regs, &frame->sf_sc);
 	err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
@@ -450,7 +450,7 @@ int setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
 	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
 		goto give_sigsegv;
 
-	install_sigtramp(frame->rs_code, __NR_rt_sigreturn);
+	err |= install_sigtramp(frame->rs_code, __NR_rt_sigreturn);
 
 	/* Create siginfo.  */
 	err |= copy_siginfo_to_user(&frame->rs_info, info);
-- 
1.4.4.3.ge6d4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 6/7] signal: factorize debug code
  2007-01-23 14:18 [PATCH 0/7] Clean up signal code Franck Bui-Huu
                   ` (4 preceding siblings ...)
  2007-01-23 14:18 ` [PATCH 5/7] signal: test return value of install_sigtramp() Franck Bui-Huu
@ 2007-01-23 14:18 ` Franck Bui-Huu
  2007-01-23 14:18 ` [PATCH 7/7] signal32: reduce {setup,restore}_sigcontext32 sizes Franck Bui-Huu
  2007-01-23 14:32 ` [PATCH 0/7] Clean up signal code Ralf Baechle
  7 siblings, 0 replies; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-23 14:18 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips, Franck Bui-Huu

From: Franck Bui-Huu <fbuihuu@gmail.com>

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/kernel/signal-common.h |    8 ++++++++
 arch/mips/kernel/signal.c        |   14 +++++---------
 arch/mips/kernel/signal32.c      |   16 ++++++----------
 arch/mips/kernel/signal_n32.c    |    7 ++-----
 4 files changed, 21 insertions(+), 24 deletions(-)

diff --git a/arch/mips/kernel/signal-common.h b/arch/mips/kernel/signal-common.h
index 5838f6d..509b914 100644
--- a/arch/mips/kernel/signal-common.h
+++ b/arch/mips/kernel/signal-common.h
@@ -11,6 +11,14 @@
 #ifndef __SIGNAL_COMMON_H
 #define __SIGNAL_COMMON_H
 
+/* #define DEBUG_SIG */
+
+#ifdef DEBUG_SIG
+#  define DEBUGP(fmt, args...) printk("%s: " fmt, __FUNCTION__ , ##args)
+#else
+#  define DEBUGP(fmt, args...)
+#endif
+
 /*
  * Horribly complicated - with the bloody RM9000 workarounds enabled
  * the signal trampolines is moving to the end of the structure so we can
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 133ef74..0a2c699 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -34,8 +34,6 @@
 
 #include "signal-common.h"
 
-#define DEBUG_SIG 0
-
 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
 
 #ifndef ICACHE_REFILLS_WORKAROUND_WAR
@@ -427,11 +425,10 @@ int setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
 	regs->regs[31] = (unsigned long) frame->sf_code;
 	regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
 
-#if DEBUG_SIG
-	printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
+	DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
 	       current->comm, current->pid,
-	       frame, regs->cp0_epc, frame->regs[31]);
-#endif
+	       frame, regs->cp0_epc, regs->regs[31]);
+
         return 0;
 
 give_sigsegv:
@@ -487,11 +484,10 @@ int setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
 	regs->regs[31] = (unsigned long) frame->rs_code;
 	regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
 
-#if DEBUG_SIG
-	printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
+	DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
 	       current->comm, current->pid,
 	       frame, regs->cp0_epc, regs->regs[31]);
-#endif
+
 	return 0;
 
 give_sigsegv:
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index d83002e..96b3412 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -104,8 +104,6 @@ typedef struct compat_siginfo {
 #define __NR_O32_rt_sigreturn		4193
 #define __NR_O32_restart_syscall	4253
 
-#define DEBUG_SIG 0
-
 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
 
 /* 32-bit compatibility types */
@@ -640,11 +638,10 @@ int setup_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
 	regs->regs[31] = (unsigned long) frame->sf_code;
 	regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
 
-#if DEBUG_SIG
-	printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
+	DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
 	       current->comm, current->pid,
-	       frame, regs->cp0_epc, frame->sf_code);
-#endif
+	       frame, regs->cp0_epc, regs->regs[31]);
+
 	return 0;
 
 give_sigsegv:
@@ -701,11 +698,10 @@ int setup_rt_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
 	regs->regs[31] = (unsigned long) frame->rs_code;
 	regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
 
-#if DEBUG_SIG
-	printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
+	DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
 	       current->comm, current->pid,
-	       frame, regs->cp0_epc, frame->rs_code);
-#endif
+	       frame, regs->cp0_epc, regs->regs[31]);
+
 	return 0;
 
 give_sigsegv:
diff --git a/arch/mips/kernel/signal_n32.c b/arch/mips/kernel/signal_n32.c
index 3830757..535f06c 100644
--- a/arch/mips/kernel/signal_n32.c
+++ b/arch/mips/kernel/signal_n32.c
@@ -47,8 +47,6 @@
 #define __NR_N32_rt_sigreturn		6211
 #define __NR_N32_restart_syscall	6214
 
-#define DEBUG_SIG 0
-
 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
 
 /* IRIX compatible stack_t  */
@@ -221,11 +219,10 @@ int setup_rt_frame_n32(struct k_sigaction * ka,
 	regs->regs[31] = (unsigned long) frame->rs_code;
 	regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
 
-#if DEBUG_SIG
-	printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
+	DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
 	       current->comm, current->pid,
 	       frame, regs->cp0_epc, regs->regs[31]);
-#endif
+
 	return 0;
 
 give_sigsegv:
-- 
1.4.4.3.ge6d4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 7/7] signal32: reduce {setup,restore}_sigcontext32 sizes
  2007-01-23 14:18 [PATCH 0/7] Clean up signal code Franck Bui-Huu
                   ` (5 preceding siblings ...)
  2007-01-23 14:18 ` [PATCH 6/7] signal: factorize debug code Franck Bui-Huu
@ 2007-01-23 14:18 ` Franck Bui-Huu
  2007-01-23 14:32 ` [PATCH 0/7] Clean up signal code Ralf Baechle
  7 siblings, 0 replies; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-23 14:18 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips, Franck Bui-Huu

From: Franck Bui-Huu <fbuihuu@gmail.com>

This trivial changes should decrease a lot the size of these
2 functions.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---
 arch/mips/kernel/signal32.c |  211 ++++++++++++++++++++-----------------------
 1 files changed, 97 insertions(+), 114 deletions(-)

diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index 96b3412..69b8d5f 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -160,6 +160,103 @@ struct rt_sigframe32 {
 
 #endif	/* !ICACHE_REFILLS_WORKAROUND_WAR */
 
+/*
+ * sigcontext handlers
+ */
+static int setup_sigcontext32(struct pt_regs *regs,
+			      struct sigcontext32 __user *sc)
+{
+	int err = 0;
+	int i;
+
+	err |= __put_user(regs->cp0_epc, &sc->sc_pc);
+	err |= __put_user(regs->cp0_status, &sc->sc_status);
+
+	err |= __put_user(0, &sc->sc_regs[0]);
+	for (i = 1; i < 32; i++)
+		err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
+
+	err |= __put_user(regs->hi, &sc->sc_mdhi);
+	err |= __put_user(regs->lo, &sc->sc_mdlo);
+	if (cpu_has_dsp) {
+		err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
+		err |= __put_user(mfhi1(), &sc->sc_hi1);
+		err |= __put_user(mflo1(), &sc->sc_lo1);
+		err |= __put_user(mfhi2(), &sc->sc_hi2);
+		err |= __put_user(mflo2(), &sc->sc_lo2);
+		err |= __put_user(mfhi3(), &sc->sc_hi3);
+		err |= __put_user(mflo3(), &sc->sc_lo3);
+	}
+
+	err |= __put_user(!!used_math(), &sc->sc_used_math);
+
+	if (used_math()) {
+		/*
+		 * Save FPU state to signal context.  Signal handler
+		 * will "inherit" current FPU state.
+		 */
+		preempt_disable();
+
+		if (!is_fpu_owner()) {
+			own_fpu();
+			restore_fp(current);
+		}
+		err |= save_fp_context32(sc);
+
+		preempt_enable();
+	}
+	return err;
+}
+
+static int restore_sigcontext32(struct pt_regs *regs,
+				struct sigcontext32 __user *sc)
+{
+	u32 used_math;
+	int err = 0;
+	s32 treg;
+	int i;
+
+	/* Always make any pending restarted system calls return -EINTR */
+	current_thread_info()->restart_block.fn = do_no_restart_syscall;
+
+	err |= __get_user(regs->cp0_epc, &sc->sc_pc);
+	err |= __get_user(regs->hi, &sc->sc_mdhi);
+	err |= __get_user(regs->lo, &sc->sc_mdlo);
+	if (cpu_has_dsp) {
+		err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
+		err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
+		err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
+		err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
+		err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
+		err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
+		err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
+	}
+
+	for (i = 1; i < 32; i++)
+		err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
+
+	err |= __get_user(used_math, &sc->sc_used_math);
+	conditional_used_math(used_math);
+
+	preempt_disable();
+
+	if (used_math()) {
+		/* restore fpu context if we have used it before */
+		own_fpu();
+		err |= restore_fp_context32(sc);
+	} else {
+		/* signal handler may have used FPU.  Give it up. */
+		lose_fpu();
+	}
+
+	preempt_enable();
+
+	return err;
+}
+
+/*
+ *
+ */
 extern void __put_sigset_unknown_nsig(void);
 extern void __get_sigset_unknown_nsig(void);
 
@@ -347,63 +444,6 @@ asmlinkage int sys32_sigaltstack(nabi_no_regargs struct pt_regs regs)
 	return ret;
 }
 
-static int restore_sigcontext32(struct pt_regs *regs, struct sigcontext32 __user *sc)
-{
-	u32 used_math;
-	int err = 0;
-	s32 treg;
-
-	/* Always make any pending restarted system calls return -EINTR */
-	current_thread_info()->restart_block.fn = do_no_restart_syscall;
-
-	err |= __get_user(regs->cp0_epc, &sc->sc_pc);
-	err |= __get_user(regs->hi, &sc->sc_mdhi);
-	err |= __get_user(regs->lo, &sc->sc_mdlo);
-	if (cpu_has_dsp) {
-		err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
-		err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
-		err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
-		err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
-		err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
-		err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
-		err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
-	}
-
-#define restore_gp_reg(i) do {						\
-	err |= __get_user(regs->regs[i], &sc->sc_regs[i]);		\
-} while(0)
-	restore_gp_reg( 1); restore_gp_reg( 2); restore_gp_reg( 3);
-	restore_gp_reg( 4); restore_gp_reg( 5); restore_gp_reg( 6);
-	restore_gp_reg( 7); restore_gp_reg( 8); restore_gp_reg( 9);
-	restore_gp_reg(10); restore_gp_reg(11); restore_gp_reg(12);
-	restore_gp_reg(13); restore_gp_reg(14); restore_gp_reg(15);
-	restore_gp_reg(16); restore_gp_reg(17); restore_gp_reg(18);
-	restore_gp_reg(19); restore_gp_reg(20); restore_gp_reg(21);
-	restore_gp_reg(22); restore_gp_reg(23); restore_gp_reg(24);
-	restore_gp_reg(25); restore_gp_reg(26); restore_gp_reg(27);
-	restore_gp_reg(28); restore_gp_reg(29); restore_gp_reg(30);
-	restore_gp_reg(31);
-#undef restore_gp_reg
-
-	err |= __get_user(used_math, &sc->sc_used_math);
-	conditional_used_math(used_math);
-
-	preempt_disable();
-
-	if (used_math()) {
-		/* restore fpu context if we have used it before */
-		own_fpu();
-		err |= restore_fp_context32(sc);
-	} else {
-		/* signal handler may have used FPU.  Give it up. */
-		lose_fpu();
-	}
-
-	preempt_enable();
-
-	return err;
-}
-
 int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
 {
 	int err;
@@ -547,63 +587,6 @@ badframe:
 	force_sig(SIGSEGV, current);
 }
 
-static inline int setup_sigcontext32(struct pt_regs *regs,
-				     struct sigcontext32 __user *sc)
-{
-	int err = 0;
-
-	err |= __put_user(regs->cp0_epc, &sc->sc_pc);
-	err |= __put_user(regs->cp0_status, &sc->sc_status);
-
-#define save_gp_reg(i) {						\
-	err |= __put_user(regs->regs[i], &sc->sc_regs[i]);		\
-} while(0)
-	__put_user(0, &sc->sc_regs[0]); save_gp_reg(1); save_gp_reg(2);
-	save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6);
-	save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10);
-	save_gp_reg(11); save_gp_reg(12); save_gp_reg(13); save_gp_reg(14);
-	save_gp_reg(15); save_gp_reg(16); save_gp_reg(17); save_gp_reg(18);
-	save_gp_reg(19); save_gp_reg(20); save_gp_reg(21); save_gp_reg(22);
-	save_gp_reg(23); save_gp_reg(24); save_gp_reg(25); save_gp_reg(26);
-	save_gp_reg(27); save_gp_reg(28); save_gp_reg(29); save_gp_reg(30);
-	save_gp_reg(31);
-#undef save_gp_reg
-
-	err |= __put_user(regs->hi, &sc->sc_mdhi);
-	err |= __put_user(regs->lo, &sc->sc_mdlo);
-	if (cpu_has_dsp) {
-		err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
-		err |= __put_user(mfhi1(), &sc->sc_hi1);
-		err |= __put_user(mflo1(), &sc->sc_lo1);
-		err |= __put_user(mfhi2(), &sc->sc_hi2);
-		err |= __put_user(mflo2(), &sc->sc_lo2);
-		err |= __put_user(mfhi3(), &sc->sc_hi3);
-		err |= __put_user(mflo3(), &sc->sc_lo3);
-	}
-
-	err |= __put_user(!!used_math(), &sc->sc_used_math);
-
-	if (!used_math())
-		goto out;
-
-	/*
-	 * Save FPU state to signal context.  Signal handler will "inherit"
-	 * current FPU state.
-	 */
-	preempt_disable();
-
-	if (!is_fpu_owner()) {
-		own_fpu();
-		restore_fp(current);
-	}
-	err |= save_fp_context32(sc);
-
-	preempt_enable();
-
-out:
-	return err;
-}
-
 int setup_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
 	int signr, sigset_t *set)
 {
-- 
1.4.4.3.ge6d4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/7] Clean up signal code
  2007-01-23 14:18 [PATCH 0/7] Clean up signal code Franck Bui-Huu
                   ` (6 preceding siblings ...)
  2007-01-23 14:18 ` [PATCH 7/7] signal32: reduce {setup,restore}_sigcontext32 sizes Franck Bui-Huu
@ 2007-01-23 14:32 ` Ralf Baechle
  2007-01-23 14:54   ` Franck Bui-Huu
  2007-01-23 14:58   ` Daniel Jacobowitz
  7 siblings, 2 replies; 18+ messages in thread
From: Ralf Baechle @ 2007-01-23 14:32 UTC (permalink / raw)
  To: Franck Bui-Huu; +Cc: linux-mips

On Tue, Jan 23, 2007 at 03:18:16PM +0100, Franck Bui-Huu wrote:

> This patchset cleans up signal related code by factorizing code
> shared by all signal sources. The consequence is that the signal
> code is decreased a lot.
> 
> This patchset has been splitted out into 7 differents patches
> to ease code review.
> 
> Two questions are still open: 
> 
>     (a) It seems that the status register is not saved by
>         setup_sigcontext() and therefore not restored by
>         restore_sigcontext(). Is it a bug ?

No.  All the information in the MIPS c0_status register is priviledged.
Unlike CISC architectures MIPS has no flags such as zero, equal, overflow
or similar in the status register that is nothing that would constitute
part of the thread context.

The one flag one could possibly argument about might be c0_status.fr - but
none of the ABIs or tools or application software can make use of it ...

>     (b) Status register is saved by setup_sigcontext32() but
>         not restored by restore_sigcontext(). Is it a bug ?

Not really a bug but useless code, yes.  We used to save c0_status in the
dark ages but again, no known code - not even IRIX code - relies on this
field.

> Unfortunately I do not have any 64 bits cross compiler setup
> and no adequate plateforms to test the changes introduced by
> this patchset in signal32.c and signal_n32.c. If someone
> could give it a try, that would be nice.

Will try to find some time but likely it'll take me well over a week so
maybe somebody else?

  Ralf

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/7] signal: clean up sigframe structure
  2007-01-23 14:18 ` [PATCH 3/7] signal: clean up sigframe structure Franck Bui-Huu
@ 2007-01-23 14:35   ` Ralf Baechle
  2007-01-23 15:00     ` Franck Bui-Huu
  0 siblings, 1 reply; 18+ messages in thread
From: Ralf Baechle @ 2007-01-23 14:35 UTC (permalink / raw)
  To: Franck Bui-Huu; +Cc: linux-mips, Franck Bui-Huu

On Tue, Jan 23, 2007 at 03:18:19PM +0100, Franck Bui-Huu wrote:

> +#ifndef ICACHE_REFILLS_WORKAROUND_WAR

The _WAR symbols are always defined as either 0 or 1 so this #ifndef
will never be true.

  Ralf

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/7] signals: reduce {setup,restore}_sigcontext sizes
  2007-01-23 14:18 ` [PATCH 1/7] signals: reduce {setup,restore}_sigcontext sizes Franck Bui-Huu
@ 2007-01-23 14:38   ` Ralf Baechle
  2007-01-23 16:26     ` Franck Bui-Huu
  2007-01-24 12:25     ` Franck Bui-Huu
  0 siblings, 2 replies; 18+ messages in thread
From: Ralf Baechle @ 2007-01-23 14:38 UTC (permalink / raw)
  To: Franck Bui-Huu; +Cc: linux-mips, Franck Bui-Huu

On Tue, Jan 23, 2007 at 03:18:17PM +0100, Franck Bui-Huu wrote:

> From: Franck Bui-Huu <fbuihuu@gmail.com>
> 
> This trivial change reduces considerably code size of these
> 2 functions callers. For instance, here is the figures for
> arch/kernel/signal.o objects:
> 
>    text    data     bss     dec     hex filename
>   11972       0       0   11972    2ec4 arch/mips/kernel/signal.o~old
>    5380       0       0    5380    1504 arch/mips/kernel/signal.o~new

Have you ran any benchmarks on this?  Unrolling the loops used to make
a noticable difference.

  Ralf

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/7] Clean up signal code
  2007-01-23 14:32 ` [PATCH 0/7] Clean up signal code Ralf Baechle
@ 2007-01-23 14:54   ` Franck Bui-Huu
  2007-01-23 14:58   ` Daniel Jacobowitz
  1 sibling, 0 replies; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-23 14:54 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

On 1/23/07, Ralf Baechle <ralf@linux-mips.org> wrote:
> No.  All the information in the MIPS c0_status register is priviledged.
> Unlike CISC architectures MIPS has no flags such as zero, equal, overflow
> or similar in the status register that is nothing that would constitute
> part of the thread context.
>
> The one flag one could possibly argument about might be c0_status.fr - but
> none of the ABIs or tools or application software can make use of it ...
>

OK.

> >     (b) Status register is saved by setup_sigcontext32() but
> >         not restored by restore_sigcontext(). Is it a bug ?
>
> Not really a bug but useless code, yes.  We used to save c0_status in the
> dark ages but again, no known code - not even IRIX code - relies on this
> field.
>

OK, for consistency I'll remove the saving in setup_sigcontext32()

thanks
-- 
               Franck

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/7] Clean up signal code
  2007-01-23 14:32 ` [PATCH 0/7] Clean up signal code Ralf Baechle
  2007-01-23 14:54   ` Franck Bui-Huu
@ 2007-01-23 14:58   ` Daniel Jacobowitz
  1 sibling, 0 replies; 18+ messages in thread
From: Daniel Jacobowitz @ 2007-01-23 14:58 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: Franck Bui-Huu, linux-mips

On Tue, Jan 23, 2007 at 02:32:14PM +0000, Ralf Baechle wrote:
> >     (b) Status register is saved by setup_sigcontext32() but
> >         not restored by restore_sigcontext(). Is it a bug ?
> 
> Not really a bug but useless code, yes.  We used to save c0_status in the
> dark ages but again, no known code - not even IRIX code - relies on this
> field.

For once not even GDB uses it :-)

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/7] signal: clean up sigframe structure
  2007-01-23 14:35   ` Ralf Baechle
@ 2007-01-23 15:00     ` Franck Bui-Huu
  2007-01-23 17:17       ` Ralf Baechle
  0 siblings, 1 reply; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-23 15:00 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, Franck Bui-Huu

On 1/23/07, Ralf Baechle <ralf@linux-mips.org> wrote:
> On Tue, Jan 23, 2007 at 03:18:19PM +0100, Franck Bui-Huu wrote:
>
> > +#ifndef ICACHE_REFILLS_WORKAROUND_WAR
>
> The _WAR symbols are always defined as either 0 or 1 so this #ifndef
> will never be true.
>

oops, true. I didn't notice that. I just look at:

#if defined(CONFIG_MOMENCO_JAGUAR_ATX) || defined(CONFIG_MOMENCO_OCELOT_3) || \
    defined(CONFIG_PMC_YOSEMITE) || defined(CONFIG_BASLER_EXCITE)
#define ICACHE_REFILLS_WORKAROUND_WAR	1
#endif

and didn't notice that the symbol could be defined to 0 below. I'll
fix it but just for my information what the point to do this ?
-- 
               Franck

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/7] signals: reduce {setup,restore}_sigcontext sizes
  2007-01-23 14:38   ` Ralf Baechle
@ 2007-01-23 16:26     ` Franck Bui-Huu
  2007-01-23 16:36       ` Ralf Baechle
  2007-01-24 12:25     ` Franck Bui-Huu
  1 sibling, 1 reply; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-23 16:26 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, Franck Bui-Huu

On 1/23/07, Ralf Baechle <ralf@linux-mips.org> wrote:
> On Tue, Jan 23, 2007 at 03:18:17PM +0100, Franck Bui-Huu wrote:
> >    text    data     bss     dec     hex filename
> >   11972       0       0   11972    2ec4 arch/mips/kernel/signal.o~old
> >    5380       0       0    5380    1504 arch/mips/kernel/signal.o~new
>
> Have you ran any benchmarks on this?  Unrolling the loops used to make
> a noticable difference.
>

No, I haven't. Since the size code has been reduced by a factor 2, I
would think that signal code can better fit in instruction cache
lines. For example, the loop is made up by 11 instructions (I don't
know why gcc makes it so big though) which fits into 3 cache lines in
my cases. Where as the old code generated 246 instructions for the
same job, which should cause many more cache misses.

Do you have any pointers on benchmarks I could run ?

thanks
-- 
               Franck

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/7] signals: reduce {setup,restore}_sigcontext sizes
  2007-01-23 16:26     ` Franck Bui-Huu
@ 2007-01-23 16:36       ` Ralf Baechle
  0 siblings, 0 replies; 18+ messages in thread
From: Ralf Baechle @ 2007-01-23 16:36 UTC (permalink / raw)
  To: Franck Bui-Huu; +Cc: linux-mips, Franck Bui-Huu

On Tue, Jan 23, 2007 at 05:26:21PM +0100, Franck Bui-Huu wrote:

> No, I haven't. Since the size code has been reduced by a factor 2, I
> would think that signal code can better fit in instruction cache
> lines. For example, the loop is made up by 11 instructions (I don't
> know why gcc makes it so big though) which fits into 3 cache lines in
> my cases. Where as the old code generated 246 instructions for the
> same job, which should cause many more cache misses.
> 
> Do you have any pointers on benchmarks I could run ?

For stuff like this microbenchmarks like lmbench are best suited.  Lmbench
recently moved to http://sourceforge.net/projects/lmbench.

  Ralf

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/7] signal: clean up sigframe structure
  2007-01-23 15:00     ` Franck Bui-Huu
@ 2007-01-23 17:17       ` Ralf Baechle
  0 siblings, 0 replies; 18+ messages in thread
From: Ralf Baechle @ 2007-01-23 17:17 UTC (permalink / raw)
  To: Franck Bui-Huu; +Cc: linux-mips, Franck Bui-Huu

On Tue, Jan 23, 2007 at 04:00:42PM +0100, Franck Bui-Huu wrote:

> and didn't notice that the symbol could be defined to 0 below. I'll
> fix it but just for my information what the point to do this ?

Some of the _WAR constants are used in if statements which produces much
less messy looking code than piles of #ifdefs.

  Ralf

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/7] signals: reduce {setup,restore}_sigcontext sizes
  2007-01-23 14:38   ` Ralf Baechle
  2007-01-23 16:26     ` Franck Bui-Huu
@ 2007-01-24 12:25     ` Franck Bui-Huu
  1 sibling, 0 replies; 18+ messages in thread
From: Franck Bui-Huu @ 2007-01-24 12:25 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, Franck Bui-Huu

On 1/23/07, Ralf Baechle <ralf@linux-mips.org> wrote:
> On Tue, Jan 23, 2007 at 03:18:17PM +0100, Franck Bui-Huu wrote:
>
> > From: Franck Bui-Huu <fbuihuu@gmail.com>
> >
> > This trivial change reduces considerably code size of these
> > 2 functions callers. For instance, here is the figures for
> > arch/kernel/signal.o objects:
> >
> >    text    data     bss     dec     hex filename
> >   11972       0       0   11972    2ec4 arch/mips/kernel/signal.o~old
> >    5380       0       0    5380    1504 arch/mips/kernel/signal.o~new
>
> Have you ran any benchmarks on this?  Unrolling the loops used to make
> a noticable difference.
>

OK, I ran a micro benchmark on setup_frame() which calls
setup_sigcontext(). I got the execution time of setup_frame() by
counting the number of cycles spent in it (by using cp0_count
register).

Without this patchset applied it takes about 14600 cycles for
setup_frame() execution whereas with this patchset applied it takes
10300 cycles. These figures are averages.

So it appears that this patchset has a positive impact on both size and speed.

thanks
-- 
               Franck

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2007-01-24 12:25 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-23 14:18 [PATCH 0/7] Clean up signal code Franck Bui-Huu
2007-01-23 14:18 ` [PATCH 1/7] signals: reduce {setup,restore}_sigcontext sizes Franck Bui-Huu
2007-01-23 14:38   ` Ralf Baechle
2007-01-23 16:26     ` Franck Bui-Huu
2007-01-23 16:36       ` Ralf Baechle
2007-01-24 12:25     ` Franck Bui-Huu
2007-01-23 14:18 ` [PATCH 2/7] signal: do not inline functions in signal-common.h Franck Bui-Huu
2007-01-23 14:18 ` [PATCH 3/7] signal: clean up sigframe structure Franck Bui-Huu
2007-01-23 14:35   ` Ralf Baechle
2007-01-23 15:00     ` Franck Bui-Huu
2007-01-23 17:17       ` Ralf Baechle
2007-01-23 14:18 ` [PATCH 4/7] signal32: remove code duplication Franck Bui-Huu
2007-01-23 14:18 ` [PATCH 5/7] signal: test return value of install_sigtramp() Franck Bui-Huu
2007-01-23 14:18 ` [PATCH 6/7] signal: factorize debug code Franck Bui-Huu
2007-01-23 14:18 ` [PATCH 7/7] signal32: reduce {setup,restore}_sigcontext32 sizes Franck Bui-Huu
2007-01-23 14:32 ` [PATCH 0/7] Clean up signal code Ralf Baechle
2007-01-23 14:54   ` Franck Bui-Huu
2007-01-23 14:58   ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox