Skip to contentSkip to conversation

rtla/timerlat: Add --bpf-action option

PATCH Superseded Tomas Glozar 3 participants 19 messages Oct 27, 2025 – Nov 25, 2025

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Tomas Glozar

author maintainer
#0 lore raw

v3 cover rtla/timerlat: Add --bpf-action option

This patchset extends rtla-timerlat's BPF support with the option of executing a user-supplied BPF program on latency threshold overflow.

See the supplied example and documentation for how to create a program. bpf_tail_call() is used to chain the program with the built-in BPF sample collection program, if the threshold is hit.

The feature can be used for both in-kernel data collection and sending signals to userspace directly from the kernel, if the kernel version allows it.

Note: The patchset will have to be rebased on top of [1], or vice versa, since they both touch stop_tracing() ([1] adds one call of it, and this patchset adds an extra argument to it).

I have contemplated adding this as --on-threshold bpf,... but it does not fit the existing actions infrastructure very well, since the action happens in the BPF program, not in RTLA, and only one BPF action is supported.

[1] https://lore.kernel.org/linux-trace-kernel/[email protected]/

v3 changes:
- Add tests/bpf/bpf_action_map.c to test commit (forgot to run git add before).

v2 changes:
- Properly bpf__object_close() also when bpf__object_load() fails.
- Use goto for error paths in timerlat_load_bpf_action_program().
- Remove unneeded NULLing of obj and prog in timerlat_bpf_init().
- Add entry to Makefile to build example.
- Add test for BPF actions.
- Rename sample/ directory to example/, also in docs.
- Run Test::Harness in verbose mode during "make check".

Thanks to Crystal and Wander for their input.

Tomas Glozar (7):
rtla/timerlat: Support tail call from BPF program rtla/timerlat: Add --bpf-action option rtla/timerlat: Add example for BPF action program rtla/tests: Test BPF action program rtla/tests: Run Test::Harness in verbose mode Documentation/rtla: Rename sample/ to example/ Documentation/rtla: Document --bpf-action option

 .../tools/rtla/common_timerlat_options.rst    | 22 ++++++-
 tools/tracing/rtla/Makefile                   | 19 +++++-
 .../rtla/example/timerlat_bpf_action.c        | 16 +++++
 .../rtla/{sample => example}/timerlat_load.py |  0
 tools/tracing/rtla/src/timerlat.bpf.c         | 23 ++++++-
 tools/tracing/rtla/src/timerlat.c             | 11 ++++
 tools/tracing/rtla/src/timerlat.h             |  2 +-
 tools/tracing/rtla/src/timerlat_bpf.c         | 66 +++++++++++++++++++
 tools/tracing/rtla/src/timerlat_bpf.h         |  7 +-
 tools/tracing/rtla/src/timerlat_hist.c        |  5 ++
 tools/tracing/rtla/src/timerlat_top.c         |  5 ++
 tools/tracing/rtla/tests/bpf/bpf_action_map.c | 25 +++++++
 tools/tracing/rtla/tests/engine.sh            |  1 -
 tools/tracing/rtla/tests/timerlat.t           | 15 +++++
 14 files changed, 207 insertions(+), 10 deletions(-)
 create mode 100644 tools/tracing/rtla/example/timerlat_bpf_action.c
 rename tools/tracing/rtla/{sample => example}/timerlat_load.py (100%)
 create mode 100644 tools/tracing/rtla/tests/bpf/bpf_action_map.c
Signature · 1 line
2.51.0
author maintainer
#1 lore raw

PATCH v3 1/7 rtla/timerlat: Support tail call from BPF program

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.

---
 tools/tracing/rtla/src/timerlat.bpf.c | 23 ++++++++++++++++++++---
 tools/tracing/rtla/src/timerlat_bpf.c | 13 +++++++++++++
 tools/tracing/rtla/src/timerlat_bpf.h |  1 +
 3 files changed, 34 insertions(+), 3 deletions(-)
tools/tracing/rtla/src/timerlat.bpf.c +20 -3
index 084cd10c21fc..19ccd9abf8d4 100644
@@ -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,13 +155,13 @@ 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);
tools/tracing/rtla/src/timerlat_bpf.c +13 -0
index e97d16646bcd..1d619e502c65 100644
@@ -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
  */
tools/tracing/rtla/src/timerlat_bpf.h +1 -0
index 118487436d30..b5009092c7a3 100644
@@ -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);
Signature · 1 line
2.51.0
#2 lore raw

Re: [PATCH v3 1/7] rtla/timerlat: Support tail call from BPF program

Quoted 83 lines · Tomas Glozar

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.

---
 tools/tracing/rtla/src/timerlat.bpf.c | 23 ++++++++++++++++++++---
 tools/tracing/rtla/src/timerlat_bpf.c | 13 +++++++++++++
 tools/tracing/rtla/src/timerlat_bpf.h |  1 +
 3 files changed, 34 insertions(+), 3 deletions(-)
tools/tracing/rtla/src/timerlat.bpf.c +20 -3
index 084cd10c21fc..19ccd9abf8d4 100644
@@ -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,13 +155,13 @@ 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);
tools/tracing/rtla/src/timerlat_bpf.c +3 -0
index e97d16646bcd..1d619e502c65 100644
@@ -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
+ */

tools/tracing/rtla/src/timerlat_bpf.c int timerlat_bpf_init(struct timerlat_params *params) · line 74

Quoted 10 lines
tools/tracing/rtla/src/timerlat_bpf.c +10 -0
+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);
+}
+

I believe it makes more sense to add the definition of this function to the patch where it is called.

Quoted 18 lines
tools/tracing/rtla/src/timerlat_bpf.c +0 -0
 /*
  * timerlat_bpf_attach - attach BPF program to collect timerlat data
  */
tools/tracing/rtla/src/timerlat_bpf.h +1 -0
index 118487436d30..b5009092c7a3 100644
@@ -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);
Signature · 1 line
2.51.0
author maintainer
#3 lore raw

