Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Apr 2011 17:50:26 +0000 (UTC)
From:      Jung-uk Kim <jkim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r220637 - head/sys/x86/x86
Message-ID:  <201104141750.p3EHoQbC042617@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jkim
Date: Thu Apr 14 17:50:26 2011
New Revision: 220637
URL: http://svn.freebsd.org/changeset/base/220637

Log:
  Work around an emulator problem where virtual CPU advertises TSC is P-state
  invariant and APERF/MPERF MSRs exist but these MSRs never tick.  When we
  calculate effective frequency from cpu_est_clockrate(), it caused panic of
  division-by-zero.  Now we test whether these MSRs actually increase to avoid
  such foot-shooting.
  
  Reported by:	dim
  Tested by:	dim

Modified:
  head/sys/x86/x86/tsc.c

Modified: head/sys/x86/x86/tsc.c
==============================================================================
--- head/sys/x86/x86/tsc.c	Thu Apr 14 17:42:21 2011	(r220636)
+++ head/sys/x86/x86/tsc.c	Thu Apr 14 17:50:26 2011	(r220637)
@@ -183,8 +183,18 @@ probe_tsc_freq(void)
 
 	if (cpu_high >= 6) {
 		do_cpuid(6, regs);
-		if ((regs[2] & CPUID_PERF_STAT) != 0)
-			tsc_perf_stat = 1;
+		if ((regs[2] & CPUID_PERF_STAT) != 0) {
+			/*
+			 * XXX Some emulators expose host CPUID without actual
+			 * support for these MSRs.  We must test whether they
+			 * really work.
+			 */
+			wrmsr(MSR_MPERF, 0);
+			wrmsr(MSR_APERF, 0);
+			DELAY(10);
+			if (rdmsr(MSR_MPERF) > 0 && rdmsr(MSR_APERF) > 0)
+				tsc_perf_stat = 1;
+		}
 	}
 
 	if (tsc_skip_calibration) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104141750.p3EHoQbC042617>