]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rtla/timerlat: Add example for BPF action program
authorTomas Glozar <tglozar@redhat.com>
Wed, 26 Nov 2025 14:42:01 +0000 (15:42 +0100)
committerTomas Glozar <tglozar@redhat.com>
Wed, 7 Jan 2026 14:57:16 +0000 (15:57 +0100)
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>
tools/tracing/rtla/Makefile
tools/tracing/rtla/example/timerlat_bpf_action.c [new file with mode: 0644]
tools/tracing/rtla/example/timerlat_load.py [moved from tools/tracing/rtla/sample/timerlat_load.py with 100% similarity]

index 746ccf2f58081d51c92be3cda148566b284e96be..5f1529ce3693b70f4b96dff812bab1465bb86f6d 100644 (file)
@@ -73,9 +73,15 @@ src/timerlat.bpf.o: src/timerlat.bpf.c
 
 src/timerlat.skel.h: src/timerlat.bpf.o
        $(QUIET_GENSKEL)$(SYSTEM_BPFTOOL) gen skeleton $< > $@
+
+example/timerlat_bpf_action.o: example/timerlat_bpf_action.c
+       $(QUIET_CLANG)$(CLANG) -g -O2 -target bpf -c $(filter %.c,$^) -o $@
 else
 src/timerlat.skel.h:
        $(Q)echo '/* BPF skeleton is disabled */' > src/timerlat.skel.h
+
+example/timerlat_bpf_action.o: example/timerlat_bpf_action.c
+       $(Q)echo "BPF skeleton support is disabled, skipping example/timerlat_bpf_action.o"
 endif
 
 $(RTLA): $(RTLA_IN)
@@ -96,7 +102,8 @@ clean: doc_clean fixdep-clean
        $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
        $(Q)rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-*
        $(Q)rm -rf feature
-       $(Q)rm -f src/timerlat.bpf.o src/timerlat.skel.h
+       $(Q)rm -f src/timerlat.bpf.o src/timerlat.skel.h example/timerlat_bpf_action.o
 check: $(RTLA)
        RTLA=$(RTLA) prove -o -f tests/
+examples: example/timerlat_bpf_action.o
 .PHONY: FORCE clean check
diff --git a/tools/tracing/rtla/example/timerlat_bpf_action.c b/tools/tracing/rtla/example/timerlat_bpf_action.c
new file mode 100644 (file)
index 0000000..ac1be04
--- /dev/null
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_tracing.h>
+
+char LICENSE[] SEC("license") = "GPL";
+
+struct trace_event_raw_timerlat_sample {
+       unsigned long long timer_latency;
+} __attribute__((preserve_access_index));
+
+SEC("tp/timerlat_action")
+int action_handler(struct trace_event_raw_timerlat_sample *tp_args)
+{
+       bpf_printk("Latency: %lld\n", tp_args->timer_latency);
+       return 0;
+}