Skip to content

Commit 91195a9

Browse files
Shenlin Liangavpatel
authored andcommitted
RISCV: KVM: add tracepoints for entry and exit events
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 <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Atish Patra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
1 parent 3385339 commit 91195a9

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

arch/riscv/kvm/trace.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Tracepoints for RISC-V KVM
4+
*
5+
* Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd.
6+
*
7+
*/
8+
#if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
9+
#define _TRACE_KVM_H
10+
11+
#include <linux/tracepoint.h>
12+
13+
#undef TRACE_SYSTEM
14+
#define TRACE_SYSTEM kvm
15+
16+
TRACE_EVENT(kvm_entry,
17+
TP_PROTO(struct kvm_vcpu *vcpu),
18+
TP_ARGS(vcpu),
19+
20+
TP_STRUCT__entry(
21+
__field(unsigned long, pc)
22+
),
23+
24+
TP_fast_assign(
25+
__entry->pc = vcpu->arch.guest_context.sepc;
26+
),
27+
28+
TP_printk("PC: 0x016%lx", __entry->pc)
29+
);
30+
31+
TRACE_EVENT(kvm_exit,
32+
TP_PROTO(struct kvm_cpu_trap *trap),
33+
TP_ARGS(trap),
34+
35+
TP_STRUCT__entry(
36+
__field(unsigned long, sepc)
37+
__field(unsigned long, scause)
38+
__field(unsigned long, stval)
39+
__field(unsigned long, htval)
40+
__field(unsigned long, htinst)
41+
),
42+
43+
TP_fast_assign(
44+
__entry->sepc = trap->sepc;
45+
__entry->scause = trap->scause;
46+
__entry->stval = trap->stval;
47+
__entry->htval = trap->htval;
48+
__entry->htinst = trap->htinst;
49+
),
50+
51+
TP_printk("SEPC:0x%lx, SCAUSE:0x%lx, STVAL:0x%lx, HTVAL:0x%lx, HTINST:0x%lx",
52+
__entry->sepc,
53+
__entry->scause,
54+
__entry->stval,
55+
__entry->htval,
56+
__entry->htinst)
57+
);
58+
59+
#endif /* _TRACE_RSICV_KVM_H */
60+
61+
#undef TRACE_INCLUDE_PATH
62+
#define TRACE_INCLUDE_PATH .
63+
#undef TRACE_INCLUDE_FILE
64+
#define TRACE_INCLUDE_FILE trace
65+
66+
/* This part must be outside protection */
67+
#include <trace/define_trace.h>

arch/riscv/kvm/vcpu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include <asm/cacheflush.h>
2222
#include <asm/kvm_vcpu_vector.h>
2323

24+
#define CREATE_TRACE_POINTS
25+
#include "trace.h"
26+
2427
const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
2528
KVM_GENERIC_VCPU_STATS(),
2629
STATS_DESC_COUNTER(VCPU, ecall_exit_stat),
@@ -831,6 +834,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
831834
*/
832835
kvm_riscv_local_tlb_sanitize(vcpu);
833836

837+
trace_kvm_entry(vcpu);
838+
834839
guest_timing_enter_irqoff();
835840

836841
kvm_riscv_vcpu_enter_exit(vcpu);
@@ -869,6 +874,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
869874

870875
local_irq_enable();
871876

877+
trace_kvm_exit(&trap);
878+
872879
preempt_enable();
873880

874881
kvm_vcpu_srcu_read_lock(vcpu);

0 commit comments

Comments
 (0)