On Wed, Nov 26, 2025 at 03:42:01PM +0100, Tomas Glozar wrote:
> 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.
> 
> Signed-off-by: Tomas Glozar <[email protected]>
> ---
>  tools/tracing/rtla/Makefile                      |  9 ++++++++-
>  tools/tracing/rtla/example/timerlat_bpf_action.c | 16 ++++++++++++++++
>  .../rtla/{sample => example}/timerlat_load.py    |  0
>  3 files changed, 24 insertions(+), 1 deletion(-)
>  create mode 100644 tools/tracing/rtla/example/timerlat_bpf_action.c
>  rename tools/tracing/rtla/{sample => example}/timerlat_load.py (100%)
> 
> diff --git a/tools/tracing/rtla/Makefile b/tools/tracing/rtla/Makefile
> index 746ccf2f5808..5f1529ce3693 100644
> --- a/tools/tracing/rtla/Makefile
> +++ b/tools/tracing/rtla/Makefile
> @@ -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 $@

I couldn't understand the need for the `filter` function.

>  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
> index 000000000000..ac1be049a848
> --- /dev/null
> +++ b/tools/tracing/rtla/example/timerlat_bpf_action.c
> @@ -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;
> +}
> diff --git a/tools/tracing/rtla/sample/timerlat_load.py 
> b/tools/tracing/rtla/example/timerlat_load.py
> similarity index 100%
> rename from tools/tracing/rtla/sample/timerlat_load.py
> rename to tools/tracing/rtla/example/timerlat_load.py
> -- 
> 2.51.1
> 


Reply via email to