Changeset View
Changeset View
Standalone View
Standalone View
sys/x86/x86/tsc.c
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | static struct timecounter tsc_timecounter = { | ||||
0, /* no poll_pps */ | 0, /* no poll_pps */ | ||||
~0u, /* counter_mask */ | ~0u, /* counter_mask */ | ||||
0, /* frequency */ | 0, /* frequency */ | ||||
"TSC", /* name */ | "TSC", /* name */ | ||||
800, /* quality (adjusted in code) */ | 800, /* quality (adjusted in code) */ | ||||
}; | }; | ||||
static void | static void | ||||
tsc_freq_vmware(void) | |||||
{ | |||||
u_int regs[4]; | |||||
if (hv_high >= 0x40000010) { | |||||
do_cpuid(0x40000010, regs); | |||||
tsc_freq = regs[0] * 1000; | |||||
} else { | |||||
vmware_hvcall(VMW_HVCMD_GETHZ, regs); | |||||
if (regs[1] != UINT_MAX) | |||||
tsc_freq = regs[0] | ((uint64_t)regs[1] << 32); | |||||
} | |||||
tsc_is_invariant = 1; | |||||
} | |||||
static void | |||||
tsc_freq_intel(void) | tsc_freq_intel(void) | ||||
{ | { | ||||
char brand[48]; | char brand[48]; | ||||
u_int regs[4]; | u_int regs[4]; | ||||
uint64_t freq; | uint64_t freq; | ||||
char *p; | char *p; | ||||
u_int i; | u_int i; | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | if ((regs[2] & CPUID_PERF_STAT) != 0) { | ||||
wrmsr(MSR_APERF, 0); | wrmsr(MSR_APERF, 0); | ||||
DELAY(10); | DELAY(10); | ||||
if (rdmsr(MSR_MPERF) > 0 && rdmsr(MSR_APERF) > 0) | if (rdmsr(MSR_MPERF) > 0 && rdmsr(MSR_APERF) > 0) | ||||
tsc_perf_stat = 1; | tsc_perf_stat = 1; | ||||
} | } | ||||
} | } | ||||
if (vm_guest == VM_GUEST_VMWARE) { | if (vm_guest == VM_GUEST_VMWARE) { | ||||
tsc_freq_vmware(); | tsc_freq = vmware_tsc_freq(); | ||||
tsc_is_invariant = 1; | |||||
return; | return; | ||||
} | } | ||||
switch (cpu_vendor_id) { | switch (cpu_vendor_id) { | ||||
case CPU_VENDOR_AMD: | case CPU_VENDOR_AMD: | ||||
if ((amd_pminfo & AMDPM_TSC_INVARIANT) != 0 || | if ((amd_pminfo & AMDPM_TSC_INVARIANT) != 0 || | ||||
(vm_guest == VM_GUEST_NO && | (vm_guest == VM_GUEST_NO && | ||||
CPUID_TO_FAMILY(cpu_id) >= 0x10)) | CPUID_TO_FAMILY(cpu_id) >= 0x10)) | ||||
▲ Show 20 Lines • Show All 528 Lines • Show Last 20 Lines |