Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Save the interrupt trap/clockframe to a per-cpu copy.



details:   https://anonhg.NetBSD.org/src/rev/10f9403de054
branches:  trunk
changeset: 445931:10f9403de054
user:      cherry <cherry%NetBSD.org@localhost>
date:      Sun Nov 18 10:24:09 2018 +0000

description:
Save the interrupt trap/clockframe to a per-cpu copy.

We can use this copy to pass on the trapframe to hardclock(9) from
within the xen timer handler. This delinks the current dependency
between MD code and the handler, which is specially prototyped to take
the clockframe unlike any other handler.

This change has performance implications, as each interrupt entry will
copy the entire trapframe over to the per-cpu cached copy. This can be
mitigated by selectively copying just the parts of the clockframe that
are used by hardclock() et. al.

Tested on amd64 XEN domU

diffstat:

 sys/arch/x86/include/cpu.h            |  26 ++++++++++++++++----------
 sys/arch/xen/x86/hypervisor_machdep.c |   8 ++++++--
 sys/arch/xen/xen/clock.c              |   5 +++--
 3 files changed, 25 insertions(+), 14 deletions(-)

diffs (109 lines):

diff -r 56f98cb54bbd -r 10f9403de054 sys/arch/x86/include/cpu.h
--- a/sys/arch/x86/include/cpu.h        Sun Nov 18 07:42:24 2018 +0000
+++ b/sys/arch/x86/include/cpu.h        Sun Nov 18 10:24:09 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.98 2018/10/05 18:51:52 maxv Exp $    */
+/*     $NetBSD: cpu.h,v 1.99 2018/11/18 10:24:09 cherry Exp $  */
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -94,6 +94,15 @@
 } __packed;
 
 /*
+ * Arguments to hardclock, softclock and statclock
+ * encapsulate the previous machine state in an opaque
+ * clockframe; for now, use generic intrframe.
+ */
+struct clockframe {
+       struct intrframe cf_if;
+};
+
+/*
  * a bunch of this belongs in cpuvar.h; move it later..
  */
 
@@ -273,6 +282,12 @@
        /* Xen periodic timer interrupt handle.  */
        struct intrhand *ci_xen_timer_intrhand;
 
+       /*
+        * Clockframe for timer interrupt handler.
+        * Saved at entry via event callback.
+        */
+       struct clockframe ci_event_clockframe;
+
        /* Event counters for various pathologies that might happen.  */
        struct evcnt    ci_xen_cpu_tsc_backwards_evcnt;
        struct evcnt    ci_xen_tsc_delta_negative_evcnt;
@@ -378,15 +393,6 @@
 #define        curpcb                  ((struct pcb *)lwp_getpcb(curlwp))
 
 /*
- * Arguments to hardclock, softclock and statclock
- * encapsulate the previous machine state in an opaque
- * clockframe; for now, use generic intrframe.
- */
-struct clockframe {
-       struct intrframe cf_if;
-};
-
-/*
  * Give a profiling tick to the current process when the user profiling
  * buffer pages are invalid.  On the i386, request an ast to send us
  * through trap(), marking the proc as needing a profiling tick.
diff -r 56f98cb54bbd -r 10f9403de054 sys/arch/xen/x86/hypervisor_machdep.c
--- a/sys/arch/xen/x86/hypervisor_machdep.c     Sun Nov 18 07:42:24 2018 +0000
+++ b/sys/arch/xen/x86/hypervisor_machdep.c     Sun Nov 18 10:24:09 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hypervisor_machdep.c,v 1.30 2018/11/17 05:26:46 cherry Exp $   */
+/*     $NetBSD: hypervisor_machdep.c,v 1.31 2018/11/18 10:24:09 cherry Exp $   */
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.30 2018/11/17 05:26:46 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.31 2018/11/18 10:24:09 cherry Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -261,6 +261,10 @@
        vci = ci->ci_vcpu;
        level = ci->ci_ilevel;
 
+       /* Save trapframe for clock handler */
+       KASSERT(regs != NULL);
+       ci->ci_event_clockframe.cf_if = *regs;
+
        // DDD printf("do_hypervisor_callback\n");
 
 #ifdef EARLY_DEBUG_EVENT
diff -r 56f98cb54bbd -r 10f9403de054 sys/arch/xen/xen/clock.c
--- a/sys/arch/xen/xen/clock.c  Sun Nov 18 07:42:24 2018 +0000
+++ b/sys/arch/xen/xen/clock.c  Sun Nov 18 10:24:09 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clock.c,v 1.72 2018/10/26 05:33:21 cherry Exp $        */
+/*     $NetBSD: clock.c,v 1.73 2018/11/18 10:24:10 cherry Exp $        */
 
 /*-
  * Copyright (c) 2017, 2018 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.72 2018/10/26 05:33:21 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.73 2018/11/18 10:24:10 cherry Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -811,6 +811,7 @@
        KASSERT(cpu_intr_p());
        KASSERT(cookie == ci);
 
+       frame = &ci->ci_event_clockframe;
 again:
        /*
         * Find how many nanoseconds of Xen system time has elapsed



Home | Main Index | Thread Index | Old Index