Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Switch alpha to use PCU to manage the FPU.



details:   https://anonhg.NetBSD.org/src/rev/85d2c76ea138
branches:  trunk
changeset: 765817:85d2c76ea138
user:      matt <matt%NetBSD.org@localhost>
date:      Tue Jun 07 00:48:29 2011 +0000

description:
Switch alpha to use PCU to manage the FPU.
Tested by mhitch and review by rmind.

diffstat:

 sys/arch/alpha/alpha/compat_13_machdep.c   |    7 +-
 sys/arch/alpha/alpha/compat_16_machdep.c   |   16 +-
 sys/arch/alpha/alpha/core_machdep.c        |    9 +-
 sys/arch/alpha/alpha/cpu.c                 |   11 +-
 sys/arch/alpha/alpha/fp_complete.c         |   75 ++++++++++++++-
 sys/arch/alpha/alpha/genassym.cf           |    3 +-
 sys/arch/alpha/alpha/ipifuncs.c            |   61 +++--------
 sys/arch/alpha/alpha/locore.s              |   12 +-
 sys/arch/alpha/alpha/machdep.c             |  138 ++++------------------------
 sys/arch/alpha/alpha/process_machdep.c     |   11 +-
 sys/arch/alpha/alpha/trap.c                |   87 +----------------
 sys/arch/alpha/alpha/vm_machdep.c          |   23 +---
 sys/arch/alpha/include/alpha.h             |   30 +++++-
 sys/arch/alpha/include/intr.h              |   10 +-
 sys/arch/alpha/include/pcb.h               |    4 +-
 sys/arch/alpha/include/proc.h              |   25 +++-
 sys/arch/alpha/include/types.h             |    7 +-
 sys/arch/mips/mips/mips_machdep.c          |    6 +-
 sys/arch/powerpc/powerpc/fpu.c             |    8 +-
 sys/arch/powerpc/powerpc/powerpc_machdep.c |    8 +-
 20 files changed, 212 insertions(+), 339 deletions(-)

diffs (truncated from 1134 to 300 lines):

diff -r 4ba9bd6120a5 -r 85d2c76ea138 sys/arch/alpha/alpha/compat_13_machdep.c
--- a/sys/arch/alpha/alpha/compat_13_machdep.c  Tue Jun 07 00:10:20 2011 +0000
+++ b/sys/arch/alpha/alpha/compat_13_machdep.c  Tue Jun 07 00:48:29 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_13_machdep.c,v 1.18 2009/11/21 05:35:40 rmind Exp $ */
+/* $NetBSD: compat_13_machdep.c,v 1.19 2011/06/07 00:48:29 matt Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.18 2009/11/21 05:35:40 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.19 2011/06/07 00:48:29 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -94,8 +94,7 @@
 
        /* XXX ksc.sc_ownedfp ? */
        pcb = lwp_getpcb(l);
-       if (pcb->pcb_fpcpu != NULL)
-               fpusave_proc(l, 0);
+       fpu_discard();
        memcpy(&pcb->pcb_fp, (struct fpreg *)ksc.sc_fpregs,
            sizeof(struct fpreg));
        /* XXX ksc.sc_fp_control ? */
diff -r 4ba9bd6120a5 -r 85d2c76ea138 sys/arch/alpha/alpha/compat_16_machdep.c
--- a/sys/arch/alpha/alpha/compat_16_machdep.c  Tue Jun 07 00:10:20 2011 +0000
+++ b/sys/arch/alpha/alpha/compat_16_machdep.c  Tue Jun 07 00:48:29 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_16_machdep.c,v 1.16 2009/11/21 05:35:40 rmind Exp $ */
+/* $NetBSD: compat_16_machdep.c,v 1.17 2011/06/07 00:48:29 matt Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -86,7 +86,7 @@
 #include <machine/cpu.h>
 #include <machine/reg.h>
 
-__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.16 2009/11/21 05:35:40 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.17 2011/06/07 00:48:29 matt Exp $");
 
 
 #ifdef DEBUG
@@ -132,9 +132,8 @@
        frame.sf_sc.sc_regs[R_SP] = alpha_pal_rdusp();
 
        /* save the floating-point state, if necessary, then copy it. */
-       if (pcb->pcb_fpcpu != NULL)
-               fpusave_proc(l, 1);
-       frame.sf_sc.sc_ownedfp = l->l_md.md_flags & MDP_FPUSED;
+       fpu_save();
+       frame.sf_sc.sc_ownedfp = fpu_used_p(l);
        memcpy((struct fpreg *)frame.sf_sc.sc_fpregs, &pcb->pcb_fp,
            sizeof(struct fpreg));
        frame.sf_sc.sc_fp_control = alpha_read_fp_c(l);
@@ -281,14 +280,13 @@
        regtoframe((struct reg *)ksc.sc_regs, l->l_md.md_tf);
        alpha_pal_wrusp(ksc.sc_regs[R_SP]);
 
