tools/perf/util/bpf_ftrace.c
Source file repositories/reference/linux-study-clean/tools/perf/util/bpf_ftrace.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/bpf_ftrace.c- Extension
.c- Size
- 5152 bytes
- Lines
- 215
- 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
errno.hfcntl.hstdint.hstdio.hstdlib.hbpf/bpf.hlinux/err.hutil/ftrace.hutil/cpumap.hutil/thread_map.hutil/debug.hutil/evlist.hutil/bpf_counter.hutil/stat.hutil/bpf_skel/func_latency.skel.h
Detected Declarations
function perf_ftrace__latency_prepare_bpffunction perf_ftrace__latency_start_bpffunction perf_ftrace__latency_stop_bpffunction perf_ftrace__latency_read_bpffunction perf_ftrace__latency_cleanup_bpf
Annotated Snippet
if (!list_is_singular(&ftrace->filters)) {
pr_err("ERROR: Too many target functions.\n");
return -1;
}
func = list_first_entry(&ftrace->filters, struct filter_entry, list);
} else {
int count = 0;
struct list_head *pos;
list_for_each(pos, &ftrace->event_pair)
count++;
if (count != 2) {
pr_err("ERROR: Needs two target events.\n");
return -1;
}
}
skel = func_latency_bpf__open();
if (!skel) {
pr_err("Failed to open func latency skeleton\n");
return -1;
}
skel->rodata->bucket_range = ftrace->bucket_range;
skel->rodata->min_latency = ftrace->min_latency;
skel->rodata->bucket_num = ftrace->bucket_num;
if (ftrace->bucket_range && ftrace->bucket_num) {
bpf_map__set_max_entries(skel->maps.latency, ftrace->bucket_num);
}
/* don't need to set cpu filter for system-wide mode */
if (ftrace->target.cpu_list) {
ncpus = perf_cpu_map__nr(ftrace->evlist->core.user_requested_cpus);
bpf_map__set_max_entries(skel->maps.cpu_filter, ncpus);
skel->rodata->has_cpu = 1;
}
if (target__has_task(&ftrace->target) || target__none(&ftrace->target)) {
ntasks = perf_thread_map__nr(ftrace->evlist->core.threads);
bpf_map__set_max_entries(skel->maps.task_filter, ntasks);
skel->rodata->has_task = 1;
}
skel->rodata->use_nsec = ftrace->use_nsec;
set_max_rlimit();
err = func_latency_bpf__load(skel);
if (err) {
pr_err("Failed to load func latency skeleton\n");
goto out;
}
if (ftrace->target.cpu_list) {
u32 cpu;
u8 val = 1;
fd = bpf_map__fd(skel->maps.cpu_filter);
for (i = 0; i < ncpus; i++) {
cpu = perf_cpu_map__cpu(ftrace->evlist->core.user_requested_cpus, i).cpu;
bpf_map_update_elem(fd, &cpu, &val, BPF_ANY);
}
}
if (target__has_task(&ftrace->target) || target__none(&ftrace->target)) {
u32 pid;
u8 val = 1;
fd = bpf_map__fd(skel->maps.task_filter);
for (i = 0; i < ntasks; i++) {
pid = perf_thread_map__pid(ftrace->evlist->core.threads, i);
bpf_map_update_elem(fd, &pid, &val, BPF_ANY);
}
}
skel->bss->min = INT64_MAX;
if (func) {
skel->links.func_begin = bpf_program__attach_kprobe(skel->progs.func_begin,
false, func->name);
if (IS_ERR(skel->links.func_begin)) {
pr_err("Failed to attach fentry program\n");
err = PTR_ERR(skel->links.func_begin);
goto out;
}
skel->links.func_end = bpf_program__attach_kprobe(skel->progs.func_end,
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `stdint.h`, `stdio.h`, `stdlib.h`, `bpf/bpf.h`, `linux/err.h`, `util/ftrace.h`.
- Detected declarations: `function perf_ftrace__latency_prepare_bpf`, `function perf_ftrace__latency_start_bpf`, `function perf_ftrace__latency_stop_bpf`, `function perf_ftrace__latency_read_bpf`, `function perf_ftrace__latency_cleanup_bpf`.
- 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.