Skip to contentSkip to conversation

vmcall latency test

PATCH New Avi Kivity 1 participant 3 messages Sep 13, 2009 KVM

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

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(-)
author
#1 lore raw

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.

---
 kvm/user/test/x86/vmexit.c |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)
kvm/user/test/x86/vmexit.c +28 -4
index 981d6c1..364837f 100644
@@ -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;
 }
Signature · 1 line
1.6.2.5
author
#2 lore raw

PATCH 2/2 test: Add vmcall latency test

In reply to Avi Kivity
---
 kvm/user/test/x86/vmexit.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
kvm/user/test/x86/vmexit.c +8 -0
index 364837f..bd1895f 100644
@@ -30,11 +30,19 @@ static void cpuid(void)
 		      : : : "eax", "ecx", "edx");
 }
 
+static void vmcall(void)
+{
+	unsigned long a = 0, b, c, d;
+
+	asm volatile ("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