vmcall latency test
cover vmcall latency test
This patchset adds a vmcall latency test to the test suite.
Avi Kivity (2):
test: Allow adding mode vmexit latency tests
test: Add vmcall latency test
kvm/user/test/x86/vmexit.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 files changed, 36 insertions(+), 4 deletions(-)
PATCH 1/2 test: Allow adding mode vmexit latency tests
Make the latency test run on an array of function pointers, which can be expanded with more tests.
Signed-off-by Avi Kivity <[email protected]>
--- kvm/user/test/x86/vmexit.c | 32 ++++++++++++++++++++++++++++---- 1 files changed, 28 insertions(+), 4 deletions(-)
kvm/user/test/x86/vmexit.c +28 -4
@@ -24,16 +24,40 @@ static inline unsigned long long rdtsc()# define R "e"#endif -int main () +static void cpuid (void ) +{ + asmvolatile ("push %%" R "bx; cpuid; pop %%" R "bx" + : : :"eax" ,"ecx" ,"edx" ); +} + +static struct test { +void (*func)(void ); +const char *name; +} tests[] = { + { cpuid,"cpuid" , }, +}; + +static void do_test (struct test *test) {int i;unsigned long long t1, t2; +void (*func)(void ) = test->func; t1 =rdtsc ();for (i =0 ; i <N ; ++i) - asmvolatile ("push %%" R "bx; cpuid; pop %%" R "bx" - : : :"eax" ,"ecx" ,"edx" ); +func (); t2 =rdtsc (); -printf ("vmexit latency: %d\n" , (int )((t2 - t1) /N )); +printf ("%s %d\n" , test->name, (int )((t2 - t1) /N )); +} + +#define ARRAY_SIZE (_x) (sizeof(_x) / sizeof((_x)[0])) + +int main (void ) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (tests); ++i) +do_test (&tests[i]); +return 0 ; }
Signature · 1 line
1.6.2.5
PATCH 2/2 test: Add vmcall latency test
In reply to Avi KivitySigned-off-by Avi Kivity <[email protected]>
--- kvm/user/test/x86/vmexit.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
kvm/user/test/x86/vmexit.c +8 -0
@@ -30,11 +30,19 @@ static void cpuid(void) : : : "eax", "ecx", "edx"); } +static void vmcall (void ) +{ +unsigned long a =0 , b, c, d; + + asmvolatile ("vmcall" :"+a" (a),"=b" (b),"=c" (c),"=d" (d)); +} +static struct test {void (*func)(void );const char *name; } tests[] = { { cpuid,"cpuid" , }, + { vmcall,"vmcall" , }, };static void do_test (struct test *test)
Signature · 1 line
1.6.2.5