lkml.org 
[lkml]   [2024]   [Jan]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 38/41] KVM: x86/pmu: Introduce PMU helper to increment counter
Date
From: Mingwei Zhang <mizhang@google.com>

Introduce PMU helper to increment counter for passthrough PMU because it is
able to conveniently return the overflow condition instead of deferring the
overflow check to KVM_REQ_PMU in original implementation. In addition, this
helper function can hide architecture details.

Signed-off-by: Mingwei Zhang <mizhang@google.com>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/pmu.c | 15 +++++++++++++++
2 files changed, 16 insertions(+)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index b02688ed74f7..869de0d81055 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -501,6 +501,7 @@ struct kvm_pmc {
bool is_paused;
bool intr;
u64 counter;
+ u64 emulated_counter;
u64 prev_counter;
u64 eventsel;
u64 eventsel_hw;
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index e7ad97734705..7b0bac1ac4bf 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -434,6 +434,21 @@ static void reprogram_counter(struct kvm_pmc *pmc)
pmc->prev_counter = 0;
}

+static bool kvm_passthrough_pmu_incr_counter(struct kvm_pmc *pmc)
+{
+ if (!pmc->emulated_counter)
+ return false;
+
+ pmc->counter += pmc->emulated_counter;
+ pmc->emulated_counter = 0;
+ pmc->counter &= pmc_bitmask(pmc);
+
+ if (!pmc->counter)
+ return true;
+
+ return false;
+}
+
void kvm_pmu_handle_event(struct kvm_vcpu *vcpu)
{
struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
--
2.34.1

\
 
 \ /
  Last update: 2024-05-27 14:34    [W:1.374 / U:0.268 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site