tools/perf/util/branch.c
Source file repositories/reference/linux-study-clean/tools/perf/util/branch.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/branch.c- Extension
.c- Size
- 4832 bytes
- Lines
- 230
- 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/map_symbol.hutil/branch.hlinux/kernel.h
Detected Declarations
function cross_areafunction branch_type_countfunction branch_type_stat_displayfunction count_str_scnprintffunction branch_type_str
Annotated Snippet
#include "util/map_symbol.h"
#include "util/branch.h"
#include <linux/kernel.h>
static bool cross_area(u64 addr1, u64 addr2, int size)
{
u64 align1, align2;
align1 = addr1 & ~(size - 1);
align2 = addr2 & ~(size - 1);
return (align1 != align2) ? true : false;
}
#define AREA_4K 4096
#define AREA_2M (2 * 1024 * 1024)
void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
u64 from, u64 to)
{
if (flags->type == PERF_BR_UNKNOWN || from == 0)
return;
if (flags->type == PERF_BR_EXTEND_ABI)
st->new_counts[flags->new_type]++;
else
st->counts[flags->type]++;
if (flags->type == PERF_BR_COND) {
if (to > from)
st->cond_fwd++;
else
st->cond_bwd++;
}
if (cross_area(from, to, AREA_2M))
st->cross_2m++;
else if (cross_area(from, to, AREA_4K))
st->cross_4k++;
}
const char *branch_new_type_name(int new_type)
{
const char *branch_new_names[PERF_BR_NEW_MAX] = {
"FAULT_ALGN",
"FAULT_DATA",
"FAULT_INST",
/*
* TODO: This switch should happen on 'perf_session__env(session)->arch'
* instead, because an arm64 platform perf recording could be
* opened for analysis on other platforms as well.
*/
#ifdef __aarch64__
"ARM64_FIQ",
"ARM64_DEBUG_HALT",
"ARM64_DEBUG_EXIT",
"ARM64_DEBUG_INST",
"ARM64_DEBUG_DATA"
#else
"ARCH_1",
"ARCH_2",
"ARCH_3",
"ARCH_4",
"ARCH_5"
#endif
};
if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
return branch_new_names[new_type];
return NULL;
}
const char *branch_type_name(int type)
{
const char *branch_names[PERF_BR_MAX] = {
"N/A",
"COND",
"UNCOND",
"IND",
"CALL",
"IND_CALL",
"RET",
"SYSCALL",
"SYSRET",
"COND_CALL",
"COND_RET",
"ERET",
"IRQ",
"SERROR",
Annotation
- Immediate include surface: `util/map_symbol.h`, `util/branch.h`, `linux/kernel.h`.
- Detected declarations: `function cross_area`, `function branch_type_count`, `function branch_type_stat_display`, `function count_str_scnprintf`, `function branch_type_str`.
- 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.