|
7 | 7 |
|
8 | 8 | static struct timerlat_bpf *bpf; |
9 | 9 |
|
| 10 | +/* BPF object and program for action program */ |
| 11 | +static struct bpf_object *obj; |
| 12 | +static struct bpf_program *prog; |
| 13 | + |
10 | 14 | /* |
11 | 15 | * timerlat_bpf_init - load and initialize BPF program to collect timerlat data |
12 | 16 | */ |
@@ -96,6 +100,11 @@ void timerlat_bpf_detach(void) |
96 | 100 | void timerlat_bpf_destroy(void) |
97 | 101 | { |
98 | 102 | timerlat_bpf__destroy(bpf); |
| 103 | + bpf = NULL; |
| 104 | + if (obj) |
| 105 | + bpf_object__close(obj); |
| 106 | + obj = NULL; |
| 107 | + prog = NULL; |
99 | 108 | } |
100 | 109 |
|
101 | 110 | 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, |
190 | 199 | bpf->maps.summary_user, |
191 | 200 | key, value_irq, value_thread, value_user, cpus); |
192 | 201 | } |
| 202 | + |
| 203 | +/* |
| 204 | + * timerlat_load_bpf_action_program - load and register a BPF action program |
| 205 | + */ |
| 206 | +int timerlat_load_bpf_action_program(const char *program_path) |
| 207 | +{ |
| 208 | + int err; |
| 209 | + |
| 210 | + obj = bpf_object__open_file(program_path, NULL); |
| 211 | + if (!obj) { |
| 212 | + err_msg("Failed to open BPF action program: %s\n", program_path); |
| 213 | + goto out_err; |
| 214 | + } |
| 215 | + |
| 216 | + err = bpf_object__load(obj); |
| 217 | + if (err) { |
| 218 | + err_msg("Failed to load BPF action program: %s\n", program_path); |
| 219 | + goto out_obj_err; |
| 220 | + } |
| 221 | + |
| 222 | + prog = bpf_object__find_program_by_name(obj, "action_handler"); |
| 223 | + if (!prog) { |
| 224 | + err_msg("BPF action program must have 'action_handler' function: %s\n", |
| 225 | + program_path); |
| 226 | + goto out_obj_err; |
| 227 | + } |
| 228 | + |
| 229 | + err = timerlat_bpf_set_action(prog); |
| 230 | + if (err) { |
| 231 | + err_msg("Failed to register BPF action program: %s\n", program_path); |
| 232 | + goto out_prog_err; |
| 233 | + } |
| 234 | + |
| 235 | + return 0; |
| 236 | + |
| 237 | +out_prog_err: |
| 238 | + prog = NULL; |
| 239 | +out_obj_err: |
| 240 | + bpf_object__close(obj); |
| 241 | + obj = NULL; |
| 242 | +out_err: |
| 243 | + return 1; |
| 244 | +} |
| 245 | + |
193 | 246 | #endif /* HAVE_BPF_SKEL */ |
0 commit comments