Implement MP-safe lazy FP context switching, modeled on the

way Bill Sommerfeld implemented it for x86 (and bug fixes
fed back to Bill :-)
This commit is contained in:
thorpej 2000-08-15 22:16:17 +00:00
parent 32e6a89b31
commit 5a7793edd9
9 changed files with 134 additions and 73 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat_13_machdep.c,v 1.6 1999/08/16 02:59:22 simonb Exp $ */
/* $NetBSD: compat_13_machdep.c,v 1.7 2000/08/15 22:16:17 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@ -29,7 +29,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.6 1999/08/16 02:59:22 simonb Exp $");
__KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.7 2000/08/15 22:16:17 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -92,8 +92,8 @@ compat_13_sys_sigreturn(p, v, retval)
alpha_pal_wrusp(ksc.sc_regs[R_SP]);
/* XXX ksc.sc_ownedfp ? */
if (p == fpcurproc)
fpcurproc = NULL;
if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
synchronize_fpstate(p, 0);
bcopy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp,
sizeof(struct fpreg));
/* XXX ksc.sc_fp_control ? */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ipifuncs.c,v 1.14 2000/08/13 18:20:55 thorpej Exp $ */
/* $NetBSD: ipifuncs.c,v 1.15 2000/08/15 22:16:17 thorpej Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@ -39,7 +39,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: ipifuncs.c,v 1.14 2000/08/13 18:20:55 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: ipifuncs.c,v 1.15 2000/08/15 22:16:17 thorpej Exp $");
/*
* Interprocessor interrupt handlers.
@ -53,6 +53,7 @@ __KERNEL_RCSID(0, "$NetBSD: ipifuncs.c,v 1.14 2000/08/13 18:20:55 thorpej Exp $"
#include <machine/atomic.h>
#include <machine/alpha_cpu.h>
#include <machine/alpha.h>
#include <machine/cpu.h>
#include <machine/cpuvar.h>
#include <machine/intr.h>
@ -63,6 +64,8 @@ void alpha_ipi_tbia(void);
void alpha_ipi_tbiap(void);
void alpha_ipi_imb(void);
void alpha_ipi_ast(void);
void alpha_ipi_synch_fpu(void);
void alpha_ipi_discard_fpu(void);
/*
* NOTE: This table must be kept in order with the bit definitions
@ -75,6 +78,8 @@ ipifunc_t ipifuncs[ALPHA_NIPIS] = {
pmap_do_tlb_shootdown,
alpha_ipi_imb,
alpha_ipi_ast,
alpha_ipi_synch_fpu,
alpha_ipi_discard_fpu,
};
/*
@ -185,3 +190,17 @@ alpha_ipi_ast(void)
aston(curcpu());
}
void
alpha_ipi_synch_fpu(void)
{
release_fpu(1);
}
void
alpha_ipi_discard_fpu(void)
{
release_fpu(0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.218 2000/07/03 17:52:33 thorpej Exp $ */
/* $NetBSD: machdep.c,v 1.219 2000/08/15 22:16:17 thorpej Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@ -73,7 +73,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.218 2000/07/03 17:52:33 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.219 2000/08/15 22:16:17 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -1503,12 +1503,8 @@ sendsig(catcher, sig, mask, code)
ksc.sc_regs[R_SP] = alpha_pal_rdusp();
/* save the floating-point state, if necessary, then copy it. */
if (p == fpcurproc) {
alpha_pal_wrfen(1);
savefpstate(&p->p_addr->u_pcb.pcb_fp);
alpha_pal_wrfen(0);
fpcurproc = NULL;
}
if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
synchronize_fpstate(p, 1);
ksc.sc_ownedfp = p->p_md.md_flags & MDP_FPUSED;
bcopy(&p->p_addr->u_pcb.pcb_fp, (struct fpreg *)ksc.sc_fpregs,
sizeof(struct fpreg));
@ -1635,8 +1631,8 @@ sys___sigreturn14(p, v, retval)
alpha_pal_wrusp(ksc.sc_regs[R_SP]);
/* XXX ksc.sc_ownedfp ? */
if (p == fpcurproc)
fpcurproc = NULL;
if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
synchronize_fpstate(p, 0);
bcopy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp,
sizeof(struct fpreg));
/* XXX ksc.sc_fp_control ? */
@ -1759,8 +1755,69 @@ setregs(p, pack, stack)
tfp->tf_regs[FRAME_T12] = tfp->tf_regs[FRAME_PC]; /* a.k.a. PV */
p->p_md.md_flags &= ~MDP_FPUSED;
if (fpcurproc == p)
fpcurproc = NULL;
if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
synchronize_fpstate(p, 0);
}
/*
* Release the FPU.
*/
void
release_fpu(int save)
{
struct proc *p;
int s;
s = splhigh();
if ((p = fpcurproc) == NULL) {
splx(s);
return;
}
fpcurproc = NULL;
splx(s);
if (save) {
alpha_pal_wrfen(1);
savefpstate(&p->p_addr->u_pcb.pcb_fp);
#if defined(MULTIPROCESSOR)
alpha_mb();
#endif
alpha_pal_wrfen(0);
}
p->p_addr->u_pcb.pcb_fpcpu = NULL;
#if defined(MULTIPROCESSOR)
alpha_mb();
#endif
}
/*
* Synchronize FP state for this process.
*/
void
synchronize_fpstate(struct proc *p, int save)
{
if (p->p_addr->u_pcb.pcb_fpcpu == NULL) {
/* Already in-sync. */
return;
}
#if defined(MULTIPROCESSOR)
if (p->p_addr->u_pcb.pcb_fpcpu == curcpu()) {
KASSERT(fpcurproc == p);
release_fpu(save);
} else {
alpha_send_ipi(p->p_addr->u_pcb.pcb_fpcpu->ci_cpuid, save ?
ALPHA_IPI_SYNCH_FPU : ALPHA_IPI_DISCARD_FPU);
do {
alpha_mb();
} while (p->p_addr->u_pcb.pcb_fpcpu != NULL);
}
#else
KASSERT(fpcurproc == p);
release_fpu(save);
#endif /* MULTIPROCESSOR */
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: process_machdep.c,v 1.13 1999/08/10 23:35:45 thorpej Exp $ */
/* $NetBSD: process_machdep.c,v 1.14 2000/08/15 22:16:17 thorpej Exp $ */
/*
* Copyright (c) 1994 Christopher G. Demetriou
@ -54,7 +54,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.13 1999/08/10 23:35:45 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.14 2000/08/15 22:16:17 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -126,11 +126,8 @@ process_read_fpregs(p, regs)
struct fpreg *regs;
{
if (p == fpcurproc) {
alpha_pal_wrfen(1);
savefpstate(process_fpframe(p));
alpha_pal_wrfen(0);
}
if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
synchronize_fpstate(p, 1);
bcopy(process_fpframe(p), regs, sizeof(struct fpreg));
return (0);
@ -142,8 +139,8 @@ process_write_fpregs(p, regs)
struct fpreg *regs;
{
if (p == fpcurproc)
fpcurproc = NULL;
if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
synchronize_fpstate(p, 0);
bcopy(regs, process_fpframe(p), sizeof(struct fpreg));
return (0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: trap.c,v 1.58 2000/06/30 00:00:26 mjacob Exp $ */
/* $NetBSD: trap.c,v 1.59 2000/08/15 22:16:17 thorpej Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -102,7 +102,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.58 2000/06/30 00:00:26 mjacob Exp $");
__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.59 2000/08/15 22:16:17 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -417,18 +417,15 @@ trap(a0, a1, a2, entry, framep)
goto dopanic;
}
if (fpcurproc != NULL)
release_fpu(1);
if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
synchronize_fpstate(p, 1);
alpha_pal_wrfen(1);
if (fpcurproc)
savefpstate(&fpcurproc->p_addr->u_pcb.pcb_fp);
/*
* XXXSMP
* Need to find out where this process's FP
* state actually is and possible cause it
* to be saved there first (via an IPI)
* before we can retore it here.
*/
restorefpstate(&p->p_addr->u_pcb.pcb_fp);
p->p_addr->u_pcb.pcb_fpcpu = curcpu();
fpcurproc = p;
restorefpstate(&fpcurproc->p_addr->u_pcb.pcb_fp);
alpha_pal_wrfen(0);
p->p_md.md_flags |= MDP_FPUSED;
@ -813,12 +810,8 @@ const static int reg_to_framereg[32] = {
(&(p)->p_addr->u_pcb.pcb_fp.fpr_regs[(reg)])
#define dump_fp_regs() \
if (p == fpcurproc) { \
alpha_pal_wrfen(1); \
savefpstate(&fpcurproc->p_addr->u_pcb.pcb_fp); \
alpha_pal_wrfen(0); \
fpcurproc = NULL; \
}
if (p->p_addr->u_pcb.pcb_fpcpu != NULL) \
synchronize_fpstate(p, 1)
#define unaligned_load(storage, ptrf, mod) \
if (copyin((caddr_t)va, &(storage), sizeof (storage)) != 0) \

View File

@ -1,4 +1,4 @@
/* $NetBSD: vm_machdep.c,v 1.59 2000/06/29 09:02:56 mrg Exp $ */
/* $NetBSD: vm_machdep.c,v 1.60 2000/08/15 22:16:18 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@ -29,7 +29,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.59 2000/06/29 09:02:56 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.60 2000/08/15 22:16:18 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -70,14 +70,11 @@ cpu_coredump(p, vp, cred, chdr)
cpustate.md_tf = *p->p_md.md_tf;
cpustate.md_tf.tf_regs[FRAME_SP] = alpha_pal_rdusp(); /* XXX */
if (p->p_md.md_flags & MDP_FPUSED)
if (p == fpcurproc) {
alpha_pal_wrfen(1);
savefpstate(&cpustate.md_fpstate);
alpha_pal_wrfen(0);
} else
cpustate.md_fpstate = p->p_addr->u_pcb.pcb_fp;
else
if (p->p_md.md_flags & MDP_FPUSED) {
if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
synchronize_fpstate(p, 1);
cpustate.md_fpstate = p->p_addr->u_pcb.pcb_fp;
} else
bzero(&cpustate.md_fpstate, sizeof(cpustate.md_fpstate));
CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
@ -111,8 +108,8 @@ cpu_exit(p)
struct proc *p;
{
if (p == fpcurproc)
fpcurproc = NULL;
if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
synchronize_fpstate(p, 0);
/*
* Deactivate the exiting address space before the vmspace
@ -167,11 +164,8 @@ cpu_fork(p1, p2, stack, stacksize, func, arg)
* Copy floating point state from the FP chip to the PCB
* if this process has state stored there.
*/
if (p1 == fpcurproc) {
alpha_pal_wrfen(1);
savefpstate(&fpcurproc->p_addr->u_pcb.pcb_fp);
alpha_pal_wrfen(0);
}
if (p1->p_addr->u_pcb.pcb_fpcpu != NULL)
synchronize_fpstate(p1, 1);
/*
* Copy pcb and user stack pointer from proc p1 to p2.
@ -262,13 +256,8 @@ cpu_swapout(p)
struct proc *p;
{
if (p != fpcurproc)
return;
alpha_pal_wrfen(1);
savefpstate(&fpcurproc->p_addr->u_pcb.pcb_fp);
alpha_pal_wrfen(0);
fpcurproc = NULL;
if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
synchronize_fpstate(p, 1);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: alpha.h,v 1.10 2000/06/08 03:10:06 thorpej Exp $ */
/* $NetBSD: alpha.h,v 1.11 2000/08/15 22:16:18 thorpej Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -95,6 +95,9 @@ void trap_init(void);
void enable_nsio_ide(bus_space_tag_t);
char * dot_conv(unsigned long);
void release_fpu(int);
void synchronize_fpstate(struct proc *, int);
/* Multiprocessor glue; cpu.c */
struct cpu_info;
int cpu_iccb_send(long, const char *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: intr.h,v 1.31 2000/08/13 18:20:55 thorpej Exp $ */
/* $NetBSD: intr.h,v 1.32 2000/08/15 22:16:19 thorpej Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -157,8 +157,10 @@ _splraise(int s)
#define ALPHA_IPI_SHOOTDOWN 0x0000000000000008UL
#define ALPHA_IPI_IMB 0x0000000000000010UL
#define ALPHA_IPI_AST 0x0000000000000020UL
#define ALPHA_IPI_SYNCH_FPU 0x0000000000000040UL
#define ALPHA_IPI_DISCARD_FPU 0x0000000000000080UL
#define ALPHA_NIPIS 6 /* must not exceed 64 */
#define ALPHA_NIPIS 8 /* must not exceed 64 */
typedef void (*ipifunc_t)(void);
extern ipifunc_t ipifuncs[ALPHA_NIPIS];

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcb.h,v 1.6 1997/04/06 08:47:33 cgd Exp $ */
/* $NetBSD: pcb.h,v 1.7 2000/08/15 22:16:19 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@ -51,6 +51,7 @@ struct pcb {
struct fpreg pcb_fp; /* FP registers [SW] */
unsigned long pcb_onfault; /* for copy faults [SW] */
unsigned long pcb_accessaddr; /* for [fs]uswintr [SW] */
struct cpu_info * __volatile pcb_fpcpu; /* CPU with our FP state[SW] */
};
/*