Re: [PATCH v3 1/7] rtla/timerlat: Support tail call from BPF program

po 3. 11. 2025 v 15:24 odesílatel Wander Lairson Costa <[email protected]> napsal:

Quoted 8 lines
Quoted 8 lines
tools/tracing/rtla/src/timerlat_bpf.c +8 -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,
Quoted 9 lines

tools/tracing/rtla/src/timerlat_bpf.c int timerlat_bpf_init(struct timerlat_params *params) · line 74

Quoted 5 lines
tools/tracing/rtla/src/timerlat_bpf.c +5 -0
+                                 &key, sizeof(key),
+                                 &value, sizeof(value),
+                                 BPF_ANY);
+}
+

I believe it makes more sense to add the definition of this function to the patch where it is called.

Maybe, but I wrote this patch first, the rest of the patchset some time after that. That is why it is this way; either way, it doesn't hurt to define something before using it, the other way is worse.

Tomas

author maintainer
#4 lore raw

PATCH v3 2/7 rtla/timerlat: Add --bpf-action option

In reply to Tomas Glozar

Add option --bpf-action that allows the user to attach an external BPF program that will be executed via BPF tail call on latency threshold overflow.

Executing additional BPF code on latency threshold overflow allows doing doing low-latency and in-kernel troubleshooting of the cause of the overflow.

The option takes an argument, which is a path to a BPF ELF file expected to contain a function named "action_handler" in a section named "tp/timerlat_action" (the section is necessary for libbpf to assign the correct BPF program type to it).

---
 tools/tracing/rtla/src/timerlat.c      | 11 ++++++
 tools/tracing/rtla/src/timerlat.h      |  2 +-
 tools/tracing/rtla/src/timerlat_bpf.c  | 53 ++++++++++++++++++++++++++
 tools/tracing/rtla/src/timerlat_bpf.h  |  6 ++-
 tools/tracing/rtla/src/timerlat_hist.c |  5 +++
 tools/tracing/rtla/src/timerlat_top.c  |  5 +++
 6 files changed, 80 insertions(+), 2 deletions(-)
tools/tracing/rtla/src/timerlat.c +11 -0
index b69212874127..6907a323f9ec 100644
@@ -48,6 +48,17 @@ timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
 		}
 	}
 
+	/* Check if BPF action program is requested but BPF is not available */
+	if (params->bpf_action_program) {
+		if (params->mode == TRACING_MODE_TRACEFS) {
+			err_msg("BPF actions are not supported in tracefs-only mode\n");
+			goto out_err;
+		}
+
+		if (timerlat_load_bpf_action_program(params->bpf_action_program))
+			goto out_err;
+	}
+
 	if (params->mode != TRACING_MODE_BPF) {
 		/*
 		 * In tracefs and mixed mode, timerlat tracer handles stopping
tools/tracing/rtla/src/timerlat.h +1 -1
index fd6065f48bb7..8dd5d134ce08 100644
@@ -27,6 +27,7 @@ struct timerlat_params {
 	int			dump_tasks;
 	int			deepest_idle_state;
 	enum timerlat_tracing_mode mode;
+	const char		*bpf_action_program;
 };
 
 #define to_timerlat_params(ptr) container_of(ptr, struct timerlat_params, common)
@@ -36,4 +37,3 @@ int timerlat_main(int argc, char *argv[]);
 int timerlat_enable(struct osnoise_tool *tool);
 void timerlat_analyze(struct osnoise_tool *tool, bool stopped);
 void timerlat_free(struct osnoise_tool *tool);
-
tools/tracing/rtla/src/timerlat_bpf.c +53 -0

69 lines not on this page · raw message

tools/tracing/rtla/src/timerlat_bpf.h +5 -1
index b5009092c7a3..169abeaf4363 100644
@@ -30,7 +30,7 @@ int timerlat_bpf_get_summary_value(enum summary_field key,
 				   long long *value_thread,
 				   long long *value_user,
 				   int cpus);
-
+int timerlat_load_bpf_action_program(const char *program_path);
 static inline int have_libbpf_support(void) { return 1; }
 #else
 static inline int timerlat_bpf_init(struct timerlat_params *params)
@@ -58,6 +58,10 @@ static inline int timerlat_bpf_get_summary_value(enum summary_field key,
 {
 	return -1;
 }
+static inline int timerlat_load_bpf_action_program(const char *program_path)
+{
+	return -1;
+}
 static inline int have_libbpf_support(void) { return 0; }
 #endif /* HAVE_BPF_SKEL */
 #endif /* __bpf__ */
tools/tracing/rtla/src/timerlat_hist.c +5 -0
index 606c1688057b..5e639cc34f64 100644
@@ -763,6 +763,7 @@ static void timerlat_hist_usage(char *usage)
 		"	     --deepest-idle-state n: only go down to idle state n on cpus used by timerlat to reduce exit from idle latency",
 		"	     --on-threshold <action>: define action to be executed at latency threshold, multiple are allowed",
 		"	     --on-end <action>: define action to be executed at measurement end, multiple are allowed",
+		"	     --bpf-action <program>: load and execute BPF program when latency threshold is exceeded",
 		NULL,
 	};
 
@@ -853,6 +854,7 @@ static struct common_params
 			{"deepest-idle-state",	required_argument,	0, '\4'},
 			{"on-threshold",	required_argument,	0, '\5'},
 			{"on-end",		required_argument,	0, '\6'},
+			{"bpf-action",		required_argument,	0, '\7'},
 			{0, 0, 0, 0}
 		};
 
@@ -1062,6 +1064,9 @@ static struct common_params
 				exit(EXIT_FAILURE);
 			}
 			break;
+		case '\7':
+			params->bpf_action_program = optarg;
+			break;
 		default:
 			timerlat_hist_usage("Invalid option");
 		}