-       /* XXX ksc.sc_ownedfp ? */
        pcb = lwp_getpcb(l);
-       if (pcb->pcb_fpcpu != NULL)
-               fpusave_proc(l, 0);
+       fpu_discard();
        memcpy(&pcb->pcb_fp, (struct fpreg *)ksc.sc_fpregs,
            sizeof(struct fpreg));
        pcb->pcb_fp.fpr_cr = ksc.sc_fpcr;
-       l->l_md.md_flags = ksc.sc_fp_control & MDP_FP_C;
+       l->l_md.md_flags = (ksc.sc_fp_control & MDLWP_FP_C)
+           | (ksc.sc_ownedfp ? MDLWP_FPUSED : 0);
 
        mutex_enter(p->p_lock);
        /* Restore signal stack. */
diff -r 4ba9bd6120a5 -r 85d2c76ea138 sys/arch/alpha/alpha/core_machdep.c
--- a/sys/arch/alpha/alpha/core_machdep.c       Tue Jun 07 00:10:20 2011 +0000
+++ b/sys/arch/alpha/alpha/core_machdep.c       Tue Jun 07 00:48:29 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: core_machdep.c,v 1.4 2010/12/15 01:32:31 matt Exp $ */
+/* $NetBSD: core_machdep.c,v 1.5 2011/06/07 00:48:29 matt Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.4 2010/12/15 01:32:31 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.5 2011/06/07 00:48:29 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -68,10 +68,9 @@
 
        cpustate.md_tf = *l->l_md.md_tf;
        cpustate.md_tf.tf_regs[FRAME_SP] = alpha_pal_rdusp();   /* XXX */
-       if (l->l_md.md_flags & MDP_FPUSED) {
+       if (fpu_used_p(l)) {
                struct pcb *pcb = lwp_getpcb(l);
-               if (pcb->pcb_fpcpu != NULL)
-                       fpusave_proc(l, 1);
+               fpu_save();
                cpustate.md_fpstate = pcb->pcb_fp;
        } else
                memset(&cpustate.md_fpstate, 0, sizeof(cpustate.md_fpstate));
diff -r 4ba9bd6120a5 -r 85d2c76ea138 sys/arch/alpha/alpha/cpu.c
--- a/sys/arch/alpha/alpha/cpu.c        Tue Jun 07 00:10:20 2011 +0000
+++ b/sys/arch/alpha/alpha/cpu.c        Tue Jun 07 00:48:29 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.90 2010/12/17 02:36:35 joerg Exp $ */
+/* $NetBSD: cpu.c,v 1.91 2011/06/07 00:48:30 matt Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.90 2010/12/17 02:36:35 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.91 2011/06/07 00:48:30 matt Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -660,16 +660,15 @@
        struct cpu_info *ci;
        CPU_INFO_ITERATOR cii;
 
-       db_printf("addr         dev     id      flags   ipis    curproc         fpcurproc\n");
+       db_printf("addr         dev     id      flags   ipis    curproc\n");
        for (CPU_INFO_FOREACH(cii, ci)) {
-               db_printf("%p   %s      %lu     %lx     %lx     %p      %p\n",
+               db_printf("%p   %s      %lu     %lx     %lx     %p\n",
                    ci,
                    ci->ci_softc->sc_dev.dv_xname,
                    ci->ci_cpuid,
                    ci->ci_flags,
                    ci->ci_ipis,
-                   ci->ci_curlwp,
-                   ci->ci_fpcurlwp);
+                   ci->ci_curlwp);
        }
 }
 
diff -r 4ba9bd6120a5 -r 85d2c76ea138 sys/arch/alpha/alpha/fp_complete.c
--- a/sys/arch/alpha/alpha/fp_complete.c        Tue Jun 07 00:10:20 2011 +0000
+++ b/sys/arch/alpha/alpha/fp_complete.c        Tue Jun 07 00:48:29 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fp_complete.c,v 1.12 2008/05/10 15:31:04 martin Exp $ */
+/* $NetBSD: fp_complete.c,v 1.13 2011/06/07 00:48:30 matt Exp $ */
 
 /*-
  * Copyright (c) 2001 Ross Harvey
@@ -35,13 +35,15 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: fp_complete.c,v 1.12 2008/05/10 15:31:04 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fp_complete.c,v 1.13 2011/06/07 00:48:30 matt Exp $");
 
 #include "opt_compat_osf1.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
+#include <sys/atomic.h>
+#include <sys/evcnt.h>
 
 #ifdef COMPAT_OSF1
 #include <compat/osf1/osf1_exec.h>
@@ -99,6 +101,9 @@
 
 #define        CRBLIT(sw, hw, m, offs) (((sw) & ~(m)) | ((hw) >> (offs) & (m)))
 
+struct evcnt fpevent_use;
+struct evcnt fpevent_reuse;
+
 /*
  * Temporary trap shadow instrumentation. The [un]resolved counters
  * could be kept permanently, as they provide information on whether
@@ -398,12 +403,13 @@
 {
        u_int64_t md_flags;
 
-       fp_c &= MDP_FP_C;
+       fp_c &= MDLWP_FP_C;
        md_flags = l->l_md.md_flags;
-       if ((md_flags & MDP_FP_C) == fp_c)
+       if ((md_flags & MDLWP_FP_C) == fp_c)
                return;
-       l->l_md.md_flags = (md_flags & ~MDP_FP_C) | fp_c;
-       alpha_enable_fp(l, 1);
+       l->l_md.md_flags = (md_flags & ~MDLWP_FP_C) | fp_c;
+       fpu_load();
+       alpha_pal_wrfen(1);
        fp_c_to_fpcr(l);
        alpha_pal_wrfen(0);
 }
@@ -417,7 +423,7 @@
         * but in a transparent way. Some of the code for that would need to
         * go right here.
         */
-       return l->l_md.md_flags & MDP_FP_C;
+       return l->l_md.md_flags & MDLWP_FP_C;
 }
 
 static float64
