diff mbox

[QEMU-KVM,1/2] test: Allow adding mode vmexit latency tests

Message ID 1252858196-4870-2-git-send-email-avi@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Avi Kivity Sept. 13, 2009, 4:09 p.m. UTC
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(-)
diff mbox

Patch

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;
 }