tools/tracing/rtla/src/timerlat_top.c +5 -0
index fc479a0dcb59..da5d5db1bc17 100644
@@ -521,6 +521,7 @@ static void timerlat_top_usage(char *usage)
 		"	     --deepest-idle-state n: only go down to idle state n on cpus used by timerlat to reduce exit from idle latency",
 		"	     --on-threshold <action>: define action to be executed at latency threshold, multiple are allowed",
 		"	     --on-end: define action to be executed at measurement end, multiple are allowed",
+		"	     --bpf-action <program>: load and execute BPF program when latency threshold is exceeded",
 		NULL,
 	};
 
@@ -603,6 +604,7 @@ static struct common_params
 			{"deepest-idle-state",	required_argument,	0, '8'},
 			{"on-threshold",	required_argument,	0, '9'},
 			{"on-end",		required_argument,	0, '\1'},
+			{"bpf-action",		required_argument,	0, '\2'},
 			{0, 0, 0, 0}
 		};
 
@@ -798,6 +800,9 @@ static struct common_params
 				exit(EXIT_FAILURE);
 			}
 			break;
+		case '\2':
+			params->bpf_action_program = optarg;
+			break;
 		default:
 			timerlat_top_usage("Invalid option");
 		}
Signature · 1 line
2.51.0
#5 lore raw
Quoted 6 lines · Tomas Glozar

Add option --bpf-action that allows the user to attach an external BPF program that will be executed via BPF tail call on latency threshold overflow.

Executing additional BPF code on latency threshold overflow allows doing doing low-latency and in-kernel troubleshooting of the cause of the

typo: double "doing"

Quoted 22 lines

overflow.

The option takes an argument, which is a path to a BPF ELF file expected to contain a function named "action_handler" in a section named "tp/timerlat_action" (the section is necessary for libbpf to assign the correct BPF program type to it).

---
 tools/tracing/rtla/src/timerlat.c      | 11 ++++++
 tools/tracing/rtla/src/timerlat.h      |  2 +-
 tools/tracing/rtla/src/timerlat_bpf.c  | 53 ++++++++++++++++++++++++++
 tools/tracing/rtla/src/timerlat_bpf.h  |  6 ++-
 tools/tracing/rtla/src/timerlat_hist.c |  5 +++
 tools/tracing/rtla/src/timerlat_top.c  |  5 +++
 6 files changed, 80 insertions(+), 2 deletions(-)
tools/tracing/rtla/src/timerlat.c +0 -0
index b69212874127..6907a323f9ec 100644

tools/tracing/rtla/src/timerlat.c timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params) · line 54

Quoted 7 lines
tools/tracing/rtla/src/timerlat.c +4 -0
@@ -48,6 +48,17 @@ timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
 		}
 	}
 
+	/* Check if BPF action program is requested but BPF is not available */
+	if (params->bpf_action_program) {
+		if (params->mode == TRACING_MODE_TRACEFS) {
+			err_msg("BPF actions are not supported in tracefs-only mode\n");

I would just emit a warning to the user and proceed ignoring the bpf action argument.

Quoted 190 lines
tools/tracing/rtla/src/timerlat.c +7 -0
+			goto out_err;
+		}
+
+		if (timerlat_load_bpf_action_program(params->bpf_action_program))
+			goto out_err;
+	}
+
 	if (params->mode != TRACING_MODE_BPF) {
 		/*
 		 * In tracefs and mixed mode, timerlat tracer handles stopping
tools/tracing/rtla/src/timerlat.h +1 -1
index fd6065f48bb7..8dd5d134ce08 100644
@@ -27,6 +27,7 @@ struct timerlat_params {
 	int			dump_tasks;
 	int			deepest_idle_state;
 	enum timerlat_tracing_mode mode;
+	const char		*bpf_action_program;
 };
 
 #define to_timerlat_params(ptr) container_of(ptr, struct timerlat_params, common)
@@ -36,4 +37,3 @@ int timerlat_main(int argc, char *argv[]);
 int timerlat_enable(struct osnoise_tool *tool);
 void timerlat_analyze(struct osnoise_tool *tool, bool stopped);
 void timerlat_free(struct osnoise_tool *tool);
-
tools/tracing/rtla/src/timerlat_bpf.c +53 -0
index 1d619e502c65..05adf18303df 100644
@@ -7,6 +7,10 @@
 
 static struct timerlat_bpf *bpf;
 
+/* BPF object and program for action program */
+static struct bpf_object *obj;
+static struct bpf_program *prog;
+
 /*
  * timerlat_bpf_init - load and initialize BPF program to collect timerlat data
  */
@@ -96,6 +100,11 @@ void timerlat_bpf_detach(void)
 void timerlat_bpf_destroy(void)
 {
 	timerlat_bpf__destroy(bpf);
+	bpf = NULL;
+	if (obj)
+		bpf_object__close(obj);
+	obj = NULL;
+	prog = NULL;
 }
 
 static int handle_rb_event(void *ctx, void *data, size_t data_sz)
@@ -190,4 +199,48 @@ int timerlat_bpf_get_summary_value(enum summary_field key,
 			 bpf->maps.summary_user,
 			 key, value_irq, value_thread, value_user, cpus);
 }
+
+/*
+ * timerlat_load_bpf_action_program - load and register a BPF action program
+ */
+int timerlat_load_bpf_action_program(const char *program_path)
+{
+	int err;
+
+	obj = bpf_object__open_file(program_path, NULL);
+	if (!obj) {
+		err_msg("Failed to open BPF action program: %s\n", program_path);
+		goto out_err;
+	}
+
+	err = bpf_object__load(obj);
+	if (err) {
+		err_msg("Failed to load BPF action program: %s\n", program_path);
+		goto out_obj_err;
+	}
+
+	prog = bpf_object__find_program_by_name(obj, "action_handler");
+	if (!prog) {
+		err_msg("BPF action program must have 'action_handler' function: %s\n",
+			program_path);
+		goto out_obj_err;
+	}
+
+	err = timerlat_bpf_set_action(prog);
+	if (err) {
+		err_msg("Failed to register BPF action program: %s\n", program_path);
+		goto out_prog_err;
+	}
+
+	return 0;
+
+out_prog_err:
+	prog = NULL;
+out_obj_err:
+	bpf_object__close(obj);
+	obj = NULL;
+out_err:
+	return 1;
+}
+
 #endif /* HAVE_BPF_SKEL */
