Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Rework dbregs, to switch the registers during conte...



details:   https://anonhg.NetBSD.org/src/rev/651a2d3725f1
branches:  trunk
changeset: 324903:651a2d3725f1
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu Jul 26 09:29:08 2018 +0000

description:
Rework dbregs, to switch the registers during context switches, and not on
each user->kernel transition via userret. Reloads of DR6/DR7 are expensive
on both native and xen.

diffstat:

 sys/arch/amd64/amd64/locore.S           |    7 +-
 sys/arch/amd64/amd64/machdep.c          |   11 +--
 sys/arch/amd64/amd64/netbsd32_machdep.c |   12 +--
 sys/arch/amd64/amd64/trap.c             |    5 +-
 sys/arch/amd64/include/pcb.h            |    3 +-
 sys/arch/amd64/include/userret.h        |   10 +--
 sys/arch/i386/i386/locore.S             |   10 ++-
 sys/arch/i386/i386/machdep.c            |   12 +--
 sys/arch/i386/i386/trap.c               |    5 +-
 sys/arch/i386/include/pcb.h             |    7 +-
 sys/arch/i386/include/userret.h         |   10 +--
 sys/arch/x86/include/dbregs.h           |    5 +-
 sys/arch/x86/x86/dbregs.c               |  101 ++++++++++++++++++++++++++++---
 sys/arch/x86/x86/vm_machdep.c           |   10 ++-
 14 files changed, 141 insertions(+), 67 deletions(-)

diffs (truncated from 545 to 300 lines):

diff -r 766e75c927d8 -r 651a2d3725f1 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Thu Jul 26 08:57:32 2018 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Thu Jul 26 09:29:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.172 2018/07/21 06:09:13 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.173 2018/07/26 09:29:08 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -1143,6 +1143,11 @@
 #endif
 .Lring0_switched:
 
+       /* Switch the dbregs. */
+       movq    %r13,%rdi
+       movq    %r12,%rsi
+       callq   _C_LABEL(x86_dbregs_switch)
+
 #ifndef XEN
        movb    _C_LABEL(x86_fpu_eager),%dl
        testb   %dl,%dl
diff -r 766e75c927d8 -r 651a2d3725f1 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Thu Jul 26 08:57:32 2018 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Thu Jul 26 09:29:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.308 2018/07/22 15:02:51 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.309 2018/07/26 09:29:08 maxv Exp $       */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.308 2018/07/22 15:02:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.309 2018/07/26 09:29:08 maxv Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -280,8 +280,6 @@
 void (*initclock_func)(void) = xen_initclocks;
 #endif
 
