Skip to content

Commit 54938ee

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 75143fb commit 54938ee

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
#include <asm/svm.h>
77
#include <asm/vmx.h>
88
#include <asm/kvm.h>
9+
#include <asm/pvm_trace.h>
10+
#include <sys/stat.h>
911

1012
define_exit_reasons_table(vmx_exit_reasons, VMX_EXIT_REASONS);
1113
define_exit_reasons_table(svm_exit_reasons, SVM_EXIT_REASONS);
14+
define_exit_reasons_table(pvm_exit_reasons, PVM_EXIT_REASONS);
1215

1316
static struct kvm_events_ops exit_events = {
1417
.is_begin_event = exit_event_begin,
@@ -198,9 +201,39 @@ const char * const kvm_skip_events[] = {
198201
NULL,
199202
};
200203

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

tools/perf/builtin-kvm.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <sys/stat.h>
3939
#include <fcntl.h>
4040

41+
#include <asm/pvm_trace.h>
4142
#include <linux/err.h>
4243
#include <linux/kernel.h>
4344
#include <linux/string.h>
@@ -620,7 +621,11 @@ void exit_event_get_key(struct evsel *evsel,
620621
struct event_key *key)
621622
{
622623
key->info = 0;
624+
key->info2 = evsel__intval(evsel, sample, "info2");
623625
key->key = evsel__intval(evsel, sample, kvm_exit_reason);
626+
627+
if (key->key == PVM_EXIT_REASONS_HYPERCALL)
628+
key->key = key->info2;
624629
}
625630

626631
bool kvm_exit_event(struct evsel *evsel)

tools/perf/util/kvm-stat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct event_key {
2323
#define INVALID_KEY (~0ULL)
2424
u64 key;
2525
int info;
26+
u64 info2;
2627
struct exit_reasons_table *exit_reasons;
2728
};
2829

0 commit comments

Comments
 (0)