tools/tracing/rtla/src/timerlat_bpf.h +5 -1
index b5009092c7a3..169abeaf4363 100644
@@ -30,7 +30,7 @@ int timerlat_bpf_get_summary_value(enum summary_field key,
 				   long long *value_thread,
 				   long long *value_user,
 				   int cpus);
-
+int timerlat_load_bpf_action_program(const char *program_path);
 static inline int have_libbpf_support(void) { return 1; }
 #else
 static inline int timerlat_bpf_init(struct timerlat_params *params)
@@ -58,6 +58,10 @@ static inline int timerlat_bpf_get_summary_value(enum summary_field key,
 {
 	return -1;
 }
+static inline int timerlat_load_bpf_action_program(const char *program_path)
+{
+	return -1;
+}
 static inline int have_libbpf_support(void) { return 0; }
 #endif /* HAVE_BPF_SKEL */
 #endif /* __bpf__ */
tools/tracing/rtla/src/timerlat_hist.c +5 -0
index 606c1688057b..5e639cc34f64 100644
@@ -763,6 +763,7 @@ static void timerlat_hist_usage(char *usage)
 		"	     --deepest-idle-state n: only go down to idle state n on cpus used by timerlat to reduce exit from idle latency",
 		"	     --on-threshold <action>: define action to be executed at latency threshold, multiple are allowed",
 		"	     --on-end <action>: define action to be executed at measurement end, multiple are allowed",
+		"	     --bpf-action <program>: load and execute BPF program when latency threshold is exceeded",
 		NULL,
 	};
 
@@ -853,6 +854,7 @@ static struct common_params
 			{"deepest-idle-state",	required_argument,	0, '\4'},
 			{"on-threshold",	required_argument,	0, '\5'},
 			{"on-end",		required_argument,	0, '\6'},
+			{"bpf-action",		required_argument,	0, '\7'},
 			{0, 0, 0, 0}
 		};
 
@@ -1062,6 +1064,9 @@ static struct common_params
 				exit(EXIT_FAILURE);
 			}
 			break;
+		case '\7':
+			params->bpf_action_program = optarg;
+			break;
 		default:
 			timerlat_hist_usage("Invalid option");
 		}
tools/tracing/rtla/src/timerlat_top.c +5 -0
index fc479a0dcb59..da5d5db1bc17 100644
@@ -521,6 +521,7 @@ static void timerlat_top_usage(char *usage)
 		"	     --deepest-idle-state n: only go down to idle state n on cpus used by timerlat to reduce exit from idle latency",
 		"	     --on-threshold <action>: define action to be executed at latency threshold, multiple are allowed",
 		"	     --on-end: define action to be executed at measurement end, multiple are allowed",
+		"	     --bpf-action <program>: load and execute BPF program when latency threshold is exceeded",
 		NULL,
 	};
 
@@ -603,6 +604,7 @@ static struct common_params
 			{"deepest-idle-state",	required_argument,	0, '8'},
 			{"on-threshold",	required_argument,	0, '9'},
 			{"on-end",		required_argument,	0, '\1'},
+			{"bpf-action",		required_argument,	0, '\2'},
 			{0, 0, 0, 0}
 		};
 
@@ -798,6 +800,9 @@ static struct common_params
 				exit(EXIT_FAILURE);
 			}
 			break;
+		case '\2':
+			params->bpf_action_program = optarg;
+			break;
 		default:
 			timerlat_top_usage("Invalid option");
 		}
Signature · 1 line
2.51.0
author maintainer
#6 lore raw

po 3. 11. 2025 v 15:45 odesílatel Wander Lairson Costa <[email protected]> napsal:

Quoted 6 lines
Quoted 3 lines

Executing additional BPF code on latency threshold overflow allows doing doing low-latency and in-kernel troubleshooting of the cause of the

typo: double "doing"

Thanks, I'll fix that :)

Quoted 6 lines
Quoted 6 lines
tools/tracing/rtla/src/timerlat.c +0 -0
@@ -48,6 +48,17 @@ timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
              }
      }
 
Quoted 7 lines

tools/tracing/rtla/src/timerlat.c timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params) · line 54

Quoted 4 lines
tools/tracing/rtla/src/timerlat.c +4 -0
+     /* Check if BPF action program is requested but BPF is not available */
+     if (params->bpf_action_program) {
+             if (params->mode == TRACING_MODE_TRACEFS) {
+                     err_msg("BPF actions are not supported in tracefs-only mode\n");

I would just emit a warning to the user and proceed ignoring the bpf action argument.

I believe if the user explicitly requests BPF actions to be used, measurement should not proceed without the action. Imagine someone setting --bpf-action in an automated test, expecting it to report something. But the action never fires, because they do not notice they are running an old kernel that does not support this.

The user can always restart/reconfigure RTLA to skip the option.

Tomas

#7 lore raw
Quoted 26 lines · Tomas Glozar

po 3. 11. 2025 v 15:45 odesílatel Wander Lairson Costa <[email protected]> napsal:

Quoted 6 lines
Quoted 3 lines

Executing additional BPF code on latency threshold overflow allows doing doing low-latency and in-kernel troubleshooting of the cause of the

typo: double "doing"

Thanks, I'll fix that :)

Quoted 6 lines
Quoted 6 lines
tools/tracing/rtla/src/timerlat.c +0 -0
@@ -48,6 +48,17 @@ timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
              }
      }
 
Quoted 7 lines

tools/tracing/rtla/src/timerlat.c timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params) · line 54

