History

perf: Add branch stack counters

Currently, the additional information of a branch entry is stored in a u64 space. With more and more information added, the space is running out. For example, the information of occurrences of events will be added for each branch. Two places were suggested to append the counters. https://lore.kernel.org/lkml/20230802215814.GH231007@hirez.programming.kicks-ass.net/ One place is right after the flags of each branch entry. It changes the existing struct perf_branch_entry. The later ARCH specific implementation has to be really careful to consistently pick the right struct. The other place is right after the entire struct perf_branch_stack. The disadvantage is that the pointer of the extra space has to be recorded. The common interface perf_sample_save_brstack() has to be updated. The latter is much straightforward, and should be easily understood and maintained. It is implemented in the patch. Add a new branch sample type, PERF_SAMPLE_BRANCH_COUNTERS, to indicate the event which is recorded in the branch info. The "u64 counters" may store the occurrences of several events. The information regarding the number of events/counters and the width of each counter should be exposed via sysfs as a reference for the perf tool. Define the branch_counter_nr and branch_counter_width ABI here. The support will be implemented later in the Intel-specific patch.

Kan Liang committed 3 years ago

Commit 571d91d1 parent 744940f9 files · +46 −7Browse files

Showing the changes to include/uapi (1 of 9 files). Show all

Unified · Split

include/uapi/linux/perf_event.h+10−0
@@ -204,6 +204,8 @@ enum perf_branch_sample_type_shift { · 203 unmodified lines
204204
205205 PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT = 18, /* save privilege mode */
206206
207+ PERF_SAMPLE_BRANCH_COUNTERS_SHIFT = 19, /* save occurrences of events on a branch */
208+
207209 PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */
208210 };
209211
@@ -235,6 +237,8 @@ enum perf_branch_sample_type { · 25 unmodified lines
235237
236238 PERF_SAMPLE_BRANCH_PRIV_SAVE = 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
237239
240+ PERF_SAMPLE_BRANCH_COUNTERS = 1U << PERF_SAMPLE_BRANCH_COUNTERS_SHIFT,
241+
238242 PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
239243 };
240244
@@ -982,6 +986,12 @@ enum perf_event_type { · 741 unmodified lines
982986 * { u64 nr;
983987 * { u64 hw_idx; } && PERF_SAMPLE_BRANCH_HW_INDEX
984988 * { u64 from, to, flags } lbr[nr];
989+ * #
990+ * # The format of the counters is decided by the
991+ * # "branch_counter_nr" and "branch_counter_width",
992+ * # which are defined in the ABI.
993+ * #
994+ * { u64 counters; } cntr[nr] && PERF_SAMPLE_BRANCH_COUNTERS
985995 * } && PERF_SAMPLE_BRANCH_STACK
986996 *
987997 * { u64 abi; # enum perf_sample_regs_abi

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t