svn commit: r220584 - in head/sys: amd64/amd64 i386/i386
Dimitry Andric
dim at FreeBSD.org
Thu Apr 14 10:49:22 UTC 2011
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.
-------------- next part --------------
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();
More information about the svn-src-all
mailing list