Quoted 4 lines
tools/tracing/rtla/src/timerlat.c +4 -0
+     /* Check if BPF action program is requested but BPF is not available */
+     if (params->bpf_action_program) {
+             if (params->mode == TRACING_MODE_TRACEFS) {
+                     err_msg("BPF actions are not supported in tracefs-only mode\n");

I would just emit a warning to the user and proceed ignoring the bpf action argument.

Quoted 8 lines

I believe if the user explicitly requests BPF actions to be used, measurement should not proceed without the action. Imagine someone setting --bpf-action in an automated test, expecting it to report something. But the action never fires, because they do not notice they are running an old kernel that does not support this.

The user can always restart/reconfigure RTLA to skip the option.

I was thinking in a more interactive debug session where you go back and forth with little changes in the command line. But you have a good point.

Quoted 2 lines

Tomas

author maintainer
#8 lore raw

PATCH v3 3/7 rtla/timerlat: Add example for BPF action program

In reply to Tomas Glozar

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.

---
 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%)
tools/tracing/rtla/Makefile +8 -1
index 746ccf2f5808..5f1529ce3693 100644
@@ -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
tools/tracing/rtla/example/timerlat_bpf_action.c new file +16 -0
new file mode 100644
index 000000000000..ac1be049a848
@@ -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;
+}
tools/tracing/rtla/example/timerlat_load.py renamed from tools/tracing/rtla/sample/timerlat_load.py +0 -0
similarity index 100%
rename from tools/tracing/rtla/sample/timerlat_load.py
rename to tools/tracing/rtla/example/timerlat_load.py
Signature · 1 line
2.51.0
author maintainer
#9 lore raw

PATCH v3 4/7 rtla/tests: Test BPF action program

In reply to Tomas Glozar

Add a test that implements a BPF program writing to a test map, which is attached to RTLA via --bpf-action to be executed on theshold overflow.

A combination of --on-threshold shell with bpftool (which is always present if BPF support is enabled) is used to check whether the BPF program has executed successfully.

---
 tools/tracing/rtla/Makefile                   | 10 ++++++--
 tools/tracing/rtla/tests/bpf/bpf_action_map.c | 25 +++++++++++++++++++
 tools/tracing/rtla/tests/timerlat.t           | 15 +++++++++++
 3 files changed, 48 insertions(+), 2 deletions(-)
 create mode 100644 tools/tracing/rtla/tests/bpf/bpf_action_map.c
tools/tracing/rtla/Makefile +8 -2
index 5f1529ce3693..aef814b639b7 100644
@@ -76,12 +76,18 @@ src/timerlat.skel.h: src/timerlat.bpf.o
 
 example/timerlat_bpf_action.o: example/timerlat_bpf_action.c
 	$(QUIET_CLANG)$(CLANG) -g -O2 -target bpf -c $(filter %.c,$^) -o $@
+
+tests/bpf/bpf_action_map.o: tests/bpf/bpf_action_map.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"
+
+tests/bpf/bpf_action_map.o: tests/bpf/bpf_action_map.c
+	$(Q)echo "BPF skeleton support is disabled, skipping tests/bpf/bpf_action_map.o"
 endif
 
 $(RTLA): $(RTLA_IN)
@@ -103,7 +109,7 @@ clean: doc_clean fixdep-clean
 	$(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 example/timerlat_bpf_action.o
-check: $(RTLA)
-	RTLA=$(RTLA) prove -o -f tests/
+check: $(RTLA) tests/bpf/bpf_action_map.o
+	RTLA=$(RTLA) BPFTOOL=$(SYSTEM_BPFTOOL) prove -o -f tests/
 examples: example/timerlat_bpf_action.o
 .PHONY: FORCE clean check
tools/tracing/rtla/tests/bpf/bpf_action_map.c new file +25 -0
new file mode 100644
index 000000000000..1686e0b858e6
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_tracing.h>
+
+char LICENSE[] SEC("license") = "GPL";
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 1);
+	__type(key, unsigned int);
+	__type(value, unsigned long long);
+} rtla_test_map SEC(".maps");
+
+struct trace_event_raw_timerlat_sample;
+
+SEC("tp/timerlat_action")
+int action_handler(struct trace_event_raw_timerlat_sample *tp_args)
+{
+	unsigned int key = 0;
+	unsigned long long value = 42;
+
+	bpf_map_update_elem(&rtla_test_map, &key, &value, BPF_ANY);
+
+	return 0;
+}
tools/tracing/rtla/tests/timerlat.t +15 -0
index b5d1e7260a9b..89e28cc6df82 100644
@@ -67,6 +67,21 @@ check "hist with trace output at end" \
 	"timerlat hist -d 1s --on-end trace" 0 "^  Saving trace to timerlat_trace.txt$"
 check "top with trace output at end" \
 	"timerlat top -d 1s --on-end trace" 0 "^  Saving trace to timerlat_trace.txt$"
+
+# BPF action program tests
+if [ "$option" -eq 0 ]
+then
+	# Test BPF action program properly in BPF mode
+	[ -z "$BPFTOOL" ] && BPFTOOL=bpftool
+	check "hist with BPF action program (BPF mode)" \
+		"timerlat hist -T 2 --bpf-action tests/bpf/bpf_action_map.o --on-threshold shell,command='$BPFTOOL map dump name rtla_test_map'" \
+		2 '"value": 42'
+else
+	# Test BPF action program failure in non-BPF mode
+	check "hist with BPF action program (non-BPF mode)" \
+		"timerlat hist -T 2 --bpf-action tests/bpf/bpf_action_map.o" \
+		1 "BPF actions are not supported in tracefs-only mode"
+fi
 done
 
 test_end
Signature · 1 line
2.51.0
#10 lore raw

Re: [PATCH v3 4/7] rtla/tests: Test BPF action program

Quoted 22 lines · Tomas Glozar

Add a test that implements a BPF program writing to a test map, which is attached to RTLA via --bpf-action to be executed on theshold overflow.

A combination of --on-threshold shell with bpftool (which is always present if BPF support is enabled) is used to check whether the BPF program has executed successfully.

