[PATCH v6 0/8] perf cs-etm: Add support for sample flags

From: Leo Yan
Date: Fri Jan 18 2019 - 20:44:35 EST


This patch seris adds support for sample flags so can facilitate perf
to print sample flags for branch instruction.

Patch 0001 is used to save last branch information in packet structure,
this includes instruction type, subtype and condition flag to help
making decision for which branch instruction it is. It passes related
information from decoder layer to cs-etm.c, so we use cs-etm.c as a
central place to set sample flags.

Patch 0002 is used to set sample flags for instruction range packet.

Patch 0003 is used to set sample flags for trace discontinuity packet.

Patches 0004/0005/0006 are preparation for exception packet handling:
Patch 0004 addes exception number in packet; pacth 0005/0006 is to use
traceID/metadata tuple to access metadata pointer based on traceID, this
can help decide if the CPU is connected with ETMv3 or ETMv4, ETMv3 and
ETMv4 have totally different definition for exception numbers.

Patch 0007 sets sample flags for exception packet; patch 0008 support
sample flags for exception return packet.

This patch series is applied on the acme's perf core branch with the
with latest commit 02bb912ae451 ("perf tools: Replace automatic const
char[] variables by statics").

After applying this patch series, we can verify sample flags with below
command:

# perf script -F,-time,+flags,+ip,+sym,+dso,+addr,+symoff -k vmlinux

Changes from v5:
* Addressed Rob's suggestion to add specification info for exception
number encoding;
* Added Rob's review tag in patch 0007.

Changes from v4:
* Fixed typos in comments, and removed redundant info from commit log;
* Addressed Mathieu's suggestion to add helper functions for metadata
fields (CS_ETM_CPU and CS_ETM_MAGIC) accessing;
* Addressed Mathieu's suggestion to include headers with alphabetical
order.

Changes from v3:
* Fixed typos in commit logs;
* Rearranged fields in cs_etm_packet by grouping with same variable
types;
* Fixed ETMv4 exception number which pointed by Mike;
* Fixed ETMv4 SVC / SMC / HVC in the same CALL, by checking svc
instruction to distinguish them;
* Refine ETMv4 return exception packet handling.

Changes from v2:
* Addressed Mathieu's suggestion to split one big patch to 3 small
patches for setting sample flags, one is for instruction range
packet, one is for discontinuity packet and one is for exception
packet.
* Added supporting for ETMv3 exception packet.
* Followed Mathieu's suggestion to move all sample flags handling
from decoder layer to cs-etm.c, thus it has enough info to set flags
based on trace context in single place.

Changes from v1:
* Moved exception packets handling patches into patch series 'perf
cs-etm: Correct packets handling'.
* Added sample flags fixing up for TRACE_OFF packet.
* Created a new function which is used to maintain flags fixing up.


Leo Yan (8):
perf cs-etm: Add last instruction information in packet
perf cs-etm: Set sample flags for instruction range packet
perf cs-etm: Set sample flags for trace discontinuity
perf cs-etm: Add exception number in exception packet
perf cs-etm: Change tuple from traceID-CPU# to traceID-metadata
perf cs-etm: Add traceID in packet
perf cs-etm: Set sample flags for exception packet
perf cs-etm: Set sample flags for exception return packet

.../perf/util/cs-etm-decoder/cs-etm-decoder.c | 41 +-
.../perf/util/cs-etm-decoder/cs-etm-decoder.h | 6 +
tools/perf/util/cs-etm.c | 405 +++++++++++++++++-
tools/perf/util/cs-etm.h | 48 ++-
4 files changed, 482 insertions(+), 18 deletions(-)

--
2.17.1