Skip to content

Commit 3b7270c

Browse files
zcxGGmuavpatel
authored andcommitted
RISC-V: perf/kvm: Add reporting of interrupt events
For `perf kvm stat` on the RISC-V, in order to avoid the occurrence of `UNKNOWN` event names, interrupts should be reported in addition to exceptions. testing without patch: Event name Samples Sample% Time(ns) --------------------------- -------- -------- ------------ STORE_GUEST_PAGE_FAULT 1496461 53.00% 889612544 UNKNOWN 887514 31.00% 272857968 LOAD_GUEST_PAGE_FAULT 305164 10.00% 189186331 VIRTUAL_INST_FAULT 70625 2.00% 134114260 SUPERVISOR_SYSCALL 32014 1.00% 58577110 INST_GUEST_PAGE_FAULT 1 0.00% 2545 testing with patch: Event name Samples Sample% Time(ns) --------------------------- -------- -------- ------------ IRQ_S_TIMER 211271 58.00% 738298680600 EXC_STORE_GUEST_PAGE_FAULT 111279 30.00% 130725914800 EXC_LOAD_GUEST_PAGE_FAULT 22039 6.00% 25441480600 EXC_VIRTUAL_INST_FAULT 8913 2.00% 21015381600 IRQ_VS_EXT 4748 1.00% 10155464300 IRQ_S_EXT 2802 0.00% 13288775800 IRQ_S_SOFT 1998 0.00% 4254129300 Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Link: https://lore.kernel.org/r/9693132df4d0f857b8be3a75750c36b40213fcc0.1726211632.git.zhouquan@iscas.ac.cn Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent f55ffaf commit 3b7270c

3 files changed

Lines changed: 60 additions & 38 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#include <memory.h>
1010
#include "../../../util/evsel.h"
1111
#include "../../../util/kvm-stat.h"
12-
#include "riscv_exception_types.h"
12+
#include "riscv_trap_types.h"
1313
#include "debug.h"
1414

15-
define_exit_reasons_table(riscv_exit_reasons, kvm_riscv_exception_class);
15+
define_exit_reasons_table(riscv_exit_reasons, kvm_riscv_trap_class);
1616

1717
const char *vcpu_id_str = "id";
1818
const char *kvm_exit_reason = "scause";
@@ -30,7 +30,7 @@ static void event_get_key(struct evsel *evsel,
3030
struct event_key *key)
3131
{
3232
key->info = 0;
33-
key->key = evsel__intval(evsel, sample, kvm_exit_reason);
33+
key->key = evsel__intval(evsel, sample, kvm_exit_reason) & ~CAUSE_IRQ_FLAG;
3434
key->exit_reasons = riscv_exit_reasons;
3535
}
3636

tools/perf/arch/riscv/util/riscv_exception_types.h

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#ifndef ARCH_PERF_RISCV_TRAP_TYPES_H
3+
#define ARCH_PERF_RISCV_TRAP_TYPES_H
4+
5+
/* Exception cause high bit - is an interrupt if set */
6+
#define CAUSE_IRQ_FLAG (_AC(1, UL) << (__riscv_xlen - 1))
7+
8+
/* Interrupt causes (minus the high bit) */
9+
#define IRQ_S_SOFT 1
10+
#define IRQ_VS_SOFT 2
11+
#define IRQ_M_SOFT 3
12+
#define IRQ_S_TIMER 5
13+
#define IRQ_VS_TIMER 6
14+
#define IRQ_M_TIMER 7
15+
#define IRQ_S_EXT 9
16+
#define IRQ_VS_EXT 10
17+
#define IRQ_M_EXT 11
18+
#define IRQ_S_GEXT 12
19+
#define IRQ_PMU_OVF 13
20+
21+
/* Exception causes */
22+
#define EXC_INST_MISALIGNED 0
23+
#define EXC_INST_ACCESS 1
24+
#define EXC_INST_ILLEGAL 2
25+
#define EXC_BREAKPOINT 3
26+
#define EXC_LOAD_MISALIGNED 4
27+
#define EXC_LOAD_ACCESS 5
28+
#define EXC_STORE_MISALIGNED 6
29+
#define EXC_STORE_ACCESS 7
30+
#define EXC_SYSCALL 8
31+
#define EXC_HYPERVISOR_SYSCALL 9
32+
#define EXC_SUPERVISOR_SYSCALL 10
33+
#define EXC_INST_PAGE_FAULT 12
34+
#define EXC_LOAD_PAGE_FAULT 13
35+
#define EXC_STORE_PAGE_FAULT 15
36+
#define EXC_INST_GUEST_PAGE_FAULT 20
37+
#define EXC_LOAD_GUEST_PAGE_FAULT 21
38+
#define EXC_VIRTUAL_INST_FAULT 22
39+
#define EXC_STORE_GUEST_PAGE_FAULT 23
40+
41+
#define TRAP(x) { x, #x }
42+
43+
#define kvm_riscv_trap_class \
44+
TRAP(IRQ_S_SOFT), TRAP(IRQ_VS_SOFT), TRAP(IRQ_M_SOFT), \
45+
TRAP(IRQ_S_TIMER), TRAP(IRQ_VS_TIMER), TRAP(IRQ_M_TIMER), \
46+
TRAP(IRQ_S_EXT), TRAP(IRQ_VS_EXT), TRAP(IRQ_M_EXT), \
47+
TRAP(IRQ_S_GEXT), TRAP(IRQ_PMU_OVF), \
48+
TRAP(EXC_INST_MISALIGNED), TRAP(EXC_INST_ACCESS), TRAP(EXC_INST_ILLEGAL), \
49+
TRAP(EXC_BREAKPOINT), TRAP(EXC_LOAD_MISALIGNED), TRAP(EXC_LOAD_ACCESS), \
50+
TRAP(EXC_STORE_MISALIGNED), TRAP(EXC_STORE_ACCESS), TRAP(EXC_SYSCALL), \
51+
TRAP(EXC_HYPERVISOR_SYSCALL), TRAP(EXC_SUPERVISOR_SYSCALL), \
52+
TRAP(EXC_INST_PAGE_FAULT), TRAP(EXC_LOAD_PAGE_FAULT), \
53+
TRAP(EXC_STORE_PAGE_FAULT), TRAP(EXC_INST_GUEST_PAGE_FAULT), \
54+
TRAP(EXC_LOAD_GUEST_PAGE_FAULT), TRAP(EXC_VIRTUAL_INST_FAULT), \
55+
TRAP(EXC_STORE_GUEST_PAGE_FAULT)
56+
57+
#endif /* ARCH_PERF_RISCV_TRAP_TYPES_H */

0 commit comments

Comments
 (0)