---
 tools/tracing/rtla/Makefile                   | 10 ++++++--
 tools/tracing/rtla/tests/bpf/bpf_action_map.c | 25 +++++++++++++++++++
 tools/tracing/rtla/tests/timerlat.t           | 15 +++++++++++
 3 files changed, 48 insertions(+), 2 deletions(-)
 create mode 100644 tools/tracing/rtla/tests/bpf/bpf_action_map.c
tools/tracing/rtla/Makefile +0 -0
index 5f1529ce3693..aef814b639b7 100644

tools/tracing/rtla/Makefile src/timerlat.skel.h: src/timerlat.bpf.o · line 78

Quoted 3 lines
tools/tracing/rtla/Makefile +0 -0
@@ -76,12 +76,18 @@ src/timerlat.skel.h: src/timerlat.bpf.o
 
 example/timerlat_bpf_action.o: example/timerlat_bpf_action.c
 	$(QUIET_CLANG)$(CLANG) -g -O2 -target bpf -c $(filter %.c,$^) -o $@

I didn't understand why the filter function is needed. $< or $^ seems enough.

tools/tracing/rtla/Makefile src/timerlat.skel.h: src/timerlat.bpf.o · line 90

Quoted 12 lines
tools/tracing/rtla/Makefile +6 -0
+
+tests/bpf/bpf_action_map.o: tests/bpf/bpf_action_map.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"
+
+tests/bpf/bpf_action_map.o: tests/bpf/bpf_action_map.c
+	$(Q)echo "BPF skeleton support is disabled, skipping tests/bpf/bpf_action_map.o"

Why not just not creating the targets if BPF is not enabled?

tools/tracing/rtla/Makefile clean: doc_clean fixdep-clean · line 112

Quoted 10 lines
tools/tracing/rtla/Makefile +1 -2
 endif
 
 $(RTLA): $(RTLA_IN)
@@ -103,7 +109,7 @@ clean: doc_clean fixdep-clean
 	$(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 example/timerlat_bpf_action.o
-check: $(RTLA)
-	RTLA=$(RTLA) prove -o -f tests/
+check: $(RTLA) tests/bpf/bpf_action_map.o

Will this work if BPF is disabled?

Quoted 63 lines
tools/tracing/rtla/Makefile +1 -0
+	RTLA=$(RTLA) BPFTOOL=$(SYSTEM_BPFTOOL) prove -o -f tests/
 examples: example/timerlat_bpf_action.o
 .PHONY: FORCE clean check
tools/tracing/rtla/tests/bpf/bpf_action_map.c new file +25 -0
new file mode 100644
index 000000000000..1686e0b858e6
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_tracing.h>
+
+char LICENSE[] SEC("license") = "GPL";
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 1);
+	__type(key, unsigned int);
+	__type(value, unsigned long long);
+} rtla_test_map SEC(".maps");
+
+struct trace_event_raw_timerlat_sample;
+
+SEC("tp/timerlat_action")
+int action_handler(struct trace_event_raw_timerlat_sample *tp_args)
+{
+	unsigned int key = 0;
+	unsigned long long value = 42;
+
+	bpf_map_update_elem(&rtla_test_map, &key, &value, BPF_ANY);
+
+	return 0;
+}
tools/tracing/rtla/tests/timerlat.t +15 -0
index b5d1e7260a9b..89e28cc6df82 100644
@@ -67,6 +67,21 @@ check "hist with trace output at end" \
 	"timerlat hist -d 1s --on-end trace" 0 "^  Saving trace to timerlat_trace.txt$"
 check "top with trace output at end" \
 	"timerlat top -d 1s --on-end trace" 0 "^  Saving trace to timerlat_trace.txt$"
+
+# BPF action program tests
+if [ "$option" -eq 0 ]
+then
+	# Test BPF action program properly in BPF mode
+	[ -z "$BPFTOOL" ] && BPFTOOL=bpftool
+	check "hist with BPF action program (BPF mode)" \
+		"timerlat hist -T 2 --bpf-action tests/bpf/bpf_action_map.o --on-threshold shell,command='$BPFTOOL map dump name rtla_test_map'" \
+		2 '"value": 42'
+else
+	# Test BPF action program failure in non-BPF mode
+	check "hist with BPF action program (non-BPF mode)" \
+		"timerlat hist -T 2 --bpf-action tests/bpf/bpf_action_map.o" \
+		1 "BPF actions are not supported in tracefs-only mode"
+fi
 done
 
 test_end
Signature · 1 line
2.51.0
author maintainer
#11 lore raw

Re: [PATCH v3 4/7] rtla/tests: Test BPF action program

po 3. 11. 2025 v 16:10 odesílatel Wander Lairson Costa <[email protected]> napsal:

Quoted 6 lines
Quoted 6 lines
tools/tracing/rtla/Makefile +0 -0
index 5f1529ce3693..aef814b639b7 100644
@@ -76,12 +76,18 @@ src/timerlat.skel.h: src/timerlat.bpf.o
 
Quoted 6 lines

tools/tracing/rtla/Makefile src/timerlat.skel.h: src/timerlat.bpf.o · line 78

Quoted 2 lines
tools/tracing/rtla/Makefile +0 -0
 example/timerlat_bpf_action.o: example/timerlat_bpf_action.c
      $(QUIET_CLANG)$(CLANG) -g -O2 -target bpf -c $(filter %.c,$^) -o $@

I didn't understand why the filter function is needed. $< or $^ seems enough.

Ah, good catch. The filter is copied from the Makefile of stalld, which includes a "vmlinux.h" in the targets. That makes the filter needed, to prevent passing of the header file to the C compiler. It is not needed here.

Quoted 7 lines
Quoted 7 lines
tools/tracing/rtla/Makefile +3 -0
+
+tests/bpf/bpf_action_map.o: tests/bpf/bpf_action_map.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
 
Quoted 8 lines

tools/tracing/rtla/Makefile src/timerlat.skel.h: src/timerlat.bpf.o · line 90

