Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf branch: Add branch privilege information request flag

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>

authored by

Anshuman Khandual and committed by
Arnaldo Carvalho de Melo
bcb96ce6 0ddea8e2

+18 -3
+13 -1
tools/include/uapi/linux/perf_event.h
··· 204 204 205 205 PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT = 17, /* save low level index of raw branch records */ 206 206 207 + PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT = 18, /* save privilege mode */ 208 + 207 209 PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */ 208 210 }; 209 211 ··· 234 232 1U << PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT, 235 233 236 234 PERF_SAMPLE_BRANCH_HW_INDEX = 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT, 235 + 236 + PERF_SAMPLE_BRANCH_PRIV_SAVE = 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT, 237 237 238 238 PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT, 239 239 }; ··· 273 269 PERF_BR_NEW_ARCH_4 = 6, /* Architecture specific */ 274 270 PERF_BR_NEW_ARCH_5 = 7, /* Architecture specific */ 275 271 PERF_BR_NEW_MAX, 272 + }; 273 + 274 + enum { 275 + PERF_BR_PRIV_UNKNOWN = 0, 276 + PERF_BR_PRIV_USER = 1, 277 + PERF_BR_PRIV_KERNEL = 2, 278 + PERF_BR_PRIV_HV = 3, 276 279 }; 277 280 278 281 #define PERF_SAMPLE_BRANCH_PLM_ALL \ ··· 1400 1389 cycles:16, /* cycle count to last branch */ 1401 1390 type:4, /* branch type */ 1402 1391 new_type:4, /* additional branch type */ 1403 - reserved:36; 1392 + priv:3, /* privilege level */ 1393 + reserved:33; 1404 1394 }; 1405 1395 1406 1396 union perf_sample_weight {
+1
tools/perf/Documentation/perf-record.txt
··· 400 400 For the platforms with Intel Arch LBR support (12th-Gen+ client or 401 401 4th-Gen Xeon+ server), the save branch type is unconditionally enabled 402 402 when the taken branch stack sampling is enabled. 403 + - priv: save privilege state during sampling in case binary is not available later 403 404 404 405 + 405 406 The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
+2 -1
tools/perf/util/branch.h
··· 25 25 u64 cycles:16; 26 26 u64 type:4; 27 27 u64 new_type:4; 28 - u64 reserved:36; 28 + u64 priv:3; 29 + u64 reserved:33; 29 30 }; 30 31 }; 31 32 };
+1
tools/perf/util/parse-branch-options.c
··· 32 32 BRANCH_OPT("call", PERF_SAMPLE_BRANCH_CALL), 33 33 BRANCH_OPT("save_type", PERF_SAMPLE_BRANCH_TYPE_SAVE), 34 34 BRANCH_OPT("stack", PERF_SAMPLE_BRANCH_CALL_STACK), 35 + BRANCH_OPT("priv", PERF_SAMPLE_BRANCH_PRIV_SAVE), 35 36 BRANCH_END 36 37 }; 37 38
+1 -1
tools/perf/util/perf_event_attr_fprintf.c
··· 52 52 bit_name(ABORT_TX), bit_name(IN_TX), bit_name(NO_TX), 53 53 bit_name(COND), bit_name(CALL_STACK), bit_name(IND_JUMP), 54 54 bit_name(CALL), bit_name(NO_FLAGS), bit_name(NO_CYCLES), 55 - bit_name(TYPE_SAVE), bit_name(HW_INDEX), 55 + bit_name(TYPE_SAVE), bit_name(HW_INDEX), bit_name(PRIV_SAVE), 56 56 { .name = NULL, } 57 57 }; 58 58 #undef bit_name