perf branch: Add branch privilege information request flag
authorAnshuman Khandual <anshuman.khandual@arm.com>
Wed, 24 Aug 2022 04:48:21 +0000 (10:18 +0530)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 4 Oct 2022 11:55:20 +0000 (08:55 -0300)
This updates the perf tools with branch privilege information request flag
i.e PERF_SAMPLE_BRANCH_PRIV_SAVE that has been added earlier in the kernel.
This also updates 'perf record' documentation, branch_modes[], and generic
branch privilege level enumeration as added earlier in the kernel.

Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20220824044822.70230-8-anshuman.khandual@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/include/uapi/linux/perf_event.h
tools/perf/Documentation/perf-record.txt
tools/perf/util/branch.h
tools/perf/util/parse-branch-options.c
tools/perf/util/perf_event_attr_fprintf.c

index 0f7c7ce..51168e2 100644 (file)
@@ -204,6 +204,8 @@ enum perf_branch_sample_type_shift {
 
        PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT       = 17, /* save low level index of raw branch records */
 
+       PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT      = 18, /* save privilege mode */
+
        PERF_SAMPLE_BRANCH_MAX_SHIFT            /* non-ABI */
 };
 
@@ -233,6 +235,8 @@ enum perf_branch_sample_type {
 
        PERF_SAMPLE_BRANCH_HW_INDEX     = 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
 
+       PERF_SAMPLE_BRANCH_PRIV_SAVE    = 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
+
        PERF_SAMPLE_BRANCH_MAX          = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
 };
 
@@ -271,6 +275,13 @@ enum {
        PERF_BR_NEW_MAX,
 };
 
+enum {
+       PERF_BR_PRIV_UNKNOWN    = 0,
+       PERF_BR_PRIV_USER       = 1,
+       PERF_BR_PRIV_KERNEL     = 2,
+       PERF_BR_PRIV_HV         = 3,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
        (PERF_SAMPLE_BRANCH_USER|\
         PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1389,7 +1400,8 @@ struct perf_branch_entry {
                cycles:16,  /* cycle count to last branch */
                type:4,     /* branch type */
                new_type:4, /* additional branch type */
-               reserved:36;
+               priv:3,     /* privilege level */
+               reserved:33;
 };
 
 union perf_sample_weight {
index b32a9c2..378f497 100644 (file)
@@ -400,6 +400,7 @@ following filters are defined:
                     For the platforms with Intel Arch LBR support (12th-Gen+ client or
                     4th-Gen Xeon+ server), the save branch type is unconditionally enabled
                     when the taken branch stack sampling is enabled.
+       - priv: save privilege state during sampling in case binary is not available later
 
 +
 The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
index 8d251b3..f838b23 100644 (file)
@@ -25,7 +25,8 @@ struct branch_flags {
                        u64 cycles:16;
                        u64 type:4;
                        u64 new_type:4;
-                       u64 reserved:36;
+                       u64 priv:3;
+                       u64 reserved:33;
                };
        };
 };
index bb4aa88..00588b9 100644 (file)
@@ -32,6 +32,7 @@ static const struct branch_mode branch_modes[] = {
        BRANCH_OPT("call", PERF_SAMPLE_BRANCH_CALL),
        BRANCH_OPT("save_type", PERF_SAMPLE_BRANCH_TYPE_SAVE),
        BRANCH_OPT("stack", PERF_SAMPLE_BRANCH_CALL_STACK),
+       BRANCH_OPT("priv", PERF_SAMPLE_BRANCH_PRIV_SAVE),
        BRANCH_END
 };
 
index 98af3fa..4b0db27 100644 (file)
@@ -52,7 +52,7 @@ static void __p_branch_sample_type(char *buf, size_t size, u64 value)
                bit_name(ABORT_TX), bit_name(IN_TX), bit_name(NO_TX),
                bit_name(COND), bit_name(CALL_STACK), bit_name(IND_JUMP),
                bit_name(CALL), bit_name(NO_FLAGS), bit_name(NO_CYCLES),
-               bit_name(TYPE_SAVE), bit_name(HW_INDEX),
+               bit_name(TYPE_SAVE), bit_name(HW_INDEX), bit_name(PRIV_SAVE),
                { .name = NULL, }
        };
 #undef bit_name