Quoted 5 lines
tools/tracing/rtla/Makefile +3 -0
 example/timerlat_bpf_action.o: example/timerlat_bpf_action.c
      $(Q)echo "BPF skeleton support is disabled, skipping example/timerlat_bpf_action.o"
+
+tests/bpf/bpf_action_map.o: tests/bpf/bpf_action_map.c
+     $(Q)echo "BPF skeleton support is disabled, skipping tests/bpf/bpf_action_map.o"

Why not just not creating the targets if BPF is not enabled?

I could do that, but then, I would have to duplicate the check target.

Quoted 13 lines

tools/tracing/rtla/Makefile clean: doc_clean fixdep-clean · line 112

Quoted 10 lines
tools/tracing/rtla/Makefile +1 -2
 endif
 
 $(RTLA): $(RTLA_IN)
@@ -103,7 +109,7 @@ clean: doc_clean fixdep-clean
      $(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 example/timerlat_bpf_action.o
-check: $(RTLA)
-     RTLA=$(RTLA) prove -o -f tests/
+check: $(RTLA) tests/bpf/bpf_action_map.o

Will this work if BPF is disabled?

Yes, the bpf_action_map.o target will simply print the warning. You can try it with:

$ make BUILD_BPF_SKEL=0 check

Thank you for the review.

Tomas

author maintainer
#12 lore raw

PATCH v3 5/7 rtla/tests: Run Test::Harness in verbose mode

In reply to Tomas Glozar

Add -v flag to prove command to also print the names of tests that succeeded, not only those that failed, to allow easier debugging of the test suite.

Also, drop printing the option and value to stdout in check_with_osnoise_options, which was a debugging print that was accidentally left in the final commit, and which would be otherwise now visible in make check output, as stdout is no longer suppressed.

---
 tools/tracing/rtla/Makefile        | 2 +-
 tools/tracing/rtla/tests/engine.sh | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)
tools/tracing/rtla/Makefile +1 -1
index aef814b639b7..2701256abaf3 100644
@@ -110,6 +110,6 @@ clean: doc_clean fixdep-clean
 	$(Q)rm -rf feature
 	$(Q)rm -f src/timerlat.bpf.o src/timerlat.skel.h example/timerlat_bpf_action.o
 check: $(RTLA) tests/bpf/bpf_action_map.o
-	RTLA=$(RTLA) BPFTOOL=$(SYSTEM_BPFTOOL) prove -o -f tests/
+	RTLA=$(RTLA) BPFTOOL=$(SYSTEM_BPFTOOL) prove -o -f -v tests/
 examples: example/timerlat_bpf_action.o
 .PHONY: FORCE clean check
tools/tracing/rtla/tests/engine.sh +0 -1
index c7de3d6ed6a8..ed261e07c6d9 100644
@@ -105,7 +105,6 @@ check_with_osnoise_options() {
 			[ "$1" == "" ] && continue
 			option=$(echo $1 | cut -d '=' -f 1)
 			value=$(echo $1 | cut -d '=' -f 2)
-			echo "option: $option, value: $value"
 			echo "$value" > "/sys/kernel/tracing/osnoise/$option" || return 1
 		done
 	fi
Signature · 1 line
2.51.0
Reviewed-by on v3 5/7
#13 lore raw

Re: [PATCH v3 5/7] rtla/tests: Run Test::Harness in verbose mode

Quoted 43 lines · Tomas Glozar

Add -v flag to prove command to also print the names of tests that succeeded, not only those that failed, to allow easier debugging of the test suite.

Also, drop printing the option and value to stdout in check_with_osnoise_options, which was a debugging print that was accidentally left in the final commit, and which would be otherwise now visible in make check output, as stdout is no longer suppressed.

---
 tools/tracing/rtla/Makefile        | 2 +-
 tools/tracing/rtla/tests/engine.sh | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)
tools/tracing/rtla/Makefile +1 -1
index aef814b639b7..2701256abaf3 100644
@@ -110,6 +110,6 @@ clean: doc_clean fixdep-clean
 	$(Q)rm -rf feature
 	$(Q)rm -f src/timerlat.bpf.o src/timerlat.skel.h example/timerlat_bpf_action.o
 check: $(RTLA) tests/bpf/bpf_action_map.o
-	RTLA=$(RTLA) BPFTOOL=$(SYSTEM_BPFTOOL) prove -o -f tests/
+	RTLA=$(RTLA) BPFTOOL=$(SYSTEM_BPFTOOL) prove -o -f -v tests/
 examples: example/timerlat_bpf_action.o
 .PHONY: FORCE clean check
