Module Name:    src
Committed By:   riastradh
Date:           Tue Jun  1 21:29:24 UTC 2021

Modified Files:
        src/sys/arch/x86/acpi: acpi_wakeup.c
        src/sys/arch/x86/x86: tsc.c tsc.h

Log Message:
x86: Reset cached tsc in every lwp to 0 on suspend/resume.

This avoids spuriously warning about tsc going backwards, which is to
be expected after a suspend/resume cycle.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/x86/acpi/acpi_wakeup.c
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/x86/x86/tsc.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x86/x86/tsc.h

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/acpi/acpi_wakeup.c
diff -u src/sys/arch/x86/acpi/acpi_wakeup.c:1.53 src/sys/arch/x86/acpi/acpi_wakeup.c:1.54
--- src/sys/arch/x86/acpi/acpi_wakeup.c:1.53	Thu May 21 21:12:30 2020
+++ src/sys/arch/x86/acpi/acpi_wakeup.c	Tue Jun  1 21:29:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_wakeup.c,v 1.53 2020/05/21 21:12:30 ad Exp $	*/
+/*	$NetBSD: acpi_wakeup.c,v 1.54 2021/06/01 21:29:24 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2011 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.53 2020/05/21 21:12:30 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.54 2021/06/01 21:29:24 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -341,6 +341,7 @@ acpi_md_sleep(int state)
 	 */
 
 	/* We just woke up (cpu0), execution is resumed here */
+	tsc_tc_reset();
 	cpu_init_msrs(&cpu_info_primary, false);
 	fpuinit(&cpu_info_primary);
 	if (rcr4() & CR4_OSXSAVE)

Index: src/sys/arch/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.54 src/sys/arch/x86/x86/tsc.c:1.55
--- src/sys/arch/x86/x86/tsc.c:1.54	Fri Feb 19 02:15:58 2021
+++ src/sys/arch/x86/x86/tsc.c	Tue Jun  1 21:29:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tsc.c,v 1.54 2021/02/19 02:15:58 christos Exp $	*/
+/*	$NetBSD: tsc.c,v 1.55 2021/06/01 21:29:24 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.54 2021/02/19 02:15:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.55 2021/06/01 21:29:24 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -440,3 +440,18 @@ tsc_get_timecount(struct timecounter *tc
 	return cpu_counter32();
 #endif
 }
+
+/*
+ * tsc has been reset; zero the cached tsc of every lwp in the system
+ * so we don't spuriously report that the tsc has gone backward.
+ * Caller must ensure all LWPs are quiescent (except the current one,
+ * obviously) and interrupts are blocked while we update this.
+ */
+void
+tsc_tc_reset(void)
+{
+	struct lwp *l;
+
+	LIST_FOREACH(l, &alllwp, l_list)
+		l->l_md.md_tsc = 0;
+}

Index: src/sys/arch/x86/x86/tsc.h
diff -u src/sys/arch/x86/x86/tsc.h:1.7 src/sys/arch/x86/x86/tsc.h:1.8
--- src/sys/arch/x86/x86/tsc.h:1.7	Mon Jun 15 09:09:24 2020
+++ src/sys/arch/x86/x86/tsc.h	Tue Jun  1 21:29:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tsc.h,v 1.7 2020/06/15 09:09:24 msaitoh Exp $	*/
+/*	$NetBSD: tsc.h,v 1.8 2021/06/01 21:29:24 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -26,6 +26,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef	_X86_TSC_H_
+#define	_X86_TSC_H_
+
 bool	tsc_is_invariant(void);
 void	tsc_setfunc(struct cpu_info *);
 void	tsc_tc_init(void);
@@ -34,3 +37,6 @@ void	tsc_sync_bp(struct cpu_info *);
 void	tsc_sync_drift(int64_t);
 void	tsc_user_enable(void);
 void	tsc_user_disable(void);
+void	tsc_tc_reset(void);
+
+#endif	/* _X86_TSC_H_ */

Reply via email to