summaryrefslogtreecommitdiffstats
path: root/test/kvm.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2022-10-27 23:35:21 +0200
committerLouis Burda <quent.burda@gmail.com>2022-10-27 23:35:34 +0200
commit434a6210041dd447acae38b95561a2d990efa153 (patch)
tree9b63edc3755b5bb3077c9b9cbc6f8ec6dfa77e3c /test/kvm.c
parent16469e2094edab39279b9f6aaa97c84722baa812 (diff)
downloadcachepc-434a6210041dd447acae38b95561a2d990efa153.tar.gz
cachepc-434a6210041dd447acae38b95561a2d990efa153.zip
Add online baseline measurement and pmc reset
Diffstat (limited to 'test/kvm.c')
-rwxr-xr-xtest/kvm.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/test/kvm.c b/test/kvm.c
index 9632fec..bd538fb 100755
--- a/test/kvm.c
+++ b/test/kvm.c
@@ -188,13 +188,13 @@ kvm_init(size_t ramsize, void *code_start, void *code_stop)
if (ret < 0) err(1, "KVM_SET_REGS");
}
-uint16_t *
+cpc_msrmt_t *
read_counts()
{
- uint16_t *counts;
+ cpc_msrmt_t *counts;
int ret;
- counts = malloc(64 * sizeof(uint16_t));
+ counts = malloc(64 * sizeof(cpc_msrmt_t));
if (!counts) err(1, "malloc");
ret = ioctl(kvm_fd, KVM_CPC_READ_COUNTS, counts);
if (ret == -1) err(1, "ioctl READ_COUNTS");
@@ -203,7 +203,7 @@ read_counts()
}
void
-print_counts(uint16_t *counts)
+print_counts(cpc_msrmt_t *counts)
{
int i;
@@ -218,15 +218,15 @@ print_counts(uint16_t *counts)
if (counts[i] > 0)
printf("\x1b[0m");
}
- printf("\n Target Set Count: %d %hu \n", TARGET_SET, counts[TARGET_SET]);
+ printf("\n Target Set Count: %d %llu \n", TARGET_SET, counts[TARGET_SET]);
printf("\n");
}
-uint16_t *
+cpc_msrmt_t *
collect(const char *prefix, void *code_start, void *code_stop)
{
struct kvm_regs regs;
- uint16_t *counts;
+ cpc_msrmt_t *counts;
int ret;
/* using cache size for alignment of kvm memory access */
@@ -263,10 +263,10 @@ collect(const char *prefix, void *code_start, void *code_stop)
int
main(int argc, const char **argv)
{
- uint16_t without_access[SAMPLE_COUNT][64];
- uint16_t with_access[SAMPLE_COUNT][64];
- uint16_t *counts, *baseline;
- uint32_t arg;
+ cpc_msrmt_t without_access[SAMPLE_COUNT][64];
+ cpc_msrmt_t with_access[SAMPLE_COUNT][64];
+ cpc_msrmt_t *counts, *baseline;
+ uint32_t arg, measure;
int i, k, ret;
setvbuf(stdout, NULL, _IONBF, 0);
@@ -281,25 +281,29 @@ main(int argc, const char **argv)
ret = ioctl(kvm_fd, KVM_CPC_INIT_PMC, &arg);
if (ret == -1) err(1, "ioctl INIT_PMC");
- baseline = calloc(sizeof(uint16_t), 64);
+ baseline = calloc(sizeof(cpc_msrmt_t), 64);
if (!baseline) err(1, "calloc");
- for (k = 0; k < 64; k++)
- baseline[k] = UINT16_MAX;
+
+ measure = true;
+ ret = ioctl(kvm_fd, KVM_CPC_MEASURE_BASELINE, &measure);
+ if (ret == -1) err(1, "ioctl MEASURE_BASELINE");
for (i = 0; i < SAMPLE_COUNT; i++) {
counts = collect("without", __start_guest_without, __stop_guest_without);
- memcpy(without_access[i], counts, 64 * sizeof(uint16_t));
+ memcpy(without_access[i], counts, 64 * sizeof(cpc_msrmt_t));
free(counts);
counts = collect("with", __start_guest_with, __stop_guest_with);
- memcpy(with_access[i], counts, 64 * sizeof(uint16_t));
+ memcpy(with_access[i], counts, 64 * sizeof(cpc_msrmt_t));
free(counts);
-
- for (k = 0; k < 64; k++) {
- baseline[k] = MIN(baseline[k], without_access[i][k]);
- baseline[k] = MIN(baseline[k], with_access[i][k]);
- }
}
+
+ measure = false;
+ ret = ioctl(kvm_fd, KVM_CPC_MEASURE_BASELINE, &measure);
+ if (ret == -1) err(1, "ioctl MEASURE_BASELINE");
+
+ ret = ioctl(kvm_fd, KVM_CPC_READ_BASELINE, baseline);
+ if (ret == -1) err(1, "ioctl READ_BASELINE");
for (i = 0; i < SAMPLE_COUNT; i++) {
for (k = 0; k < 64; k++) {