Make the latency test run on an array of function pointers, which can be expanded with more tests. Signed-off-by: Avi Kivity <avi@xxxxxxxxxx> --- kvm/user/test/x86/vmexit.c | 32 ++++++++++++++++++++++++++++---- 1 files changed, 28 insertions(+), 4 deletions(-) diff --git a/kvm/user/test/x86/vmexit.c b/kvm/user/test/x86/vmexit.c index 981d6c1..364837f 100644 --- a/kvm/user/test/x86/vmexit.c +++ b/kvm/user/test/x86/vmexit.c @@ -24,16 +24,40 @@ static inline unsigned long long rdtsc() # define R "e" #endif -int main() +static void cpuid(void) +{ + asm volatile ("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) - asm volatile ("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; } -- 1.6.2.5 -- 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