Skip to content

Commit

Permalink
riscv: Add tracepoints for SBI calls and returns
Browse files Browse the repository at this point in the history
These are useful for measuring the latency of SBI calls. The SBI HSM
extension is excluded because those functions are called from contexts
such as cpuidle where instrumentation is not allowed.

Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20240321230131.1838105-1-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
  • Loading branch information
Samuel Holland authored and Palmer Dabbelt committed Jul 10, 2024
1 parent a43fe27 commit 56c1c1a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
54 changes: 54 additions & 0 deletions arch/riscv/include/asm/trace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM riscv

#if !defined(_TRACE_RISCV_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_RISCV_H

#include <linux/tracepoint.h>

TRACE_EVENT_CONDITION(sbi_call,
TP_PROTO(int ext, int fid),
TP_ARGS(ext, fid),
TP_CONDITION(ext != SBI_EXT_HSM),

TP_STRUCT__entry(
__field(int, ext)
__field(int, fid)
),

TP_fast_assign(
__entry->ext = ext;
__entry->fid = fid;
),

TP_printk("ext=0x%x fid=%d", __entry->ext, __entry->fid)
);

TRACE_EVENT_CONDITION(sbi_return,
TP_PROTO(int ext, long error, long value),
TP_ARGS(ext, error, value),
TP_CONDITION(ext != SBI_EXT_HSM),

TP_STRUCT__entry(
__field(long, error)
__field(long, value)
),

TP_fast_assign(
__entry->error = error;
__entry->value = value;
),

TP_printk("error=%ld value=0x%lx", __entry->error, __entry->value)
);

#endif /* _TRACE_RISCV_H */

#undef TRACE_INCLUDE_PATH
#undef TRACE_INCLUDE_FILE

#define TRACE_INCLUDE_PATH asm
#define TRACE_INCLUDE_FILE trace

#include <trace/define_trace.h>
7 changes: 7 additions & 0 deletions arch/riscv/kernel/sbi.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include <asm/smp.h>
#include <asm/tlbflush.h>

#define CREATE_TRACE_POINTS
#include <asm/trace.h>

/* default SBI version is 0.1 */
unsigned long sbi_spec_version __ro_after_init = SBI_SPEC_VERSION_DEFAULT;
EXPORT_SYMBOL(sbi_spec_version);
Expand All @@ -31,6 +34,8 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
{
struct sbiret ret;

trace_sbi_call(ext, fid);

register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0);
register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1);
register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2);
Expand All @@ -46,6 +51,8 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
ret.error = a0;
ret.value = a1;

trace_sbi_return(ext, ret.error, ret.value);

return ret;
}
EXPORT_SYMBOL(sbi_ecall);
Expand Down

0 comments on commit 56c1c1a

Please sign in to comment.