kernel/trace/trace_events_filter.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace_events_filter.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace_events_filter.c- Extension
.c- Size
- 72257 bytes
- Lines
- 2925
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/uaccess.hlinux/module.hlinux/ctype.hlinux/mutex.hlinux/perf_event.hlinux/slab.htrace.htrace_output.hlinux/types.hlinux/tracepoint.htrace_events_filter_test.h
Detected Declarations
struct filter_predstruct prog_entrystruct filter_parse_errorstruct ustring_bufferstruct filter_liststruct filter_headstruct function_filter_dataenum filter_op_idsenum filter_pred_fnenum pred_cmp_typesfunction is_notfunction update_predsfunction parse_errorfunction free_predicatefunction arrayfunction do_filter_cpumaskfunction do_filter_scalar_cpumaskfunction do_filter_cpumask_scalarfunction filter_pred_stringfunction filter_pcharfunction filter_pred_pcharfunction filter_pred_pchar_userfunction filter_pred_strlocfunction filter_pred_strrellocfunction filter_pred_cpufunction filter_pred_cpu_cpumaskfunction filter_pred_cpumaskfunction filter_pred_cpumask_cpufunction filter_pred_commfunction filter_pred_functionfunction regex_match_fullfunction regex_match_frontfunction regex_match_middlefunction regex_match_endfunction regex_match_globfunction isfunction filter_build_regexfunction test_pred_visited_fnfunction filter_match_predsfunction remove_filter_stringfunction append_filter_errfunction print_event_filterfunction print_subsystem_event_filterfunction free_progfunction filter_disablefunction __free_filterfunction free_event_filterfunction __remove_filter
Annotated Snippet
struct filter_pred {
struct regex *regex;
struct cpumask *mask;
unsigned short *ops;
struct ftrace_event_field *field;
u64 val;
u64 val2;
enum filter_pred_fn fn_num;
int offset;
int not;
int op;
};
/*
* pred functions are OP_LE, OP_LT, OP_GE, OP_GT, and OP_BAND
* pred_funcs_##type below must match the order of them above.
*/
#define PRED_FUNC_START OP_LE
#define PRED_FUNC_MAX (OP_BAND - PRED_FUNC_START)
#define ERRORS \
C(NONE, "No error"), \
C(INVALID_OP, "Invalid operator"), \
C(TOO_MANY_OPEN, "Too many '('"), \
C(TOO_MANY_CLOSE, "Too few '('"), \
C(MISSING_QUOTE, "Missing matching quote"), \
C(MISSING_BRACE_OPEN, "Missing '{'"), \
C(MISSING_BRACE_CLOSE, "Missing '}'"), \
C(OPERAND_TOO_LONG, "Operand too long"), \
C(EXPECT_STRING, "Expecting string field"), \
C(EXPECT_DIGIT, "Expecting numeric field"), \
C(ILLEGAL_FIELD_OP, "Illegal operation for field type"), \
C(FIELD_NOT_FOUND, "Field not found"), \
C(ILLEGAL_INTVAL, "Illegal integer value"), \
C(BAD_SUBSYS_FILTER, "Couldn't find or set field in one of a subsystem's events"), \
C(TOO_MANY_PREDS, "Too many terms in predicate expression"), \
C(INVALID_FILTER, "Meaningless filter expression"), \
C(INVALID_CPULIST, "Invalid cpulist"), \
C(IP_FIELD_ONLY, "Only 'ip' field is supported for function trace"), \
C(INVALID_VALUE, "Invalid value (did you forget quotes)?"), \
C(NO_FUNCTION, "Function not found"), \
C(ERRNO, "Error"), \
C(NO_FILTER, "No filter found")
#undef C
#define C(a, b) FILT_ERR_##a
enum { ERRORS };
#undef C
#define C(a, b) b
static const char *err_text[] = { ERRORS };
/* Called after a '!' character but "!=" and "!~" are not "not"s */
static bool is_not(const char *str)
{
switch (str[1]) {
case '=':
case '~':
return false;
}
return true;
}
/**
* struct prog_entry - a single entry in the filter program
* @target: Index to jump to on a branch (actually one minus the index)
* @when_to_branch: The value of the result of the predicate to do a branch
* @pred: The predicate to execute.
*/
struct prog_entry {
int target;
int when_to_branch;
struct filter_pred *pred;
};
/**
* update_preds - assign a program entry a label target
* @prog: The program array
* @N: The index of the current entry in @prog
* @invert: What to assign a program entry for its branch condition
*
* The program entry at @N has a target that points to the index of a program
* entry that can have its target and when_to_branch fields updated.
* Update the current program entry denoted by index @N target field to be
* that of the updated entry. This will denote the entry to update if
* we are processing an "||" after an "&&".
*/
static void update_preds(struct prog_entry *prog, int N, int invert)
Annotation
- Immediate include surface: `linux/uaccess.h`, `linux/module.h`, `linux/ctype.h`, `linux/mutex.h`, `linux/perf_event.h`, `linux/slab.h`, `trace.h`, `trace_output.h`.
- Detected declarations: `struct filter_pred`, `struct prog_entry`, `struct filter_parse_error`, `struct ustring_buffer`, `struct filter_list`, `struct filter_head`, `struct function_filter_data`, `enum filter_op_ids`, `enum filter_pred_fn`, `enum pred_cmp_types`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.