Module Name:    src
Committed By:   dsl
Date:           Tue Feb  4 21:09:24 UTC 2014

Modified Files:
        src/sys/arch/amd64/amd64: fpu.c
        src/sys/arch/i386/i386: i386_trap.S
        src/sys/arch/i386/isa: npx.c
        src/sys/arch/x86/include: cpu.h

Log Message:
There is no need to check for recursive calls into fpudna().
Rename the associated ci_fpsaving field to 'unused'.
I'm not sure they could ever happen, you could get unwanted calls into
  the fpu trap code while saving state when using INT13 - but these are
  different.
The return value from the i386 fpudna() was always 1 - possibly a historic
  relic of the kernel fp emulation. Remove and don't check in trap.S.
The amd64 and i386 fpudna() code is now almost identical.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/amd64/amd64/fpu.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/i386/i386/i386_trap.S
cvs rdiff -u -r1.151 -r1.152 src/sys/arch/i386/isa/npx.c
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/x86/include/cpu.h

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/amd64/amd64/fpu.c
diff -u src/sys/arch/amd64/amd64/fpu.c:1.44 src/sys/arch/amd64/amd64/fpu.c:1.45
--- src/sys/arch/amd64/amd64/fpu.c:1.44	Wed Dec 11 22:06:51 2013
+++ src/sys/arch/amd64/amd64/fpu.c	Tue Feb  4 21:09:23 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.44 2013/12/11 22:06:51 dsl Exp $	*/
+/*	$NetBSD: fpu.c,v 1.45 2014/02/04 21:09:23 dsl Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -100,7 +100,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.44 2013/12/11 22:06:51 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.45 2014/02/04 21:09:23 dsl Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -256,12 +256,6 @@ fpudna(struct cpu_info *ci)
 	struct pcb *pcb;
 	int s;
 
-	if (ci->ci_fpsaving) {
-		/* Recursive trap. */
-		x86_enable_intr();
-		return;
-	}
-
 	/* Lock out IPIs and disable preemption. */
 	s = splhigh();
 	x86_enable_intr();
@@ -361,16 +355,8 @@ fpusave_cpu(bool save)
 	pcb = lwp_getpcb(l);
 
 	if (save) {
-		 /*
-		  * Set ci->ci_fpsaving, so that any pending exception will
-		  * be thrown away.  It will be caught again if/when the
-		  * FPU state is restored.
-		  */
-		KASSERT(ci->ci_fpsaving == 0);
 		clts();
-		ci->ci_fpsaving = 1;
 		fxsave(&pcb->pcb_savefpu);
-		ci->ci_fpsaving = 0;
 	}
 
 	stts();

Index: src/sys/arch/i386/i386/i386_trap.S
diff -u src/sys/arch/i386/i386/i386_trap.S:1.3 src/sys/arch/i386/i386/i386_trap.S:1.4
--- src/sys/arch/i386/i386/i386_trap.S:1.3	Sun Feb  2 22:41:20 2014
+++ src/sys/arch/i386/i386/i386_trap.S	Tue Feb  4 21:09:23 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386_trap.S,v 1.3 2014/02/02 22:41:20 dsl Exp $	*/
+/*	$NetBSD: i386_trap.S,v 1.4 2014/02/04 21:09:23 dsl Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.3 2014/02/02 22:41:20 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.4 2014/02/04 21:09:23 dsl Exp $");
 #endif
 
 /*
@@ -165,8 +165,6 @@ IDTVEC(trap07)
 	pushl	CPUVAR(SELF)
 	call	_C_LABEL(fpudna)
 	addl	$4,%esp
-	testl	%eax,%eax
-	jz	calltrap
 	jmp	_C_LABEL(trapreturn)
 IDTVEC_END(trap07)
 IDTVEC(trap08)

Index: src/sys/arch/i386/isa/npx.c
diff -u src/sys/arch/i386/isa/npx.c:1.151 src/sys/arch/i386/isa/npx.c:1.152
--- src/sys/arch/i386/isa/npx.c:1.151	Mon Feb  3 23:00:32 2014
+++ src/sys/arch/i386/isa/npx.c	Tue Feb  4 21:09:23 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: npx.c,v 1.151 2014/02/03 23:00:32 dsl Exp $	*/
+/*	$NetBSD: npx.c,v 1.152 2014/02/04 21:09:23 dsl Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.151 2014/02/03 23:00:32 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.152 2014/02/04 21:09:23 dsl Exp $");
 
 #if 0
 #define IPRINTF(x)	printf x
@@ -151,7 +151,7 @@ __KERNEL_RCSID(0, "$NetBSD: npx.c,v 1.15
 
 static int	x86fpflags_to_ksiginfo(uint32_t flags);
 /* Called directly from i386_trap.S */
