From owner-svn-src-all@FreeBSD.ORG Thu Apr 14 10:49:22 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 A4754106566B; Thu, 14 Apr 2011 10:49:22 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (cl-327.ede-01.nl.sixxs.net [IPv6:2001:7b8:2ff:146::2]) by mx1.freebsd.org (Postfix) with ESMTP id 5D2588FC16; Thu, 14 Apr 2011 10:49:22 +0000 (UTC) Received: from [IPv6:2001:7b8:3a7:0:dd48:486e:166b:644] (unknown [IPv6:2001:7b8:3a7:0:dd48:486e:166b:644]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 629125C59; Thu, 14 Apr 2011 12:49:21 +0200 (CEST) Message-ID: <4DA6D145.8070804@FreeBSD.org> Date: Thu, 14 Apr 2011 12:49:41 +0200 From: Dimitry Andric Organization: The FreeBSD Project User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16pre) Gecko/20110319 Lanikai/3.1.10pre MIME-Version: 1.0 To: Jung-uk Kim References: <201104122349.p3CNn7kK039179@svn.freebsd.org> <4DA6189A.5040200@FreeBSD.org> <4DA61A70.8040609@FreeBSD.org> <201104131827.39373.jkim@FreeBSD.org> In-Reply-To: <201104131827.39373.jkim@FreeBSD.org> Content-Type: multipart/mixed; boundary="------------090705030302090306020404" Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r220584 - in head/sys: amd64/amd64 i386/i386 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 10:49:22 -0000 This is a multi-part message in MIME format. --------------090705030302090306020404 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 2011-04-14 00:27, Jung-uk Kim wrote: ... >> will still read 0 from MSR_MPERF, leading to a division by zero. >> Maybe just fallback to the second method in the 'else' branch then? > > That means your VM has broken CPUID support. To get there, it has to > meet two conditions, i.e., TSC is invariant and it has APERF/MPERF > MSRs. Well, VM hosts like VMware and VirtualBox usually just return the 'native' CPUID values to guests, but can't really support stuff like those MSRs, for all kinds of reasons. I was just looking at this from a viewpoint of "it worked for years, and now it broke". :) In any case, I don't see why a bit of defensive programming would be bad here, so I propose the following patch to revert to the 'old' way of estimating the rate, in case reading the MPERF MSR returns zero. --------------090705030302090306020404 Content-Type: text/plain; name="est-zero-mcnt-workaround-1.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="est-zero-mcnt-workaround-1.diff" Index: sys/i386/i386/machdep.c =================================================================== --- sys/i386/i386/machdep.c (revision 220620) +++ sys/i386/i386/machdep.c (working copy) @@ -1172,7 +1172,7 @@ cpu_est_clockrate(int cpu_id, uint64_t *rate) acnt = rdmsr(MSR_APERF); tsc2 = rdtsc(); intr_restore(reg); - perf = 1000 * acnt / mcnt; + perf = (mcnt != 0) ? 1000 * acnt / mcnt : 1000; *rate = (tsc2 - tsc1) * perf; } else { tsc1 = rdtsc(); Index: sys/amd64/amd64/machdep.c =================================================================== --- sys/amd64/amd64/machdep.c (revision 220620) +++ sys/amd64/amd64/machdep.c (working copy) @@ -579,7 +579,7 @@ cpu_est_clockrate(int cpu_id, uint64_t *rate) acnt = rdmsr(MSR_APERF); tsc2 = rdtsc(); intr_restore(reg); - perf = 1000 * acnt / mcnt; + perf = (mcnt != 0) ? 1000 * acnt / mcnt : 1000; *rate = (tsc2 - tsc1) * perf; } else { tsc1 = rdtsc(); --------------090705030302090306020404--