diff options
Diffstat (limited to 'test/kvm.c')
| -rwxr-xr-x | test/kvm.c | 46 |
1 files changed, 25 insertions, 21 deletions
@@ -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++) { |
