Commit 76d287b2 authored by Like Xu's avatar Like Xu Committed by Paolo Bonzini

KVM: x86/pmu: Drop "u8 ctrl, int idx" for reprogram_fixed_counter()

Since afrer reprogram_fixed_counter() is called, it's bound to assign
the requested fixed_ctr_ctrl to pmu->fixed_ctr_ctrl, this assignment step
can be moved forward (the stale value for diff is saved extra early),
thus simplifying the passing of parameters.

No functional change intended.
Signed-off-by: default avatarLike Xu <likexu@tencent.com>
Message-Id: <20220518132512.37864-7-likexu@tencent.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent fb121aaf
...@@ -327,8 +327,11 @@ void reprogram_gp_counter(struct kvm_pmc *pmc) ...@@ -327,8 +327,11 @@ void reprogram_gp_counter(struct kvm_pmc *pmc)
} }
EXPORT_SYMBOL_GPL(reprogram_gp_counter); EXPORT_SYMBOL_GPL(reprogram_gp_counter);
void reprogram_fixed_counter(struct kvm_pmc *pmc, u8 ctrl, int idx) void reprogram_fixed_counter(struct kvm_pmc *pmc)
{ {
struct kvm_pmu *pmu = pmc_to_pmu(pmc);
int idx = pmc->idx - INTEL_PMC_IDX_FIXED;
u8 ctrl = fixed_ctrl_field(pmu->fixed_ctr_ctrl, idx);
unsigned en_field = ctrl & 0x3; unsigned en_field = ctrl & 0x3;
bool pmi = ctrl & 0x8; bool pmi = ctrl & 0x8;
...@@ -358,12 +361,8 @@ void reprogram_counter(struct kvm_pmc *pmc) ...@@ -358,12 +361,8 @@ void reprogram_counter(struct kvm_pmc *pmc)
{ {
if (pmc_is_gp(pmc)) if (pmc_is_gp(pmc))
reprogram_gp_counter(pmc); reprogram_gp_counter(pmc);
else { else
int idx = pmc->idx - INTEL_PMC_IDX_FIXED; reprogram_fixed_counter(pmc);
u8 ctrl = fixed_ctrl_field(pmc_to_pmu(pmc)->fixed_ctr_ctrl, idx);
reprogram_fixed_counter(pmc, ctrl, idx);
}
} }
EXPORT_SYMBOL_GPL(reprogram_counter); EXPORT_SYMBOL_GPL(reprogram_counter);
......
...@@ -174,7 +174,7 @@ static inline void kvm_init_pmu_capability(void) ...@@ -174,7 +174,7 @@ static inline void kvm_init_pmu_capability(void)
} }
void reprogram_gp_counter(struct kvm_pmc *pmc); void reprogram_gp_counter(struct kvm_pmc *pmc);
void reprogram_fixed_counter(struct kvm_pmc *pmc, u8 ctrl, int fixed_idx); void reprogram_fixed_counter(struct kvm_pmc *pmc);
void reprogram_counter(struct kvm_pmc *pmc); void reprogram_counter(struct kvm_pmc *pmc);
void kvm_pmu_deliver_pmi(struct kvm_vcpu *vcpu); void kvm_pmu_deliver_pmi(struct kvm_vcpu *vcpu);
......
...@@ -37,23 +37,23 @@ static int fixed_pmc_events[] = {1, 0, 7}; ...@@ -37,23 +37,23 @@ static int fixed_pmc_events[] = {1, 0, 7};
static void reprogram_fixed_counters(struct kvm_pmu *pmu, u64 data) static void reprogram_fixed_counters(struct kvm_pmu *pmu, u64 data)
{ {
struct kvm_pmc *pmc;
u8 old_fixed_ctr_ctrl = pmu->fixed_ctr_ctrl;
int i; int i;
pmu->fixed_ctr_ctrl = data;
for (i = 0; i < pmu->nr_arch_fixed_counters; i++) { for (i = 0; i < pmu->nr_arch_fixed_counters; i++) {
u8 new_ctrl = fixed_ctrl_field(data, i); u8 new_ctrl = fixed_ctrl_field(data, i);
u8 old_ctrl = fixed_ctrl_field(pmu->fixed_ctr_ctrl, i); u8 old_ctrl = fixed_ctrl_field(old_fixed_ctr_ctrl, i);
struct kvm_pmc *pmc;
pmc = get_fixed_pmc(pmu, MSR_CORE_PERF_FIXED_CTR0 + i);
if (old_ctrl == new_ctrl) if (old_ctrl == new_ctrl)
continue; continue;
pmc = get_fixed_pmc(pmu, MSR_CORE_PERF_FIXED_CTR0 + i);
__set_bit(INTEL_PMC_IDX_FIXED + i, pmu->pmc_in_use); __set_bit(INTEL_PMC_IDX_FIXED + i, pmu->pmc_in_use);
reprogram_fixed_counter(pmc, new_ctrl, i); reprogram_fixed_counter(pmc);
} }
pmu->fixed_ctr_ctrl = data;
} }
static struct kvm_pmc *intel_pmc_idx_to_pmc(struct kvm_pmu *pmu, int pmc_idx) static struct kvm_pmc *intel_pmc_idx_to_pmc(struct kvm_pmu *pmu, int pmc_idx)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment