Skip to content

Commit 3b78670

Browse files
lenticularis39rostedt
authored andcommitted
rtla/timerlat_bpf: Allow resuming tracing
Currently, rtla-timerlat BPF program uses a global variable stored in a .bss section to store whether tracing has been stopped. Move the information to a separate map, so that it is easily writable from userspace, and add a function that clears the value, resuming tracing after it has been stopped. Cc: John Kacur <[email protected]> Cc: Luis Goncalves <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Chang Yin <[email protected]> Cc: Costa Shulyupin <[email protected]> Cc: Crystal Wood <[email protected]> Cc: Gabriele Monaco <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Tomas Glozar <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 6ea082b commit 3b78670

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

tools/tracing/rtla/src/timerlat.bpf.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ struct {
2828
__type(value, unsigned long long);
2929
} summary_irq SEC(".maps"), summary_thread SEC(".maps"), summary_user SEC(".maps");
3030

31+
struct {
32+
__uint(type, BPF_MAP_TYPE_ARRAY);
33+
__uint(max_entries, 1);
34+
__type(key, unsigned int);
35+
__type(value, unsigned long long);
36+
} stop_tracing SEC(".maps");
37+
3138
struct {
3239
__uint(type, BPF_MAP_TYPE_RINGBUF);
3340
__uint(max_entries, 1);
@@ -41,8 +48,6 @@ const volatile int irq_threshold;
4148
const volatile int thread_threshold;
4249
const volatile bool aa_only;
4350

44-
int stop_tracing;
45-
4651
nosubprog unsigned long long map_get(void *map,
4752
unsigned int key)
4853
{
@@ -109,7 +114,7 @@ nosubprog void set_stop_tracing(void)
109114
int value = 0;
110115

111116
/* Suppress further sample processing */
112-
stop_tracing = 1;
117+
map_set(&stop_tracing, 0, 1);
113118

114119
/* Signal to userspace */
115120
bpf_ringbuf_output(&signal_stop_tracing, &value, sizeof(value), 0);
@@ -121,7 +126,7 @@ int handle_timerlat_sample(struct trace_event_raw_timerlat_sample *tp_args)
121126
unsigned long long latency, latency_us;
122127
int bucket;
123128

124-
if (stop_tracing)
129+
if (map_get(&stop_tracing, 0))
125130
return 0;
126131

127132
latency = tp_args->timer_latency / output_divisor;

tools/tracing/rtla/src/timerlat_bpf.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ int timerlat_bpf_wait(int timeout)
106106
return retval;
107107
}
108108

109+
/*
110+
* timerlat_bpf_restart_tracing - restart stopped tracing
111+
*/
112+
int timerlat_bpf_restart_tracing(void)
113+
{
114+
unsigned int key = 0;
115+
unsigned long long value = 0;
116+
117+
return bpf_map__update_elem(bpf->maps.stop_tracing,
118+
&key, sizeof(key),
119+
&value, sizeof(value), BPF_ANY);
120+
}
121+
109122
static int get_value(struct bpf_map *map_irq,
110123
struct bpf_map *map_thread,
111124
struct bpf_map *map_user,

tools/tracing/rtla/src/timerlat_bpf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int timerlat_bpf_attach(void);
1818
void timerlat_bpf_detach(void);
1919
void timerlat_bpf_destroy(void);
2020
int timerlat_bpf_wait(int timeout);
21+
int timerlat_bpf_restart_tracing(void);
2122
int timerlat_bpf_get_hist_value(int key,
2223
long long *value_irq,
2324
long long *value_thread,
@@ -28,6 +29,7 @@ int timerlat_bpf_get_summary_value(enum summary_field key,
2829
long long *value_thread,
2930
long long *value_user,
3031
int cpus);
32+
3133
static inline int have_libbpf_support(void) { return 1; }
3234
#else
3335
static inline int timerlat_bpf_init(struct timerlat_params *params)
@@ -38,6 +40,7 @@ static inline int timerlat_bpf_attach(void) { return -1; }
3840
static inline void timerlat_bpf_detach(void) { };
3941
static inline void timerlat_bpf_destroy(void) { };
4042
static inline int timerlat_bpf_wait(int timeout) { return -1; }
43+
static inline int timerlat_bpf_restart_tracing(void) { return -1; };
4144
static inline int timerlat_bpf_get_hist_value(int key,
4245
long long *value_irq,
4346
long long *value_thread,

0 commit comments

Comments
 (0)