Thu Apr 23 20:38:33 2020 UTC ()
When computing TSC skew make 8 measurements and use the average.


(ad)
diff -r1.41 -r1.42 src/sys/arch/x86/x86/tsc.c

cvs diff -r1.41 -r1.42 src/sys/arch/x86/x86/tsc.c (expand / switch to context diff)
--- src/sys/arch/x86/x86/tsc.c 2020/04/21 02:56:37 1.41
+++ src/sys/arch/x86/x86/tsc.c 2020/04/23 20:38:33 1.42
@@ -1,7 +1,7 @@
-/*	$NetBSD: tsc.c,v 1.41 2020/04/21 02:56:37 msaitoh Exp $	*/
+/*	$NetBSD: tsc.c,v 1.42 2020/04/23 20:38:33 ad Exp $	*/
 
 /*-
- * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.41 2020/04/21 02:56:37 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.42 2020/04/23 20:38:33 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -229,13 +229,17 @@
 void
 tsc_sync_bp(struct cpu_info *ci)
 {
-	uint64_t bptsc, aptsc;
+	int64_t bptsc, aptsc, bsum = 0, asum = 0;
 
 	tsc_read_bp(ci, &bptsc, &aptsc); /* discarded - cache effects */
-	tsc_read_bp(ci, &bptsc, &aptsc);
+	for (int i = 0; i < 8; i++) {
+		tsc_read_bp(ci, &bptsc, &aptsc);
+		bsum += bptsc;
+		asum += aptsc;
+	}
 
 	/* Compute final value to adjust for skew. */
-	ci->ci_data.cpu_cc_skew = bptsc - aptsc;
+	ci->ci_data.cpu_cc_skew = (bsum - asum) >> 3;
 }
 
 /*
@@ -270,7 +274,9 @@
 {
 
 	tsc_post_ap(ci);
-	tsc_post_ap(ci);
+	for (int i = 0; i < 8; i++) {
+		tsc_post_ap(ci);
+	}
 }
 
 static void