tools/tracing/rtla/src/timerlat_bpf.c
Source file repositories/reference/linux-study-clean/tools/tracing/rtla/src/timerlat_bpf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/tracing/rtla/src/timerlat_bpf.c- Extension
.c- Size
- 5789 bytes
- Lines
- 244
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
timerlat.htimerlat_bpf.htimerlat.skel.h
Detected Declarations
function timerlat_bpf_initfunction timerlat_bpf_set_actionfunction timerlat_bpf_attachfunction timerlat_bpf_detachfunction timerlat_bpf_destroyfunction handle_rb_eventfunction timerlat_bpf_waitfunction timerlat_bpf_restart_tracingfunction get_valuefunction timerlat_bpf_get_hist_valuefunction timerlat_bpf_get_summary_valuefunction timerlat_load_bpf_action_program
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#ifdef HAVE_BPF_SKEL
#define _GNU_SOURCE
#include "timerlat.h"
#include "timerlat_bpf.h"
#include "timerlat.skel.h"
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
*/
int timerlat_bpf_init(struct timerlat_params *params)
{
int err;
debug_msg("Loading BPF program\n");
bpf = timerlat_bpf__open();
if (!bpf)
return 1;
/* Pass common options */
bpf->rodata->output_divisor = params->common.output_divisor;
bpf->rodata->entries = params->common.hist.entries;
bpf->rodata->irq_threshold = params->common.stop_us;
bpf->rodata->thread_threshold = params->common.stop_total_us;
bpf->rodata->aa_only = params->common.aa_only;
if (params->common.hist.entries != 0) {
/* Pass histogram options */
bpf->rodata->bucket_size = params->common.hist.bucket_size;
/* Set histogram array sizes */
bpf_map__set_max_entries(bpf->maps.hist_irq, params->common.hist.entries);
bpf_map__set_max_entries(bpf->maps.hist_thread, params->common.hist.entries);
bpf_map__set_max_entries(bpf->maps.hist_user, params->common.hist.entries);
} else {
/* No entries, disable histogram */
bpf_map__set_autocreate(bpf->maps.hist_irq, false);
bpf_map__set_autocreate(bpf->maps.hist_thread, false);
bpf_map__set_autocreate(bpf->maps.hist_user, false);
}
if (params->common.aa_only) {
/* Auto-analysis only, disable summary */
bpf_map__set_autocreate(bpf->maps.summary_irq, false);
bpf_map__set_autocreate(bpf->maps.summary_thread, false);
bpf_map__set_autocreate(bpf->maps.summary_user, false);
}
/* Load and verify BPF program */
err = timerlat_bpf__load(bpf);
if (err) {
timerlat_bpf__destroy(bpf);
return err;
}
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
*/
int timerlat_bpf_attach(void)
{
debug_msg("Attaching BPF program\n");
return timerlat_bpf__attach(bpf);
}
/*
* timerlat_bpf_detach - detach BPF program to collect timerlat data
Annotation
- Immediate include surface: `timerlat.h`, `timerlat_bpf.h`, `timerlat.skel.h`.
- Detected declarations: `function timerlat_bpf_init`, `function timerlat_bpf_set_action`, `function timerlat_bpf_attach`, `function timerlat_bpf_detach`, `function timerlat_bpf_destroy`, `function handle_rb_event`, `function timerlat_bpf_wait`, `function timerlat_bpf_restart_tracing`, `function get_value`, `function timerlat_bpf_get_hist_value`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.