kernel/trace/trace_branch.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace_branch.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace_branch.c- Extension
.c- Size
- 10070 bytes
- Lines
- 447
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kallsyms.hlinux/seq_file.hlinux/spinlock.hlinux/irqflags.hlinux/uaccess.hlinux/module.hlinux/ftrace.hlinux/hash.hlinux/fs.hasm/local.htrace.htrace_stat.htrace_output.h
Detected Declarations
function probe_likely_conditionfunction trace_likely_conditionfunction enable_branch_tracingfunction disable_branch_tracingfunction branch_trace_initfunction branch_trace_resetfunction trace_branch_printfunction branch_print_headerfunction init_branch_tracerfunction trace_likely_conditionfunction annotated_branch_stat_headersfunction get_incorrect_percentfunction branch_stat_showfunction branch_stat_show_normalfunction annotate_branch_stat_showfunction annotated_branch_stat_nextfunction annotated_branch_stat_cmpfunction init_annotated_branch_statsfunction all_branch_stat_headersfunction all_branch_stat_nextfunction all_branch_stat_showfunction all_annotated_branch_statsmodule init init_branch_tracermodule init init_annotated_branch_statsmodule init all_annotated_branch_statsexport ftrace_likely_update
Annotated Snippet
core_initcall(init_branch_tracer);
#else
static inline
void trace_likely_condition(struct ftrace_likely_data *f, int val, int expect)
{
}
#endif /* CONFIG_BRANCH_TRACER */
void ftrace_likely_update(struct ftrace_likely_data *f, int val,
int expect, int is_constant)
{
unsigned long flags = user_access_save();
/* A constant is always correct */
if (is_constant) {
f->constant++;
val = expect;
}
/*
* I would love to have a trace point here instead, but the
* trace point code is so inundated with unlikely and likely
* conditions that the recursive nightmare that exists is too
* much to try to get working. At least for now.
*/
trace_likely_condition(f, val, expect);
/* FIXME: Make this atomic! */
if (val == expect)
f->data.correct++;
else
f->data.incorrect++;
user_access_restore(flags);
}
EXPORT_SYMBOL(ftrace_likely_update);
extern unsigned long __start_annotated_branch_profile[];
extern unsigned long __stop_annotated_branch_profile[];
static int annotated_branch_stat_headers(struct seq_file *m)
{
seq_puts(m, " correct incorrect % "
" Function "
" File Line\n"
" ------- --------- - "
" -------- "
" ---- ----\n");
return 0;
}
static inline long get_incorrect_percent(const struct ftrace_branch_data *p)
{
long percent;
if (p->correct) {
percent = p->incorrect * 100;
percent /= p->correct + p->incorrect;
} else
percent = p->incorrect ? 100 : -1;
return percent;
}
static const char *branch_stat_process_file(struct ftrace_branch_data *p)
{
const char *f;
/* Only print the file, not the path */
f = p->file + strlen(p->file);
while (f >= p->file && *f != '/')
f--;
return ++f;
}
static void branch_stat_show(struct seq_file *m,
struct ftrace_branch_data *p, const char *f)
{
long percent;
/*
* The miss is overlayed on correct, and hit on incorrect.
*/
percent = get_incorrect_percent(p);
if (percent < 0)
seq_puts(m, " X ");
else
seq_printf(m, "%3ld ", percent);
Annotation
- Immediate include surface: `linux/kallsyms.h`, `linux/seq_file.h`, `linux/spinlock.h`, `linux/irqflags.h`, `linux/uaccess.h`, `linux/module.h`, `linux/ftrace.h`, `linux/hash.h`.
- Detected declarations: `function probe_likely_condition`, `function trace_likely_condition`, `function enable_branch_tracing`, `function disable_branch_tracing`, `function branch_trace_init`, `function branch_trace_reset`, `function trace_branch_print`, `function branch_print_header`, `function init_branch_tracer`, `function trace_likely_condition`.
- 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.