tools/perf/util/bpf_kwork.c
Source file repositories/reference/linux-study-clean/tools/perf/util/bpf_kwork.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/bpf_kwork.c- Extension
.c- Size
- 8257 bytes
- Lines
- 354
- 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
time.hfcntl.hsignal.hstdio.hunistd.hlinux/time64.hutil/debug.hutil/evsel.hutil/kwork.hbpf/bpf.hperf/cpumap.hutil/bpf_skel/kwork_trace.skel.h
Detected Declarations
struct work_keystruct report_datastruct kwork_class_bpffunction perf_kwork__trace_startfunction perf_kwork__trace_finishfunction get_work_name_from_mapfunction irq_load_preparefunction softirq_load_preparefunction workqueue_load_preparefunction valid_kwork_class_typefunction setup_filtersfunction perf_cpu_map__for_each_cpufunction perf_kwork__trace_prepare_bpffunction list_for_each_entryfunction add_workfunction perf_kwork__report_read_bpffunction perf_kwork__report_cleanup_bpf
Annotated Snippet
struct work_key {
u32 type;
u32 cpu;
u64 id;
};
struct report_data {
u64 nr;
u64 total_time;
u64 max_time;
u64 max_time_start;
u64 max_time_end;
};
struct kwork_class_bpf {
struct kwork_class *class;
void (*load_prepare)(struct perf_kwork *kwork);
int (*get_work_name)(struct work_key *key, char **ret_name);
};
static struct kwork_trace_bpf *skel;
static struct timespec ts_start;
static struct timespec ts_end;
void perf_kwork__trace_start(void)
{
clock_gettime(CLOCK_MONOTONIC, &ts_start);
skel->bss->enabled = 1;
}
void perf_kwork__trace_finish(void)
{
clock_gettime(CLOCK_MONOTONIC, &ts_end);
skel->bss->enabled = 0;
}
static int get_work_name_from_map(struct work_key *key, char **ret_name)
{
char name[MAX_KWORKNAME] = { 0 };
int fd = bpf_map__fd(skel->maps.perf_kwork_names);
*ret_name = NULL;
if (fd < 0) {
pr_debug("Invalid names map fd\n");
return 0;
}
if ((bpf_map_lookup_elem(fd, key, name) == 0) && (strlen(name) != 0)) {
*ret_name = strdup(name);
if (*ret_name == NULL) {
pr_err("Failed to copy work name\n");
return -1;
}
}
return 0;
}
static void irq_load_prepare(struct perf_kwork *kwork)
{
if (kwork->report == KWORK_REPORT_RUNTIME) {
bpf_program__set_autoload(skel->progs.report_irq_handler_entry, true);
bpf_program__set_autoload(skel->progs.report_irq_handler_exit, true);
}
}
static struct kwork_class_bpf kwork_irq_bpf = {
.load_prepare = irq_load_prepare,
.get_work_name = get_work_name_from_map,
};
static void softirq_load_prepare(struct perf_kwork *kwork)
{
if (kwork->report == KWORK_REPORT_RUNTIME) {
bpf_program__set_autoload(skel->progs.report_softirq_entry, true);
bpf_program__set_autoload(skel->progs.report_softirq_exit, true);
} else if (kwork->report == KWORK_REPORT_LATENCY) {
bpf_program__set_autoload(skel->progs.latency_softirq_raise, true);
bpf_program__set_autoload(skel->progs.latency_softirq_entry, true);
}
}
static struct kwork_class_bpf kwork_softirq_bpf = {
.load_prepare = softirq_load_prepare,
.get_work_name = get_work_name_from_map,
};
Annotation
- Immediate include surface: `time.h`, `fcntl.h`, `signal.h`, `stdio.h`, `unistd.h`, `linux/time64.h`, `util/debug.h`, `util/evsel.h`.
- Detected declarations: `struct work_key`, `struct report_data`, `struct kwork_class_bpf`, `function perf_kwork__trace_start`, `function perf_kwork__trace_finish`, `function get_work_name_from_map`, `function irq_load_prepare`, `function softirq_load_prepare`, `function workqueue_load_prepare`, `function valid_kwork_class_type`.
- 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.