summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbryanv <bryanv@FreeBSD.org>2015-02-04 08:33:04 +0000
committerbryanv <bryanv@FreeBSD.org>2015-02-04 08:33:04 +0000
commit7a68cf4e596dc6f95b785e75b92299a43a3d3399 (patch)
tree0380d0a6f9ddb290d0e2a2fc511afdb91ef775e3
parent25ce9181cfd88fce73c121eaab1a8e5237d61dda (diff)
downloadFreeBSD-src-7a68cf4e596dc6f95b785e75b92299a43a3d3399.zip
FreeBSD-src-7a68cf4e596dc6f95b785e75b92299a43a3d3399.tar.gz
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
-rw-r--r--sys/x86/include/pvclock.h1
-rw-r--r--sys/x86/x86/pvclock.c15
2 files changed, 16 insertions, 0 deletions
diff --git a/sys/x86/include/pvclock.h b/sys/x86/include/pvclock.h
index 88a596f..402ffed 100644
--- a/sys/x86/include/pvclock.h
+++ b/sys/x86/include/pvclock.h
@@ -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);
diff --git a/sys/x86/x86/pvclock.c b/sys/x86/x86/pvclock.c
index ebc37a4..c1e6f83 100644
--- a/sys/x86/x86/pvclock.c
+++ b/sys/x86/x86/pvclock.c
@@ -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.
OpenPOWER on IntegriCloud