Merge branch 'qemu-cvs'
[kvm-userspace.git] / user / test / x86 / vmexit.c
blobbd57bfa90832f7a0975e62620082742d64cab151
2 #include "libcflat.h"
4 static inline unsigned long long rdtsc()
6 long long r;
8 #ifdef __x86_64__
9 unsigned a, d;
11 asm volatile ("rdtsc" : "=a"(a), "=d"(d));
12 r = a | ((long long)d << 32);
13 #else
14 asm volatile ("rdtsc" : "=A"(r));
15 #endif
16 return r;
19 #define N (1 << 22)
21 #ifdef __x86_64__
22 # define R "r"
23 #else
24 # define R "e"
25 #endif
27 int main()
29 int i;
30 unsigned long long t1, t2;
32 t1 = rdtsc();
33 for (i = 0; i < N; ++i)
34 asm volatile ("push %%"R"bx; cpuid; pop %%"R"bx"
35 : : : "eax", "ecx", "edx");
36 t2 = rdtsc();
37 printf("vmexit latency: %d\n", (int)((t2 - t1) / N));
38 return 0;