* [PATCH v3 1/2] RISCV: KVM: add tracepoints for entry and exit events
2024-04-22 8:08 [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv Shenlin Liang
@ 2024-04-22 8:08 ` Shenlin Liang
2024-04-22 8:08 ` [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V Shenlin Liang
` (3 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Shenlin Liang @ 2024-04-22 8:08 UTC (permalink / raw)
To: anup, atishp, paul.walmsley, palmer, aou, kvm, kvm-riscv,
linux-riscv, linux-kernel, peterz, mingo, acme, namhyung,
mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
linux-perf-users
Cc: Shenlin Liang
Like other architectures, RISCV KVM also needs to add these event
tracepoints to count the number of times kvm guest entry/exit.
Signed-off-by: Shenlin Liang <liangshenlin@eswincomputing.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
---
arch/riscv/kvm/trace.h | 67 ++++++++++++++++++++++++++++++++++++++++++
arch/riscv/kvm/vcpu.c | 7 +++++
2 files changed, 74 insertions(+)
create mode 100644 arch/riscv/kvm/trace.h
diff --git a/arch/riscv/kvm/trace.h b/arch/riscv/kvm/trace.h
new file mode 100644
index 000000000000..3d54175d805c
--- /dev/null
+++ b/arch/riscv/kvm/trace.h
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Tracepoints for RISC-V KVM
+ *
+ * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd.
+ *
+ */
+#if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_KVM_H
+
+#include <linux/tracepoint.h>
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM kvm
+
+TRACE_EVENT(kvm_entry,
+ TP_PROTO(struct kvm_vcpu *vcpu),
+ TP_ARGS(vcpu),
+
+ TP_STRUCT__entry(
+ __field(unsigned long, pc)
+ ),
+
+ TP_fast_assign(
+ __entry->pc = vcpu->arch.guest_context.sepc;
+ ),
+
+ TP_printk("PC: 0x016%lx", __entry->pc)
+);
+
+TRACE_EVENT(kvm_exit,
+ TP_PROTO(struct kvm_cpu_trap *trap),
+ TP_ARGS(trap),
+
+ TP_STRUCT__entry(
+ __field(unsigned long, sepc)
+ __field(unsigned long, scause)
+ __field(unsigned long, stval)
+ __field(unsigned long, htval)
+ __field(unsigned long, htinst)
+ ),
+
+ TP_fast_assign(
+ __entry->sepc = trap->sepc;
+ __entry->scause = trap->scause;
+ __entry->stval = trap->stval;
+ __entry->htval = trap->htval;
+ __entry->htinst = trap->htinst;
+ ),
+
+ TP_printk("SEPC:0x%lx, SCAUSE:0x%lx, STVAL:0x%lx, HTVAL:0x%lx, HTINST:0x%lx",
+ __entry->sepc,
+ __entry->scause,
+ __entry->stval,
+ __entry->htval,
+ __entry->htinst)
+);
+
+#endif /* _TRACE_RSICV_KVM_H */
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE trace
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
index b5ca9f2e98ac..f4e27004ceb8 100644
--- a/arch/riscv/kvm/vcpu.c
+++ b/arch/riscv/kvm/vcpu.c
@@ -21,6 +21,9 @@
#include <asm/cacheflush.h>
#include <asm/kvm_vcpu_vector.h>
+#define CREATE_TRACE_POINTS
+#include "trace.h"
+
const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
KVM_GENERIC_VCPU_STATS(),
STATS_DESC_COUNTER(VCPU, ecall_exit_stat),
@@ -782,6 +785,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
*/
kvm_riscv_local_tlb_sanitize(vcpu);
+ trace_kvm_entry(vcpu);
+
guest_timing_enter_irqoff();
kvm_riscv_vcpu_enter_exit(vcpu);
@@ -820,6 +825,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
local_irq_enable();
+ trace_kvm_exit(&trap);
+
preempt_enable();
kvm_vcpu_srcu_read_lock(vcpu);
--
2.37.2
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V
2024-04-22 8:08 [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv Shenlin Liang
2024-04-22 8:08 ` [PATCH v3 1/2] RISCV: KVM: add tracepoints for entry and exit events Shenlin Liang
@ 2024-04-22 8:08 ` Shenlin Liang
2024-05-04 0:25 ` Atish Patra
` (2 more replies)
2024-04-29 6:13 ` [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv Shenlin Liang
` (2 subsequent siblings)
4 siblings, 3 replies; 13+ messages in thread
From: Shenlin Liang @ 2024-04-22 8:08 UTC (permalink / raw)
To: anup, atishp, paul.walmsley, palmer, aou, kvm, kvm-riscv,
linux-riscv, linux-kernel, peterz, mingo, acme, namhyung,
mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
linux-perf-users
Cc: Shenlin Liang
'perf kvm stat report/record' generates a statistical analysis of KVM
events and can be used to analyze guest exit reasons.
"report" reports statistical analysis of guest exit events.
To record kvm events on the host:
# perf kvm stat record -a
To report kvm VM EXIT events:
# perf kvm stat report --event=vmexit
Signed-off-by: Shenlin Liang <liangshenlin@eswincomputing.com>
---
tools/perf/arch/riscv/Makefile | 1 +
tools/perf/arch/riscv/util/Build | 1 +
tools/perf/arch/riscv/util/kvm-stat.c | 79 +++++++++++++++++++
.../arch/riscv/util/riscv_exception_types.h | 35 ++++++++
4 files changed, 116 insertions(+)
create mode 100644 tools/perf/arch/riscv/util/kvm-stat.c
create mode 100644 tools/perf/arch/riscv/util/riscv_exception_types.h
diff --git a/tools/perf/arch/riscv/Makefile b/tools/perf/arch/riscv/Makefile
index a8d25d005207..e1e445615536 100644
--- a/tools/perf/arch/riscv/Makefile
+++ b/tools/perf/arch/riscv/Makefile
@@ -3,3 +3,4 @@ PERF_HAVE_DWARF_REGS := 1
endif
PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
PERF_HAVE_JITDUMP := 1
+HAVE_KVM_STAT_SUPPORT := 1
\ No newline at end of file
diff --git a/tools/perf/arch/riscv/util/Build b/tools/perf/arch/riscv/util/Build
index 603dbb5ae4dc..d72b04f8d32b 100644
--- a/tools/perf/arch/riscv/util/Build
+++ b/tools/perf/arch/riscv/util/Build
@@ -1,5 +1,6 @@
perf-y += perf_regs.o
perf-y += header.o
+perf-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
perf-$(CONFIG_DWARF) += dwarf-regs.o
perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
diff --git a/tools/perf/arch/riscv/util/kvm-stat.c b/tools/perf/arch/riscv/util/kvm-stat.c
new file mode 100644
index 000000000000..58813049fc45
--- /dev/null
+++ b/tools/perf/arch/riscv/util/kvm-stat.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Arch specific functions for perf kvm stat.
+ *
+ * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd.
+ *
+ */
+#include <errno.h>
+#include <memory.h>
+#include "../../../util/evsel.h"
+#include "../../../util/kvm-stat.h"
+#include "riscv_exception_types.h"
+#include "debug.h"
+
+define_exit_reasons_table(riscv_exit_reasons, kvm_riscv_exception_class);
+
+const char *vcpu_id_str = "id";
+const char *kvm_exit_reason = "scause";
+const char *kvm_entry_trace = "kvm:kvm_entry";
+const char *kvm_exit_trace = "kvm:kvm_exit";
+
+const char *kvm_events_tp[] = {
+ "kvm:kvm_entry",
+ "kvm:kvm_exit",
+ NULL,
+};
+
+static void event_get_key(struct evsel *evsel,
+ struct perf_sample *sample,
+ struct event_key *key)
+{
+ key->info = 0;
+ key->key = evsel__intval(evsel, sample, kvm_exit_reason);
+ key->key = (int)key->key;
+ key->exit_reasons = riscv_exit_reasons;
+}
+
+static bool event_begin(struct evsel *evsel,
+ struct perf_sample *sample __maybe_unused,
+ struct event_key *key __maybe_unused)
+{
+ return evsel__name_is(evsel, kvm_entry_trace);
+}
+
+static bool event_end(struct evsel *evsel,
+ struct perf_sample *sample,
+ struct event_key *key)
+{
+ if (evsel__name_is(evsel, kvm_exit_trace)) {
+ event_get_key(evsel, sample, key);
+ return true;
+ }
+ return false;
+}
+
+static struct kvm_events_ops exit_events = {
+ .is_begin_event = event_begin,
+ .is_end_event = event_end,
+ .decode_key = exit_event_decode_key,
+ .name = "VM-EXIT"
+};
+
+struct kvm_reg_events_ops kvm_reg_events_ops[] = {
+ {
+ .name = "vmexit",
+ .ops = &exit_events,
+ },
+ { NULL, NULL },
+};
+
+const char * const kvm_skip_events[] = {
+ NULL,
+};
+
+int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused)
+{
+ kvm->exit_reasons_isa = "riscv64";
+ return 0;
+}
diff --git a/tools/perf/arch/riscv/util/riscv_exception_types.h b/tools/perf/arch/riscv/util/riscv_exception_types.h
new file mode 100644
index 000000000000..c49b8fa5e847
--- /dev/null
+++ b/tools/perf/arch/riscv/util/riscv_exception_types.h
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef ARCH_PERF_RISCV_EXCEPTION_TYPES_H
+#define ARCH_PERF_RISCV_EXCEPTION_TYPES_H
+
+#define EXC_INST_MISALIGNED 0
+#define EXC_INST_ACCESS 1
+#define EXC_INST_ILLEGAL 2
+#define EXC_BREAKPOINT 3
+#define EXC_LOAD_MISALIGNED 4
+#define EXC_LOAD_ACCESS 5
+#define EXC_STORE_MISALIGNED 6
+#define EXC_STORE_ACCESS 7
+#define EXC_SYSCALL 8
+#define EXC_HYPERVISOR_SYSCALL 9
+#define EXC_SUPERVISOR_SYSCALL 10
+#define EXC_INST_PAGE_FAULT 12
+#define EXC_LOAD_PAGE_FAULT 13
+#define EXC_STORE_PAGE_FAULT 15
+#define EXC_INST_GUEST_PAGE_FAULT 20
+#define EXC_LOAD_GUEST_PAGE_FAULT 21
+#define EXC_VIRTUAL_INST_FAULT 22
+#define EXC_STORE_GUEST_PAGE_FAULT 23
+
+#define EXC(x) {EXC_##x, #x }
+
+#define kvm_riscv_exception_class \
+ EXC(INST_MISALIGNED), EXC(INST_ACCESS), EXC(INST_ILLEGAL), \
+ EXC(BREAKPOINT), EXC(LOAD_MISALIGNED), EXC(LOAD_ACCESS), \
+ EXC(STORE_MISALIGNED), EXC(STORE_ACCESS), EXC(SYSCALL), \
+ EXC(HYPERVISOR_SYSCALL), EXC(SUPERVISOR_SYSCALL), \
+ EXC(INST_PAGE_FAULT), EXC(LOAD_PAGE_FAULT), EXC(STORE_PAGE_FAULT), \
+ EXC(INST_GUEST_PAGE_FAULT), EXC(LOAD_GUEST_PAGE_FAULT), \
+ EXC(VIRTUAL_INST_FAULT), EXC(STORE_GUEST_PAGE_FAULT)
+
+#endif /* ARCH_PERF_RISCV_EXCEPTION_TYPES_H */
--
2.37.2
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V
2024-04-22 8:08 ` [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V Shenlin Liang
@ 2024-05-04 0:25 ` Atish Patra
2024-06-06 9:40 ` Andreas Schwab
2024-06-07 0:27 ` Namhyung Kim
2 siblings, 0 replies; 13+ messages in thread
From: Atish Patra @ 2024-05-04 0:25 UTC (permalink / raw)
To: Shenlin Liang, anup, atishp, paul.walmsley, palmer, aou, kvm,
kvm-riscv, linux-riscv, linux-kernel, peterz, mingo, acme,
namhyung, mark.rutland, alexander.shishkin, jolsa, irogers,
adrian.hunter, linux-perf-users
On 4/22/24 01:08, Shenlin Liang wrote:
> 'perf kvm stat report/record' generates a statistical analysis of KVM
> events and can be used to analyze guest exit reasons.
>
> "report" reports statistical analysis of guest exit events.
>
> To record kvm events on the host:
> # perf kvm stat record -a
>
> To report kvm VM EXIT events:
> # perf kvm stat report --event=vmexit
>
> Signed-off-by: Shenlin Liang <liangshenlin@eswincomputing.com>
> ---
> tools/perf/arch/riscv/Makefile | 1 +
> tools/perf/arch/riscv/util/Build | 1 +
> tools/perf/arch/riscv/util/kvm-stat.c | 79 +++++++++++++++++++
> .../arch/riscv/util/riscv_exception_types.h | 35 ++++++++
> 4 files changed, 116 insertions(+)
> create mode 100644 tools/perf/arch/riscv/util/kvm-stat.c
> create mode 100644 tools/perf/arch/riscv/util/riscv_exception_types.h
>
> diff --git a/tools/perf/arch/riscv/Makefile b/tools/perf/arch/riscv/Makefile
> index a8d25d005207..e1e445615536 100644
> --- a/tools/perf/arch/riscv/Makefile
> +++ b/tools/perf/arch/riscv/Makefile
> @@ -3,3 +3,4 @@ PERF_HAVE_DWARF_REGS := 1
> endif
> PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
> PERF_HAVE_JITDUMP := 1
> +HAVE_KVM_STAT_SUPPORT := 1
> \ No newline at end of file
> diff --git a/tools/perf/arch/riscv/util/Build b/tools/perf/arch/riscv/util/Build
> index 603dbb5ae4dc..d72b04f8d32b 100644
> --- a/tools/perf/arch/riscv/util/Build
> +++ b/tools/perf/arch/riscv/util/Build
> @@ -1,5 +1,6 @@
> perf-y += perf_regs.o
> perf-y += header.o
>
> +perf-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
> perf-$(CONFIG_DWARF) += dwarf-regs.o
> perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
> diff --git a/tools/perf/arch/riscv/util/kvm-stat.c b/tools/perf/arch/riscv/util/kvm-stat.c
> new file mode 100644
> index 000000000000..58813049fc45
> --- /dev/null
> +++ b/tools/perf/arch/riscv/util/kvm-stat.c
> @@ -0,0 +1,79 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Arch specific functions for perf kvm stat.
> + *
> + * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd.
> + *
> + */
> +#include <errno.h>
> +#include <memory.h>
> +#include "../../../util/evsel.h"
> +#include "../../../util/kvm-stat.h"
> +#include "riscv_exception_types.h"
> +#include "debug.h"
> +
> +define_exit_reasons_table(riscv_exit_reasons, kvm_riscv_exception_class);
> +
> +const char *vcpu_id_str = "id";
> +const char *kvm_exit_reason = "scause";
> +const char *kvm_entry_trace = "kvm:kvm_entry";
> +const char *kvm_exit_trace = "kvm:kvm_exit";
> +
> +const char *kvm_events_tp[] = {
> + "kvm:kvm_entry",
> + "kvm:kvm_exit",
> + NULL,
> +};
> +
> +static void event_get_key(struct evsel *evsel,
> + struct perf_sample *sample,
> + struct event_key *key)
> +{
> + key->info = 0;
> + key->key = evsel__intval(evsel, sample, kvm_exit_reason);
> + key->key = (int)key->key;
> + key->exit_reasons = riscv_exit_reasons;
> +}
> +
> +static bool event_begin(struct evsel *evsel,
> + struct perf_sample *sample __maybe_unused,
> + struct event_key *key __maybe_unused)
> +{
> + return evsel__name_is(evsel, kvm_entry_trace);
> +}
> +
> +static bool event_end(struct evsel *evsel,
> + struct perf_sample *sample,
> + struct event_key *key)
> +{
> + if (evsel__name_is(evsel, kvm_exit_trace)) {
> + event_get_key(evsel, sample, key);
> + return true;
> + }
> + return false;
> +}
> +
> +static struct kvm_events_ops exit_events = {
> + .is_begin_event = event_begin,
> + .is_end_event = event_end,
> + .decode_key = exit_event_decode_key,
> + .name = "VM-EXIT"
> +};
> +
> +struct kvm_reg_events_ops kvm_reg_events_ops[] = {
> + {
> + .name = "vmexit",
> + .ops = &exit_events,
> + },
> + { NULL, NULL },
> +};
> +
> +const char * const kvm_skip_events[] = {
> + NULL,
> +};
> +
> +int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused)
> +{
> + kvm->exit_reasons_isa = "riscv64";
> + return 0;
> +}
> diff --git a/tools/perf/arch/riscv/util/riscv_exception_types.h b/tools/perf/arch/riscv/util/riscv_exception_types.h
> new file mode 100644
> index 000000000000..c49b8fa5e847
> --- /dev/null
> +++ b/tools/perf/arch/riscv/util/riscv_exception_types.h
> @@ -0,0 +1,35 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#ifndef ARCH_PERF_RISCV_EXCEPTION_TYPES_H
> +#define ARCH_PERF_RISCV_EXCEPTION_TYPES_H
> +
> +#define EXC_INST_MISALIGNED 0
> +#define EXC_INST_ACCESS 1
> +#define EXC_INST_ILLEGAL 2
> +#define EXC_BREAKPOINT 3
> +#define EXC_LOAD_MISALIGNED 4
> +#define EXC_LOAD_ACCESS 5
> +#define EXC_STORE_MISALIGNED 6
> +#define EXC_STORE_ACCESS 7
> +#define EXC_SYSCALL 8
> +#define EXC_HYPERVISOR_SYSCALL 9
> +#define EXC_SUPERVISOR_SYSCALL 10
> +#define EXC_INST_PAGE_FAULT 12
> +#define EXC_LOAD_PAGE_FAULT 13
> +#define EXC_STORE_PAGE_FAULT 15
> +#define EXC_INST_GUEST_PAGE_FAULT 20
> +#define EXC_LOAD_GUEST_PAGE_FAULT 21
> +#define EXC_VIRTUAL_INST_FAULT 22
> +#define EXC_STORE_GUEST_PAGE_FAULT 23
> +
> +#define EXC(x) {EXC_##x, #x }
> +
> +#define kvm_riscv_exception_class \
> + EXC(INST_MISALIGNED), EXC(INST_ACCESS), EXC(INST_ILLEGAL), \
> + EXC(BREAKPOINT), EXC(LOAD_MISALIGNED), EXC(LOAD_ACCESS), \
> + EXC(STORE_MISALIGNED), EXC(STORE_ACCESS), EXC(SYSCALL), \
> + EXC(HYPERVISOR_SYSCALL), EXC(SUPERVISOR_SYSCALL), \
> + EXC(INST_PAGE_FAULT), EXC(LOAD_PAGE_FAULT), EXC(STORE_PAGE_FAULT), \
> + EXC(INST_GUEST_PAGE_FAULT), EXC(LOAD_GUEST_PAGE_FAULT), \
> + EXC(VIRTUAL_INST_FAULT), EXC(STORE_GUEST_PAGE_FAULT)
> +
> +#endif /* ARCH_PERF_RISCV_EXCEPTION_TYPES_H */
For some reason my previous RB email doesn't show up in lore. So here it
goes agian. Sorry for the spam it gets delivered twice.
Reviewed-by: Atish Patra <atishp@rivosinc.com>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V
2024-04-22 8:08 ` [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V Shenlin Liang
2024-05-04 0:25 ` Atish Patra
@ 2024-06-06 9:40 ` Andreas Schwab
2024-06-06 9:51 ` Anup Patel
2024-06-07 0:27 ` Namhyung Kim
2 siblings, 1 reply; 13+ messages in thread
From: Andreas Schwab @ 2024-06-06 9:40 UTC (permalink / raw)
To: Shenlin Liang
Cc: anup, atishp, paul.walmsley, palmer, aou, kvm, kvm-riscv,
linux-riscv, linux-kernel, peterz, mingo, acme, namhyung,
mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
linux-perf-users
On Apr 22 2024, Shenlin Liang wrote:
> \ No newline at end of file
Please fix that.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V
2024-06-06 9:40 ` Andreas Schwab
@ 2024-06-06 9:51 ` Anup Patel
0 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2024-06-06 9:51 UTC (permalink / raw)
To: Andreas Schwab
Cc: Shenlin Liang, anup, atishp, paul.walmsley, palmer, aou, kvm,
kvm-riscv, linux-riscv, linux-kernel, peterz, mingo, acme,
namhyung, mark.rutland, alexander.shishkin, jolsa, irogers,
adrian.hunter, linux-perf-users
On Thu, Jun 6, 2024 at 3:10 PM Andreas Schwab <schwab@suse.de> wrote:
>
> On Apr 22 2024, Shenlin Liang wrote:
>
> > \ No newline at end of file
>
> Please fix that.
Fixed in KVM RISC-V queue.
Thanks,
Anup
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V
2024-04-22 8:08 ` [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V Shenlin Liang
2024-05-04 0:25 ` Atish Patra
2024-06-06 9:40 ` Andreas Schwab
@ 2024-06-07 0:27 ` Namhyung Kim
2024-06-07 2:11 ` Shenlin Liang
2 siblings, 1 reply; 13+ messages in thread
From: Namhyung Kim @ 2024-06-07 0:27 UTC (permalink / raw)
To: Shenlin Liang
Cc: anup, atishp, paul.walmsley, palmer, aou, kvm, kvm-riscv,
linux-riscv, linux-kernel, peterz, mingo, acme, mark.rutland,
alexander.shishkin, jolsa, irogers, adrian.hunter,
linux-perf-users
Hello,
On Mon, Apr 22, 2024 at 08:08:33AM +0000, Shenlin Liang wrote:
> 'perf kvm stat report/record' generates a statistical analysis of KVM
> events and can be used to analyze guest exit reasons.
>
> "report" reports statistical analysis of guest exit events.
>
> To record kvm events on the host:
> # perf kvm stat record -a
>
> To report kvm VM EXIT events:
> # perf kvm stat report --event=vmexit
>
> Signed-off-by: Shenlin Liang <liangshenlin@eswincomputing.com>
> ---
> tools/perf/arch/riscv/Makefile | 1 +
> tools/perf/arch/riscv/util/Build | 1 +
> tools/perf/arch/riscv/util/kvm-stat.c | 79 +++++++++++++++++++
> .../arch/riscv/util/riscv_exception_types.h | 35 ++++++++
> 4 files changed, 116 insertions(+)
> create mode 100644 tools/perf/arch/riscv/util/kvm-stat.c
> create mode 100644 tools/perf/arch/riscv/util/riscv_exception_types.h
>
> diff --git a/tools/perf/arch/riscv/Makefile b/tools/perf/arch/riscv/Makefile
> index a8d25d005207..e1e445615536 100644
> --- a/tools/perf/arch/riscv/Makefile
> +++ b/tools/perf/arch/riscv/Makefile
> @@ -3,3 +3,4 @@ PERF_HAVE_DWARF_REGS := 1
> endif
> PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
> PERF_HAVE_JITDUMP := 1
> +HAVE_KVM_STAT_SUPPORT := 1
> \ No newline at end of file
> diff --git a/tools/perf/arch/riscv/util/Build b/tools/perf/arch/riscv/util/Build
> index 603dbb5ae4dc..d72b04f8d32b 100644
> --- a/tools/perf/arch/riscv/util/Build
> +++ b/tools/perf/arch/riscv/util/Build
> @@ -1,5 +1,6 @@
> perf-y += perf_regs.o
> perf-y += header.o
>
> +perf-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
> perf-$(CONFIG_DWARF) += dwarf-regs.o
> perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
> diff --git a/tools/perf/arch/riscv/util/kvm-stat.c b/tools/perf/arch/riscv/util/kvm-stat.c
> new file mode 100644
> index 000000000000..58813049fc45
> --- /dev/null
> +++ b/tools/perf/arch/riscv/util/kvm-stat.c
> @@ -0,0 +1,79 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Arch specific functions for perf kvm stat.
> + *
> + * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd.
> + *
> + */
> +#include <errno.h>
> +#include <memory.h>
> +#include "../../../util/evsel.h"
> +#include "../../../util/kvm-stat.h"
> +#include "riscv_exception_types.h"
> +#include "debug.h"
> +
> +define_exit_reasons_table(riscv_exit_reasons, kvm_riscv_exception_class);
> +
> +const char *vcpu_id_str = "id";
> +const char *kvm_exit_reason = "scause";
> +const char *kvm_entry_trace = "kvm:kvm_entry";
> +const char *kvm_exit_trace = "kvm:kvm_exit";
> +
> +const char *kvm_events_tp[] = {
> + "kvm:kvm_entry",
> + "kvm:kvm_exit",
> + NULL,
> +};
> +
> +static void event_get_key(struct evsel *evsel,
> + struct perf_sample *sample,
> + struct event_key *key)
> +{
> + key->info = 0;
> + key->key = evsel__intval(evsel, sample, kvm_exit_reason);
> + key->key = (int)key->key;
Looks unnecessary..
Thanks,
Namhyung
> + key->exit_reasons = riscv_exit_reasons;
> +}
> +
> +static bool event_begin(struct evsel *evsel,
> + struct perf_sample *sample __maybe_unused,
> + struct event_key *key __maybe_unused)
> +{
> + return evsel__name_is(evsel, kvm_entry_trace);
> +}
> +
> +static bool event_end(struct evsel *evsel,
> + struct perf_sample *sample,
> + struct event_key *key)
> +{
> + if (evsel__name_is(evsel, kvm_exit_trace)) {
> + event_get_key(evsel, sample, key);
> + return true;
> + }
> + return false;
> +}
> +
> +static struct kvm_events_ops exit_events = {
> + .is_begin_event = event_begin,
> + .is_end_event = event_end,
> + .decode_key = exit_event_decode_key,
> + .name = "VM-EXIT"
> +};
> +
> +struct kvm_reg_events_ops kvm_reg_events_ops[] = {
> + {
> + .name = "vmexit",
> + .ops = &exit_events,
> + },
> + { NULL, NULL },
> +};
> +
> +const char * const kvm_skip_events[] = {
> + NULL,
> +};
> +
> +int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused)
> +{
> + kvm->exit_reasons_isa = "riscv64";
> + return 0;
> +}
> diff --git a/tools/perf/arch/riscv/util/riscv_exception_types.h b/tools/perf/arch/riscv/util/riscv_exception_types.h
> new file mode 100644
> index 000000000000..c49b8fa5e847
> --- /dev/null
> +++ b/tools/perf/arch/riscv/util/riscv_exception_types.h
> @@ -0,0 +1,35 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#ifndef ARCH_PERF_RISCV_EXCEPTION_TYPES_H
> +#define ARCH_PERF_RISCV_EXCEPTION_TYPES_H
> +
> +#define EXC_INST_MISALIGNED 0
> +#define EXC_INST_ACCESS 1
> +#define EXC_INST_ILLEGAL 2
> +#define EXC_BREAKPOINT 3
> +#define EXC_LOAD_MISALIGNED 4
> +#define EXC_LOAD_ACCESS 5
> +#define EXC_STORE_MISALIGNED 6
> +#define EXC_STORE_ACCESS 7
> +#define EXC_SYSCALL 8
> +#define EXC_HYPERVISOR_SYSCALL 9
> +#define EXC_SUPERVISOR_SYSCALL 10
> +#define EXC_INST_PAGE_FAULT 12
> +#define EXC_LOAD_PAGE_FAULT 13
> +#define EXC_STORE_PAGE_FAULT 15
> +#define EXC_INST_GUEST_PAGE_FAULT 20
> +#define EXC_LOAD_GUEST_PAGE_FAULT 21
> +#define EXC_VIRTUAL_INST_FAULT 22
> +#define EXC_STORE_GUEST_PAGE_FAULT 23
> +
> +#define EXC(x) {EXC_##x, #x }
> +
> +#define kvm_riscv_exception_class \
> + EXC(INST_MISALIGNED), EXC(INST_ACCESS), EXC(INST_ILLEGAL), \
> + EXC(BREAKPOINT), EXC(LOAD_MISALIGNED), EXC(LOAD_ACCESS), \
> + EXC(STORE_MISALIGNED), EXC(STORE_ACCESS), EXC(SYSCALL), \
> + EXC(HYPERVISOR_SYSCALL), EXC(SUPERVISOR_SYSCALL), \
> + EXC(INST_PAGE_FAULT), EXC(LOAD_PAGE_FAULT), EXC(STORE_PAGE_FAULT), \
> + EXC(INST_GUEST_PAGE_FAULT), EXC(LOAD_GUEST_PAGE_FAULT), \
> + EXC(VIRTUAL_INST_FAULT), EXC(STORE_GUEST_PAGE_FAULT)
> +
> +#endif /* ARCH_PERF_RISCV_EXCEPTION_TYPES_H */
> --
> 2.37.2
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V
2024-06-07 0:27 ` Namhyung Kim
@ 2024-06-07 2:11 ` Shenlin Liang
2024-06-07 6:50 ` Anup Patel
0 siblings, 1 reply; 13+ messages in thread
From: Shenlin Liang @ 2024-06-07 2:11 UTC (permalink / raw)
To: Namhyung Kim
Cc: anup, atishp, paul.walmsley, palmer, aou, kvm, kvm-riscv,
linux-riscv, linux-kernel, peterz, mingo, acme, mark.rutland,
alexander.shishkin, jolsa, irogers, adrian.hunter,
linux-perf-users
On 2024-06-07 08:27, Namhyung Kim <namhyung@kernel.org> wrote:
>
> Hello,
>
> On Mon, Apr 22, 2024 at 08:08:33AM +0000, Shenlin Liang wrote:
> > 'perf kvm stat report/record' generates a statistical analysis of KVM
> > events and can be used to analyze guest exit reasons.
> >
> > "report" reports statistical analysis of guest exit events.
> >
> > To record kvm events on the host:
> > # perf kvm stat record -a
> >
> > To report kvm VM EXIT events:
> > # perf kvm stat report --event=vmexit
> >
> > Signed-off-by: Shenlin Liang <liangshenlin@eswincomputing.com>
> > ---
> > tools/perf/arch/riscv/Makefile | 1 +
> > tools/perf/arch/riscv/util/Build | 1 +
> > tools/perf/arch/riscv/util/kvm-stat.c | 79 +++++++++++++++++++
> > .../arch/riscv/util/riscv_exception_types.h | 35 ++++++++
> > 4 files changed, 116 insertions(+)
> > create mode 100644 tools/perf/arch/riscv/util/kvm-stat.c
> > create mode 100644 tools/perf/arch/riscv/util/riscv_exception_types.h
> >
> > diff --git a/tools/perf/arch/riscv/Makefile b/tools/perf/arch/riscv/Makefile
> > index a8d25d005207..e1e445615536 100644
> > --- a/tools/perf/arch/riscv/Makefile
> > +++ b/tools/perf/arch/riscv/Makefile
> > @@ -3,3 +3,4 @@ PERF_HAVE_DWARF_REGS := 1
> > endif
> > PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
> > PERF_HAVE_JITDUMP := 1
> > +HAVE_KVM_STAT_SUPPORT := 1
> > \ No newline at end of file
> > diff --git a/tools/perf/arch/riscv/util/Build b/tools/perf/arch/riscv/util/Build
> > index 603dbb5ae4dc..d72b04f8d32b 100644
> > --- a/tools/perf/arch/riscv/util/Build
> > +++ b/tools/perf/arch/riscv/util/Build
> > @@ -1,5 +1,6 @@
> > perf-y += perf_regs.o
> > perf-y += header.o
> >
> > +perf-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
> > perf-$(CONFIG_DWARF) += dwarf-regs.o
> > perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
> > diff --git a/tools/perf/arch/riscv/util/kvm-stat.c b/tools/perf/arch/riscv/util/kvm-stat.c
> > new file mode 100644
> > index 000000000000..58813049fc45
> > --- /dev/null
> > +++ b/tools/perf/arch/riscv/util/kvm-stat.c
> > @@ -0,0 +1,79 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Arch specific functions for perf kvm stat.
> > + *
> > + * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd.
> > + *
> > + */
> > +#include <errno.h>
> > +#include <memory.h>
> > +#include "../../../util/evsel.h"
> > +#include "../../../util/kvm-stat.h"
> > +#include "riscv_exception_types.h"
> > +#include "debug.h"
> > +
> > +define_exit_reasons_table(riscv_exit_reasons, kvm_riscv_exception_class);
> > +
> > +const char *vcpu_id_str = "id";
> > +const char *kvm_exit_reason = "scause";
> > +const char *kvm_entry_trace = "kvm:kvm_entry";
> > +const char *kvm_exit_trace = "kvm:kvm_exit";
> > +
> > +const char *kvm_events_tp[] = {
> > + "kvm:kvm_entry",
> > + "kvm:kvm_exit",
> > + NULL,
> > +};
> > +
> > +static void event_get_key(struct evsel *evsel,
> > + struct perf_sample *sample,
> > + struct event_key *key)
> > +{
> > + key->info = 0;
> > + key->key = evsel__intval(evsel, sample, kvm_exit_reason);
> > + key->key = (int)key->key;
>
> Looks unnecessary..
>
> Thanks,
> Namhyung
Yes,it's unnecessary...
@Anup, Could you delete this line when merging, or should I send another revision ?
Thanks,
Shenlin
>
>
> > + key->exit_reasons = riscv_exit_reasons;
> > +}
> > +
> > +static bool event_begin(struct evsel *evsel,
> > + struct perf_sample *sample __maybe_unused,
> > + struct event_key *key __maybe_unused)
> > +{
> > + return evsel__name_is(evsel, kvm_entry_trace);
> > +}
> > +
> > +static bool event_end(struct evsel *evsel,
> > + struct perf_sample *sample,
> > + struct event_key *key)
> > +{
> > + if (evsel__name_is(evsel, kvm_exit_trace)) {
> > + event_get_key(evsel, sample, key);
> > + return true;
> > + }
> > + return false;
> > +}
> > +
> > +static struct kvm_events_ops exit_events = {
> > + .is_begin_event = event_begin,
> > + .is_end_event = event_end,
> > + .decode_key = exit_event_decode_key,
> > + .name = "VM-EXIT"
> > +};
> > +
> > +struct kvm_reg_events_ops kvm_reg_events_ops[] = {
> > + {
> > + .name = "vmexit",
> > + .ops = &exit_events,
> > + },
> > + { NULL, NULL },
> > +};
> > +
> > +const char * const kvm_skip_events[] = {
> > + NULL,
> > +};
> > +
> > +int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused)
> > +{
> > + kvm->exit_reasons_isa = "riscv64";
> > + return 0;
> > +}
> > diff --git a/tools/perf/arch/riscv/util/riscv_exception_types.h b/tools/perf/arch/riscv/util/riscv_exception_types.h
> > new file mode 100644
> > index 000000000000..c49b8fa5e847
> > --- /dev/null
> > +++ b/tools/perf/arch/riscv/util/riscv_exception_types.h
> > @@ -0,0 +1,35 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +#ifndef ARCH_PERF_RISCV_EXCEPTION_TYPES_H
> > +#define ARCH_PERF_RISCV_EXCEPTION_TYPES_H
> > +
> > +#define EXC_INST_MISALIGNED 0
> > +#define EXC_INST_ACCESS 1
> > +#define EXC_INST_ILLEGAL 2
> > +#define EXC_BREAKPOINT 3
> > +#define EXC_LOAD_MISALIGNED 4
> > +#define EXC_LOAD_ACCESS 5
> > +#define EXC_STORE_MISALIGNED 6
> > +#define EXC_STORE_ACCESS 7
> > +#define EXC_SYSCALL 8
> > +#define EXC_HYPERVISOR_SYSCALL 9
> > +#define EXC_SUPERVISOR_SYSCALL 10
> > +#define EXC_INST_PAGE_FAULT 12
> > +#define EXC_LOAD_PAGE_FAULT 13
> > +#define EXC_STORE_PAGE_FAULT 15
> > +#define EXC_INST_GUEST_PAGE_FAULT 20
> > +#define EXC_LOAD_GUEST_PAGE_FAULT 21
> > +#define EXC_VIRTUAL_INST_FAULT 22
> > +#define EXC_STORE_GUEST_PAGE_FAULT 23
> > +
> > +#define EXC(x) {EXC_##x, #x }
> > +
> > +#define kvm_riscv_exception_class \
> > + EXC(INST_MISALIGNED), EXC(INST_ACCESS), EXC(INST_ILLEGAL), \
> > + EXC(BREAKPOINT), EXC(LOAD_MISALIGNED), EXC(LOAD_ACCESS), \
> > + EXC(STORE_MISALIGNED), EXC(STORE_ACCESS), EXC(SYSCALL), \
> > + EXC(HYPERVISOR_SYSCALL), EXC(SUPERVISOR_SYSCALL), \
> > + EXC(INST_PAGE_FAULT), EXC(LOAD_PAGE_FAULT), EXC(STORE_PAGE_FAULT), \
> > + EXC(INST_GUEST_PAGE_FAULT), EXC(LOAD_GUEST_PAGE_FAULT), \
> > + EXC(VIRTUAL_INST_FAULT), EXC(STORE_GUEST_PAGE_FAULT)
> > +
> > +#endif /* ARCH_PERF_RISCV_EXCEPTION_TYPES_H */
> > --
> > 2.37.2
> >
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V
2024-06-07 2:11 ` Shenlin Liang
@ 2024-06-07 6:50 ` Anup Patel
0 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2024-06-07 6:50 UTC (permalink / raw)
To: Shenlin Liang
Cc: Namhyung Kim, atishp, paul.walmsley, palmer, aou, kvm, kvm-riscv,
linux-riscv, linux-kernel, peterz, mingo, acme, mark.rutland,
alexander.shishkin, jolsa, irogers, adrian.hunter,
linux-perf-users
On Fri, Jun 7, 2024 at 7:44 AM Shenlin Liang
<liangshenlin@eswincomputing.com> wrote:
>
>
> On 2024-06-07 08:27, Namhyung Kim <namhyung@kernel.org> wrote:
>
> >
> > Hello,
> >
> > On Mon, Apr 22, 2024 at 08:08:33AM +0000, Shenlin Liang wrote:
> > > 'perf kvm stat report/record' generates a statistical analysis of KVM
> > > events and can be used to analyze guest exit reasons.
> > >
> > > "report" reports statistical analysis of guest exit events.
> > >
> > > To record kvm events on the host:
> > > # perf kvm stat record -a
> > >
> > > To report kvm VM EXIT events:
> > > # perf kvm stat report --event=vmexit
> > >
> > > Signed-off-by: Shenlin Liang <liangshenlin@eswincomputing.com>
> > > ---
> > > tools/perf/arch/riscv/Makefile | 1 +
> > > tools/perf/arch/riscv/util/Build | 1 +
> > > tools/perf/arch/riscv/util/kvm-stat.c | 79 +++++++++++++++++++
> > > .../arch/riscv/util/riscv_exception_types.h | 35 ++++++++
> > > 4 files changed, 116 insertions(+)
> > > create mode 100644 tools/perf/arch/riscv/util/kvm-stat.c
> > > create mode 100644 tools/perf/arch/riscv/util/riscv_exception_types.h
> > >
> > > diff --git a/tools/perf/arch/riscv/Makefile b/tools/perf/arch/riscv/Makefile
> > > index a8d25d005207..e1e445615536 100644
> > > --- a/tools/perf/arch/riscv/Makefile
> > > +++ b/tools/perf/arch/riscv/Makefile
> > > @@ -3,3 +3,4 @@ PERF_HAVE_DWARF_REGS := 1
> > > endif
> > > PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
> > > PERF_HAVE_JITDUMP := 1
> > > +HAVE_KVM_STAT_SUPPORT := 1
> > > \ No newline at end of file
> > > diff --git a/tools/perf/arch/riscv/util/Build b/tools/perf/arch/riscv/util/Build
> > > index 603dbb5ae4dc..d72b04f8d32b 100644
> > > --- a/tools/perf/arch/riscv/util/Build
> > > +++ b/tools/perf/arch/riscv/util/Build
> > > @@ -1,5 +1,6 @@
> > > perf-y += perf_regs.o
> > > perf-y += header.o
> > >
> > > +perf-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
> > > perf-$(CONFIG_DWARF) += dwarf-regs.o
> > > perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
> > > diff --git a/tools/perf/arch/riscv/util/kvm-stat.c b/tools/perf/arch/riscv/util/kvm-stat.c
> > > new file mode 100644
> > > index 000000000000..58813049fc45
> > > --- /dev/null
> > > +++ b/tools/perf/arch/riscv/util/kvm-stat.c
> > > @@ -0,0 +1,79 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +/*
> > > + * Arch specific functions for perf kvm stat.
> > > + *
> > > + * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd.
> > > + *
> > > + */
> > > +#include <errno.h>
> > > +#include <memory.h>
> > > +#include "../../../util/evsel.h"
> > > +#include "../../../util/kvm-stat.h"
> > > +#include "riscv_exception_types.h"
> > > +#include "debug.h"
> > > +
> > > +define_exit_reasons_table(riscv_exit_reasons, kvm_riscv_exception_class);
> > > +
> > > +const char *vcpu_id_str = "id";
> > > +const char *kvm_exit_reason = "scause";
> > > +const char *kvm_entry_trace = "kvm:kvm_entry";
> > > +const char *kvm_exit_trace = "kvm:kvm_exit";
> > > +
> > > +const char *kvm_events_tp[] = {
> > > + "kvm:kvm_entry",
> > > + "kvm:kvm_exit",
> > > + NULL,
> > > +};
> > > +
> > > +static void event_get_key(struct evsel *evsel,
> > > + struct perf_sample *sample,
> > > + struct event_key *key)
> > > +{
> > > + key->info = 0;
> > > + key->key = evsel__intval(evsel, sample, kvm_exit_reason);
> > > + key->key = (int)key->key;
> >
> > Looks unnecessary..
> >
> > Thanks,
> > Namhyung
>
> Yes,it's unnecessary...
> @Anup, Could you delete this line when merging, or should I send another revision ?
No need for another revision, I have updated the riscv_kvm_queue.
Regards,
Anup
> Thanks,
> Shenlin
>
> >
> >
> > > + key->exit_reasons = riscv_exit_reasons;
> > > +}
> > > +
> > > +static bool event_begin(struct evsel *evsel,
> > > + struct perf_sample *sample __maybe_unused,
> > > + struct event_key *key __maybe_unused)
> > > +{
> > > + return evsel__name_is(evsel, kvm_entry_trace);
> > > +}
> > > +
> > > +static bool event_end(struct evsel *evsel,
> > > + struct perf_sample *sample,
> > > + struct event_key *key)
> > > +{
> > > + if (evsel__name_is(evsel, kvm_exit_trace)) {
> > > + event_get_key(evsel, sample, key);
> > > + return true;
> > > + }
> > > + return false;
> > > +}
> > > +
> > > +static struct kvm_events_ops exit_events = {
> > > + .is_begin_event = event_begin,
> > > + .is_end_event = event_end,
> > > + .decode_key = exit_event_decode_key,
> > > + .name = "VM-EXIT"
> > > +};
> > > +
> > > +struct kvm_reg_events_ops kvm_reg_events_ops[] = {
> > > + {
> > > + .name = "vmexit",
> > > + .ops = &exit_events,
> > > + },
> > > + { NULL, NULL },
> > > +};
> > > +
> > > +const char * const kvm_skip_events[] = {
> > > + NULL,
> > > +};
> > > +
> > > +int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused)
> > > +{
> > > + kvm->exit_reasons_isa = "riscv64";
> > > + return 0;
> > > +}
> > > diff --git a/tools/perf/arch/riscv/util/riscv_exception_types.h b/tools/perf/arch/riscv/util/riscv_exception_types.h
> > > new file mode 100644
> > > index 000000000000..c49b8fa5e847
> > > --- /dev/null
> > > +++ b/tools/perf/arch/riscv/util/riscv_exception_types.h
> > > @@ -0,0 +1,35 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +#ifndef ARCH_PERF_RISCV_EXCEPTION_TYPES_H
> > > +#define ARCH_PERF_RISCV_EXCEPTION_TYPES_H
> > > +
> > > +#define EXC_INST_MISALIGNED 0
> > > +#define EXC_INST_ACCESS 1
> > > +#define EXC_INST_ILLEGAL 2
> > > +#define EXC_BREAKPOINT 3
> > > +#define EXC_LOAD_MISALIGNED 4
> > > +#define EXC_LOAD_ACCESS 5
> > > +#define EXC_STORE_MISALIGNED 6
> > > +#define EXC_STORE_ACCESS 7
> > > +#define EXC_SYSCALL 8
> > > +#define EXC_HYPERVISOR_SYSCALL 9
> > > +#define EXC_SUPERVISOR_SYSCALL 10
> > > +#define EXC_INST_PAGE_FAULT 12
> > > +#define EXC_LOAD_PAGE_FAULT 13
> > > +#define EXC_STORE_PAGE_FAULT 15
> > > +#define EXC_INST_GUEST_PAGE_FAULT 20
> > > +#define EXC_LOAD_GUEST_PAGE_FAULT 21
> > > +#define EXC_VIRTUAL_INST_FAULT 22
> > > +#define EXC_STORE_GUEST_PAGE_FAULT 23
> > > +
> > > +#define EXC(x) {EXC_##x, #x }
> > > +
> > > +#define kvm_riscv_exception_class \
> > > + EXC(INST_MISALIGNED), EXC(INST_ACCESS), EXC(INST_ILLEGAL), \
> > > + EXC(BREAKPOINT), EXC(LOAD_MISALIGNED), EXC(LOAD_ACCESS), \
> > > + EXC(STORE_MISALIGNED), EXC(STORE_ACCESS), EXC(SYSCALL), \
> > > + EXC(HYPERVISOR_SYSCALL), EXC(SUPERVISOR_SYSCALL), \
> > > + EXC(INST_PAGE_FAULT), EXC(LOAD_PAGE_FAULT), EXC(STORE_PAGE_FAULT), \
> > > + EXC(INST_GUEST_PAGE_FAULT), EXC(LOAD_GUEST_PAGE_FAULT), \
> > > + EXC(VIRTUAL_INST_FAULT), EXC(STORE_GUEST_PAGE_FAULT)
> > > +
> > > +#endif /* ARCH_PERF_RISCV_EXCEPTION_TYPES_H */
> > > --
> > > 2.37.2
> > >
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv
2024-04-22 8:08 [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv Shenlin Liang
2024-04-22 8:08 ` [PATCH v3 1/2] RISCV: KVM: add tracepoints for entry and exit events Shenlin Liang
2024-04-22 8:08 ` [PATCH v3 2/2] perf kvm/riscv: Port perf kvm stat to RISC-V Shenlin Liang
@ 2024-04-29 6:13 ` Shenlin Liang
2024-04-29 18:50 ` Arnaldo Carvalho de Melo
2024-05-04 0:21 ` Atish Patra
2024-06-06 9:20 ` Anup Patel
4 siblings, 1 reply; 13+ messages in thread
From: Shenlin Liang @ 2024-04-29 6:13 UTC (permalink / raw)
To: anup, atishp, paul.walmsley, palmer, aou, kvm, kvm-riscv,
linux-riscv, linux-kernel, peterz, mingo, acme, namhyung,
mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
linux-perf-users
Gentle ping...
>
> 'perf kvm stat report/record' generates a statistical analysis of KVM
> events and can be used to analyze guest exit reasons. This patch tries
> to add stat support on riscv.
>
> Map the return value of trace_kvm_exit() to the specific cause of the
> exception, and export it to userspace.
>
> It records on two available KVM tracepoints for riscv: "kvm:kvm_entry"
> and "kvm:kvm_exit", and reports statistical data which includes events
> handles time, samples, and so on.
>
> Cross compiling perf in X86 environment may encounter issues with missing
> libraries and tools. Suggest compiling nativly in RISC-V environment
>
> Simple tests go below:
>
> # ./perf kvm record -e "kvm:kvm_entry" -e "kvm:kvm_exit"
> Lowering default frequency rate from 4000 to 2500.
> Please consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
> [ perf record: Woken up 18 times to write data ]
> [ perf record: Captured and wrote 5.433 MB perf.data.guest (62519 samples)
>
> # ./perf kvm report
> 31K kvm:kvm_entry
> 31K kvm:kvm_exit
>
> # ./perf kvm stat record -a
> [ perf record: Woken up 3 times to write data ]
> [ perf record: Captured and wrote 8.502 MB perf.data.guest (99338 samples) ]
>
> # ./perf kvm stat report --event=vmexit
> Event name Samples Sample% Time (ns) Time% Max Time (ns) Min Time (ns) Mean Time (ns)
> STORE_GUEST_PAGE_FAULT 26968 54.00% 2003031800 40.00% 3361400 27600 74274
> LOAD_GUEST_PAGE_FAULT 17645 35.00% 1153338100 23.00% 2513400 30800 65363
> VIRTUAL_INST_FAULT 1247 2.00% 340820800 6.00% 1190800 43300 273312
> INST_GUEST_PAGE_FAULT 1128 2.00% 340645800 6.00% 2123200 30200 301990
> SUPERVISOR_SYSCALL 1019 2.00% 245989900 4.00% 1851500 29300 241403
> LOAD_ACCESS 986 1.00% 671556200 13.00% 4180200 100700 681091
> INST_ACCESS 655 1.00% 170054800 3.00% 1808300 54600 259625
> HYPERVISOR_SYSCALL 21 0.00% 4276400 0.00% 716500 116000 203638
>
> Changes from v1->v2:
> - Rebased on Linux 6.9-rc3.
>
> Changes from v2->v3:
> - Add the missing assignment for 'vcpu_id_str' in patch 2.
> - Remove parentheses that cause compilation errors
>
> Shenlin Liang (2):
> RISCV: KVM: add tracepoints for entry and exit events
> perf kvm/riscv: Port perf kvm stat to RISC-V
>
> arch/riscv/kvm/trace.h | 67 ++++++++++++++++
> arch/riscv/kvm/vcpu.c | 7 ++
> tools/perf/arch/riscv/Makefile | 1 +
> tools/perf/arch/riscv/util/Build | 1 +
> tools/perf/arch/riscv/util/kvm-stat.c | 79 +++++++++++++++++++
> .../arch/riscv/util/riscv_exception_types.h | 35 ++++++++
> 6 files changed, 190 insertions(+)
> create mode 100644 arch/riscv/kvm/trace.h
> create mode 100644 tools/perf/arch/riscv/util/kvm-stat.c
> create mode 100644 tools/perf/arch/riscv/util/riscv_exception_types.h
>
> --
> 2.37.2
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv
2024-04-29 6:13 ` [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv Shenlin Liang
@ 2024-04-29 18:50 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-04-29 18:50 UTC (permalink / raw)
To: Shenlin Liang
Cc: anup, atishp, paul.walmsley, palmer, aou, kvm, kvm-riscv,
linux-riscv, linux-kernel, peterz, mingo, namhyung, mark.rutland,
alexander.shishkin, jolsa, irogers, adrian.hunter,
linux-perf-users
On Mon, Apr 29, 2024 at 02:13:22PM +0800, Shenlin Liang wrote:
> Gentle ping...
It would be great to have people with such boards testing your patchkit
and providing Tested-by tags.
Also the patch set has both kernel and tooling support, thus needs to
find a RiscV kernel maintainer to pick the kernel bits and then, when
that was merged, I would look at reports of tests for the tooling side
to then merge it.
Hope this clarifies the process,
- Arnaldo
> > 'perf kvm stat report/record' generates a statistical analysis of KVM
> > events and can be used to analyze guest exit reasons. This patch tries
> > to add stat support on riscv.
> >
> > Map the return value of trace_kvm_exit() to the specific cause of the
> > exception, and export it to userspace.
> >
> > It records on two available KVM tracepoints for riscv: "kvm:kvm_entry"
> > and "kvm:kvm_exit", and reports statistical data which includes events
> > handles time, samples, and so on.
> >
> > Cross compiling perf in X86 environment may encounter issues with missing
> > libraries and tools. Suggest compiling nativly in RISC-V environment
> >
> > Simple tests go below:
> >
> > # ./perf kvm record -e "kvm:kvm_entry" -e "kvm:kvm_exit"
> > Lowering default frequency rate from 4000 to 2500.
> > Please consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
> > [ perf record: Woken up 18 times to write data ]
> > [ perf record: Captured and wrote 5.433 MB perf.data.guest (62519 samples)
> >
> > # ./perf kvm report
> > 31K kvm:kvm_entry
> > 31K kvm:kvm_exit
> >
> > # ./perf kvm stat record -a
> > [ perf record: Woken up 3 times to write data ]
> > [ perf record: Captured and wrote 8.502 MB perf.data.guest (99338 samples) ]
> >
> > # ./perf kvm stat report --event=vmexit
> > Event name Samples Sample% Time (ns) Time% Max Time (ns) Min Time (ns) Mean Time (ns)
> > STORE_GUEST_PAGE_FAULT 26968 54.00% 2003031800 40.00% 3361400 27600 74274
> > LOAD_GUEST_PAGE_FAULT 17645 35.00% 1153338100 23.00% 2513400 30800 65363
> > VIRTUAL_INST_FAULT 1247 2.00% 340820800 6.00% 1190800 43300 273312
> > INST_GUEST_PAGE_FAULT 1128 2.00% 340645800 6.00% 2123200 30200 301990
> > SUPERVISOR_SYSCALL 1019 2.00% 245989900 4.00% 1851500 29300 241403
> > LOAD_ACCESS 986 1.00% 671556200 13.00% 4180200 100700 681091
> > INST_ACCESS 655 1.00% 170054800 3.00% 1808300 54600 259625
> > HYPERVISOR_SYSCALL 21 0.00% 4276400 0.00% 716500 116000 203638
> >
> > Changes from v1->v2:
> > - Rebased on Linux 6.9-rc3.
> >
> > Changes from v2->v3:
> > - Add the missing assignment for 'vcpu_id_str' in patch 2.
> > - Remove parentheses that cause compilation errors
> >
> > Shenlin Liang (2):
> > RISCV: KVM: add tracepoints for entry and exit events
> > perf kvm/riscv: Port perf kvm stat to RISC-V
> >
> > arch/riscv/kvm/trace.h | 67 ++++++++++++++++
> > arch/riscv/kvm/vcpu.c | 7 ++
> > tools/perf/arch/riscv/Makefile | 1 +
> > tools/perf/arch/riscv/util/Build | 1 +
> > tools/perf/arch/riscv/util/kvm-stat.c | 79 +++++++++++++++++++
> > .../arch/riscv/util/riscv_exception_types.h | 35 ++++++++
> > 6 files changed, 190 insertions(+)
> > create mode 100644 arch/riscv/kvm/trace.h
> > create mode 100644 tools/perf/arch/riscv/util/kvm-stat.c
> > create mode 100644 tools/perf/arch/riscv/util/riscv_exception_types.h
> >
> > --
> > 2.37.2
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv
2024-04-22 8:08 [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv Shenlin Liang
` (2 preceding siblings ...)
2024-04-29 6:13 ` [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv Shenlin Liang
@ 2024-05-04 0:21 ` Atish Patra
2024-06-06 9:20 ` Anup Patel
4 siblings, 0 replies; 13+ messages in thread
From: Atish Patra @ 2024-05-04 0:21 UTC (permalink / raw)
To: Shenlin Liang, anup, atishp, paul.walmsley, palmer, aou, kvm,
kvm-riscv, linux-riscv, linux-kernel, peterz, mingo, acme,
namhyung, mark.rutland, alexander.shishkin, jolsa, irogers,
adrian.hunter, linux-perf-users
On 4/22/24 01:08, Shenlin Liang wrote:
> 'perf kvm stat report/record' generates a statistical analysis of KVM
> events and can be used to analyze guest exit reasons. This patch tries
> to add stat support on riscv.
>
> Map the return value of trace_kvm_exit() to the specific cause of the
> exception, and export it to userspace.
>
> It records on two available KVM tracepoints for riscv: "kvm:kvm_entry"
> and "kvm:kvm_exit", and reports statistical data which includes events
> handles time, samples, and so on.
>
> Cross compiling perf in X86 environment may encounter issues with missing
> libraries and tools. Suggest compiling nativly in RISC-V environment
>
Indeed. I am able to test the series with native build.
For the entire series:
Tested-by: Atish Patra <atishp@rivosinc.com>
> Simple tests go below:
>
> # ./perf kvm record -e "kvm:kvm_entry" -e "kvm:kvm_exit"
> Lowering default frequency rate from 4000 to 2500.
> Please consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
> [ perf record: Woken up 18 times to write data ]
> [ perf record: Captured and wrote 5.433 MB perf.data.guest (62519 samples)
>
> # ./perf kvm report
> 31K kvm:kvm_entry
> 31K kvm:kvm_exit
>
> # ./perf kvm stat record -a
> [ perf record: Woken up 3 times to write data ]
> [ perf record: Captured and wrote 8.502 MB perf.data.guest (99338 samples) ]
>
> # ./perf kvm stat report --event=vmexit
> Event name Samples Sample% Time (ns) Time% Max Time (ns) Min Time (ns) Mean Time (ns)
> STORE_GUEST_PAGE_FAULT 26968 54.00% 2003031800 40.00% 3361400 27600 74274
> LOAD_GUEST_PAGE_FAULT 17645 35.00% 1153338100 23.00% 2513400 30800 65363
> VIRTUAL_INST_FAULT 1247 2.00% 340820800 6.00% 1190800 43300 273312
> INST_GUEST_PAGE_FAULT 1128 2.00% 340645800 6.00% 2123200 30200 301990
> SUPERVISOR_SYSCALL 1019 2.00% 245989900 4.00% 1851500 29300 241403
> LOAD_ACCESS 986 1.00% 671556200 13.00% 4180200 100700 681091
> INST_ACCESS 655 1.00% 170054800 3.00% 1808300 54600 259625
> HYPERVISOR_SYSCALL 21 0.00% 4276400 0.00% 716500 116000 203638
>
> Changes from v1->v2:
> - Rebased on Linux 6.9-rc3.
>
> Changes from v2->v3:
> - Add the missing assignment for 'vcpu_id_str' in patch 2.
> - Remove parentheses that cause compilation errors
>
> Shenlin Liang (2):
> RISCV: KVM: add tracepoints for entry and exit events
> perf kvm/riscv: Port perf kvm stat to RISC-V
>
> arch/riscv/kvm/trace.h | 67 ++++++++++++++++
> arch/riscv/kvm/vcpu.c | 7 ++
> tools/perf/arch/riscv/Makefile | 1 +
> tools/perf/arch/riscv/util/Build | 1 +
> tools/perf/arch/riscv/util/kvm-stat.c | 79 +++++++++++++++++++
> .../arch/riscv/util/riscv_exception_types.h | 35 ++++++++
> 6 files changed, 190 insertions(+)
> create mode 100644 arch/riscv/kvm/trace.h
> create mode 100644 tools/perf/arch/riscv/util/kvm-stat.c
> create mode 100644 tools/perf/arch/riscv/util/riscv_exception_types.h
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv
2024-04-22 8:08 [PATCH v3 0/2] perf kvm: Add kvm stat support on riscv Shenlin Liang
` (3 preceding siblings ...)
2024-05-04 0:21 ` Atish Patra
@ 2024-06-06 9:20 ` Anup Patel
4 siblings, 0 replies; 13+ messages in thread
From: Anup Patel @ 2024-06-06 9:20 UTC (permalink / raw)
To: Shenlin Liang
Cc: atishp, paul.walmsley, palmer, aou, kvm, kvm-riscv, linux-riscv,
linux-kernel, peterz, mingo, acme, namhyung, mark.rutland,
alexander.shishkin, jolsa, irogers, adrian.hunter,
linux-perf-users
On Mon, Apr 22, 2024 at 1:42 PM Shenlin Liang
<liangshenlin@eswincomputing.com> wrote:
>
> 'perf kvm stat report/record' generates a statistical analysis of KVM
> events and can be used to analyze guest exit reasons. This patch tries
> to add stat support on riscv.
>
> Map the return value of trace_kvm_exit() to the specific cause of the
> exception, and export it to userspace.
>
> It records on two available KVM tracepoints for riscv: "kvm:kvm_entry"
> and "kvm:kvm_exit", and reports statistical data which includes events
> handles time, samples, and so on.
>
> Cross compiling perf in X86 environment may encounter issues with missing
> libraries and tools. Suggest compiling nativly in RISC-V environment
>
> Simple tests go below:
>
> # ./perf kvm record -e "kvm:kvm_entry" -e "kvm:kvm_exit"
> Lowering default frequency rate from 4000 to 2500.
> Please consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
> [ perf record: Woken up 18 times to write data ]
> [ perf record: Captured and wrote 5.433 MB perf.data.guest (62519 samples)
>
> # ./perf kvm report
> 31K kvm:kvm_entry
> 31K kvm:kvm_exit
>
> # ./perf kvm stat record -a
> [ perf record: Woken up 3 times to write data ]
> [ perf record: Captured and wrote 8.502 MB perf.data.guest (99338 samples) ]
>
> # ./perf kvm stat report --event=vmexit
> Event name Samples Sample% Time (ns) Time% Max Time (ns) Min Time (ns) Mean Time (ns)
> STORE_GUEST_PAGE_FAULT 26968 54.00% 2003031800 40.00% 3361400 27600 74274
> LOAD_GUEST_PAGE_FAULT 17645 35.00% 1153338100 23.00% 2513400 30800 65363
> VIRTUAL_INST_FAULT 1247 2.00% 340820800 6.00% 1190800 43300 273312
> INST_GUEST_PAGE_FAULT 1128 2.00% 340645800 6.00% 2123200 30200 301990
> SUPERVISOR_SYSCALL 1019 2.00% 245989900 4.00% 1851500 29300 241403
> LOAD_ACCESS 986 1.00% 671556200 13.00% 4180200 100700 681091
> INST_ACCESS 655 1.00% 170054800 3.00% 1808300 54600 259625
> HYPERVISOR_SYSCALL 21 0.00% 4276400 0.00% 716500 116000 203638
>
> Changes from v1->v2:
> - Rebased on Linux 6.9-rc3.
>
> Changes from v2->v3:
> - Add the missing assignment for 'vcpu_id_str' in patch 2.
> - Remove parentheses that cause compilation errors
>
> Shenlin Liang (2):
> RISCV: KVM: add tracepoints for entry and exit events
> perf kvm/riscv: Port perf kvm stat to RISC-V
>
> arch/riscv/kvm/trace.h | 67 ++++++++++++++++
> arch/riscv/kvm/vcpu.c | 7 ++
> tools/perf/arch/riscv/Makefile | 1 +
> tools/perf/arch/riscv/util/Build | 1 +
> tools/perf/arch/riscv/util/kvm-stat.c | 79 +++++++++++++++++++
> .../arch/riscv/util/riscv_exception_types.h | 35 ++++++++
> 6 files changed, 190 insertions(+)
> create mode 100644 arch/riscv/kvm/trace.h
> create mode 100644 tools/perf/arch/riscv/util/kvm-stat.c
> create mode 100644 tools/perf/arch/riscv/util/riscv_exception_types.h
Queued this series for Linux-6.11
Thanks,
Anup
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread