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.

Dependency Surface

Detected Declarations

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

Implementation Notes