2020-03-05 10:00:11

by Luwei Kang

[permalink] [raw]
Subject: [PATCH v1 04/11] KVM: x86/pmu: Decouple event enablement from event creation

From: Kan Liang <[email protected]>

KVM needs to specially configure the event before enabling the event, e.g.
set event to assign a dedicated counter and handle auto-reload flags.

Set disabled = 1 when allocating the event. So perf will not enable the
event by default. Then enable the event explicitly. Previously, the process
is creating and enabling. Now, it's creating, KVM configure, and enabling.

Signed-off-by: Kan Liang <[email protected]>
---
arch/x86/kvm/pmu.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index bcc6a73..b4f9e97 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -109,6 +109,7 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,
.exclude_user = exclude_user,
.exclude_kernel = exclude_kernel,
.config = config,
+ .disabled = 1,
};

attr.sample_period = (-pmc->counter) & pmc_bitmask(pmc);
@@ -136,6 +137,7 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,

pmc->perf_event = event;
pmc_to_pmu(pmc)->event_count++;
+ perf_event_enable(event);
clear_bit(pmc->idx, pmc_to_pmu(pmc)->reprogram_pmi);
}

--
1.8.3.1