aboutsummaryrefslogtreecommitdiff
path: root/kvm/user/test/vmexit.c
blob: 11faf61477c99269507df2b7bf9edd44c48a3702 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "printf.h"

static inline unsigned long long rdtsc()
{
	long long r;

#ifdef __x86_64__
	unsigned a, d;

	asm volatile ("rdtsc" : "=a"(a), "=d"(d));
	r = a | ((long long)d << 32);
#else
	asm volatile ("rdtsc" : "=A"(r));
#endif
	return r;
}

#define N (1 << 21)

int main()
{
	int i;
	unsigned long long t1, t2;

	t1 = rdtsc();
	for (i = 0; i < N; ++i)
		asm volatile ("cpuid" : : : "eax", "ebx", "ecx", "edx");
	t2 = rdtsc();
	printf("vmexit latency: %d\n", (int)((t2 - t1) / N));
	return 0;
}