Module Name:    src
Committed By:   cherry
Date:           Sun Nov 18 23:50:48 UTC 2018

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

Log Message:
On Xen, copy just the bits we need from the trapframe for hardclock(9)
and statclock(9).

Current, the macros that use the trapframe are:
CLKF_USERMODE()
CLKF_PC()
CLKF_INTR()

Of these, CLKF_INTR() already ignores the frame and uses the ci_idepth
variable to do its job.

Convert the two remaining ones to do this, but only for XEN.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/amd64/include/cpu.h
cvs rdiff -u -r1.179 -r1.180 src/sys/arch/i386/include/cpu.h
cvs rdiff -u -r1.99 -r1.100 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.73 -r1.74 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/amd64/include/cpu.h
diff -u src/sys/arch/amd64/include/cpu.h:1.62 src/sys/arch/amd64/include/cpu.h:1.63
--- src/sys/arch/amd64/include/cpu.h:1.62	Fri Mar 16 12:21:50 2018
+++ src/sys/arch/amd64/include/cpu.h	Sun Nov 18 23:50:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.62 2018/03/16 12:21:50 maxv Exp $	*/
+/*	$NetBSD: cpu.h,v 1.63 2018/11/18 23:50:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -83,8 +83,13 @@ cpu_set_curpri(int pri)
 }
 #endif	/* __GNUC__ && !_MODULE */
 
+#ifdef XEN
+#define	CLKF_USERMODE(frame)	(curcpu()->ci_xen_clockf_usermode)
+#define CLKF_PC(frame)		(curcpu()->ci_xen_clockf_pc)
+#else /* XEN */
 #define	CLKF_USERMODE(frame)	USERMODE((frame)->cf_if.if_tf.tf_cs)
 #define CLKF_PC(frame)		((frame)->cf_if.if_tf.tf_rip)
+#endif /* XEN */
 #define CLKF_INTR(frame)	(curcpu()->ci_idepth > 0)
 #define LWP_PC(l)		((l)->l_md.md_regs->tf_rip)
 

Index: src/sys/arch/i386/include/cpu.h
diff -u src/sys/arch/i386/include/cpu.h:1.179 src/sys/arch/i386/include/cpu.h:1.180
--- src/sys/arch/i386/include/cpu.h:1.179	Sun Sep 17 09:41:35 2017
+++ src/sys/arch/i386/include/cpu.h	Sun Nov 18 23:50:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.179 2017/09/17 09:41:35 maxv Exp $	*/
+/*	$NetBSD: cpu.h,v 1.180 2018/11/18 23:50:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -81,8 +81,13 @@ cpu_set_curpri(int pri)
 }
 #endif
 
+#ifdef XEN
+#define	CLKF_USERMODE(frame)	(curcpu()->ci_xen_clockf_usermode)
+#define CLKF_PC(frame)		(curcpu()->ci_xen_clockf_pc)
+#else /* XEN */
 #define	CLKF_USERMODE(frame)	USERMODE((frame)->cf_if.if_cs)
 #define	CLKF_PC(frame)		((frame)->cf_if.if_eip)
+#endif /* XEN */
 #define	CLKF_INTR(frame)	(curcpu()->ci_idepth > 0)
 #define	LWP_PC(l)		((l)->l_md.md_regs->tf_eip)
 

Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.99 src/sys/arch/x86/include/cpu.h:1.100
--- src/sys/arch/x86/include/cpu.h:1.99	Sun Nov 18 10:24:09 2018
+++ src/sys/arch/x86/include/cpu.h	Sun Nov 18 23:50:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.99 2018/11/18 10:24:09 cherry Exp $	*/
+/*	$NetBSD: cpu.h,v 1.100 2018/11/18 23:50:48 cherry Exp $	*/
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -286,7 +286,8 @@ struct cpu_info {
 	 * Clockframe for timer interrupt handler.
 	 * Saved at entry via event callback.
 	 */
-	struct clockframe ci_event_clockframe;
+	vaddr_t ci_xen_clockf_pc; /* RIP at last event interrupt */
+	bool ci_xen_clockf_usermode; /* Was the guest in usermode ? */
 
 	/* Event counters for various pathologies that might happen.  */
 	struct evcnt	ci_xen_cpu_tsc_backwards_evcnt;

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.31 src/sys/arch/xen/x86/hypervisor_machdep.c:1.32
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.31	Sun Nov 18 10:24:09 2018
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Sun Nov 18 23:50:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.31 2018/11/18 10:24:09 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.32 2018/11/18 23:50:48 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.31 2018/11/18 10:24:09 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.32 2018/11/18 23:50:48 cherry Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -263,7 +263,8 @@ do_hypervisor_callback(struct intrframe 
 
 	/* Save trapframe for clock handler */
 	KASSERT(regs != NULL);
-	ci->ci_event_clockframe.cf_if = *regs;
+	ci->ci_xen_clockf_usermode = USERMODE(regs->if_tf.tf_cs);
+	ci->ci_xen_clockf_pc = regs->if_tf.tf_rip;
 
 	// DDD printf("do_hypervisor_callback\n");
 

Index: src/sys/arch/xen/xen/clock.c
diff -u src/sys/arch/xen/xen/clock.c:1.73 src/sys/arch/xen/xen/clock.c:1.74
--- src/sys/arch/xen/xen/clock.c:1.73	Sun Nov 18 10:24:10 2018
+++ src/sys/arch/xen/xen/clock.c	Sun Nov 18 23:50:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.73 2018/11/18 10:24:10 cherry Exp $	*/
+/*	$NetBSD: clock.c,v 1.74 2018/11/18 23:50:48 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.73 2018/11/18 10:24:10 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.74 2018/11/18 23:50:48 cherry Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -811,7 +811,7 @@ xen_timer_handler(void *cookie, struct c
 	KASSERT(cpu_intr_p());
 	KASSERT(cookie == ci);
 
-	frame = &ci->ci_event_clockframe;
+	frame = NULL; /* We use values cached in curcpu()  */
 again:
 	/*
 	 * Find how many nanoseconds of Xen system time has elapsed

Reply via email to