Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Revert "x86: Add kthread_fpu_enter/exit support, ta...
details: https://anonhg.NetBSD.org/src/rev/dadbf401a5ed
branches: trunk
changeset: 373813:dadbf401a5ed
user: riastradh <riastradh%NetBSD.org@localhost>
date: Fri Mar 03 14:32:48 2023 +0000
description:
Revert "x86: Add kthread_fpu_enter/exit support, take two."
kthread_fpu_enter/exit changes broke some hardware, unclear why, to
investigate before fixing and reapplying these changes.
diffstat:
sys/arch/amd64/amd64/genassym.cf | 3 +-
sys/arch/amd64/amd64/locore.S | 19 +--------
sys/arch/x86/x86/fpu.c | 82 ++++++---------------------------------
3 files changed, 17 insertions(+), 87 deletions(-)
diffs (231 lines):
diff -r 972316739163 -r dadbf401a5ed sys/arch/amd64/amd64/genassym.cf
--- a/sys/arch/amd64/amd64/genassym.cf Fri Mar 03 14:32:38 2023 +0000
+++ b/sys/arch/amd64/amd64/genassym.cf Fri Mar 03 14:32:48 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.94 2023/02/25 18:04:42 riastradh Exp $
+# $NetBSD: genassym.cf,v 1.95 2023/03/03 14:32:48 riastradh Exp $
#
# Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -166,7 +166,6 @@
define L_MD_ASTPENDING offsetof(struct lwp, l_md.md_astpending)
define LW_SYSTEM LW_SYSTEM
-define LW_SYSTEM_FPU LW_SYSTEM_FPU
define MDL_IRET MDL_IRET
define MDL_COMPAT32 MDL_COMPAT32
define MDL_FPU_IN_CPU MDL_FPU_IN_CPU
diff -r 972316739163 -r dadbf401a5ed sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S Fri Mar 03 14:32:38 2023 +0000
+++ b/sys/arch/amd64/amd64/locore.S Fri Mar 03 14:32:48 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.217 2023/03/01 08:38:50 riastradh Exp $ */
+/* $NetBSD: locore.S,v 1.218 2023/03/03 14:32:48 riastradh Exp $ */
/*
* Copyright-o-rama!
@@ -1271,7 +1271,7 @@
/* Don't bother with the rest if switching to a system process. */
testl $LW_SYSTEM,L_FLAG(%r12)
- jnz .Lswitch_system
+ jnz .Lswitch_return
/* Is this process using RAS (restartable atomic sequences)? */
movq L_PROC(%r12),%rdi
@@ -1360,21 +1360,6 @@
popq %r12
popq %rbx
ret
-
-.Lswitch_system:
- /*
- * If it has LWP_SYSTEM_FPU set, meaning it's running in
- * kthread_fpu_enter/exit, we need to restore the FPU state
- * and enable FPU instructions with fpu_handle_deferred.
- *
- * No need to test MDL_FPU_IN_CPU via HANDLE_DEFERRED_FPU --
- * fpu_switch guarantees it is clear, so we can just call
- * fpu_handle_deferred unconditionally.
- */
- testl $LW_SYSTEM_FPU,L_FLAG(%r12)
- jz .Lswitch_return
- callq _C_LABEL(fpu_handle_deferred)
- jmp .Lswitch_return
END(cpu_switchto)
/*
diff -r 972316739163 -r dadbf401a5ed sys/arch/x86/x86/fpu.c
--- a/sys/arch/x86/x86/fpu.c Fri Mar 03 14:32:38 2023 +0000
+++ b/sys/arch/x86/x86/fpu.c Fri Mar 03 14:32:48 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fpu.c,v 1.84 2023/03/03 14:32:38 riastradh Exp $ */
+/* $NetBSD: fpu.c,v 1.85 2023/03/03 14:32:48 riastradh Exp $ */
/*
* Copyright (c) 2008, 2019 The NetBSD Foundation, Inc. All
@@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.84 2023/03/03 14:32:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.85 2023/03/03 14:32:48 riastradh Exp $");
#include "opt_multiprocessor.h"
@@ -107,7 +107,6 @@
#include <sys/file.h>
#include <sys/proc.h>
#include <sys/kernel.h>
-#include <sys/kthread.h>
#include <sys/sysctl.h>
#include <sys/xcall.h>
@@ -132,35 +131,13 @@
uint32_t x86_fpu_mxcsr_mask __read_mostly = 0;
-/*
- * True if this a thread that is allowed to use the FPU -- either a
- * user thread, or a system thread with LW_SYSTEM_FPU enabled.
- */
-static inline bool
-lwp_can_haz_fpu(struct lwp *l)
-{
-
- return (l->l_flag & (LW_SYSTEM|LW_SYSTEM_FPU)) != LW_SYSTEM;
-}
-
-/*
- * 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 inline union savefpu *
fpu_lwp_area(struct lwp *l)
{
struct pcb *pcb = lwp_getpcb(l);
union savefpu *area = &pcb->pcb_savefpu;
- KASSERT(lwp_can_haz_fpu(l));
+ KASSERT((l->l_flag & LW_SYSTEM) == 0);
if (l == curlwp) {
fpu_save();
}
@@ -178,7 +155,7 @@
s = splvm();
if (l->l_md.md_flags & MDL_FPU_IN_CPU) {
- KASSERT(lwp_can_haz_fpu(l));
+ KASSERT((l->l_flag & LW_SYSTEM) == 0);
fpu_area_save(area, x86_xsave_features, !(l->l_proc->p_flag & PK_32));
l->l_md.md_flags &= ~MDL_FPU_IN_CPU;
}
@@ -337,7 +314,7 @@
cpu_index(ci), ci->ci_ilevel);
if (oldlwp->l_md.md_flags & MDL_FPU_IN_CPU) {
- KASSERT(lwp_can_haz_fpu(oldlwp));
+ KASSERT(!(oldlwp->l_flag & LW_SYSTEM));
pcb = lwp_getpcb(oldlwp);
fpu_area_save(&pcb->pcb_savefpu, x86_xsave_features,
!(oldlwp->l_proc->p_flag & PK_32));
@@ -353,11 +330,11 @@
union savefpu *fpu_save;
/* Kernel threads have no FPU. */
- if (__predict_false(!lwp_can_haz_fpu(l2))) {
+ if (__predict_false(l2->l_flag & LW_SYSTEM)) {
return;
}
/* For init(8). */
- if (__predict_false(!lwp_can_haz_fpu(l1))) {
+ if (__predict_false(l1->l_flag & LW_SYSTEM)) {
memset(&pcb2->pcb_savefpu, 0, x86_fpu_save_size);
return;
}
@@ -381,13 +358,6 @@
/* -------------------------------------------------------------------------- */
-static const union savefpu safe_fpu __aligned(64) = {
- .sv_xmm = {
- .fx_mxcsr = __SAFE_MXCSR__,
- },
-};
-static const union savefpu zero_fpu __aligned(64);
-
/*
* fpu_kern_enter()
*
@@ -403,15 +373,15 @@
void
fpu_kern_enter(void)
{
+ static const union savefpu safe_fpu __aligned(64) = {
+ .sv_xmm = {
+ .fx_mxcsr = __SAFE_MXCSR__,
+ },
+ };
struct lwp *l = curlwp;
struct cpu_info *ci;
int s;
- if (lwp_system_fpu_p(l) && !cpu_intr_p()) {
- KASSERT(!cpu_softintr_p());
- return;
- }
-
s = splvm();
ci = curcpu();
@@ -457,16 +427,10 @@
void
fpu_kern_leave(void)
{
- struct cpu_info *ci;
+ static const union savefpu zero_fpu __aligned(64);
+ struct cpu_info *ci = curcpu();
int s;
- if (lwp_system_fpu_p(curlwp) && !cpu_intr_p()) {
- KASSERT(!cpu_softintr_p());
- return;
- }
-
- ci = curcpu();
-
#if 0
/*
* Can't assert this because if the caller holds a spin lock at
@@ -495,24 +459,6 @@
splx(s);
}
-void
-kthread_fpu_enter_md(void)
-{
-
- /* Enable the FPU by clearing CR0_TS, and enter a safe FPU state. */
- clts();
- fpu_area_restore(&safe_fpu, x86_xsave_features, /*is_64bit*/false);
-}
-
-void
-kthread_fpu_exit_md(void)
-{
-
- /* Zero the FPU state and disable the FPU by setting CR0_TS. */
- fpu_area_restore(&zero_fpu, x86_xsave_features, /*is_64bit*/false);
- stts();
-}
-
/* -------------------------------------------------------------------------- */
/*
Home |
Main Index |
Thread Index |
Old Index