Skip to content

Commit 0304a3b

Browse files
rtla/timerlat: Add example for BPF action program
Add an example BPF action program that prints the measured latency to the tracefs buffer via bpf_printk(). A new Makefile target, "examples", is added to build the example. In addition, "sample/" subfolder is renamed to "example". If BPF skeleton support is unavailable or disabled, a warning will be displayed when building the BPF action program example. Link: https://lore.kernel.org/r/20251126144205.331954-4-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
1 parent f967d1e commit 0304a3b

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

tools/tracing/rtla/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,15 @@ src/timerlat.bpf.o: src/timerlat.bpf.c
7373

7474
src/timerlat.skel.h: src/timerlat.bpf.o
7575
$(QUIET_GENSKEL)$(SYSTEM_BPFTOOL) gen skeleton $< > $@
76+
77+
example/timerlat_bpf_action.o: example/timerlat_bpf_action.c
78+
$(QUIET_CLANG)$(CLANG) -g -O2 -target bpf -c $(filter %.c,$^) -o $@
7679
else
7780
src/timerlat.skel.h:
7881
$(Q)echo '/* BPF skeleton is disabled */' > src/timerlat.skel.h
82+
83+
example/timerlat_bpf_action.o: example/timerlat_bpf_action.c
84+
$(Q)echo "BPF skeleton support is disabled, skipping example/timerlat_bpf_action.o"
7985
endif
8086

8187
$(RTLA): $(RTLA_IN)
@@ -96,7 +102,8 @@ clean: doc_clean fixdep-clean
96102
$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
97103
$(Q)rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-*
98104
$(Q)rm -rf feature
99-
$(Q)rm -f src/timerlat.bpf.o src/timerlat.skel.h
105+
$(Q)rm -f src/timerlat.bpf.o src/timerlat.skel.h example/timerlat_bpf_action.o
100106
check: $(RTLA)
101107
RTLA=$(RTLA) prove -o -f tests/
108+
examples: example/timerlat_bpf_action.o
102109
.PHONY: FORCE clean check
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/bpf.h>
3+
#include <bpf/bpf_tracing.h>
4+
5+
char LICENSE[] SEC("license") = "GPL";
6+
7+
struct trace_event_raw_timerlat_sample {
8+
unsigned long long timer_latency;
9+
} __attribute__((preserve_access_index));
10+
11+
SEC("tp/timerlat_action")
12+
int action_handler(struct trace_event_raw_timerlat_sample *tp_args)
13+
{
14+
bpf_printk("Latency: %lld\n", tp_args->timer_latency);
15+
return 0;
16+
}
File renamed without changes.

0 commit comments

Comments
 (0)