Module Name:    src
Committed By:   cherry
Date:           Sun Nov 18 10:24:10 UTC 2018

Modified Files:
        src/sys/arch/x86/include: cpu.h
        src/sys/arch/xen/x86: hypervisor_machdep.c
        src/sys/arch/xen/xen: clock.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/xen/xen/clock.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/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.98 src/sys/arch/x86/include/cpu.h:1.99
--- src/sys/arch/x86/include/cpu.h:1.98	Fri Oct  5 18:51:52 2018
+++ src/sys/arch/x86/include/cpu.h	Sun Nov 18 10:24:09 2018
@@ -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 @@ struct cpu_tss {
 } __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 @@ struct cpu_info {
 	/* 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 @@ void cpu_speculation_init(struct cpu_inf
 #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.

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.30 src/sys/arch/xen/x86/hypervisor_machdep.c:1.31
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.30	Sat Nov 17 05:26:46 2018
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Sun Nov 18 10:24:09 2018
@@ -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 @@ do_hypervisor_callback(struct intrframe 
 	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

Index: src/sys/arch/xen/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.72 src/sys/arch/xen/xen/clock.c:1.73
--- src/sys/arch/xen/xen/clock.c:1.72	Fri Oct 26 05:33:21 2018
+++ src/sys/arch/xen/xen/clock.c	Sun Nov 18 10:24:10 2018
@@ -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 @@ xen_timer_handler(void *cookie, struct c
 	KASSERT(cpu_intr_p());
 	KASSERT(cookie == ci);
 
+	frame = &ci->ci_event_clockframe;
 again:
 	/*
 	 * Find how many nanoseconds of Xen system time has elapsed

Reply via email to