Module Name:    src
Committed By:   ad
Date:           Thu Apr 23 20:38:33 UTC 2020

Modified Files:
        src/sys/arch/x86/x86: tsc.c

Log Message:
When computing TSC skew make 8 measurements and use the average.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/x86/tsc.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/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.41 src/sys/arch/x86/x86/tsc.c:1.42
--- src/sys/arch/x86/x86/tsc.c:1.41	Tue Apr 21 02:56:37 2020
+++ src/sys/arch/x86/x86/tsc.c	Thu Apr 23 20:38:33 2020
@@ -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 @@ tsc_read_bp(struct cpu_info *ci, uint64_
 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_sync_ap(struct cpu_info *ci)
 {
 
 	tsc_post_ap(ci);
-	tsc_post_ap(ci);
+	for (int i = 0; i < 8; i++) {
+		tsc_post_ap(ci);
+	}
 }
 
 static void

Reply via email to