diff options
| author | Louis Burda <quent.burda@gmail.com> | 2022-10-27 23:35:21 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2022-10-27 23:35:34 +0200 |
| commit | 434a6210041dd447acae38b95561a2d990efa153 (patch) | |
| tree | 9b63edc3755b5bb3077c9b9cbc6f8ec6dfa77e3c /test/sev.c | |
| parent | 16469e2094edab39279b9f6aaa97c84722baa812 (diff) | |
| download | cachepc-434a6210041dd447acae38b95561a2d990efa153.tar.gz cachepc-434a6210041dd447acae38b95561a2d990efa153.zip | |
Add online baseline measurement and pmc reset
Diffstat (limited to 'test/sev.c')
| -rwxr-xr-x | test/sev.c | 46 |
1 files changed, 25 insertions, 21 deletions
@@ -398,13 +398,13 @@ sev_kvm_deinit(struct kvm *kvm) munmap(kvm->mem, kvm->memsize); } -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_dev, KVM_CPC_READ_COUNTS, counts); if (ret == -1) err(1, "ioctl READ_COUNTS"); @@ -413,7 +413,7 @@ read_counts() } void -print_counts(uint16_t *counts) +print_counts(cpc_msrmt_t *counts) { int i; @@ -428,16 +428,16 @@ print_counts(uint16_t *counts) if (counts[i] > 0) printf("\x1b[0m"); } - printf("\n Target Set %i Count: %hu\n", TARGET_SET, counts[TARGET_SET]); + printf("\n Target Set %i Count: %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; struct kvm kvm; - uint16_t *counts; + cpc_msrmt_t *counts; int ret; sev_kvm_init(&kvm, 64 * 64 * 8 * 2, code_start, code_stop); @@ -468,10 +468,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); @@ -494,25 +494,29 @@ main(int argc, const char **argv) ret = ioctl(kvm_dev, KVM_CPC_INIT_PMC, &arg); if (ret < 0) 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_dev, 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_dev, KVM_CPC_MEASURE_BASELINE, &measure); + if (ret == -1) err(1, "ioctl MEASURE_BASELINE"); + + ret = ioctl(kvm_dev, 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++) { |
