Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm/vfp Add kthread_fpu_enter/exit support to arm.



details:   https://anonhg.NetBSD.org/src/rev/3b629bc7067e
branches:  trunk
changeset: 936627:3b629bc7067e
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Aug 01 02:13:04 2020 +0000

description:
Add kthread_fpu_enter/exit support to arm.

diffstat:

 sys/arch/arm/vfp/vfp_init.c |  51 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 46 insertions(+), 5 deletions(-)

diffs (114 lines):

diff -r fefd06d3b944 -r 3b629bc7067e sys/arch/arm/vfp/vfp_init.c
--- a/sys/arch/arm/vfp/vfp_init.c       Sat Aug 01 02:06:59 2020 +0000
+++ b/sys/arch/arm/vfp/vfp_init.c       Sat Aug 01 02:13:04 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: vfp_init.c,v 1.70 2020/07/27 20:51:29 riastradh Exp $ */
+/*      $NetBSD: vfp_init.c,v 1.71 2020/08/01 02:13:04 riastradh Exp $ */
 
 /*
  * Copyright (c) 2008 ARM Ltd
@@ -32,12 +32,13 @@
 #include "opt_cputypes.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfp_init.c,v 1.70 2020/07/27 20:51:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfp_init.c,v 1.71 2020/08/01 02:13:04 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/systm.h>
 #include <sys/device.h>
+#include <sys/kthread.h>
 #include <sys/proc.h>
 #include <sys/cpu.h>
 
@@ -424,7 +425,8 @@
        struct cpu_info * const ci = curcpu();
 
        /* This shouldn't ever happen.  */
-       if (fault_code != FAULT_USER)
+       if (fault_code != FAULT_USER &&
+           (curlwp->l_flag & (LW_SYSTEM|LW_SYSTEM_FPU)) == LW_SYSTEM)
                panic("VFP fault at %#x in non-user mode", frame->tf_pc);
 
        if (ci->ci_vfp_id == 0) {
@@ -504,7 +506,8 @@
                return 1;
 
        /* This shouldn't ever happen.  */
-       if (fault_code != FAULT_USER)
+       if (fault_code != FAULT_USER &&
+           (curlwp->l_flag & (LW_SYSTEM|LW_SYSTEM_FPU)) == LW_SYSTEM)
                panic("NEON fault in non-user mode");
 
        /* if we already own the FPU and it's enabled, raise SIGILL */
@@ -668,6 +671,19 @@
            sizeof(mcp->__fpu.__vfpregs.__vfp_fstmx));
 }
 
+/*
+ * True if this is a system thread with its own private FPU state.
+ */
+static inline bool
+lwp_system_fpu_p(struct lwp *l)
+{
+
+       return (l->l_flag & (LW_SYSTEM|LW_SYSTEM_FPU)) ==
+           (LW_SYSTEM|LW_SYSTEM_FPU);
+}
+
+static const struct vfpreg zero_vfpreg;
+
 void
 fpu_kern_enter(void)
 {
@@ -675,6 +691,11 @@
        uint32_t fpexc;
        int s;
 
+       if (lwp_system_fpu_p(curlwp) && !cpu_intr_p()) {
+               KASSERT(!cpu_softintr_p());
+               return;
+       }
+
        /*
         * Block interrupts up to IPL_VM.  We must block preemption
         * since -- if this is a user thread -- there is nowhere to
@@ -701,11 +722,15 @@
 void
 fpu_kern_leave(void)
 {
-       static const struct vfpreg zero_vfpreg;
        struct cpu_info *ci = curcpu();
        int s;
        uint32_t fpexc;
 
+       if (lwp_system_fpu_p(curlwp) && !cpu_intr_p()) {
+               KASSERT(!cpu_softintr_p());
+               return;
+       }
+
        KASSERT(ci->ci_cpl == IPL_VM);
        KASSERT(ci->ci_kfpu_spl != -1);
 
@@ -730,4 +755,20 @@
        splx(s);
 }
 
+void
+kthread_fpu_enter_md(void)
+{
+
+       pcu_load(&arm_vfp_ops);
+}
+
+void
+kthread_fpu_exit_md(void)
+{
+
+       /* XXX Should vfp_state_release zero the registers itself?  */
+       load_vfpregs(&zero_vfpreg);
+       vfp_discardcontext(curlwp, 0);
+}
+
 #endif /* FPU_VFP */



Home | Main Index | Thread Index | Old Index