selftests/powerpc/pmu: Add support for branch sampling in get_intr_regs function
authorKajol Jain <kjain@linux.ibm.com>
Fri, 10 Jun 2022 13:40:42 +0000 (19:10 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 28 Jun 2022 13:57:51 +0000 (23:57 +1000)
Add support for sample type as PERF_SAMPLE_BRANCH_STACK in sampling
tests. This change is a precursor/helper for sampling testcases, that
test branck stack feature in perf interface.

Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220610134113.62991-5-atrajeev@linux.vnet.ibm.com
tools/testing/selftests/powerpc/pmu/sampling_tests/misc.c

index 6e30b455cbd6d3b62aefa982893816374412c2a7..5a26fc3a970681108486fa1c56598131699ef845 100644 (file)
@@ -259,13 +259,32 @@ u64 *get_intr_regs(struct event *event, void *sample_buff)
        u64 *intr_regs;
        size_t size = 0;
 
-       if ((type ^ PERF_SAMPLE_REGS_INTR))
+       if ((type ^ (PERF_SAMPLE_REGS_INTR | PERF_SAMPLE_BRANCH_STACK)) &&
+                       (type  ^ PERF_SAMPLE_REGS_INTR))
                return NULL;
 
        intr_regs = (u64 *)perf_read_first_sample(sample_buff, &size);
        if (!intr_regs)
                return NULL;
 
+       if (type & PERF_SAMPLE_BRANCH_STACK) {
+               /*
+                * PERF_RECORD_SAMPLE and PERF_SAMPLE_BRANCH_STACK:
+                * struct {
+                *     struct perf_event_header hdr;
+                *     u64 number_of_branches;
+                *     struct perf_branch_entry[number_of_branches];
+                *     u64 data[];
+                * };
+                * struct perf_branch_entry {
+                *     u64      from;
+                *     u64      to;
+                *     u64      misc;
+                * };
+                */
+               intr_regs += ((*intr_regs) * 3) + 1;
+       }
+
        /*
         * First entry in the sample buffer used to specify
         * PERF_SAMPLE_REGS_ABI_64, skip perf regs abi to access