Module Name: src Committed By: maxv Date: Thu Oct 3 05:06:29 UTC 2019
Modified Files: src/sys/arch/amd64/amd64: locore.S src/sys/arch/i386/i386: locore.S src/sys/arch/x86/include: cpu.h src/sys/arch/x86/x86: fpu.c identcpu.c x86_machdep.c Log Message: Remove the LazyFPU code, as posted 5 months ago on port-amd64@. To generate a diff of this commit: cvs rdiff -u -r1.186 -r1.187 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.168 -r1.169 src/sys/arch/i386/i386/locore.S cvs rdiff -u -r1.108 -r1.109 src/sys/arch/x86/include/cpu.h cvs rdiff -u -r1.55 -r1.56 src/sys/arch/x86/x86/fpu.c cvs rdiff -u -r1.95 -r1.96 src/sys/arch/x86/x86/identcpu.c cvs rdiff -u -r1.127 -r1.128 src/sys/arch/x86/x86/x86_machdep.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/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.186 src/sys/arch/amd64/amd64/locore.S:1.187 --- src/sys/arch/amd64/amd64/locore.S:1.186 Wed Aug 21 16:35:10 2019 +++ src/sys/arch/amd64/amd64/locore.S Thu Oct 3 05:06:29 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.186 2019/08/21 16:35:10 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.187 2019/10/03 05:06:29 maxv Exp $ */ /* * Copyright-o-rama! @@ -1147,13 +1147,10 @@ ENTRY(cpu_switchto) movq %r12,%rsi callq _C_LABEL(x86_dbregs_switch) - movb _C_LABEL(x86_fpu_eager),%dl - testb %dl,%dl - jz .Lno_eagerfpu + /* Switch the FPU. */ movq %r13,%rdi movq %r12,%rsi callq _C_LABEL(fpu_eagerswitch) -.Lno_eagerfpu: /* Don't bother with the rest if switching to a system process. */ testl $LW_SYSTEM,L_FLAG(%r12) Index: src/sys/arch/i386/i386/locore.S diff -u src/sys/arch/i386/i386/locore.S:1.168 src/sys/arch/i386/i386/locore.S:1.169 --- src/sys/arch/i386/i386/locore.S:1.168 Sun May 19 08:17:02 2019 +++ src/sys/arch/i386/i386/locore.S Thu Oct 3 05:06:29 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.168 2019/05/19 08:17:02 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.169 2019/10/03 05:06:29 maxv Exp $ */ /* * Copyright-o-rama! @@ -128,7 +128,7 @@ */ #include <machine/asm.h> -__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.168 2019/05/19 08:17:02 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.169 2019/10/03 05:06:29 maxv Exp $"); #include "opt_copy_symtab.h" #include "opt_ddb.h" @@ -1137,15 +1137,12 @@ skip_save: call _C_LABEL(x86_dbregs_switch) addl $8,%esp + /* Switch the FPU. */ pushl %edx - movb _C_LABEL(x86_fpu_eager),%dl - testb %dl,%dl - jz .Lno_eagerfpu pushl %edi pushl %esi call _C_LABEL(fpu_eagerswitch) addl $8,%esp -.Lno_eagerfpu: popl %edx /* Don't bother with the rest if switching to a system process. */ Index: src/sys/arch/x86/include/cpu.h diff -u src/sys/arch/x86/include/cpu.h:1.108 src/sys/arch/x86/include/cpu.h:1.109 --- src/sys/arch/x86/include/cpu.h:1.108 Wed Aug 7 06:23:48 2019 +++ src/sys/arch/x86/include/cpu.h Thu Oct 3 05:06:29 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.108 2019/08/07 06:23:48 maxv Exp $ */ +/* $NetBSD: cpu.h,v 1.109 2019/10/03 05:06:29 maxv Exp $ */ /* * Copyright (c) 1990 The Regents of the University of California. @@ -462,7 +462,6 @@ extern uint64_t x86_xsave_features; extern size_t x86_xsave_offsets[]; extern size_t x86_xsave_sizes[]; extern uint32_t x86_fpu_mxcsr_mask; -extern bool x86_fpu_eager; extern void (*x86_cpu_idle)(void); #define cpu_idle() (*x86_cpu_idle)() Index: src/sys/arch/x86/x86/fpu.c diff -u src/sys/arch/x86/x86/fpu.c:1.55 src/sys/arch/x86/x86/fpu.c:1.56 --- src/sys/arch/x86/x86/fpu.c:1.55 Fri Jul 5 17:08:56 2019 +++ src/sys/arch/x86/x86/fpu.c Thu Oct 3 05:06:29 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: fpu.c,v 1.55 2019/07/05 17:08:56 maxv Exp $ */ +/* $NetBSD: fpu.c,v 1.56 2019/10/03 05:06:29 maxv Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. All @@ -96,7 +96,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.55 2019/07/05 17:08:56 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.56 2019/10/03 05:06:29 maxv Exp $"); #include "opt_multiprocessor.h" @@ -127,7 +127,6 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.55 #endif uint32_t x86_fpu_mxcsr_mask __read_mostly = 0; -bool x86_fpu_eager __read_mostly = false; static inline union savefpu * lwp_fpuarea(struct lwp *l) @@ -440,20 +439,13 @@ fputrap(struct trapframe *frame) } /* - * Implement device not available (DNA) exception. - * - * 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. - * - * Called directly from the trap 0x13 entry with interrupts still disabled. + * Implement device not available (DNA) exception. Called with interrupts still + * disabled. */ void fpudna(struct trapframe *frame) { struct cpu_info *ci = curcpu(); - struct lwp *l, *fl; - struct pcb *pcb; int s; if (!USERMODE(frame->tf_cs)) { @@ -461,55 +453,9 @@ fpudna(struct trapframe *frame) (void *)X86_TF_RIP(frame), frame); } - s = splhigh(); - - /* Save state on current CPU. */ - l = ci->ci_curlwp; - pcb = lwp_getpcb(l); - fl = ci->ci_fpcurlwp; - if (fl != NULL) { - if (__predict_false(x86_fpu_eager)) { - panic("%s: FPU busy with EagerFPU enabled", - __func__); - } - - /* - * It seems we can get here on Xen even if we didn't - * switch lwp. In this case do nothing - */ - if (fl == l) { - KASSERT(pcb->pcb_fpcpu == ci); - clts(); - splx(s); - return; - } - fpusave_cpu(true); - } - - /* Save our state if on a remote CPU. */ - if (pcb->pcb_fpcpu != NULL) { - if (__predict_false(x86_fpu_eager)) { - panic("%s: LWP busy with EagerFPU enabled", - __func__); - } - - /* Explicitly disable preemption before dropping spl. */ - kpreempt_disable(); - splx(s); - - /* Actually enable interrupts */ - x86_enable_intr(); - - fpusave_lwp(l, true); - KASSERT(pcb->pcb_fpcpu == NULL); - s = splhigh(); - kpreempt_enable(); - } - /* Install the LWP's FPU state. */ - fpu_lwp_install(l); - - KASSERT(ci == curcpu()); + s = splhigh(); + fpu_lwp_install(ci->ci_curlwp); splx(s); } @@ -625,14 +571,9 @@ fpu_clear(struct lwp *l, unsigned int x8 pcb = lwp_getpcb(l); s = splhigh(); - if (x86_fpu_eager) { - KASSERT(pcb->pcb_fpcpu == NULL || - pcb->pcb_fpcpu == curcpu()); - fpusave_cpu(false); - } else { - splx(s); - fpusave_lwp(l, false); - } + + KASSERT(pcb->pcb_fpcpu == NULL || pcb->pcb_fpcpu == curcpu()); + fpusave_cpu(false); KASSERT(pcb->pcb_fpcpu == NULL); switch (x86_fpu_save) { @@ -667,10 +608,8 @@ fpu_clear(struct lwp *l, unsigned int x8 pcb->pcb_fpu_dflt_cw = x87_cw; - if (x86_fpu_eager) { - fpu_lwp_install(l); - splx(s); - } + fpu_lwp_install(l); + splx(s); } void @@ -1073,110 +1012,3 @@ process_write_xstate(struct lwp *l, cons return 0; } - -/* -------------------------------------------------------------------------- */ - -static volatile unsigned long eagerfpu_cpu_barrier1 __cacheline_aligned; -static volatile unsigned long eagerfpu_cpu_barrier2 __cacheline_aligned; - -static void -eager_change_cpu(void *arg1, void *arg2) -{ - struct cpu_info *ci = curcpu(); - bool enabled = (bool)arg1; - int s; - - s = splhigh(); - - /* Rendez-vous 1. */ - atomic_dec_ulong(&eagerfpu_cpu_barrier1); - while (atomic_cas_ulong(&eagerfpu_cpu_barrier1, 0, 0) != 0) { - x86_pause(); - } - - fpusave_cpu(true); - if (ci == &cpu_info_primary) { - x86_fpu_eager = enabled; - } - - /* Rendez-vous 2. */ - atomic_dec_ulong(&eagerfpu_cpu_barrier2); - while (atomic_cas_ulong(&eagerfpu_cpu_barrier2, 0, 0) != 0) { - x86_pause(); - } - - splx(s); -} - -static int -eager_change(bool enabled) -{ - struct cpu_info *ci = NULL; - CPU_INFO_ITERATOR cii; - uint64_t xc; - - mutex_enter(&cpu_lock); - - /* - * We expect all the CPUs to be online. - */ - for (CPU_INFO_FOREACH(cii, ci)) { - struct schedstate_percpu *spc = &ci->ci_schedstate; - if (spc->spc_flags & SPCF_OFFLINE) { - printf("[!] cpu%d offline, EagerFPU not changed\n", - cpu_index(ci)); - mutex_exit(&cpu_lock); - return EOPNOTSUPP; - } - } - - /* Initialize the barriers */ - eagerfpu_cpu_barrier1 = ncpu; - eagerfpu_cpu_barrier2 = ncpu; - - printf("[+] %s EagerFPU...", - enabled ? "Enabling" : "Disabling"); - xc = xc_broadcast(0, eager_change_cpu, - (void *)enabled, NULL); - xc_wait(xc); - printf(" done!\n"); - - mutex_exit(&cpu_lock); - - return 0; -} - -static int -sysctl_machdep_fpu_eager(SYSCTLFN_ARGS) -{ - struct sysctlnode node; - int error; - bool val; - - val = *(bool *)rnode->sysctl_data; - - node = *rnode; - node.sysctl_data = &val; - - error = sysctl_lookup(SYSCTLFN_CALL(&node)); - if (error != 0 || newp == NULL) - return error; - - if (val == x86_fpu_eager) - return 0; - return eager_change(val); -} - -void sysctl_eagerfpu_init(struct sysctllog **); - -void -sysctl_eagerfpu_init(struct sysctllog **clog) -{ - sysctl_createv(clog, 0, NULL, NULL, - CTLFLAG_READWRITE, - CTLTYPE_BOOL, "fpu_eager", - SYSCTL_DESCR("Whether the kernel uses Eager FPU Switch"), - sysctl_machdep_fpu_eager, 0, - &x86_fpu_eager, 0, - CTL_MACHDEP, CTL_CREATE, CTL_EOL); -} Index: src/sys/arch/x86/x86/identcpu.c diff -u src/sys/arch/x86/x86/identcpu.c:1.95 src/sys/arch/x86/x86/identcpu.c:1.96 --- src/sys/arch/x86/x86/identcpu.c:1.95 Thu Sep 12 06:39:47 2019 +++ src/sys/arch/x86/x86/identcpu.c Thu Oct 3 05:06:29 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: identcpu.c,v 1.95 2019/09/12 06:39:47 maxv Exp $ */ +/* $NetBSD: identcpu.c,v 1.96 2019/10/03 05:06:29 maxv Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.95 2019/09/12 06:39:47 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.96 2019/10/03 05:06:29 maxv Exp $"); #include "opt_xen.h" @@ -758,7 +758,6 @@ cpu_probe_fpu(struct cpu_info *ci) u_int descs[4]; int i; - x86_fpu_eager = true; x86_fpu_save = FPU_SAVE_FSAVE; #ifdef i386 Index: src/sys/arch/x86/x86/x86_machdep.c diff -u src/sys/arch/x86/x86/x86_machdep.c:1.127 src/sys/arch/x86/x86/x86_machdep.c:1.128 --- src/sys/arch/x86/x86/x86_machdep.c:1.127 Wed May 29 16:54:41 2019 +++ src/sys/arch/x86/x86/x86_machdep.c Thu Oct 3 05:06:29 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_machdep.c,v 1.127 2019/05/29 16:54:41 maxv Exp $ */ +/* $NetBSD: x86_machdep.c,v 1.128 2019/10/03 05:06:29 maxv Exp $ */ /*- * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi, @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.127 2019/05/29 16:54:41 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.128 2019/10/03 05:06:29 maxv Exp $"); #include "opt_modular.h" #include "opt_physmem.h" @@ -1312,9 +1312,6 @@ SYSCTL_SETUP(sysctl_machdep_setup, "sysc sysctl_speculation_init(clog); #endif - void sysctl_eagerfpu_init(struct sysctllog **); - sysctl_eagerfpu_init(clog); - /* None of these can ever change once the system has booted */ const_sysctl(clog, "fpu_present", CTLTYPE_INT, i386_fpu_present, CPU_FPU_PRESENT);