Skip to content

Commit 649bccd

Browse files
Like Xusean-jc
authored andcommitted
KVM: x86/pmu: Rewrite reprogram_counters() to improve performance
A valid pmc is always tested before using pmu->reprogram_pmi. Eliminate this part of the redundancy by setting the counter's bitmask directly, and in addition, trigger KVM_REQ_PMU only once to save more cpu cycles. Signed-off-by: Like Xu <likexu@tencent.com> Link: https://lore.kernel.org/r/20230214050757.9623-4-likexu@tencent.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 8bca8c5 commit 649bccd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ static struct kvm_pmc *intel_pmc_idx_to_pmc(struct kvm_pmu *pmu, int pmc_idx)
7676
static void reprogram_counters(struct kvm_pmu *pmu, u64 diff)
7777
{
7878
int bit;
79-
struct kvm_pmc *pmc;
8079

81-
for_each_set_bit(bit, (unsigned long *)&diff, X86_PMC_IDX_MAX) {
82-
pmc = intel_pmc_idx_to_pmc(pmu, bit);
83-
if (pmc)
84-
kvm_pmu_request_counter_reprogam(pmc);
85-
}
80+
if (!diff)
81+
return;
82+
83+
for_each_set_bit(bit, (unsigned long *)&diff, X86_PMC_IDX_MAX)
84+
set_bit(bit, pmu->reprogram_pmi);
85+
kvm_make_request(KVM_REQ_PMU, pmu_to_vcpu(pmu));
8686
}
8787

8888
static bool intel_hw_event_available(struct kvm_pmc *pmc)

0 commit comments

Comments
 (0)