summaryrefslogtreecommitdiffstats
path: root/arch/x86/include/asm/pvclock.h
diff options
context:
space:
mode:
authorMarcelo Tosatti <mtosatti@redhat.com>2012-11-27 23:28:51 -0200
committerMarcelo Tosatti <mtosatti@redhat.com>2012-11-27 23:29:07 -0200
commitdce2db0a35197e2f4421245079f19ab753e97348 (patch)
treec3151bef0ca980cf1c1af1fa6c4585df41e5a760 /arch/x86/include/asm/pvclock.h
parent42b5637d6989f75a7a0e8ea8633583564ff443ff (diff)
downloadop-kernel-dev-dce2db0a35197e2f4421245079f19ab753e97348.zip
op-kernel-dev-dce2db0a35197e2f4421245079f19ab753e97348.tar.gz
x86: pvclock: create helper for pvclock data retrieval
Originally from Jeremy Fitzhardinge. So code can be reused. Acked-by: Glauber Costa <glommer@parallels.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch/x86/include/asm/pvclock.h')
-rw-r--r--arch/x86/include/asm/pvclock.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h
index c59cc97..47e25d4 100644
--- a/arch/x86/include/asm/pvclock.h
+++ b/arch/x86/include/asm/pvclock.h
@@ -56,4 +56,32 @@ static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
return product;
}
+static __always_inline
+u64 pvclock_get_nsec_offset(const struct pvclock_vcpu_time_info *src)
+{
+ u64 delta = __native_read_tsc() - src->tsc_timestamp;
+ return pvclock_scale_delta(delta, src->tsc_to_system_mul,
+ src->tsc_shift);
+}
+
+static __always_inline
+unsigned __pvclock_read_cycles(const struct pvclock_vcpu_time_info *src,
+ cycle_t *cycles, u8 *flags)
+{
+ unsigned version;
+ cycle_t ret, offset;
+ u8 ret_flags;
+
+ version = src->version;
+ rdtsc_barrier();
+ offset = pvclock_get_nsec_offset(src);
+ ret = src->system_time + offset;
+ ret_flags = src->flags;
+ rdtsc_barrier();
+
+ *cycles = ret;
+ *flags = ret_flags;
+ return version;
+}
+
#endif /* _ASM_X86_PVCLOCK_H */
OpenPOWER on IntegriCloud