Module Name:    src
Committed By:   riastradh
Date:           Sat Aug  1 02:06:59 UTC 2020

Modified Files:
        src/sys/arch/aarch64/aarch64: fpu.c trap.c

Log Message:
Add kthread_fpu_enter/exit support to aarch64.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/aarch64/aarch64/fpu.c
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/aarch64/aarch64/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/fpu.c
diff -u src/sys/arch/aarch64/aarch64/fpu.c:1.7 src/sys/arch/aarch64/aarch64/fpu.c:1.8
--- src/sys/arch/aarch64/aarch64/fpu.c:1.7	Mon Jul 13 16:54:03 2020
+++ src/sys/arch/aarch64/aarch64/fpu.c	Sat Aug  1 02:06:59 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: fpu.c,v 1.7 2020/07/13 16:54:03 riastradh Exp $ */
+/* $NetBSD: fpu.c,v 1.8 2020/08/01 02:06:59 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,10 +31,12 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(1, "$NetBSD: fpu.c,v 1.7 2020/07/13 16:54:03 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: fpu.c,v 1.8 2020/08/01 02:06:59 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
+#include <sys/cpu.h>
+#include <sys/kthread.h>
 #include <sys/lwp.h>
 #include <sys/evcnt.h>
 
@@ -176,12 +178,30 @@ fpu_state_release(lwp_t *l)
 	__asm __volatile ("isb");
 }
 
+static const struct fpreg zero_fpreg;
+
+/*
+ * 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);
+}
+
 void
 fpu_kern_enter(void)
 {
 	struct cpu_info *ci;
 	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
@@ -209,10 +229,16 @@ fpu_kern_enter(void)
 void
 fpu_kern_leave(void)
 {
-	static const struct fpreg zero_fpreg;
-	struct cpu_info *ci = curcpu();
+	struct cpu_info *ci;
 	int s;
 
+	if (lwp_system_fpu_p(curlwp) && !cpu_intr_p()) {
+		KASSERT(!cpu_softintr_p());
+		return;
+	}
+
+	ci = curcpu();
+
 	KASSERT(ci->ci_cpl == IPL_VM);
 	KASSERT(ci->ci_kfpu_spl != -1);
 
@@ -234,3 +260,19 @@ fpu_kern_leave(void)
 	ci->ci_kfpu_spl = -1;
 	splx(s);
 }
+
+void
+kthread_fpu_enter_md(void)
+{
+
+	fpu_load(curlwp);
+}
+
+void
+kthread_fpu_exit_md(void)
+{
+
+	/* XXX Should fpu_state_release zero the registers itself?  */
+	load_fpregs(&zero_fpreg);
+	fpu_discard(curlwp, 0);
+}

Index: src/sys/arch/aarch64/aarch64/trap.c
diff -u src/sys/arch/aarch64/aarch64/trap.c:1.34 src/sys/arch/aarch64/aarch64/trap.c:1.35
--- src/sys/arch/aarch64/aarch64/trap.c:1.34	Mon Jul 27 07:32:48 2020
+++ src/sys/arch/aarch64/aarch64/trap.c	Sat Aug  1 02:06:59 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.34 2020/07/27 07:32:48 ryo Exp $ */
+/* $NetBSD: trap.c,v 1.35 2020/08/01 02:06:59 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.34 2020/07/27 07:32:48 ryo Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.35 2020/08/01 02:06:59 riastradh Exp $");
 
 #include "opt_arm_intr_impl.h"
 #include "opt_compat_netbsd32.h"
@@ -242,6 +242,12 @@ trap_el1h_sync(struct trapframe *tf)
 		break;
 
 	case ESR_EC_FP_ACCESS:
+		if ((curlwp->l_flag & (LW_SYSTEM|LW_SYSTEM_FPU)) ==
+		    (LW_SYSTEM|LW_SYSTEM_FPU)) {
+			fpu_load(curlwp);
+			break;
+		}
+		/*FALLTHROUGH*/
 	case ESR_EC_FP_TRAP_A64:
 	case ESR_EC_PC_ALIGNMENT:
 	case ESR_EC_SP_ALIGNMENT:

Reply via email to