This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BACKPORT: arm64: KVM: Add accessors to track guest/host only counters
In order to effeciently switch events_{guest,host} perf counters at guest entry/exit we add bitfields to kvm_cpu_context for guest and host events as well as accessors for updating them. A function is also provided which allows the PMU driver to determine if a counter should start counting when it is enabled. With exclude_host, we may only start counting when entering the guest. This patch is a part of KVM PMU patchset to fix the overflow issue (pmu-mem-access, pmu-chain-promotion, pmu-overflow-interrupt) in CentOS 8.0 This patch is backported from: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.10-rc6&id=eb41238cf19fda694e3a99c1f4f58bd88479a5ee Signed-off-by: Andrew Murray <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Khuong Dinh <[email protected]>
- Loading branch information
1 parent
cd9edc4
commit 4a447c5
Showing
3 changed files
with
63 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Copyright 2019 Arm Limited | ||
* Author: Andrew Murray <[email protected]> | ||
*/ | ||
#include <linux/kvm_host.h> | ||
#include <linux/perf_event.h> | ||
|
||
/* | ||
* Given the exclude_{host,guest} attributes, determine if we are going | ||
* to need to switch counters at guest entry/exit. | ||
*/ | ||
static bool kvm_pmu_switch_needed(struct perf_event_attr *attr) | ||
{ | ||
/* Only switch if attributes are different */ | ||
return (attr->exclude_host != attr->exclude_guest); | ||
} | ||
|
||
/* | ||
* Add events to track that we may want to switch at guest entry/exit | ||
* time. | ||
*/ | ||
void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr) | ||
{ | ||
struct kvm_host_data *ctx = this_cpu_ptr(&kvm_host_data); | ||
|
||
if (!kvm_pmu_switch_needed(attr)) | ||
return; | ||
|
||
if (!attr->exclude_host) | ||
ctx->pmu_events.events_host |= set; | ||
if (!attr->exclude_guest) | ||
ctx->pmu_events.events_guest |= set; | ||
} | ||
|
||
/* | ||
* Stop tracking events | ||
*/ | ||
void kvm_clr_pmu_events(u32 clr) | ||
{ | ||
struct kvm_host_data *ctx = this_cpu_ptr(&kvm_host_data); | ||
|
||
ctx->pmu_events.events_host &= ~clr; | ||
ctx->pmu_events.events_guest &= ~clr; | ||
} |