commit 1caab14ce3bf1ed6ea1074e5ced4b3e5bd4e4b89
parent aa27d3b55fb46c7eb44e8a61aaaaae2aa6eed63c
Author: Louis Burda <quent.burda@gmail.com>
Date: Tue, 7 Feb 2023 08:25:55 -0600
Add counter for L1 misses in guest
Diffstat:
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
@@ -3957,8 +3957,8 @@ static bool page_fault_handle_page_track(struct kvm_vcpu *vcpu,
case CPC_TRACK_FAULT_NO_RUN:
BUG_ON(modes[i] != KVM_PAGE_TRACK_ACCESS);
- cpc_send_track_step_event_single(
- fault->gfn, fault->error_code, cpc_retinst);
+ cpc_send_track_step_event_single(fault->gfn, fault->error_code,
+ cpc_retinst, cpc_guest_misses);
return true;
case CPC_TRACK_STEPS:
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
@@ -2178,7 +2178,7 @@ static int intr_interception(struct kvm_vcpu *vcpu)
break;
}
- cpc_send_track_step_event(&cpc_faults);
+ cpc_send_track_step_event(&cpc_faults, cpc_guest_misses);
list_for_each_entry_safe(fault, next, &cpc_faults, list) {
if (cpc_track_steps.with_data && cpc_track_steps.stepping)
cpc_track_single(vcpu, fault->gfn, KVM_PAGE_TRACK_ACCESS);
@@ -3974,6 +3974,7 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
cpc_retinst = cpc_read_pmc(CPC_RETINST_PMC);
cpc_retinst_user = cpc_read_pmc(CPC_RETINST_USER_PMC);
+ cpc_guest_misses = cpc_read_pmc(CPC_L1MISS_GUEST_PMC);
if (sev_es_guest(vcpu->kvm)) {
__svm_sev_es_vcpu_run(vmcb_pa);
@@ -3995,6 +3996,15 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
cpc_retinst = cpc_read_pmc(CPC_RETINST_PMC) - cpc_retinst;
cpc_retinst_user = cpc_read_pmc(CPC_RETINST_USER_PMC) - cpc_retinst_user;
+ cpc_guest_misses = cpc_read_pmc(CPC_L1MISS_GUEST_PMC) - cpc_guest_misses;
+
+ if (cpc_baseline_measure && cpc_guest_misses < cpc_baseline_guest_misses)
+ cpc_baseline_guest_misses = cpc_guest_misses;
+
+ if (cpc_baseline_active) {
+ WARN_ON_ONCE(cpc_guest_misses < cpc_baseline_guest_misses);
+ cpc_guest_misses -= cpc_baseline_guest_misses;
+ }
if (cpc_prime_probe)
cpc_save_msrmts(cpc_ds);