From: Avi Kivity <[EMAIL PROTECTED]>

Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>

diff --git a/user/config-x86-common.mak b/user/config-x86-common.mak
index ec3f1ac..e44491c 100644
--- a/user/config-x86-common.mak
+++ b/user/config-x86-common.mak
@@ -7,7 +7,7 @@ kvmctl_objs= main.o ../libkvm/libkvm.a
 balloon_ctl: balloon_ctl.o
 
 tests-common = $(TEST_DIR)/bootstrap \
-                       $(TEST_DIR)/vmexit.flat \
+                       $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \
                        $(TEST_DIR)/smp.flat  $(TEST_DIR)/port80.flat
 
 test_cases: $(tests-common) $(tests)
@@ -36,6 +36,8 @@ $(TEST_DIR)/emulator.flat: $(cstart.o) $(TEST_DIR)/vm.o 
$(TEST_DIR)/print.o
 
 $(TEST_DIR)/port80.flat: $(cstart.o) $(TEST_DIR)/port80.o
 
+$(TEST_DIR)/tsc.flat: $(cstart.o) $(TEST_DIR)/tsc.o
+
 $(TEST_DIR)/libcflat.a: $(TEST_DIR)/lib/exit.o $(TEST_DIR)/lib/printf.o \
        $(TEST_DIR)/lib/smp.o $(TEST_DIR)/lib/string.o
        ar rcs $@ $^
diff --git a/user/test/x86/tsc.c b/user/test/x86/tsc.c
new file mode 100644
index 0000000..3ead720
--- /dev/null
+++ b/user/test/x86/tsc.c
@@ -0,0 +1,41 @@
+
+#include "printf.h"
+
+typedef unsigned long long u64;
+
+u64 rdtsc(void)
+{
+       unsigned a, d;
+
+       asm volatile("rdtsc" : "=a"(a), "=d"(d));
+       return a | (u64)d << 32;
+}
+
+void wrtsc(u64 tsc)
+{
+       unsigned a = tsc, d = tsc >> 32;
+
+       asm volatile("wrmsr" : : "a"(a), "d"(d), "c"(0x10));
+}
+
+void test_wrtsc(u64 t1)
+{
+       u64 t2;
+
+       wrtsc(t1);
+       t2 = rdtsc();
+       printf("rdtsc after wrtsc(%d): %d\n", t1, t2);
+}
+
+int main()
+{
+       u64 t1, t2;
+
+       t1 = rdtsc();
+       t2 = rdtsc();
+       printf("rdtsc latency %d\n", (unsigned)(t2 - t1));
+
+       test_wrtsc(0);
+       test_wrtsc(100000000000ull);
+       return 0;
+}

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
kvm-commits mailing list
kvm-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-commits

Reply via email to