-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arm64: KVM: Add access handler for event counter register
These kind of registers include PMEVCNTRn, PMCCNTR and PMXEVCNTR which is mapped to PMEVCNTRn. The access handler translates all aarch32 register offsets to aarch64 ones and uses vcpu_sys_reg() to access their values to avoid taking care of big endian. When reading these registers, return the sum of register value and the value perf event counts. Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org> Reviewed-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
- Loading branch information
Shannon Zhao
authored and
Marc Zyngier
committed
Feb 29, 2016
1 parent
a86b550
commit 051ff58
Showing
5 changed files
with
213 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2015 Linaro Ltd. | ||
* Author: Shannon Zhao <shannon.zhao@linaro.org> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <linux/cpu.h> | ||
#include <linux/kvm.h> | ||
#include <linux/kvm_host.h> | ||
#include <linux/perf_event.h> | ||
#include <asm/kvm_emulate.h> | ||
#include <kvm/arm_pmu.h> | ||
|
||
/** | ||
* kvm_pmu_get_counter_value - get PMU counter value | ||
* @vcpu: The vcpu pointer | ||
* @select_idx: The counter index | ||
*/ | ||
u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, u64 select_idx) | ||
{ | ||
u64 counter, reg, enabled, running; | ||
struct kvm_pmu *pmu = &vcpu->arch.pmu; | ||
struct kvm_pmc *pmc = &pmu->pmc[select_idx]; | ||
|
||
reg = (select_idx == ARMV8_PMU_CYCLE_IDX) | ||
? PMCCNTR_EL0 : PMEVCNTR0_EL0 + select_idx; | ||
counter = vcpu_sys_reg(vcpu, reg); | ||
|
||
/* The real counter value is equal to the value of counter register plus | ||
* the value perf event counts. | ||
*/ | ||
if (pmc->perf_event) | ||
counter += perf_event_read_value(pmc->perf_event, &enabled, | ||
&running); | ||
|
||
return counter & pmc->bitmask; | ||
} | ||
|
||
/** | ||
* kvm_pmu_set_counter_value - set PMU counter value | ||
* @vcpu: The vcpu pointer | ||
* @select_idx: The counter index | ||
* @val: The counter value | ||
*/ | ||
void kvm_pmu_set_counter_value(struct kvm_vcpu *vcpu, u64 select_idx, u64 val) | ||
{ | ||
u64 reg; | ||
|
||
reg = (select_idx == ARMV8_PMU_CYCLE_IDX) | ||
? PMCCNTR_EL0 : PMEVCNTR0_EL0 + select_idx; | ||
vcpu_sys_reg(vcpu, reg) += (s64)val - kvm_pmu_get_counter_value(vcpu, select_idx); | ||
} |