Module Name:    src
Committed By:   drochner
Date:           Fri Mar 27 19:53:20 UTC 2009

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

Log Message:
Rearrange TSC inter-CPU synchronization code so that the gory details
are dealt with in x86/tsc.c and callers don't have to care that much.
Also add some comments and make some variables static.
approved by ad (a while ago)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/x86/acpi/acpi_wakeup.c
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.24 -r1.25 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/acpi/acpi_wakeup.c
diff -u src/sys/arch/x86/acpi/acpi_wakeup.c:1.13 src/sys/arch/x86/acpi/acpi_wakeup.c:1.14
--- src/sys/arch/x86/acpi/acpi_wakeup.c:1.13	Wed Mar 18 17:06:48 2009
+++ src/sys/arch/x86/acpi/acpi_wakeup.c	Fri Mar 27 19:53:19 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_wakeup.c,v 1.13 2009/03/18 17:06:48 cegger Exp $	*/
+/*	$NetBSD: acpi_wakeup.c,v 1.14 2009/03/27 19:53:19 drochner Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.13 2009/03/18 17:06:48 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.14 2009/03/27 19:53:19 drochner Exp $");
 
 /*-
  * Copyright (c) 2001 Takanori Watanabe <[email protected]>
@@ -309,7 +309,6 @@
 	atomic_or_32(&ci->ci_flags, CPUF_RUNNING);
 	atomic_or_32(&cpus_running, ci->ci_cpumask);
 	tsc_sync_ap(ci);
-	tsc_sync_ap(ci);
 
 	x86_enable_intr();
 }
@@ -396,7 +395,6 @@
 			x86_pause();
 
 		tsc_sync_bp(ci);
-		tsc_sync_bp(ci);
 	}
 #endif
 

Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.62 src/sys/arch/x86/x86/cpu.c:1.63
--- src/sys/arch/x86/x86/cpu.c:1.62	Wed Jan 21 21:26:01 2009
+++ src/sys/arch/x86/x86/cpu.c	Fri Mar 27 19:53:19 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.62 2009/01/21 21:26:01 bouyer Exp $	*/
+/*	$NetBSD: cpu.c,v 1.63 2009/03/27 19:53:19 drochner Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.62 2009/01/21 21:26:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.63 2009/03/27 19:53:19 drochner Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -503,7 +503,6 @@
 		wbinvd();
 		atomic_or_32(&ci->ci_flags, CPUF_RUNNING);
 		tsc_sync_ap(ci);
-		tsc_sync_ap(ci);
 	} else {
 		atomic_or_32(&ci->ci_flags, CPUF_RUNNING);
 	}
@@ -616,7 +615,6 @@
 		x86_disable_intr();
 		wbinvd();
 		tsc_sync_bp(ci);
-		tsc_sync_bp(ci);
 		x86_write_psl(psl);
 	}
 
@@ -648,7 +646,6 @@
 		x86_disable_intr();
 		wbinvd();
 		tsc_sync_bp(ci);
-		tsc_sync_bp(ci);
 		x86_write_psl(psl);
 		drift -= ci->ci_data.cpu_cc_skew;
 		aprint_debug_dev(ci->ci_dev, "TSC skew=%lld drift=%lld\n",
@@ -687,7 +684,6 @@
 	wbinvd();
 	atomic_or_32(&ci->ci_flags, CPUF_PRESENT);
 	tsc_sync_ap(ci);
-	tsc_sync_ap(ci);
 
 	/*
 	 * Wait to be brought online.  Use 'monitor/mwait' if available,

Index: src/sys/arch/x86/x86/tsc.c
diff -u src/sys/arch/x86/x86/tsc.c:1.24 src/sys/arch/x86/x86/tsc.c:1.25
--- src/sys/arch/x86/x86/tsc.c:1.24	Fri Dec 19 11:21:52 2008
+++ src/sys/arch/x86/x86/tsc.c	Fri Mar 27 19:53:20 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: tsc.c,v 1.24 2008/12/19 11:21:52 ad Exp $	*/
+/*	$NetBSD: tsc.c,v 1.25 2009/03/27 19:53:20 drochner Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.24 2008/12/19 11:21:52 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.25 2009/03/27 19:53:20 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -48,9 +48,9 @@
 
 u_int	tsc_get_timecount(struct timecounter *);
 
-uint64_t	tsc_freq;
-int64_t		tsc_drift_max = 250;	/* max cycles */
-int64_t		tsc_drift_observed;
+uint64_t	tsc_freq; /* exported for sysctl */
+static int64_t	tsc_drift_max = 250;	/* max cycles */
+static int64_t	tsc_drift_observed;
 
 static volatile int64_t	tsc_sync_val;
 static volatile struct cpu_info	*tsc_sync_cpu;
@@ -166,10 +166,10 @@
  * Called during startup of APs, by the boot processor.  Interrupts
  * are disabled on entry.
  */
-void
-tsc_sync_bp(struct cpu_info *ci)
+static void
+tsc_read_bp(struct cpu_info *ci, uint64_t *bptscp, uint64_t *aptscp)
 {
-	uint64_t tsc;
+	uint64_t bptsc;
 
 	if (atomic_swap_ptr(&tsc_sync_cpu, ci) != NULL) {
 		panic("tsc_sync_bp: 1");
@@ -177,13 +177,13 @@
 
 	/* Flag it and read our TSC. */
 	atomic_or_uint(&ci->ci_flags, CPUF_SYNCTSC);
-	tsc = rdmsr(MSR_TSC) >> 1;
+	bptsc = rdmsr(MSR_TSC) >> 1;
 
 	/* Wait for remote to complete, and read ours again. */
 	while ((ci->ci_flags & CPUF_SYNCTSC) != 0) {
 		__insn_barrier();
 	}
-	tsc += (rdmsr(MSR_TSC) >> 1);
+	bptsc += (rdmsr(MSR_TSC) >> 1);
 
 	/* Wait for the results to come in. */
 	while (tsc_sync_cpu == ci) {
@@ -193,16 +193,28 @@
 		panic("tsc_sync_bp: 2");
 	}
 
+	*bptscp = bptsc;
+	*aptscp = tsc_sync_val;
+}
+
+void
+tsc_sync_bp(struct cpu_info *ci)
+{
+	uint64_t bptsc, aptsc;
+
+	tsc_read_bp(ci, &bptsc, &aptsc); /* discarded - cache effects */
+	tsc_read_bp(ci, &bptsc, &aptsc);
+
 	/* Compute final value to adjust for skew. */
-	ci->ci_data.cpu_cc_skew = tsc - tsc_sync_val;
+	ci->ci_data.cpu_cc_skew = bptsc - aptsc;
 }
 
 /*
  * Called during startup of AP, by the AP itself.  Interrupts are
  * disabled on entry.
  */
-void
-tsc_sync_ap(struct cpu_info *ci)
+static void
+tsc_post_ap(struct cpu_info *ci)
 {
 	uint64_t tsc;
 
@@ -224,6 +236,14 @@
 	}
 }
 
+void
+tsc_sync_ap(struct cpu_info *ci)
+{
+
+	tsc_post_ap(ci);
+	tsc_post_ap(ci);
+}
+
 uint64_t
 cpu_frequency(struct cpu_info *ci)
 {

Reply via email to