-extern struct pool x86_dbregspl;
-
 struct nmistore {
        uint64_t cr3;
        uint64_t scratch;
@@ -1367,10 +1365,7 @@
        fpu_save_area_clear(l, pack->ep_osversion >= 699002600
            ? __NetBSD_NPXCW__ : __NetBSD_COMPAT_NPXCW__);
        pcb->pcb_flags = 0;
-       if (pcb->pcb_dbregs != NULL) {
-               pool_put(&x86_dbregspl, pcb->pcb_dbregs);
-               pcb->pcb_dbregs = NULL;
-       }
+       x86_dbregs_clear(l);
 
        l->l_proc->p_flag &= ~PK_32;
 
diff -r 766e75c927d8 -r 651a2d3725f1 sys/arch/amd64/amd64/netbsd32_machdep.c
--- a/sys/arch/amd64/amd64/netbsd32_machdep.c   Thu Jul 26 08:57:32 2018 +0000
+++ b/sys/arch/amd64/amd64/netbsd32_machdep.c   Thu Jul 26 09:29:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_machdep.c,v 1.115 2017/12/07 23:11:50 christos Exp $  */
+/*     $NetBSD: netbsd32_machdep.c,v 1.116 2018/07/26 09:29:08 maxv Exp $      */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.115 2017/12/07 23:11:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.116 2018/07/26 09:29:08 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -63,6 +63,7 @@
 #include <sys/kauth.h>
 
 #include <x86/fpu.h>
+#include <x86/dbregs.h>
 #include <machine/frame.h>
 #include <machine/reg.h>
 #include <machine/vmparam.h>
@@ -80,8 +81,6 @@
 #include <compat/sys/signal.h>
 #include <compat/sys/signalvar.h>
 
-extern struct pool x86_dbregspl;
-
 /* Provide a the name of the architecture we're emulating */
 const char     machine32[] = "i386";
 const char     machine_arch32[] = "i386";      
@@ -138,10 +137,7 @@
        fpu_save_area_clear(l, pack->ep_osversion >= 699002600
            ?  __NetBSD_NPXCW__ : __NetBSD_COMPAT_NPXCW__);
 
-       if (pcb->pcb_dbregs != NULL) {
-               pool_put(&x86_dbregspl, pcb->pcb_dbregs);
-               pcb->pcb_dbregs = NULL;
-       }
+       x86_dbregs_clear(l);
 
        p->p_flag |= PK_32;
 
diff -r 766e75c927d8 -r 651a2d3725f1 sys/arch/amd64/amd64/trap.c
--- a/sys/arch/amd64/amd64/trap.c       Thu Jul 26 08:57:32 2018 +0000
+++ b/sys/arch/amd64/amd64/trap.c       Thu Jul 26 09:29:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.113 2018/02/25 13:09:33 maxv Exp $  */
+/*     $NetBSD: trap.c,v 1.114 2018/07/26 09:29:08 maxv Exp $  */
 
 /*
  * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.113 2018/02/25 13:09:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.114 2018/07/26 09:29:08 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -93,6 +93,7 @@
 
 #include <machine/cpufunc.h>
 #include <x86/fpu.h>
+#include <x86/dbregs.h>
 #include <machine/psl.h>
 #include <machine/reg.h>
 #include <machine/trap.h>
diff -r 766e75c927d8 -r 651a2d3725f1 sys/arch/amd64/include/pcb.h
--- a/sys/arch/amd64/include/pcb.h      Thu Jul 26 08:57:32 2018 +0000
+++ b/sys/arch/amd64/include/pcb.h      Thu Jul 26 09:29:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcb.h,v 1.28 2017/12/31 07:23:09 maxv Exp $    */
+/*     $NetBSD: pcb.h,v 1.29 2018/07/26 09:29:08 maxv Exp $    */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -80,6 +80,7 @@
 struct pcb {
        int       pcb_flags;
 #define        PCB_COMPAT32    0x01
+#define        PCB_DBREGS      0x02
        u_int     pcb_cr0;              /* saved image of CR0 */
        uint64_t pcb_rsp0;
        uint64_t pcb_cr2;               /* page fault address (CR2) */
diff -r 766e75c927d8 -r 651a2d3725f1 sys/arch/amd64/include/userret.h
--- a/sys/arch/amd64/include/userret.h  Thu Jul 26 08:57:32 2018 +0000
+++ b/sys/arch/amd64/include/userret.h  Thu Jul 26 09:29:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: userret.h,v 1.12 2017/02/23 03:34:22 kamil Exp $       */
+/*     $NetBSD: userret.h,v 1.13 2018/07/26 09:29:08 maxv Exp $        */
 
 /*
  * XXXfvdl same as i386 counterpart, but should probably be independent.
@@ -67,7 +67,6 @@
  */
 
 #include <sys/userret.h>
-#include <x86/dbregs.h>
 
 static __inline void userret(struct lwp *);
 
@@ -78,13 +77,6 @@
 static __inline void
 userret(struct lwp *l)
 {
-       struct pcb *pcb = lwp_getpcb(l);
-
        /* Invoke MI userret code */
        mi_userret(l);
-
-       if (pcb->pcb_dbregs)
-               x86_dbregs_set(l);
-       else
-               x86_dbregs_clear(l);
 }
diff -r 766e75c927d8 -r 651a2d3725f1 sys/arch/i386/i386/locore.S
--- a/sys/arch/i386/i386/locore.S       Thu Jul 26 08:57:32 2018 +0000
+++ b/sys/arch/i386/i386/locore.S       Thu Jul 26 09:29:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.159 2018/07/14 14:29:40 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.160 2018/07/26 09:29:08 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.159 2018/07/14 14:29:40 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.160 2018/07/26 09:29:08 maxv Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -1116,6 +1116,12 @@
        movl    %eax,TSS_ESP0(%ecx)
 #endif
 
+       /* Switch the dbregs. */
+       pushl   %edi
+       pushl   %esi
+       call    _C_LABEL(x86_dbregs_switch)
+       addl    $8,%esp
+
 #ifndef XEN
        pushl   %edx
        movb    _C_LABEL(x86_fpu_eager),%dl
diff -r 766e75c927d8 -r 651a2d3725f1 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Thu Jul 26 08:57:32 2018 +0000
+++ b/sys/arch/i386/i386/machdep.c      Thu Jul 26 09:29:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.807 2018/07/22 15:02:51 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.808 2018/07/26 09:29:08 maxv Exp $       */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.807 2018/07/22 15:02:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.808 2018/07/26 09:29:08 maxv Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -213,8 +213,6 @@
 int i386_has_sse;
 int i386_has_sse2;
 
-extern struct pool x86_dbregspl;
-
 vaddr_t idt_vaddr;
 paddr_t idt_paddr;
 vaddr_t gdt_vaddr;
@@ -874,10 +872,8 @@
 
        memcpy(&pcb->pcb_fsd, &gdtstore[GUDATA_SEL], sizeof(pcb->pcb_fsd));
        memcpy(&pcb->pcb_gsd, &gdtstore[GUDATA_SEL], sizeof(pcb->pcb_gsd));
-       if (pcb->pcb_dbregs != NULL) {
-               pool_put(&x86_dbregspl, pcb->pcb_dbregs);
-               pcb->pcb_dbregs = NULL;
-       }
+
+       x86_dbregs_clear(l);
 
        tf = l->l_md.md_regs;
        tf->tf_gs = GSEL(GUGS_SEL, SEL_UPL);
diff -r 766e75c927d8 -r 651a2d3725f1 sys/arch/i386/i386/trap.c
--- a/sys/arch/i386/i386/trap.c Thu Jul 26 08:57:32 2018 +0000
+++ b/sys/arch/i386/i386/trap.c Thu Jul 26 09:29:08 2018 +0000
@@ -1,5 +1,5 @@
 
-/*     $NetBSD: trap.c,v 1.295 2018/05/16 16:33:23 maxv Exp $  */
+/*     $NetBSD: trap.c,v 1.296 2018/07/26 09:29:08 maxv Exp $  */
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.295 2018/05/16 16:33:23 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.296 2018/07/26 09:29:08 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -106,6 +106,7 @@
 #include <machine/mca_machdep.h>
 #endif
 
+#include <x86/dbregs.h>
 #include <x86/nmi.h>
 
 #include "isa.h"
diff -r 766e75c927d8 -r 651a2d3725f1 sys/arch/i386/include/pcb.h
--- a/sys/arch/i386/include/pcb.h       Thu Jul 26 08:57:32 2018 +0000
+++ b/sys/arch/i386/include/pcb.h       Thu Jul 26 09:29:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcb.h,v 1.57 2017/10/31 12:02:20 maxv Exp $    */
+/*     $NetBSD: pcb.h,v 1.58 2018/07/26 09:29:08 maxv Exp $    */
 
 /*
  * Copyright (c) 1998, 2009 The NetBSD Foundation, Inc.
@@ -93,7 +93,10 @@
        struct dbreg    *pcb_dbregs;    /* CPU Debug Registers */
        uint16_t pcb_fpu_dflt_cw;
 
-       int     not_used[16];
+#define        PCB_DBREGS      0x01
+       int     pcb_flags;
+
+       int     not_used[15];
 
        /* floating point state */
        struct cpu_info *pcb_fpcpu;     /* cpu holding our fp state. */



Home | Main Index | Thread Index | Old Index