Date: Wed, 4 Feb 2015 08:33:04 +0000 (UTC) From: Bryan Venteicher <bryanv@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r278184 - in head/sys/x86: include x86 Message-ID: <201502040833.t148X4cJ001146@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bryanv Date: Wed Feb 4 08:33:04 2015 New Revision: 278184 URL: https://svnweb.freebsd.org/changeset/base/278184 Log: Add interface to derive a TSC frequency from the pvclock This can later use this to determine the TSC frequency like is done with VMware, instead of using a DELAY loop that is not always accurate in an VM. MFC after: 1 month Modified: head/sys/x86/include/pvclock.h head/sys/x86/x86/pvclock.c Modified: head/sys/x86/include/pvclock.h ============================================================================== --- head/sys/x86/include/pvclock.h Wed Feb 4 08:26:43 2015 (r278183) +++ head/sys/x86/include/pvclock.h Wed Feb 4 08:33:04 2015 (r278184) @@ -51,6 +51,7 @@ struct pvclock_wall_clock { void pvclock_resume(void); uint64_t pvclock_get_last_cycles(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: head/sys/x86/x86/pvclock.c ============================================================================== --- head/sys/x86/x86/pvclock.c Wed Feb 4 08:26:43 2015 (r278183) +++ head/sys/x86/x86/pvclock.c Wed Feb 4 08:33:04 2015 (r278184) @@ -58,6 +58,21 @@ pvclock_get_last_cycles(void) return (atomic_load_acq_64(&pvclock_last_cycles)); } +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?201502040833.t148X4cJ001146>