* [PATCH kvm-unit-tests] x86: tsc: add test for RDTSCP
@ 2015-11-12 11:12 Paolo Bonzini
2015-11-13 1:42 ` Wanpeng Li
2015-11-13 1:48 ` Wanpeng Li
0 siblings, 2 replies; 4+ messages in thread
From: Paolo Bonzini @ 2015-11-12 11:12 UTC (permalink / raw)
To: kvm
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
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 <stdint.h>
#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_80000001_EDX_RDTSCP (1 << 27)
+int check_cpuid_80000001_edx(unsigned int bit)
+{
+ return (cpuid(0x80000001).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(100000000000ull);
+
+ if (check_cpuid_80000001_edx(CPUID_80000001_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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH kvm-unit-tests] x86: tsc: add test for RDTSCP
2015-11-12 11:12 [PATCH kvm-unit-tests] x86: tsc: add test for RDTSCP Paolo Bonzini
@ 2015-11-13 1:42 ` Wanpeng Li
2015-11-13 1:48 ` Wanpeng Li
1 sibling, 0 replies; 4+ messages in thread
From: Wanpeng Li @ 2015-11-13 1:42 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: kvm
2015-11-12 19:12 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>:
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> 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 <stdint.h>
>
> #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_80000001_EDX_RDTSCP (1 << 27)
> +int check_cpuid_80000001_edx(unsigned int bit)
> +{
> + return (cpuid(0x80000001).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(100000000000ull);
> +
> + if (check_cpuid_80000001_edx(CPUID_80000001_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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH kvm-unit-tests] x86: tsc: add test for RDTSCP
2015-11-12 11:12 [PATCH kvm-unit-tests] x86: tsc: add test for RDTSCP Paolo Bonzini
2015-11-13 1:42 ` Wanpeng Li
@ 2015-11-13 1:48 ` Wanpeng Li
2015-11-13 9:23 ` Paolo Bonzini
1 sibling, 1 reply; 4+ messages in thread
From: Wanpeng Li @ 2015-11-13 1:48 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: kvm
2015-11-12 19:12 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> 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 <stdint.h>
>
> #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_80000001_EDX_RDTSCP (1 << 27)
> +int check_cpuid_80000001_edx(unsigned int bit)
> +{
> + return (cpuid(0x80000001).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(100000000000ull);
> +
> + if (check_cpuid_80000001_edx(CPUID_80000001_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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH kvm-unit-tests] x86: tsc: add test for RDTSCP
2015-11-13 1:48 ` Wanpeng Li
@ 2015-11-13 9:23 ` Paolo Bonzini
0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2015-11-13 9:23 UTC (permalink / raw)
To: Wanpeng Li; +Cc: kvm
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-11-13 9:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-12 11:12 [PATCH kvm-unit-tests] x86: tsc: add test for RDTSCP Paolo Bonzini
2015-11-13 1:42 ` Wanpeng Li
2015-11-13 1:48 ` Wanpeng Li
2015-11-13 9:23 ` Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.