perf tools: Add hw_idx in struct branch_stack
The low level index of raw branch records for the most recent branch can be recorded in a sample with PERF_SAMPLE_BRANCH_HW_INDEX branch_sample_type. Extend struct branch_stack to support it. However, if the PERF_SAMPLE_BRANCH_HW_INDEX is not applied, only nr and entries[] will be output by kernel. The pointer of entries[] could be wrong, since the output format is different with new struct branch_stack. Add a variable no_hw_idx in struct perf_sample to indicate whether the hw_idx is output. Add get_branch_entry() to return corresponding pointer of entries[0]. To make dummy branch sample consistent as new branch sample, add hw_idx in struct dummy_branch_stack for cs-etm and intel-pt. Apply the new struct branch_stack for synthetic events as well. Extend test case sample-parsing to support new struct branch_stack. Committer notes: Renamed get_branch_entries() to perf_sample__branch_entries() to have proper namespacing and pave the way for this to be moved to libperf, eventually. Add 'static' to that inline as it is in a header. Add 'hw_idx' to 'struct dummy_branch_stack' in cs-etm.c to fix the build on arm64. Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexey Budankov <alexey.budankov@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Pavel Gerasimov <pavel.gerasimov@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com> Cc: Stephane Eranian <eranian@google.com> Cc: Vitaly Slobodskoy <vitaly.slobodskoy@intel.com> Link: http://lore.kernel.org/lkml/20200228163011.19358-2-kan.liang@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:

committed by
Arnaldo Carvalho de Melo

parent
6339998d22
commit
42bbabed09
@@ -99,6 +99,7 @@ static bool samples_same(const struct perf_sample *s1,
|
||||
|
||||
if (type & PERF_SAMPLE_BRANCH_STACK) {
|
||||
COMP(branch_stack->nr);
|
||||
COMP(branch_stack->hw_idx);
|
||||
for (i = 0; i < s1->branch_stack->nr; i++)
|
||||
MCOMP(branch_stack->entries[i]);
|
||||
}
|
||||
@@ -186,7 +187,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)
|
||||
u64 data[64];
|
||||
} branch_stack = {
|
||||
/* 1 branch_entry */
|
||||
.data = {1, 211, 212, 213},
|
||||
.data = {1, -1ULL, 211, 212, 213},
|
||||
};
|
||||
u64 regs[64];
|
||||
const u64 raw_data[] = {0x123456780a0b0c0dULL, 0x1102030405060708ULL};
|
||||
@@ -208,6 +209,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)
|
||||
.transaction = 112,
|
||||
.raw_data = (void *)raw_data,
|
||||
.callchain = &callchain.callchain,
|
||||
.no_hw_idx = false,
|
||||
.branch_stack = &branch_stack.branch_stack,
|
||||
.user_regs = {
|
||||
.abi = PERF_SAMPLE_REGS_ABI_64,
|
||||
@@ -244,6 +246,9 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)
|
||||
if (sample_type & PERF_SAMPLE_REGS_INTR)
|
||||
evsel.core.attr.sample_regs_intr = sample_regs;
|
||||
|
||||
if (sample_type & PERF_SAMPLE_BRANCH_STACK)
|
||||
evsel.core.attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
|
||||
|
||||
for (i = 0; i < sizeof(regs); i++)
|
||||
*(i + (u8 *)regs) = i & 0xfe;
|
||||
|
||||
|
Reference in New Issue
Block a user