mirror of
https://github.com/torvalds/linux.git
synced 2026-05-28 09:04:39 +02:00
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. Link: https://lore.kernel.org/r/20251126144205.331954-2-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
This commit is contained in:
parent
a08e012e81
commit
8cd0f08ac7
|
|
@ -40,6 +40,17 @@ struct {
|
||||||
__uint(max_entries, 1);
|
__uint(max_entries, 1);
|
||||||
} signal_stop_tracing SEC(".maps");
|
} 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 */
|
/* Params to be set by rtla */
|
||||||
const volatile int bucket_size = 1;
|
const volatile int bucket_size = 1;
|
||||||
const volatile int output_divisor = 1000;
|
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);
|
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;
|
int value = 0;
|
||||||
|
|
||||||
|
|
@ -118,6 +129,12 @@ nosubprog void set_stop_tracing(void)
|
||||||
|
|
||||||
/* Signal to userspace */
|
/* Signal to userspace */
|
||||||
bpf_ringbuf_output(&signal_stop_tracing, &value, sizeof(value), 0);
|
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")
|
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);
|
update_summary(&summary_irq, latency, bucket);
|
||||||
|
|
||||||
if (irq_threshold != 0 && latency_us >= irq_threshold)
|
if (irq_threshold != 0 && latency_us >= irq_threshold)
|
||||||
set_stop_tracing();
|
set_stop_tracing(tp_args);
|
||||||
} else if (tp_args->context == 1) {
|
} else if (tp_args->context == 1) {
|
||||||
update_main_hist(&hist_thread, bucket);
|
update_main_hist(&hist_thread, bucket);
|
||||||
update_summary(&summary_thread, latency, bucket);
|
update_summary(&summary_thread, latency, bucket);
|
||||||
|
|
||||||
if (thread_threshold != 0 && latency_us >= thread_threshold)
|
if (thread_threshold != 0 && latency_us >= thread_threshold)
|
||||||
set_stop_tracing();
|
set_stop_tracing(tp_args);
|
||||||
} else {
|
} else {
|
||||||
update_main_hist(&hist_user, bucket);
|
update_main_hist(&hist_user, bucket);
|
||||||
update_summary(&summary_user, latency, bucket);
|
update_summary(&summary_user, latency, bucket);
|
||||||
|
|
||||||
if (thread_threshold != 0 && latency_us >= thread_threshold)
|
if (thread_threshold != 0 && latency_us >= thread_threshold)
|
||||||
set_stop_tracing();
|
set_stop_tracing(tp_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,19 @@ int timerlat_bpf_init(struct timerlat_params *params)
|
||||||
return 0;
|
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
|
* timerlat_bpf_attach - attach BPF program to collect timerlat data
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ enum summary_field {
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef __bpf__
|
#ifndef __bpf__
|
||||||
|
#include <bpf/libbpf.h>
|
||||||
#ifdef HAVE_BPF_SKEL
|
#ifdef HAVE_BPF_SKEL
|
||||||
int timerlat_bpf_init(struct timerlat_params *params);
|
int timerlat_bpf_init(struct timerlat_params *params);
|
||||||
int timerlat_bpf_attach(void);
|
int timerlat_bpf_attach(void);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user