* Re: [PATCH] perf kvm: Fix arm64 VM-EXIT event detection
[not found] <ZNG9PNB-fEBNyK9E@B-Q60VQ05P-2326.local>
@ 2025-05-09 1:54 ` Zenghui Yu
0 siblings, 0 replies; only message in thread
From: Zenghui Yu @ 2025-05-09 1:54 UTC (permalink / raw)
To: Haixin Yu
Cc: John Garry, Will Deacon, James Clark, Mike Leach, Leo Yan,
Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Liang, Kan, linux-arm-kernel,
linux-perf-users, linux-kernel, Shannon Zhao, Sergey Senozhatsky
[ +Cc the original author of perf kvm stat ]
On 2023/8/8 11:57, Haixin Yu wrote:
> A VM-EXIT event shall start at kvm:kvm_exit, and end with the next
> kvm:kvm_entry. But it's reversed on arm64, which means the time running
> guest code in fact.
Good catch! It'd be great if Sergey could take a look.
>
> Example:
>
> # perf kvm stat record -p 2772 -- sleep 1
>
> Before this change:
>
> # perf kvm stat report
>
> Analyze events for all VMs, all VCPUs:
>
> VM-EXIT Samples Samples% Time% Min Time Max Time Avg time
>
> IRQ 756 100.00% 100.00% 2.28us 3674.38us 1375.66us ( +- 4.34% )
>
> Total Samples:756, Total events handled time:1039996.94us.
>
> After:
>
> # perf kvm stat report
>
> Analyze events for all VMs, all VCPUs:
>
> VM-EXIT Samples Samples% Time% Min Time Max Time Avg time
>
> IRQ 772 100.00% 100.00% 0.24us 62.86us 6.34us ( +- 3.55% )
>
> Total Samples:772, Total events handled time:4890.80us.
>
> IRQ average handled time decreases to 6us, which is a more rational result
> as KVM handles IRQ by returning to guest directly.
>
> Signed-off-by: Haixin Yu <yuhaixin.yhx@linux.alibaba.com>
> ---
> tools/perf/arch/arm64/util/kvm-stat.c | 24 +++---------------------
> tools/perf/builtin-kvm.c | 2 +-
> 2 files changed, 4 insertions(+), 22 deletions(-)
>
> diff --git a/tools/perf/arch/arm64/util/kvm-stat.c b/tools/perf/arch/arm64/util/kvm-stat.c
> index 6611aa21cba9..eeb659ceedc2 100644
> --- a/tools/perf/arch/arm64/util/kvm-stat.c
> +++ b/tools/perf/arch/arm64/util/kvm-stat.c
> @@ -21,7 +21,7 @@ const char *kvm_events_tp[] = {
> NULL,
> };
>
> -static void event_get_key(struct evsel *evsel,
> +void exit_event_get_key(struct evsel *evsel,
> struct perf_sample *sample,
> struct event_key *key)
> {
> @@ -40,27 +40,9 @@ static void event_get_key(struct evsel *evsel,
> }
> }
>
> -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,
> + .is_begin_event = exit_event_begin,
> + .is_end_event = exit_event_end,
> .decode_key = exit_event_decode_key,
> .name = "VM-EXIT"
> };
> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> index 71165036e4ca..498cd8e21134 100644
> --- a/tools/perf/builtin-kvm.c
> +++ b/tools/perf/builtin-kvm.c
> @@ -615,7 +615,7 @@ static const char *get_filename_for_perf_kvm(void)
>
> #if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
>
> -void exit_event_get_key(struct evsel *evsel,
> +void __weak exit_event_get_key(struct evsel *evsel,
> struct perf_sample *sample,
> struct event_key *key)
> {
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-05-09 2:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <ZNG9PNB-fEBNyK9E@B-Q60VQ05P-2326.local>
2025-05-09 1:54 ` [PATCH] perf kvm: Fix arm64 VM-EXIT event detection Zenghui Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).