@@ -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;
}
Make the latency test run on an array of function pointers, which can be expanded with more tests. Signed-off-by: Avi Kivity <avi@redhat.com> --- kvm/user/test/x86/vmexit.c | 32 ++++++++++++++++++++++++++++---- 1 files changed, 28 insertions(+), 4 deletions(-)