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

perf script: Add not taken event for branch stack

The branch stack has an existed field for printing mispredict, extend
the field for printing events and add support not-taken event.

Reviewed-by: Ian Rogers <irogers@google.com>
Reviewed-by: James Clark <james.clark@linaro.org>
Signed-off-by: Leo Yan <leo.yan@arm.com>
Link: https://lore.kernel.org/r/20250304111240.3378214-6-leo.yan@arm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Leo Yan and committed by
Namhyung Kim
1e66dcff 4caa9710

+15 -8
+13 -7
tools/perf/builtin-script.c
··· 935 935 return printed; 936 936 } 937 937 938 - static inline char 939 - mispred_str(struct branch_entry *br) 938 + static inline size_t 939 + bstack_event_str(struct branch_entry *br, char *buf, size_t sz) 940 940 { 941 - if (!(br->flags.mispred || br->flags.predicted)) 942 - return '-'; 941 + if (!(br->flags.mispred || br->flags.predicted || br->flags.not_taken)) 942 + return snprintf(buf, sz, "-"); 943 943 944 - return br->flags.predicted ? 'P' : 'M'; 944 + return snprintf(buf, sz, "%s%s", 945 + br->flags.predicted ? "P" : "M", 946 + br->flags.not_taken ? "N" : ""); 945 947 } 946 948 947 949 static int print_bstack_flags(FILE *fp, struct branch_entry *br) 948 950 { 949 - return fprintf(fp, "/%c/%c/%c/%d/%s/%s ", 950 - mispred_str(br), 951 + char events[16] = { 0 }; 952 + size_t pos; 953 + 954 + pos = bstack_event_str(br, events, sizeof(events)); 955 + return fprintf(fp, "/%s/%c/%c/%d/%s/%s ", 956 + pos < 0 ? "-" : events, 951 957 br->flags.in_tx ? 'X' : '-', 952 958 br->flags.abort ? 'A' : '-', 953 959 br->flags.cycles,
+2 -1
tools/perf/util/branch.h
··· 25 25 u64 spec:2; 26 26 u64 new_type:4; 27 27 u64 priv:3; 28 - u64 reserved:31; 28 + u64 not_taken:1; 29 + u64 reserved:30; 29 30 }; 30 31 }; 31 32 };