Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F150548740
D55996.id174029.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D55996.id174029.diff
View Options
diff --git a/sys/x86/x86/cpu_machdep.c b/sys/x86/x86/cpu_machdep.c
--- a/sys/x86/x86/cpu_machdep.c
+++ b/sys/x86/x86/cpu_machdep.c
@@ -423,7 +423,7 @@
cpu_est_clockrate(int cpu_id, uint64_t *rate)
{
uint64_t tsc1, tsc2;
- uint64_t acnt, mcnt, perf;
+ uint64_t acnt_start, acnt_end, mcnt_start, mcnt_end, perf;
register_t reg;
if (pcpu_find(cpu_id) == NULL || rate == NULL)
@@ -452,15 +452,19 @@
/* Calibrate by measuring a short delay. */
reg = intr_disable();
if (tsc_is_invariant) {
- wrmsr(MSR_MPERF, 0);
- wrmsr(MSR_APERF, 0);
+ mcnt_start = rdmsr(MSR_MPERF);
+ acnt_start = rdmsr(MSR_APERF);
tsc1 = rdtsc();
DELAY(1000);
- mcnt = rdmsr(MSR_MPERF);
- acnt = rdmsr(MSR_APERF);
+ mcnt_end = rdmsr(MSR_MPERF);
+ acnt_end = rdmsr(MSR_APERF);
tsc2 = rdtsc();
intr_restore(reg);
- perf = 1000 * acnt / mcnt;
+ if (mcnt_end == mcnt_start) {
+ tsc_perf_stat = 0;
+ return (EOPNOTSUPP);
+ }
+ perf = 1000 * (acnt_end - acnt_start) / (mcnt_end - mcnt_start);
*rate = (tsc2 - tsc1) * perf;
} else {
tsc1 = rdtsc();
diff --git a/sys/x86/x86/tsc.c b/sys/x86/x86/tsc.c
--- a/sys/x86/x86/tsc.c
+++ b/sys/x86/x86/tsc.c
@@ -433,6 +433,8 @@
void
start_TSC(void)
{
+ uint64t_ mperf, aperf;
+
if ((cpu_feature & CPUID_TSC) == 0 || tsc_disabled)
return;
@@ -441,13 +443,15 @@
if (cpu_power_ecx & CPUID_PERF_STAT) {
/*
* XXX Some emulators expose host CPUID without actual support
- * for these MSRs. We must test whether they really work.
+ * for these MSRs, or do work but only for reading. We must test
+ * whether they really work.
*/
- wrmsr(MSR_MPERF, 0);
- wrmsr(MSR_APERF, 0);
+ mperf = rdmsr(MSR_MPERF);
+ aperf = rdmsr(MSR_APERF);
DELAY(10);
- if (rdmsr(MSR_MPERF) > 0 && rdmsr(MSR_APERF) > 0)
+ if (rdmsr(MSR_MPERF) != mperf && rdmsr(MSR_APERF) != aperf ) {
tsc_perf_stat = 1;
+ }
}
/*
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 3, 6:28 AM (11 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30747359
Default Alt Text
D55996.id174029.diff (1 KB)
Attached To
Mode
D55996: x86: Handle when MPERF/APERF MSRs aren't writable
Attached
Detach File
Event Timeline
Log In to Comment