]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rtla/timerlat: Support tail call from BPF program
authorTomas Glozar <tglozar@redhat.com>
Wed, 26 Nov 2025 14:41:59 +0000 (15:41 +0100)
committerTomas Glozar <tglozar@redhat.com>
Wed, 7 Jan 2026 14:57:15 +0000 (15:57 +0100)
Add a map to the rtla-timerlat BPF program that holds a file descriptor
of another BPF program, to be executed on threshold overflow.

timerlat_bpf_set_action() is added as an interface to set the program.

Link: https://lore.kernel.org/r/20251126144205.331954-2-tglozar@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
tools/tracing/rtla/src/timerlat.bpf.c
tools/tracing/rtla/src/timerlat_bpf.c
tools/tracing/rtla/src/timerlat_bpf.h

index e2265b5d649100a9b0d7d2e2e884f71fafeca266..549d2d2191d2f5be2087931d5be9fb802b839ad1 100644 (file)
@@ -40,6 +40,17 @@ struct {
        __uint(max_entries, 1);
 } signal_stop_tracing SEC(".maps");
 
+struct {
+       __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
+       __uint(key_size, sizeof(unsigned int));
+       __uint(max_entries, 1);
+       __array(values, unsigned int (void *));
+} bpf_action SEC(".maps") = {
+       .values = {
+               [0] = 0
+       },
+};
+
 /* Params to be set by rtla */
 const volatile int bucket_size = 1;
 const volatile int output_divisor = 1000;
@@ -109,7 +120,7 @@ nosubprog void update_summary(void *map,
        map_set(map, SUMMARY_SUM, map_get(map, SUMMARY_SUM) + latency);
 }
 
-nosubprog void set_stop_tracing(void)
+nosubprog void set_stop_tracing(struct trace_event_raw_timerlat_sample *tp_args)
 {
        int value = 0;
 
@@ -118,6 +129,12 @@ nosubprog void set_stop_tracing(void)
 
        /* Signal to userspace */
        bpf_ringbuf_output(&signal_stop_tracing, &value, sizeof(value), 0);
+
+       /*
+        * Call into BPF action program, if attached.
+        * Otherwise, just silently fail.
+        */
+       bpf_tail_call(tp_args, &bpf_action, 0);
 }
 
 SEC("tp/osnoise/timerlat_sample")
@@ -138,19 +155,19 @@ int handle_timerlat_sample(struct trace_event_raw_timerlat_sample *tp_args)
                update_summary(&summary_irq, latency, bucket);
 
                if (irq_threshold != 0 && latency_us >= irq_threshold)
-                       set_stop_tracing();
+                       set_stop_tracing(tp_args);
        } else if (tp_args->context == 1) {
                update_main_hist(&hist_thread, bucket);
                update_summary(&summary_thread, latency, bucket);
 
                if (thread_threshold != 0 && latency_us >= thread_threshold)
-                       set_stop_tracing();
+                       set_stop_tracing(tp_args);
        } else {
                update_main_hist(&hist_user, bucket);
                update_summary(&summary_user, latency, bucket);
 
                if (thread_threshold != 0 && latency_us >= thread_threshold)
-                       set_stop_tracing();
+                       set_stop_tracing(tp_args);
        }
 
        return 0;
index e97d16646bcdf108b67cc0c6d3aee191abb3fc53..1d619e502c657a4659a1a05d5435f75fe4668949 100644 (file)
@@ -59,6 +59,19 @@ int timerlat_bpf_init(struct timerlat_params *params)
        return 0;
 }
 
+/*
+ * timerlat_bpf_set_action - set action on threshold executed on BPF side
+ */
+static int timerlat_bpf_set_action(struct bpf_program *prog)
+{
+       unsigned int key = 0, value = bpf_program__fd(prog);
+
+       return bpf_map__update_elem(bpf->maps.bpf_action,
+                                   &key, sizeof(key),
+                                   &value, sizeof(value),
+                                   BPF_ANY);
+}
+
 /*
  * timerlat_bpf_attach - attach BPF program to collect timerlat data
  */
index 118487436d3048e0dff935df82f7e84624098944..b5009092c7a3e51480ad321a96cb4b0bb4968a59 100644 (file)
@@ -12,6 +12,7 @@ enum summary_field {
 };
 
 #ifndef __bpf__
+#include <bpf/libbpf.h>
 #ifdef HAVE_BPF_SKEL
 int timerlat_bpf_init(struct timerlat_params *params);
 int timerlat_bpf_attach(void);