From owner-svn-src-all@FreeBSD.ORG Thu Apr 14 17:50:26 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6F80F106566C; Thu, 14 Apr 2011 17:50:26 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5FCF58FC17; Thu, 14 Apr 2011 17:50:26 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p3EHoQ7x042619; Thu, 14 Apr 2011 17:50:26 GMT (envelope-from jkim@svn.freebsd.org) Received: (from jkim@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p3EHoQbC042617; Thu, 14 Apr 2011 17:50:26 GMT (envelope-from jkim@svn.freebsd.org) Message-Id: <201104141750.p3EHoQbC042617@svn.freebsd.org> From: Jung-uk Kim Date: Thu, 14 Apr 2011 17:50:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r220637 - head/sys/x86/x86 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2011 17:50:26 -0000 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) {