tools/perf/util/bpf_lock_contention.c
Source file repositories/reference/linux-study-clean/tools/perf/util/bpf_lock_contention.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/bpf_lock_contention.c- Extension
.c- Size
- 21032 bytes
- Lines
- 856
- 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
util/cgroup.hutil/debug.hutil/evlist.hutil/hashmap.hutil/machine.hutil/map.hutil/symbol.hutil/target.hutil/thread.hutil/thread_map.hutil/lock-contention.hlinux/zalloc.hlinux/string.hapi/fs/fs.hbpf/bpf.hbpf/btf.hinttypes.hbpf_skel/lock_contention.skel.hbpf_skel/lock_data.h
Detected Declarations
function slab_cache_hashfunction slab_cache_equalfunction check_slab_cache_iterfunction run_slab_cache_iterfunction exit_slab_cache_iterfunction init_numa_datafunction lock_contention_preparefunction mark_end_timestampfunction update_lock_statfunction mapfunction lock_contention_startfunction lock_contention_stopfunction lock_contention_readfunction lock_contention_finish
Annotated Snippet
if (con->owner) {
bpf_map__set_value_size(skel->maps.stack_buf, con->max_stack * sizeof(u64));
bpf_map__set_key_size(skel->maps.owner_stacks,
con->max_stack * sizeof(u64));
bpf_map__set_max_entries(skel->maps.owner_stacks, con->map_nr_entries);
bpf_map__set_max_entries(skel->maps.owner_data, con->map_nr_entries);
bpf_map__set_max_entries(skel->maps.owner_stat, con->map_nr_entries);
skel->rodata->max_stack = con->max_stack;
}
} else {
bpf_map__set_max_entries(skel->maps.stacks, 1);
}
if (target__has_cpu(target)) {
skel->rodata->has_cpu = 1;
ncpus = perf_cpu_map__nr(evlist->core.user_requested_cpus);
}
if (target__has_task(target)) {
skel->rodata->has_task = 1;
ntasks = perf_thread_map__nr(evlist->core.threads);
}
if (con->filters->nr_types) {
skel->rodata->has_type = 1;
ntypes = con->filters->nr_types;
}
if (con->filters->nr_cgrps) {
skel->rodata->has_cgroup = 1;
ncgrps = con->filters->nr_cgrps;
}
/* resolve lock name filters to addr */
if (con->filters->nr_syms) {
struct symbol *sym;
struct map *kmap;
unsigned long *addrs;
for (i = 0; i < con->filters->nr_syms; i++) {
sym = machine__find_kernel_symbol_by_name(con->machine,
con->filters->syms[i],
&kmap);
if (sym == NULL) {
pr_warning("ignore unknown symbol: %s\n",
con->filters->syms[i]);
continue;
}
addrs = realloc(con->filters->addrs,
(con->filters->nr_addrs + 1) * sizeof(*addrs));
if (addrs == NULL) {
pr_warning("memory allocation failure\n");
continue;
}
addrs[con->filters->nr_addrs++] = map__unmap_ip(kmap, sym->start);
con->filters->addrs = addrs;
}
naddrs = con->filters->nr_addrs;
skel->rodata->has_addr = 1;
}
/* resolve lock name in delays */
if (con->nr_delays) {
struct symbol *sym;
struct map *kmap;
for (i = 0; i < con->nr_delays; i++) {
sym = machine__find_kernel_symbol_by_name(con->machine,
con->delays[i].sym,
&kmap);
if (sym == NULL) {
pr_warning("ignore unknown symbol: %s\n",
con->delays[i].sym);
continue;
}
con->delays[i].addr = map__unmap_ip(kmap, sym->start);
}
skel->rodata->lock_delay = 1;
bpf_map__set_max_entries(skel->maps.lock_delays, con->nr_delays);
}
bpf_map__set_max_entries(skel->maps.cpu_filter, ncpus);
bpf_map__set_max_entries(skel->maps.task_filter, ntasks);
bpf_map__set_max_entries(skel->maps.type_filter, ntypes);
bpf_map__set_max_entries(skel->maps.addr_filter, naddrs);
bpf_map__set_max_entries(skel->maps.cgroup_filter, ncgrps);
skel->rodata->stack_skip = con->stack_skip;
skel->rodata->aggr_mode = con->aggr_mode;
skel->rodata->needs_callstack = con->save_callstack;
Annotation
- Immediate include surface: `util/cgroup.h`, `util/debug.h`, `util/evlist.h`, `util/hashmap.h`, `util/machine.h`, `util/map.h`, `util/symbol.h`, `util/target.h`.
- Detected declarations: `function slab_cache_hash`, `function slab_cache_equal`, `function check_slab_cache_iter`, `function run_slab_cache_iter`, `function exit_slab_cache_iter`, `function init_numa_data`, `function lock_contention_prepare`, `function mark_end_timestamp`, `function update_lock_stat`, `function map`.
- 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.