@@ -579,7 +585,8 @@
                this_cannot_happen(6, -1);
                return SIGSEGV;
        }
-       alpha_enable_fp(l, 1);
+       fpu_load();
+       alpha_pal_wrfen(1);
        /*
         * If necessary, lie about the dynamic rounding mode so emulation
         * software need go to only one place for it, and so we don't have to
@@ -707,3 +714,55 @@
        }
        return 0;
 }
+
+/*
+ * Load the float-point context for the current lwp.
+ */
+void
+fpu_state_load(struct lwp *l, bool used)
+{
+       struct pcb * const pcb = lwp_getpcb(l);
+
+       /*
+        * Instrument FP usage -- if a process had not previously
+        * used FP, mark it as having used FP for the first time,
+        * and count this event.
+        *
+        * If a process has used FP, count a "used FP, and took
+        * a trap to use it again" event.
+        */
+       if (!fpu_used_p(l)) {
+               atomic_inc_ulong(&fpevent_use.ev_count);
+               fpu_mark_used(l);
+       } else
+               atomic_inc_ulong(&fpevent_reuse.ev_count);
+
+       alpha_pal_wrfen(1);
+       restorefpstate(&pcb->pcb_fp);
+       alpha_pal_wrfen(0);
+
+       l->l_md.md_flags |= MDLWP_FPACTIVE;
+}
+
+/*
+ * Save the FPU state.
+ */
+
+void
+fpu_state_save(struct lwp *l)
+{
+       struct pcb * const pcb = lwp_getpcb(l);
+
+       alpha_pal_wrfen(1);
+       savefpstate(&pcb->pcb_fp);
+       alpha_pal_wrfen(0);
+}
+
+/*
+ * Release the FPU.
+ */
+void
+fpu_state_release(struct lwp *l)
+{
+       l->l_md.md_flags &= ~MDLWP_FPACTIVE;
+}
diff -r 4ba9bd6120a5 -r 85d2c76ea138 sys/arch/alpha/alpha/genassym.cf
--- a/sys/arch/alpha/alpha/genassym.cf  Tue Jun 07 00:10:20 2011 +0000
+++ b/sys/arch/alpha/alpha/genassym.cf  Tue Jun 07 00:48:29 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.19 2010/12/15 01:33:37 matt Exp $
+# $NetBSD: genassym.cf,v 1.20 2011/06/07 00:48:30 matt Exp $
 
 #
 # Copyright (c) 1982, 1990, 1993
@@ -190,7 +190,6 @@
 
 # CPU info
 define CPU_INFO_CURLWP         offsetof(struct cpu_info, ci_curlwp)
-define CPU_INFO_FPCURLWP       offsetof(struct cpu_info, ci_fpcurlwp)
 define CPU_INFO_CURPCB         offsetof(struct cpu_info, ci_curpcb)
 define CPU_INFO_IDLE_LWP       offsetof(struct cpu_info, ci_data.cpu_idlelwp)
 define CPU_INFO_SIZEOF         sizeof(struct cpu_info)
diff -r 4ba9bd6120a5 -r 85d2c76ea138 sys/arch/alpha/alpha/ipifuncs.c
--- a/sys/arch/alpha/alpha/ipifuncs.c   Tue Jun 07 00:10:20 2011 +0000
+++ b/sys/arch/alpha/alpha/ipifuncs.c   Tue Jun 07 00:48:29 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ipifuncs.c,v 1.45 2010/12/17 02:36:35 joerg Exp $ */
+/* $NetBSD: ipifuncs.c,v 1.46 2011/06/07 00:48:30 matt Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.



Home | Main Index | Thread Index | Old Index