Skip to content

Commit 7f6c6e6

Browse files
author
Jinrong Liang
committed
perf kvm: Add PVM support for perf kvm
Integrate PVM support into the perf kvm tool to enable performance analysis for PVM-based workloads. This change allows users to better understand the behavior and performance characteristics of their PVM-based workloads, thus extending the usefulness of the perf tool for a wider range of virtualization scenarios. Signed-off-by: Jinrong Liang <cloudliang@tencent.com>
1 parent baffc30 commit 7f6c6e6

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

tools/perf/arch/x86/util/kvm-stat.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <errno.h>
33
#include <string.h>
4+
#include <stdbool.h>
5+
#include <sys/stat.h>
46
#include "../../../util/kvm-stat.h"
57
#include "../../../util/evsel.h"
68
#include <asm/svm.h>
79
#include <asm/vmx.h>
810
#include <asm/kvm.h>
11+
#include <asm/pvm.h>
912

1013
define_exit_reasons_table(vmx_exit_reasons, VMX_EXIT_REASONS);
1114
define_exit_reasons_table(svm_exit_reasons, SVM_EXIT_REASONS);
15+
define_exit_reasons_table(pvm_exit_reasons, PVM_EXIT_REASONS);
1216

1317
static struct kvm_events_ops exit_events = {
1418
.is_begin_event = exit_event_begin,
@@ -198,9 +202,39 @@ const char * const kvm_skip_events[] = {
198202
NULL,
199203
};
200204

205+
#define INITSTATE_PATH_MAX 256
206+
#define INITSTATE_MAX 16
207+
208+
static bool module_is_live(const char *module_name)
209+
{
210+
char initstate_path[INITSTATE_PATH_MAX];
211+
char initstate[INITSTATE_MAX];
212+
bool ret = false;
213+
struct stat st;
214+
FILE *fp;
215+
216+
snprintf(initstate_path, sizeof(initstate_path),
217+
"/sys/module/%s/initstate", module_name);
218+
219+
if (!stat(initstate_path, &st) && S_ISREG(st.st_mode)) {
220+
fp = fopen(initstate_path, "r");
221+
if (fp) {
222+
if (fgets(initstate, sizeof(initstate), fp))
223+
ret = !strncmp(initstate, "live", 4);
224+
225+
fclose(fp);
226+
}
227+
}
228+
229+
return ret;
230+
}
231+
201232
int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
202233
{
203-
if (strstr(cpuid, "Intel")) {
234+
if (module_is_live("kvm_pvm")) {
235+
kvm->exit_reasons = pvm_exit_reasons;
236+
kvm->exit_reasons_isa = "PVM";
237+
} else if (strstr(cpuid, "Intel")) {
204238
kvm->exit_reasons = vmx_exit_reasons;
205239
kvm->exit_reasons_isa = "VMX";
206240
} else if (strstr(cpuid, "AMD") || strstr(cpuid, "Hygon")) {

0 commit comments

Comments
 (0)