Signed-off-by: Jason Wang <jasowang@xxxxxxxxxx> --- lib/x86/processor.h | 22 ++++++++++++++++++++++ x86/tsc.c | 16 +--------------- x86/vmexit.c | 15 --------------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/lib/x86/processor.h b/lib/x86/processor.h index 67d7ca5..c348808 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -258,4 +258,26 @@ static inline void sti(void) asm volatile ("sti"); } +static inline unsigned long long rdtsc() +{ + long long r; + +#ifdef __x86_64__ + unsigned a, d; + + asm volatile ("rdtsc" : "=a"(a), "=d"(d)); + r = a | ((long long)d << 32); +#else + asm volatile ("rdtsc" : "=A"(r)); +#endif + return r; +} + +static inline void wrtsc(u64 tsc) +{ + unsigned a = tsc, d = tsc >> 32; + + asm volatile("wrmsr" : : "a"(a), "d"(d), "c"(0x10)); +} + #endif diff --git a/x86/tsc.c b/x86/tsc.c index 394a9c6..58f332d 100644 --- a/x86/tsc.c +++ b/x86/tsc.c @@ -1,19 +1,5 @@ #include "libcflat.h" - -u64 rdtsc(void) -{ - unsigned a, d; - - asm volatile("rdtsc" : "=a"(a), "=d"(d)); - return a | (u64)d << 32; -} - -void wrtsc(u64 tsc) -{ - unsigned a = tsc, d = tsc >> 32; - - asm volatile("wrmsr" : : "a"(a), "d"(d), "c"(0x10)); -} +#include "processor.h" void test_wrtsc(u64 t1) { diff --git a/x86/vmexit.c b/x86/vmexit.c index 84c384d..551083d 100644 --- a/x86/vmexit.c +++ b/x86/vmexit.c @@ -3,21 +3,6 @@ #include "smp.h" #include "processor.h" -static inline unsigned long long rdtsc() -{ - long long r; - -#ifdef __x86_64__ - unsigned a, d; - - asm volatile ("rdtsc" : "=a"(a), "=d"(d)); - r = a | ((long long)d << 32); -#else - asm volatile ("rdtsc" : "=A"(r)); -#endif - return r; -} - static unsigned int inl(unsigned short port) { unsigned int val; -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html