tools/tracing/rtla/tests/engine.sh +0 -1
index c7de3d6ed6a8..ed261e07c6d9 100644
@@ -105,7 +105,6 @@ check_with_osnoise_options() {
 			[ "$1" == "" ] && continue
 			option=$(echo $1 | cut -d '=' -f 1)
 			value=$(echo $1 | cut -d '=' -f 2)
-			echo "option: $option, value: $value"
 			echo "$value" > "/sys/kernel/tracing/osnoise/$option" || return 1
 		done
 	fi
Signature · 1 line
2.51.0
author maintainer
#14 lore raw

PATCH v3 6/7 Documentation/rtla: Rename sample/ to example/

In reply to Tomas Glozar

The sample/ directory in tools/tracing/rtla was renamed to example/ in an earlier commit.

Rename it also in the documentation.

---
 Documentation/tools/rtla/common_timerlat_options.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/tools/rtla/common_timerlat_options.rst +1 -1
index 1f5d024b53aa..c6046fcf52dc 100644
@@ -64,4 +64,4 @@
 
         Set timerlat to run without workload, waiting for the user to dispatch a per-cpu
         task that waits for a new period on the tracing/osnoise/per_cpu/cpu$ID/timerlat_fd.
-        See linux/tools/rtla/sample/timerlat_load.py for an example of user-load code.
+        See linux/tools/rtla/example/timerlat_load.py for an example of user-load code.
Signature · 1 line
2.51.0
Reviewed-by on v3 6/7
#15 lore raw

Re: [PATCH v3 6/7] Documentation/rtla: Rename sample/ to example/

Quoted 23 lines · Tomas Glozar

The sample/ directory in tools/tracing/rtla was renamed to example/ in an earlier commit.

Rename it also in the documentation.

---
 Documentation/tools/rtla/common_timerlat_options.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/tools/rtla/common_timerlat_options.rst +1 -1
index 1f5d024b53aa..c6046fcf52dc 100644
@@ -64,4 +64,4 @@
 
         Set timerlat to run without workload, waiting for the user to dispatch a per-cpu
         task that waits for a new period on the tracing/osnoise/per_cpu/cpu$ID/timerlat_fd.
-        See linux/tools/rtla/sample/timerlat_load.py for an example of user-load code.
+        See linux/tools/rtla/example/timerlat_load.py for an example of user-load code.
Signature · 1 line
2.51.0
author maintainer
#16 lore raw

PATCH v3 7/7 Documentation/rtla: Document --bpf-action option

In reply to Tomas Glozar

Add new option --bpf-action into common_timerlat_options.txt, including the format in which it takes the BPF program, and a reference to an example.

---
 .../tools/rtla/common_timerlat_options.rst    | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/tools/rtla/common_timerlat_options.rst +20 -0
index c6046fcf52dc..7e08a27e87fe 100644
@@ -65,3 +65,23 @@
         Set timerlat to run without workload, waiting for the user to dispatch a per-cpu
         task that waits for a new period on the tracing/osnoise/per_cpu/cpu$ID/timerlat_fd.
         See linux/tools/rtla/example/timerlat_load.py for an example of user-load code.
+
+**--bpf-action** *bpf-program*
+
+        Loads a BPF program from an ELF file and executes it when a latency threshold is exceeded.
+
+        The BPF program must be a valid ELF file loadable with libbpf. The program must contain
+        a function named ``action_handler``, declared with ``SEC("tp/timerlat_action")`` or
+        a different section name beginning with "tp/". This tells libbpf that the program type is
+        BPF_PROG_TYPE_TRACEPOINT, without it, the program will not be loaded properly.
+
+        The program receives a ``struct trace_event_raw_timerlat_sample`` parameter
+        containing timerlat sample data.
+
+        An example is provided in ``tools/tracing/rtla/example/timerlat_bpf_action.c``.
+        This example demonstrates how to create a BPF program that prints latency information using
+        bpf_trace_printk() when a threshold is exceeded.
+
+        **Note**: BPF actions require BPF support to be available. If BPF is not available
+        or disabled, the tool will fall back to tracefs mode and BPF actions will not be
+        supported.
Signature · 1 line
2.51.0
#17 lore raw

Re: [PATCH v3 7/7] Documentation/rtla: Document --bpf-action option

Quoted 15 lines · Tomas Glozar

Add new option --bpf-action into common_timerlat_options.txt, including the format in which it takes the BPF program, and a reference to an example.

---
 .../tools/rtla/common_timerlat_options.rst    | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/tools/rtla/common_timerlat_options.rst +0 -0
index c6046fcf52dc..7e08a27e87fe 100644
@@ -65,3 +65,23 @@
         Set timerlat to run without workload, waiting for the user to dispatch a per-cpu

Documentation/tools/rtla/common_timerlat_options.rst line 75

Quoted 10 lines
Documentation/tools/rtla/common_timerlat_options.rst +8 -0
         task that waits for a new period on the tracing/osnoise/per_cpu/cpu$ID/timerlat_fd.
         See linux/tools/rtla/example/timerlat_load.py for an example of user-load code.
+
+**--bpf-action** *bpf-program*
+
+        Loads a BPF program from an ELF file and executes it when a latency threshold is exceeded.
+
+        The BPF program must be a valid ELF file loadable with libbpf. The program must contain
+        a function named ``action_handler``, declared with ``SEC("tp/timerlat_action")`` or
+        a different section name beginning with "tp/". This tells libbpf that the program type is

nit: simply document that the section name must start with "tp/", the part saying about "tp/timerlat_action" seems redudant, IIUC.

Quoted 15 lines
Documentation/tools/rtla/common_timerlat_options.rst +12 -0
+        BPF_PROG_TYPE_TRACEPOINT, without it, the program will not be loaded properly.
+
+        The program receives a ``struct trace_event_raw_timerlat_sample`` parameter
+        containing timerlat sample data.
+
+        An example is provided in ``tools/tracing/rtla/example/timerlat_bpf_action.c``.
+        This example demonstrates how to create a BPF program that prints latency information using
+        bpf_trace_printk() when a threshold is exceeded.
+
+        **Note**: BPF actions require BPF support to be available. If BPF is not available
+        or disabled, the tool will fall back to tracefs mode and BPF actions will not be
+        supported.
Signature · 1 line
2.51.0
Reviewed-by on the v3 series
#18 lore raw
In reply to Tomas Glozar
Quoted 7 lines · Tomas Glozar

This patchset extends rtla-timerlat's BPF support with the option of executing a user-supplied BPF program on latency threshold overflow.

See the supplied example and documentation for how to create a program. bpf_tail_call() is used to chain the program with the built-in BPF sample collection program, if the threshold is hit.

Quoted 7 lines

The feature can be used for both in-kernel data collection and sending signals to userspace directly from the kernel, if the kernel version allows it.

Note: The patchset will have to be rebased on top of [1], or vice versa, since they both touch stop_tracing() ([1] adds one call of it, and this patchset adds an extra argument to it).

Probably best to add an updated version of that patch to this patchset.

Quoted 3 lines

v3 changes:
- Add tests/bpf/bpf_action_map.c to test commit (forgot to run git add before).

Might be nice to build that as part of "all", for the sake of people running the tests directly (FWIW, I still don't see anything in the makefile or engine.sh documenting how to satisfy that dependency).

In any case:

-Crystal