summaryrefslogtreecommitdiffstats
path: root/test/eviction.c
blob: 8cb5914d54b7c8c9606e2afb2f700c5f8df162f3 (plain) (blame)
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
39
40
41
42
43
#include "cachepc/uapi.h"

#include <sys/ioctl.h>
#include <fcntl.h>
#include <assert.h>
#include <unistd.h>
#include <err.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

int
main(int argc, const char **argv)
{
	uint8_t counts[L1_SETS];
	uint32_t set;
	int i, fd, ret;

	fd = open("/dev/kvm", O_RDONLY);
	if (fd < 0) err(1, "open");

	set = 48;
	if (argc > 1) set = atoi(argv[1]);

	ret = ioctl(fd, KVM_CPC_TEST_EVICTION, &set);
	if (ret == -1) err(1, "ioctl KVM_CPC_TEST_EVICTION");

	ret = ioctl(fd, KVM_CPC_READ_COUNTS, counts);
	if (ret == -1) err(1, "ioctl KVM_CPC_READ_COUNTS");

	for (i = 0; i < 64; i++) {
		if (i % 16 == 0 && i)
			printf("\n");
		if (counts[i] > 0)
			printf("\x1b[91m");
		printf("%2i ", i);
		if (counts[i] > 0)
			printf("\x1b[0m");
	}
	printf("\n");

	close(fd);
}