tools/perf/util/bpf-filter.c
Source file repositories/reference/linux-study-clean/tools/perf/util/bpf-filter.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/bpf-filter.c- Extension
.c- Size
- 19579 bytes
- Lines
- 808
- 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
stdlib.hfcntl.hsys/ioctl.hsys/stat.hbpf/bpf.hlinux/err.hlinux/list.hapi/fs/fs.hinternal/xyarray.hperf/threadmap.hutil/cap.hutil/debug.hutil/evsel.hutil/target.hutil/bpf-utils.hutil/bpf-filter.hutil/bpf-filter-flex.hutil/bpf-filter-bison.hbpf_skel/sample-filter.hbpf_skel/sample_filter.skel.h
Detected Declarations
struct pinned_filter_idxfunction flagfunction check_sample_flagsfunction list_for_each_entryfunction get_filter_entriesfunction list_for_each_entryfunction list_for_each_entryfunction convert_to_tgidfunction create_event_hashfunction idfunction destroy_idx_hashfunction create_idx_hashfunction perf_bpf_filter__preparefunction list_for_each_entry_safefunction perf_bpf_filter__destroyfunction list_for_each_entry_safefunction list_for_each_entry_safefunction perf_bpf_filter__lost_countfunction list_for_each_entryfunction check_bpf_filter_capablefunction perf_bpf_filter__parsefunction perf_bpf_filter__pinfunction perf_bpf_filter__unpinfunction get_pinned_fd
Annotated Snippet
struct pinned_filter_idx {
struct list_head list;
struct evsel *evsel;
u64 event_id;
int hash_idx;
};
static LIST_HEAD(pinned_filters);
static const struct perf_sample_info {
enum perf_bpf_filter_term type;
const char *name;
const char *option;
} sample_table[] = {
/* default sample flags */
PERF_SAMPLE_TYPE(IP, NULL),
PERF_SAMPLE_TYPE(TID, NULL),
PERF_SAMPLE_TYPE(PERIOD, NULL),
/* flags mostly set by default, but still have options */
PERF_SAMPLE_TYPE(ID, "--sample-identifier"),
PERF_SAMPLE_TYPE(CPU, "--sample-cpu"),
PERF_SAMPLE_TYPE(TIME, "-T"),
/* optional sample flags */
PERF_SAMPLE_TYPE(ADDR, "-d"),
PERF_SAMPLE_TYPE(DATA_SRC, "-d"),
PERF_SAMPLE_TYPE(PHYS_ADDR, "--phys-data"),
PERF_SAMPLE_TYPE(WEIGHT, "-W"),
PERF_SAMPLE_TYPE(WEIGHT_STRUCT, "-W"),
PERF_SAMPLE_TYPE(TRANSACTION, "--transaction"),
PERF_SAMPLE_TYPE(CODE_PAGE_SIZE, "--code-page-size"),
PERF_SAMPLE_TYPE(DATA_PAGE_SIZE, "--data-page-size"),
PERF_SAMPLE_TYPE(CGROUP, "--all-cgroups"),
};
static int get_pinned_fd(const char *name);
static const struct perf_sample_info *get_sample_info(enum perf_bpf_filter_term type)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(sample_table); i++) {
if (sample_table[i].type == type)
return &sample_table[i];
}
return NULL;
}
static int check_sample_flags(struct evsel *evsel, struct perf_bpf_filter_expr *expr)
{
const struct perf_sample_info *info;
if (expr->term >= PBF_TERM_SAMPLE_START && expr->term <= PBF_TERM_SAMPLE_END &&
(evsel->core.attr.sample_type & (1 << (expr->term - PBF_TERM_SAMPLE_START))))
return 0;
if (expr->term == PBF_TERM_UID || expr->term == PBF_TERM_GID) {
/* Not dependent on the sample_type as computed from a BPF helper. */
return 0;
}
if (expr->op == PBF_OP_GROUP_BEGIN) {
struct perf_bpf_filter_expr *group;
list_for_each_entry(group, &expr->groups, list) {
if (check_sample_flags(evsel, group) < 0)
return -1;
}
return 0;
}
info = get_sample_info(expr->term);
if (info == NULL) {
pr_err("Error: %s event does not have sample flags %d\n",
evsel__name(evsel), expr->term);
return -1;
}
pr_err("Error: %s event does not have %s\n", evsel__name(evsel), info->name);
if (info->option)
pr_err(" Hint: please add %s option to perf record\n", info->option);
return -1;
}
static int get_filter_entries(struct evsel *evsel, struct perf_bpf_filter_entry *entry)
{
int i = 0;
struct perf_bpf_filter_expr *expr;
list_for_each_entry(expr, &evsel->bpf_filters, list) {
if (check_sample_flags(evsel, expr) < 0)
Annotation
- Immediate include surface: `stdlib.h`, `fcntl.h`, `sys/ioctl.h`, `sys/stat.h`, `bpf/bpf.h`, `linux/err.h`, `linux/list.h`, `api/fs/fs.h`.
- Detected declarations: `struct pinned_filter_idx`, `function flag`, `function check_sample_flags`, `function list_for_each_entry`, `function get_filter_entries`, `function list_for_each_entry`, `function list_for_each_entry`, `function convert_to_tgid`, `function create_event_hash`, `function id`.
- 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.