Contributors: 13
Author Tokens Token Proportion Commits Commit Proportion
Jin Yao 96 29.63% 2 8.33%
Kan Liang 71 21.91% 2 8.33%
Roberto Agostino Vitillo 46 14.20% 1 4.17%
Anshuman Khandual 34 10.49% 2 8.33%
Arnaldo Carvalho de Melo 28 8.64% 7 29.17%
Andi Kleen 23 7.10% 3 12.50%
Sandipan Das 9 2.78% 1 4.17%
James Clark 6 1.85% 1 4.17%
Frédéric Weisbecker 4 1.23% 1 4.17%
Ian Rogers 2 0.62% 1 4.17%
Namhyung Kim 2 0.62% 1 4.17%
Jiri Olsa 2 0.62% 1 4.17%
Gustavo A. R. Silva 1 0.31% 1 4.17%
Total 324 24


#ifndef _PERF_BRANCH_H
#define _PERF_BRANCH_H 1
/*
 * The linux/stddef.h isn't need here, but is needed for __always_inline used
 * in files included from uapi/linux/perf_event.h such as
 * /usr/include/linux/swab.h and /usr/include/linux/byteorder/little_endian.h,
 * detected in at least musl libc, used in Alpine Linux. -acme
 */
#include <stdio.h>
#include <linux/perf_event.h>
#include <linux/types.h>
#include "util/map_symbol.h"
#include "util/sample.h"

struct branch_flags {
	union {
		u64 value;
		struct {
			u64 mispred:1;
			u64 predicted:1;
			u64 in_tx:1;
			u64 abort:1;
			u64 cycles:16;
			u64 type:4;
			u64 spec:2;
			u64 new_type:4;
			u64 priv:3;
			u64 reserved:31;
		};
	};
};

struct branch_info {
	struct addr_map_symbol from;
	struct addr_map_symbol to;
	struct branch_flags    flags;
	char		       *srcline_from;
	char		       *srcline_to;
};

struct branch_entry {
	u64			from;
	u64			to;
	struct branch_flags	flags;
};

struct branch_stack {
	u64			nr;
	u64			hw_idx;
	struct branch_entry	entries[];
};

/*
 * The hw_idx is only available when PERF_SAMPLE_BRANCH_HW_INDEX is applied.
 * Otherwise, the output format of a sample with branch stack is
 * struct branch_stack {
 *	u64			nr;
 *	struct branch_entry	entries[0];
 * }
 * Check whether the hw_idx is available,
 * and return the corresponding pointer of entries[0].
 */
static inline struct branch_entry *perf_sample__branch_entries(struct perf_sample *sample)
{
	u64 *entry = (u64 *)sample->branch_stack;

	entry++;
	if (sample->no_hw_idx)
		return (struct branch_entry *)entry;
	return (struct branch_entry *)(++entry);
}

struct branch_type_stat {
	bool	branch_to;
	u64	counts[PERF_BR_MAX];
	u64	new_counts[PERF_BR_NEW_MAX];
	u64	cond_fwd;
	u64	cond_bwd;
	u64	cross_4k;
	u64	cross_2m;
};

void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
		       u64 from, u64 to);

const char *branch_type_name(int type);
const char *branch_new_type_name(int new_type);
const char *get_branch_type(struct branch_entry *e);
void branch_type_stat_display(FILE *fp, const struct branch_type_stat *st);
int branch_type_str(const struct branch_type_stat *st, char *bf, int bfsize);

const char *branch_spec_desc(int spec);

#endif /* _PERF_BRANCH_H */