Re: [PATCH kvm-unit-tests] x86: tsc: add test for RDTSCP
On 13/11/2015 02:48, Wanpeng Li wrote: > > diff --git a/x86/unittests.cfg b/x86/unittests.cfg > > index ac652fc..fd7e9b2 100644 > > --- a/x86/unittests.cfg > > +++ b/x86/unittests.cfg > > @@ -114,6 +114,7 @@ file = sieve.flat > > > > [tsc] > > file = tsc.flat > > +extra_params = -cpu kvm64,+rdtscp > > > > [tsc_adjust] > > file = tsc_adjust.flat > > When I run cpuid tool in a real linux guest, the rdtscp, tsc_adjust, > tsc deadline timer are present, however, kvm-unit-tests always report > these features are not detected, what is the issue here? Your guest is probably run with some "-cpu" option, while kvm-unit-tests' x86/run script doesn't add any. This is why I needed the extra_params line above. Paolo -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH kvm-unit-tests] x86: tsc: add test for RDTSCP
2015-11-12 19:12 GMT+08:00 Paolo Bonzini : > Signed-off-by: Paolo Bonzini > --- > lib/x86/processor.h | 16 > x86/tsc.c | 23 +++ > x86/unittests.cfg | 1 + > 3 files changed, 40 insertions(+) > > diff --git a/lib/x86/processor.h b/lib/x86/processor.h > index 7973879..b9cb753 100644 > --- a/lib/x86/processor.h > +++ b/lib/x86/processor.h > @@ -2,6 +2,7 @@ > #define LIBCFLAT_PROCESSOR_H > > #include "libcflat.h" > +#include "msr.h" > #include > > #ifdef __x86_64__ > @@ -340,6 +341,21 @@ static inline unsigned long long rdtsc() > return r; > } > > +static inline unsigned long long rdtscp(u32 *aux) > +{ > + long long r; > + > +#ifdef __x86_64__ > + unsigned a, d; > + > + asm volatile ("rdtscp" : "=a"(a), "=d"(d), "=c"(*aux)); > + r = a | ((long long)d << 32); > +#else > + asm volatile ("rdtscp" : "=A"(r), "=c"(*aux)); > +#endif > + return r; > +} > + > static inline void wrtsc(u64 tsc) > { > unsigned a = tsc, d = tsc >> 32; > diff --git a/x86/tsc.c b/x86/tsc.c > index 58f332d..c71dc2a 100644 > --- a/x86/tsc.c > +++ b/x86/tsc.c > @@ -1,6 +1,13 @@ > #include "libcflat.h" > #include "processor.h" > > +#define CPUID_8001_EDX_RDTSCP (1 << 27) > +int check_cpuid_8001_edx(unsigned int bit) > +{ > +return (cpuid(0x8001).d & bit) != 0; > +} > + > + > void test_wrtsc(u64 t1) > { > u64 t2; > @@ -10,6 +17,15 @@ void test_wrtsc(u64 t1) > printf("rdtsc after wrtsc(%lld): %lld\n", t1, t2); > } > > +void test_rdtscp(u64 aux) > +{ > + u32 ecx; > + > + wrmsr(MSR_TSC_AUX, aux); > + rdtscp(&ecx); > + report("Test RDTSCP %d", ecx == aux, aux); > +} > + > int main() > { > u64 t1, t2; > @@ -20,5 +36,12 @@ int main() > > test_wrtsc(0); > test_wrtsc(1000ull); > + > + if (check_cpuid_8001_edx(CPUID_8001_EDX_RDTSCP)) { > + test_rdtscp(0); > + test_rdtscp(10); > + test_rdtscp(0x100); > + } else > + printf("rdtscp not supported\n"); > return 0; > } > diff --git a/x86/unittests.cfg b/x86/unittests.cfg > index ac652fc..fd7e9b2 100644 > --- a/x86/unittests.cfg > +++ b/x86/unittests.cfg > @@ -114,6 +114,7 @@ file = sieve.flat > > [tsc] > file = tsc.flat > +extra_params = -cpu kvm64,+rdtscp > > [tsc_adjust] > file = tsc_adjust.flat When I run cpuid tool in a real linux guest, the rdtscp, tsc_adjust, tsc deadline timer are present, however, kvm-unit-tests always report these features are not detected, what is the issue here? Regards, Wanpeng Li -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH kvm-unit-tests] x86: tsc: add test for RDTSCP
2015-11-12 19:12 GMT+08:00 Paolo Bonzini : > > Signed-off-by: Paolo Bonzini > --- > lib/x86/processor.h | 16 > x86/tsc.c | 23 +++ > x86/unittests.cfg | 1 + > 3 files changed, 40 insertions(+) > > diff --git a/lib/x86/processor.h b/lib/x86/processor.h > index 7973879..b9cb753 100644 > --- a/lib/x86/processor.h > +++ b/lib/x86/processor.h > @@ -2,6 +2,7 @@ > #define LIBCFLAT_PROCESSOR_H > > #include "libcflat.h" > +#include "msr.h" > #include > > #ifdef __x86_64__ > @@ -340,6 +341,21 @@ static inline unsigned long long rdtsc() > return r; > } > > +static inline unsigned long long rdtscp(u32 *aux) > +{ > + long long r; > + > +#ifdef __x86_64__ > + unsigned a, d; > + > + asm volatile ("rdtscp" : "=a"(a), "=d"(d), "=c"(*aux)); > + r = a | ((long long)d << 32); > +#else > + asm volatile ("rdtscp" : "=A"(r), "=c"(*aux)); > +#endif > + return r; > +} > + > static inline void wrtsc(u64 tsc) > { > unsigned a = tsc, d = tsc >> 32; > diff --git a/x86/tsc.c b/x86/tsc.c > index 58f332d..c71dc2a 100644 > --- a/x86/tsc.c > +++ b/x86/tsc.c > @@ -1,6 +1,13 @@ > #include "libcflat.h" > #include "processor.h" > > +#define CPUID_8001_EDX_RDTSCP (1 << 27) > +int check_cpuid_8001_edx(unsigned int bit) > +{ > +return (cpuid(0x8001).d & bit) != 0; > +} > + > + > void test_wrtsc(u64 t1) > { > u64 t2; > @@ -10,6 +17,15 @@ void test_wrtsc(u64 t1) > printf("rdtsc after wrtsc(%lld): %lld\n", t1, t2); > } > > +void test_rdtscp(u64 aux) > +{ > + u32 ecx; > + > + wrmsr(MSR_TSC_AUX, aux); > + rdtscp(&ecx); > + report("Test RDTSCP %d", ecx == aux, aux); > +} > + > int main() > { > u64 t1, t2; > @@ -20,5 +36,12 @@ int main() > > test_wrtsc(0); > test_wrtsc(1000ull); > + > + if (check_cpuid_8001_edx(CPUID_8001_EDX_RDTSCP)) { > + test_rdtscp(0); > + test_rdtscp(10); > + test_rdtscp(0x100); > + } else > + printf("rdtscp not supported\n"); > return 0; > } > diff --git a/x86/unittests.cfg b/x86/unittests.cfg > index ac652fc..fd7e9b2 100644 > --- a/x86/unittests.cfg > +++ b/x86/unittests.cfg > @@ -114,6 +114,7 @@ file = sieve.flat > > [tsc] > file = tsc.flat > +extra_params = -cpu kvm64,+rdtscp > > [tsc_adjust] > file = tsc_adjust.flat When I run cpuid tool in a real linux guest, the rdtscp, tsc_adjust, tsc deadline timer are present, however, kvm-unit-tests always report these features are not detected, what is the issue here? Regards, Wanpeng Li -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH kvm-unit-tests] x86: tsc: add test for RDTSCP
Signed-off-by: Paolo Bonzini --- lib/x86/processor.h | 16 x86/tsc.c | 23 +++ x86/unittests.cfg | 1 + 3 files changed, 40 insertions(+) diff --git a/lib/x86/processor.h b/lib/x86/processor.h index 7973879..b9cb753 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -2,6 +2,7 @@ #define LIBCFLAT_PROCESSOR_H #include "libcflat.h" +#include "msr.h" #include #ifdef __x86_64__ @@ -340,6 +341,21 @@ static inline unsigned long long rdtsc() return r; } +static inline unsigned long long rdtscp(u32 *aux) +{ + long long r; + +#ifdef __x86_64__ + unsigned a, d; + + asm volatile ("rdtscp" : "=a"(a), "=d"(d), "=c"(*aux)); + r = a | ((long long)d << 32); +#else + asm volatile ("rdtscp" : "=A"(r), "=c"(*aux)); +#endif + return r; +} + static inline void wrtsc(u64 tsc) { unsigned a = tsc, d = tsc >> 32; diff --git a/x86/tsc.c b/x86/tsc.c index 58f332d..c71dc2a 100644 --- a/x86/tsc.c +++ b/x86/tsc.c @@ -1,6 +1,13 @@ #include "libcflat.h" #include "processor.h" +#define CPUID_8001_EDX_RDTSCP (1 << 27) +int check_cpuid_8001_edx(unsigned int bit) +{ +return (cpuid(0x8001).d & bit) != 0; +} + + void test_wrtsc(u64 t1) { u64 t2; @@ -10,6 +17,15 @@ void test_wrtsc(u64 t1) printf("rdtsc after wrtsc(%lld): %lld\n", t1, t2); } +void test_rdtscp(u64 aux) +{ + u32 ecx; + + wrmsr(MSR_TSC_AUX, aux); + rdtscp(&ecx); + report("Test RDTSCP %d", ecx == aux, aux); +} + int main() { u64 t1, t2; @@ -20,5 +36,12 @@ int main() test_wrtsc(0); test_wrtsc(1000ull); + + if (check_cpuid_8001_edx(CPUID_8001_EDX_RDTSCP)) { + test_rdtscp(0); + test_rdtscp(10); + test_rdtscp(0x100); + } else + printf("rdtscp not supported\n"); return 0; } diff --git a/x86/unittests.cfg b/x86/unittests.cfg index ac652fc..fd7e9b2 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -114,6 +114,7 @@ file = sieve.flat [tsc] file = tsc.flat +extra_params = -cpu kvm64,+rdtscp [tsc_adjust] file = tsc_adjust.flat -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html