summaryrefslogtreecommitdiff
blob: 394a9c6b8e12fe21111d376d4960ca44505f42f9 (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
33
34
35
36
37
38
#include "libcflat.h"

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(%lld): %lld\n", t1, t2);
}

int main()
{
	u64 t1, t2;

	t1 = rdtsc();
	t2 = rdtsc();
	printf("rdtsc latency %lld\n", (unsigned)(t2 - t1));

	test_wrtsc(0);
	test_wrtsc(100000000000ull);
	return 0;
}