-int	fpudna(struct cpu_info *);
+void	fpudna(struct cpu_info *);
 
 #ifdef XEN
 #define	clts() HYPERVISOR_fpu_taskswitch(0)
@@ -358,22 +358,19 @@ x86fpflags_to_ksiginfo(uint32_t flags)
 /*
  * Implement device not available (DNA) exception
  *
+ * Called directly from i386_trap.S with interrupts still disabled
+ *
  * If we were the last lwp to use the FPU, we can simply return.
  * Otherwise, we save the previous state, if necessary, and restore
  * our last saved state.
  */
-int
+void
 fpudna(struct cpu_info *ci)
 {
 	struct lwp *l, *fl;
 	struct pcb *pcb;
 	int s;
 
-	if (ci->ci_fpsaving) {
-		/* Recursive trap. */
-		return 1;
-	}
-
 	/* Lock out IPIs and disable preemption. */
 	s = splhigh();
 #ifndef XEN
@@ -394,7 +391,7 @@ fpudna(struct cpu_info *ci)
 			ci->ci_fpused = 1;
 			clts();
 			splx(s);
-			return 1;
+			return;
 		}
 		KASSERT(fl != l);
 		fpusave_cpu(true);
@@ -457,7 +454,6 @@ fpudna(struct cpu_info *ci)
 
 	KASSERT(ci == curcpu());
 	splx(s);
-	return 1;
 }
 
 /*
@@ -480,20 +476,12 @@ fpusave_cpu(bool save)
 	pcb = lwp_getpcb(l);
 
 	if (save) {
-		 /*
-		  * Set ci->ci_fpsaving, so that any pending exception will
-		  * be thrown away.  It will be caught again if/when the
-		  * FPU state is restored.
-		  */
-		KASSERT(ci->ci_fpsaving == 0);
 		clts();
-		ci->ci_fpsaving = 1;
 		if (i386_use_fxsave) {
 			fxsave(&pcb->pcb_savefpu.sv_xmm);
 		} else {
 			fnsave(&pcb->pcb_savefpu.sv_87);
 		}
-		ci->ci_fpsaving = 0;
 	}
 
 	stts();

Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.59 src/sys/arch/x86/include/cpu.h:1.60
--- src/sys/arch/x86/include/cpu.h:1.59	Sun Jan 26 19:16:17 2014
+++ src/sys/arch/x86/include/cpu.h	Tue Feb  4 21:09:24 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.59 2014/01/26 19:16:17 dsl Exp $	*/
+/*	$NetBSD: cpu.h,v 1.60 2014/02/04 21:09:24 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -101,7 +101,7 @@ struct cpu_info {
 	struct cpu_info *ci_next;	/* next cpu */
 	struct lwp *ci_curlwp;		/* current owner of the processor */
 	struct lwp *ci_fpcurlwp;	/* current owner of the FPU */
-	int	ci_fpsaving;		/* save in progress */
+	int	_unused1;
 	int	ci_fpused;		/* XEN: FPU was used by curlwp */
 	cpuid_t ci_cpuid;		/* our CPU ID */
 	int	_unused;

Reply via email to