Date: Wed, 31 Dec 2014 06:59:23 +0000 (UTC) From: Bryan Venteicher <bryanv@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r276454 - in projects/paravirt/sys/x86: include x86 Message-ID: <201412310659.sBV6xNPj061088@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bryanv Date: Wed Dec 31 06:59:22 2014 New Revision: 276454 URL: https://svnweb.freebsd.org/changeset/base/276454 Log: Add code to calculate the TSC frequency from the KVM/PV clock Not currently used. Could later be used similarly to the VMware code to avoid attempting to calibrate the TSC. Modified: projects/paravirt/sys/x86/include/kvm.h projects/paravirt/sys/x86/include/pvclock.h projects/paravirt/sys/x86/x86/kvm_clock.c projects/paravirt/sys/x86/x86/pvclock.c Modified: projects/paravirt/sys/x86/include/kvm.h ============================================================================== --- projects/paravirt/sys/x86/include/kvm.h Wed Dec 31 06:54:28 2014 (r276453) +++ projects/paravirt/sys/x86/include/kvm.h Wed Dec 31 06:59:22 2014 (r276454) @@ -43,5 +43,6 @@ int kvm_paravirt_supported(void); uint32_t kvm_get_features(void); +uint64_t kvm_clock_tsc_freq(void); #endif /* !_X86_KVM_H_ */ Modified: projects/paravirt/sys/x86/include/pvclock.h ============================================================================== --- projects/paravirt/sys/x86/include/pvclock.h Wed Dec 31 06:54:28 2014 (r276453) +++ projects/paravirt/sys/x86/include/pvclock.h Wed Dec 31 06:59:22 2014 (r276454) @@ -50,6 +50,7 @@ struct pvclock_wall_clock { } __packed; void pvclock_resume(void); +uint64_t pvclock_tsc_freq(struct pvclock_vcpu_time_info *ti); uint64_t pvclock_get_timecount(struct pvclock_vcpu_time_info *ti); void pvclock_get_wallclock(struct pvclock_wall_clock *wc, struct timespec *ts); Modified: projects/paravirt/sys/x86/x86/kvm_clock.c ============================================================================== --- projects/paravirt/sys/x86/x86/kvm_clock.c Wed Dec 31 06:54:28 2014 (r276453) +++ projects/paravirt/sys/x86/x86/kvm_clock.c Wed Dec 31 06:59:22 2014 (r276454) @@ -58,6 +58,20 @@ static struct timecounter kvm_clock_time static uint32_t kvm_clock_wall_clock_msr; static uint32_t kvm_clock_system_time_msr; +uint64_t +kvm_clock_tsc_freq(void) +{ + struct pvclock_vcpu_time_info *ti; + uint64_t freq; + + critical_enter(); + ti = DPCPU_PTR(kvm_clock_vcpu_time_info); + freq = pvclock_tsc_freq(ti); + critical_exit(); + + return (freq); +} + static u_int kvm_clock_get_timecounter(struct timecounter *tc) { Modified: projects/paravirt/sys/x86/x86/pvclock.c ============================================================================== --- projects/paravirt/sys/x86/x86/pvclock.c Wed Dec 31 06:54:28 2014 (r276453) +++ projects/paravirt/sys/x86/x86/pvclock.c Wed Dec 31 06:59:22 2014 (r276454) @@ -50,6 +50,21 @@ pvclock_resume(void) atomic_store_rel_64(&pvclock_last_cycles, 0); } +uint64_t +pvclock_tsc_freq(struct pvclock_vcpu_time_info *ti) +{ + uint64_t freq; + + freq = (1000000000ULL << 32) / ti->tsc_to_system_mul; + + if (ti->tsc_shift < 0) + freq <<= -ti->tsc_shift; + else + freq >>= ti->tsc_shift; + + return (freq); +} + /* * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction, * yielding a 64-bit result.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201412310659.sBV6xNPj061088>