^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) perf-intel-pt(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) ================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) NAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) perf-intel-pt - Support for Intel Processor Trace within perf tools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) SYNOPSIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) --------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) [verse]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 'perf record' -e intel_pt//
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) DESCRIPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) Intel Processor Trace (Intel PT) is an extension of Intel Architecture that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) collects information about software execution such as control flow, execution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) modes and timings and formats it into highly compressed binary packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) Technical details are documented in the Intel 64 and IA-32 Architectures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) Software Developer Manuals, Chapter 36 Intel Processor Trace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) Intel PT is first supported in Intel Core M and 5th generation Intel Core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) processors that are based on the Intel micro-architecture code name Broadwell.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) Trace data is collected by 'perf record' and stored within the perf.data file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) See below for options to 'perf record'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) Trace data must be 'decoded' which involves walking the object code and matching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) the trace data packets. For example a TNT packet only tells whether a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) conditional branch was taken or not taken, so to make use of that packet the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) decoder must know precisely which instruction was being executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) Decoding is done on-the-fly. The decoder outputs samples in the same format as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) samples output by perf hardware events, for example as though the "instructions"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) or "branches" events had been recorded. Presently 3 tools support this:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 'perf script', 'perf report' and 'perf inject'. See below for more information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) on using those tools.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) The main distinguishing feature of Intel PT is that the decoder can determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) the exact flow of software execution. Intel PT can be used to understand why
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) and how did software get to a certain point, or behave a certain way. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) software does not have to be recompiled, so Intel PT works with debug or release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) builds, however the executed images are needed - which makes use in JIT-compiled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) environments, or with self-modified code, a challenge. Also symbols need to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) provided to make sense of addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) A limitation of Intel PT is that it produces huge amounts of trace data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) (hundreds of megabytes per second per core) which takes a long time to decode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) for example two or three orders of magnitude longer than it took to collect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) Another limitation is the performance impact of tracing, something that will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) vary depending on the use-case and architecture.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) Quickstart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) It is important to start small. That is because it is easy to capture vastly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) more data than can possibly be processed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) The simplest thing to do with Intel PT is userspace profiling of small programs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) Data is captured with 'perf record' e.g. to trace 'ls' userspace-only:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) perf record -e intel_pt//u ls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) And profiled with 'perf report' e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) perf report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) To also trace kernel space presents a problem, namely kernel self-modifying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) code. A fairly good kernel image is available in /proc/kcore but to get an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) accurate image a copy of /proc/kcore needs to be made under the same conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) as the data capture. 'perf record' can make a copy of /proc/kcore if the option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) --kcore is used, but access to /proc/kcore is restricted e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) sudo perf record -o pt_ls --kcore -e intel_pt// -- ls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) which will create a directory named 'pt_ls' and put the perf.data file (named
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) simply 'data') and copies of /proc/kcore, /proc/kallsyms and /proc/modules into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) it. The other tools understand the directory format, so to use 'perf report'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) becomes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) sudo perf report -i pt_ls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) Because samples are synthesized after-the-fact, the sampling period can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) selected for reporting. e.g. sample every microsecond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) sudo perf report pt_ls --itrace=i1usge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) See the sections below for more information about the --itrace option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) Beware the smaller the period, the more samples that are produced, and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) longer it takes to process them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) Also note that the coarseness of Intel PT timing information will start to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) distort the statistical value of the sampling as the sampling period becomes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) smaller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) To represent software control flow, "branches" samples are produced. By default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) a branch sample is synthesized for every single branch. To get an idea what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) data is available you can use the 'perf script' tool with all itrace sampling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) options, which will list all the samples.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) perf record -e intel_pt//u ls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) perf script --itrace=ibxwpe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) An interesting field that is not printed by default is 'flags' which can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) displayed as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) perf script --itrace=ibxwpe -F+flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) The flags are "bcrosyiABEx" which stand for branch, call, return, conditional,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) system, asynchronous, interrupt, transaction abort, trace begin, trace end, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) in transaction, respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) perf script also supports higher level ways to dump instruction traces:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) perf script --insn-trace --xed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) Dump all instructions. This requires installing the xed tool (see XED below)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) Dumping all instructions in a long trace can be fairly slow. It is usually better
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) to start with higher level decoding, like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) perf script --call-trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) perf script --call-ret-trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) and then select a time range of interest. The time range can then be examined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) in detail with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) perf script --time starttime,stoptime --insn-trace --xed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) While examining the trace it's also useful to filter on specific CPUs using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) the -C option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) perf script --time starttime,stoptime --insn-trace --xed -C 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) Dump all instructions in time range on CPU 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) Another interesting field that is not printed by default is 'ipc' which can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) displayed as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) perf script --itrace=be -F+ipc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) There are two ways that instructions-per-cycle (IPC) can be calculated depending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) on the recording.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) If the 'cyc' config term (see config terms section below) was used, then IPC is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) calculated using the cycle count from CYC packets, otherwise MTC packets are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) used - refer to the 'mtc' config term. When MTC is used, however, the values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) are less accurate because the timing is less accurate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) Because Intel PT does not update the cycle count on every branch or instruction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) the values will often be zero. When there are values, they will be the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) of instructions and number of cycles since the last update, and thus represent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) the average IPC since the last IPC for that event type. Note IPC for "branches"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) events is calculated separately from IPC for "instructions" events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) Also note that the IPC instruction count may or may not include the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) instruction. If the cycle count is associated with an asynchronous branch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) (e.g. page fault or interrupt), then the instruction count does not include the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) current instruction, otherwise it does. That is consistent with whether or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) that instruction has retired when the cycle count is updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) Another note, in the case of "branches" events, non-taken branches are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) presently sampled, so IPC values for them do not appear e.g. a CYC packet with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) TNT packet that starts with a non-taken branch. To see every possible IPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) value, "instructions" events can be used e.g. --itrace=i0ns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) While it is possible to create scripts to analyze the data, an alternative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) approach is available to export the data to a sqlite or postgresql database.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) Refer to script export-to-sqlite.py or export-to-postgresql.py for more details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) and to script exported-sql-viewer.py for an example of using the database.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) There is also script intel-pt-events.py which provides an example of how to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) unpack the raw data for power events and PTWRITE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) As mentioned above, it is easy to capture too much data. One way to limit the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) data captured is to use 'snapshot' mode which is explained further below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) Refer to 'new snapshot option' and 'Intel PT modes of operation' further below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) Another problem that will be experienced is decoder errors. They can be caused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) by inability to access the executed image, self-modified or JIT-ed code, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) inability to match side-band information (such as context switches and mmaps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) which results in the decoder not knowing what code was executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) There is also the problem of perf not being able to copy the data fast enough,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) resulting in data lost because the buffer was full. See 'Buffer handling' below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) perf record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) new event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) The Intel PT kernel driver creates a new PMU for Intel PT. PMU events are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) selected by providing the PMU name followed by the "config" separated by slashes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) An enhancement has been made to allow default "config" e.g. the option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) -e intel_pt//
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) will use a default config value. Currently that is the same as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) -e intel_pt/tsc,noretcomp=0/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) which is the same as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) -e intel_pt/tsc=1,noretcomp=0/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) Note there are now new config terms - see section 'config terms' further below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) The config terms are listed in /sys/devices/intel_pt/format. They are bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) fields within the config member of the struct perf_event_attr which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) passed to the kernel by the perf_event_open system call. They correspond to bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) fields in the IA32_RTIT_CTL MSR. Here is a list of them and their definitions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) $ grep -H . /sys/bus/event_source/devices/intel_pt/format/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /sys/bus/event_source/devices/intel_pt/format/cyc:config:1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /sys/bus/event_source/devices/intel_pt/format/cyc_thresh:config:19-22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /sys/bus/event_source/devices/intel_pt/format/mtc:config:9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /sys/bus/event_source/devices/intel_pt/format/mtc_period:config:14-17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /sys/bus/event_source/devices/intel_pt/format/noretcomp:config:11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /sys/bus/event_source/devices/intel_pt/format/psb_period:config:24-27
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /sys/bus/event_source/devices/intel_pt/format/tsc:config:10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) Note that the default config must be overridden for each term i.e.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) -e intel_pt/noretcomp=0/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) is the same as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) -e intel_pt/tsc=1,noretcomp=0/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) So, to disable TSC packets use:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) -e intel_pt/tsc=0/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) It is also possible to specify the config value explicitly:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) -e intel_pt/config=0x400/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) Note that, as with all events, the event is suffixed with event modifiers:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) u userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) k kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) h hypervisor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) G guest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) H host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) p precise ip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 'h', 'G' and 'H' are for virtualization which is not supported by Intel PT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 'p' is also not relevant to Intel PT. So only options 'u' and 'k' are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) meaningful for Intel PT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) perf_event_attr is displayed if the -vv option is used e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) ------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) perf_event_attr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) type 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) size 112
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) config 0x400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) { sample_period, sample_freq } 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) sample_type IP|TID|TIME|CPU|IDENTIFIER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) read_format ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) disabled 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) inherit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) exclude_kernel 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) exclude_hv 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) enable_on_exec 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) sample_id_all 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) ------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) sys_perf_event_open: pid 31104 cpu 0 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) sys_perf_event_open: pid 31104 cpu 1 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) sys_perf_event_open: pid 31104 cpu 2 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) sys_perf_event_open: pid 31104 cpu 3 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) ------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) config terms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) The June 2015 version of Intel 64 and IA-32 Architectures Software Developer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) Manuals, Chapter 36 Intel Processor Trace, defined new Intel PT features.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) Some of the features are reflect in new config terms. All the config terms are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) described below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) tsc Always supported. Produces TSC timestamp packets to provide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) timing information. In some cases it is possible to decode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) without timing information, for example a per-thread context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) that does not overlap executable memory maps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) The default config selects tsc (i.e. tsc=1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) noretcomp Always supported. Disables "return compression" so a TIP packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) is produced when a function returns. Causes more packets to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) produced but might make decoding more reliable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) The default config does not select noretcomp (i.e. noretcomp=0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) psb_period Allows the frequency of PSB packets to be specified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) The PSB packet is a synchronization packet that provides a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) starting point for decoding or recovery from errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) Support for psb_period is indicated by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /sys/bus/event_source/devices/intel_pt/caps/psb_cyc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) which contains "1" if the feature is supported and "0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) Valid values are given by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /sys/bus/event_source/devices/intel_pt/caps/psb_periods
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) which contains a hexadecimal value, the bits of which represent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) valid values e.g. bit 2 set means value 2 is valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) The psb_period value is converted to the approximate number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) trace bytes between PSB packets as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 2 ^ (value + 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) e.g. value 3 means 16KiB bytes between PSBs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) If an invalid value is entered, the error message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) will give a list of valid values e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) $ perf record -e intel_pt/psb_period=15/u uname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) Invalid psb_period for intel_pt. Valid values are: 0-5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) If MTC packets are selected, the default config selects a value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) of 3 (i.e. psb_period=3) or the nearest lower value that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) supported (0 is always supported). Otherwise the default is 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) If decoding is expected to be reliable and the buffer is large
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) then a large PSB period can be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) Because a TSC packet is produced with PSB, the PSB period can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) also affect the granularity to timing information in the absence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) of MTC or CYC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) mtc Produces MTC timing packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) MTC packets provide finer grain timestamp information than TSC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) packets. MTC packets record time using the hardware crystal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) clock (CTC) which is related to TSC packets using a TMA packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) Support for this feature is indicated by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) /sys/bus/event_source/devices/intel_pt/caps/mtc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) which contains "1" if the feature is supported and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) "0" otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) The frequency of MTC packets can also be specified - see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) mtc_period below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) mtc_period Specifies how frequently MTC packets are produced - see mtc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) above for how to determine if MTC packets are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) Valid values are given by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) /sys/bus/event_source/devices/intel_pt/caps/mtc_periods
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) which contains a hexadecimal value, the bits of which represent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) valid values e.g. bit 2 set means value 2 is valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) The mtc_period value is converted to the MTC frequency as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) CTC-frequency / (2 ^ value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) e.g. value 3 means one eighth of CTC-frequency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) Where CTC is the hardware crystal clock, the frequency of which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) can be related to TSC via values provided in cpuid leaf 0x15.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) If an invalid value is entered, the error message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) will give a list of valid values e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) $ perf record -e intel_pt/mtc_period=15/u uname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) Invalid mtc_period for intel_pt. Valid values are: 0,3,6,9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) The default value is 3 or the nearest lower value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) that is supported (0 is always supported).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) cyc Produces CYC timing packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) CYC packets provide even finer grain timestamp information than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) MTC and TSC packets. A CYC packet contains the number of CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) cycles since the last CYC packet. Unlike MTC and TSC packets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) CYC packets are only sent when another packet is also sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) Support for this feature is indicated by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /sys/bus/event_source/devices/intel_pt/caps/psb_cyc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) which contains "1" if the feature is supported and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) "0" otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) The number of CYC packets produced can be reduced by specifying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) a threshold - see cyc_thresh below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) cyc_thresh Specifies how frequently CYC packets are produced - see cyc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) above for how to determine if CYC packets are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) Valid cyc_thresh values are given by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) /sys/bus/event_source/devices/intel_pt/caps/cycle_thresholds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) which contains a hexadecimal value, the bits of which represent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) valid values e.g. bit 2 set means value 2 is valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) The cyc_thresh value represents the minimum number of CPU cycles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) that must have passed before a CYC packet can be sent. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) number of CPU cycles is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 2 ^ (value - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) e.g. value 4 means 8 CPU cycles must pass before a CYC packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) can be sent. Note a CYC packet is still only sent when another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) packet is sent, not at, e.g. every 8 CPU cycles.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) If an invalid value is entered, the error message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) will give a list of valid values e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) $ perf record -e intel_pt/cyc,cyc_thresh=15/u uname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) Invalid cyc_thresh for intel_pt. Valid values are: 0-12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) CYC packets are not requested by default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) pt Specifies pass-through which enables the 'branch' config term.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) The default config selects 'pt' if it is available, so a user will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) never need to specify this term.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) branch Enable branch tracing. Branch tracing is enabled by default so to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) disable branch tracing use 'branch=0'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) The default config selects 'branch' if it is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) ptw Enable PTWRITE packets which are produced when a ptwrite instruction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) is executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) Support for this feature is indicated by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /sys/bus/event_source/devices/intel_pt/caps/ptwrite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) which contains "1" if the feature is supported and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) "0" otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) fup_on_ptw Enable a FUP packet to follow the PTWRITE packet. The FUP packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) provides the address of the ptwrite instruction. In the absence of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) fup_on_ptw, the decoder will use the address of the previous branch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if branch tracing is enabled, otherwise the address will be zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) Note that fup_on_ptw will work even when branch tracing is disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) pwr_evt Enable power events. The power events provide information about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) changes to the CPU C-state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) Support for this feature is indicated by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /sys/bus/event_source/devices/intel_pt/caps/power_event_trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) which contains "1" if the feature is supported and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) "0" otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) AUX area sampling option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) ~~~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) To select Intel PT "sampling" the AUX area sampling option can be used:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) --aux-sample
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) Optionally it can be followed by the sample size in bytes e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) --aux-sample=8192
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) In addition, the Intel PT event to sample must be defined e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) -e intel_pt//u
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) Samples on other events will be created containing Intel PT data e.g. the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) following will create Intel PT samples on the branch-misses event, note the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) events must be grouped using {}:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) perf record --aux-sample -e '{intel_pt//u,branch-misses:u}'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) An alternative to '--aux-sample' is to add the config term 'aux-sample-size' to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) events. In this case, the grouping is implied e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) perf record -e intel_pt//u -e branch-misses/aux-sample-size=8192/u
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) is the same as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) perf record -e '{intel_pt//u,branch-misses/aux-sample-size=8192/u}'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) but allows for also using an address filter e.g.:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) perf record -e intel_pt//u --filter 'filter * @/bin/ls' -e branch-misses/aux-sample-size=8192/u -- ls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) It is important to select a sample size that is big enough to contain at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) one PSB packet. If not a warning will be displayed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) Intel PT sample size (%zu) may be too small for PSB period (%zu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) The calculation used for that is: if sample_size <= psb_period + 256 display the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) warning. When sampling is used, psb_period defaults to 0 (2KiB).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) The default sample size is 4KiB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) The sample size is passed in aux_sample_size in struct perf_event_attr. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) sample size is limited by the maximum event size which is 64KiB. It is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) difficult to know how big the event might be without the trace sample attached,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) but the tool validates that the sample size is not greater than 60KiB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) new snapshot option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) ~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) The difference between full trace and snapshot from the kernel's perspective is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) that in full trace we don't overwrite trace data that the user hasn't collected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) yet (and indicated that by advancing aux_tail), whereas in snapshot mode we let
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) the trace run and overwrite older data in the buffer so that whenever something
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) interesting happens, we can stop it and grab a snapshot of what was going on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) around that interesting moment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) To select snapshot mode a new option has been added:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) -S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) Optionally it can be followed by the snapshot size e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) -S0x100000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) The default snapshot size is the auxtrace mmap size. If neither auxtrace mmap size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) nor snapshot size is specified, then the default is 4MiB for privileged users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) (or if /proc/sys/kernel/perf_event_paranoid < 0), 128KiB for unprivileged users.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) If an unprivileged user does not specify mmap pages, the mmap pages will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) reduced as described in the 'new auxtrace mmap size option' section below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) The snapshot size is displayed if the option -vv is used e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) Intel PT snapshot size: %zu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) new auxtrace mmap size option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) Intel PT buffer size is specified by an addition to the -m option e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) -m,16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) selects a buffer size of 16 pages i.e. 64KiB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) Note that the existing functionality of -m is unchanged. The auxtrace mmap size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) is specified by the optional addition of a comma and the value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) The default auxtrace mmap size for Intel PT is 4MiB/page_size for privileged users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) (or if /proc/sys/kernel/perf_event_paranoid < 0), 128KiB for unprivileged users.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) If an unprivileged user does not specify mmap pages, the mmap pages will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) reduced from the default 512KiB/page_size to 256KiB/page_size, otherwise the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) user is likely to get an error as they exceed their mlock limit (Max locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) memory as shown in /proc/self/limits). Note that perf does not count the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 512KiB (actually /proc/sys/kernel/perf_event_mlock_kb minus 1 page) per cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) against the mlock limit so an unprivileged user is allowed 512KiB per cpu plus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) their mlock limit (which defaults to 64KiB but is not multiplied by the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) of cpus).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) In full-trace mode, powers of two are allowed for buffer size, with a minimum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) size of 2 pages. In snapshot mode or sampling mode, it is the same but the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) minimum size is 1 page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) The mmap size and auxtrace mmap size are displayed if the -vv option is used e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) mmap length 528384
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) auxtrace mmap length 4198400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) Intel PT modes of operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) ~~~~~~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) Intel PT can be used in 3 modes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) full-trace mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) sample mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) snapshot mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) Full-trace mode traces continuously e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) perf record -e intel_pt//u uname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) Sample mode attaches a Intel PT sample to other events e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) perf record --aux-sample -e intel_pt//u -e branch-misses:u
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) Snapshot mode captures the available data when a signal is sent or "snapshot"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) control command is issued. e.g. using a signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) perf record -v -e intel_pt//u -S ./loopy 1000000000 &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) [1] 11435
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) kill -USR2 11435
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) Recording AUX area tracing snapshot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) Note that the signal sent is SIGUSR2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) Note that "Recording AUX area tracing snapshot" is displayed because the -v
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) option is used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) The advantage of using "snapshot" control command is that the access is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) controlled by access to a FIFO e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) $ mkfifo perf.control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) $ mkfifo perf.ack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) $ cat perf.ack &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) [1] 15235
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) $ sudo ~/bin/perf record --control fifo:perf.control,perf.ack -S -e intel_pt//u -- sleep 60 &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) [2] 15243
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) $ ps -e | grep perf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 15244 pts/1 00:00:00 perf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) $ kill -USR2 15244
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) bash: kill: (15244) - Operation not permitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) $ echo snapshot > perf.control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) ack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) The 3 Intel PT modes of operation cannot be used together.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) Buffer handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) ~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) There may be buffer limitations (i.e. single ToPa entry) which means that actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) buffer sizes are limited to powers of 2 up to 4MiB (MAX_ORDER). In order to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) provide other sizes, and in particular an arbitrarily large size, multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) buffers are logically concatenated. However an interrupt must be used to switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) between buffers. That has two potential problems:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) a) the interrupt may not be handled in time so that the current buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) becomes full and some trace data is lost.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) b) the interrupts may slow the system and affect the performance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) If trace data is lost, the driver sets 'truncated' in the PERF_RECORD_AUX event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) which the tools report as an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) In full-trace mode, the driver waits for data to be copied out before allowing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) the (logical) buffer to wrap-around. If data is not copied out quickly enough,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) again 'truncated' is set in the PERF_RECORD_AUX event. If the driver has to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) wait, the intel_pt event gets disabled. Because it is difficult to know when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) that happens, perf tools always re-enable the intel_pt event after copying out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) Intel PT and build ids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) ~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) By default "perf record" post-processes the event stream to find all build ids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) for executables for all addresses sampled. Deliberately, Intel PT is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) decoded for that purpose (it would take too long). Instead the build ids for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) all executables encountered (due to mmap, comm or task events) are included
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) in the perf.data file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) To see buildids included in the perf.data file use the command:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) perf buildid-list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) If the perf.data file contains Intel PT data, that is the same as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) perf buildid-list --with-hits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) Snapshot mode and event disabling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) In order to make a snapshot, the intel_pt event is disabled using an IOCTL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) namely PERF_EVENT_IOC_DISABLE. However doing that can also disable the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) collection of side-band information. In order to prevent that, a dummy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) software event has been introduced that permits tracking events (like mmaps) to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) continue to be recorded while intel_pt is disabled. That is important to ensure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) there is complete side-band information to allow the decoding of subsequent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) snapshots.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) A test has been created for that. To find the test:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) perf test list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 23: Test using a dummy software event to keep tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) To run the test:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) perf test 23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 23: Test using a dummy software event to keep tracking : Ok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) perf record modes (nothing new here)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) perf record essentially operates in one of three modes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) per thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) per cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) workload only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) "per thread" mode is selected by -t or by --per-thread (with -p or -u or just a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) workload).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) "per cpu" is selected by -C or -a.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) "workload only" mode is selected by not using the other options but providing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) command to run (i.e. the workload).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) In per-thread mode an exact list of threads is traced. There is no inheritance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) Each thread has its own event buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) In per-cpu mode all processes (or processes from the selected cgroup i.e. -G
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) option, or processes selected with -p or -u) are traced. Each cpu has its own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) buffer. Inheritance is allowed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) In workload-only mode, the workload is traced but with per-cpu buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) Inheritance is allowed. Note that you can now trace a workload in per-thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) mode by using the --per-thread option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) Privileged vs non-privileged users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) Unless /proc/sys/kernel/perf_event_paranoid is set to -1, unprivileged users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) have memory limits imposed upon them. That affects what buffer sizes they can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) have as outlined above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) The v4.2 kernel introduced support for a context switch metadata event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) PERF_RECORD_SWITCH, which allows unprivileged users to see when their processes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) are scheduled out and in, just not by whom, which is left for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) PERF_RECORD_SWITCH_CPU_WIDE, that is only accessible in system wide context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) which in turn requires CAP_PERFMON or CAP_SYS_ADMIN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) Please see the 45ac1403f564 ("perf: Add PERF_RECORD_SWITCH to indicate context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) switches") commit, that introduces these metadata events for further info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) When working with kernels < v4.2, the following considerations must be taken,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) as the sched:sched_switch tracepoints will be used to receive such information:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) Unless /proc/sys/kernel/perf_event_paranoid is set to -1, unprivileged users are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) not permitted to use tracepoints which means there is insufficient side-band
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) information to decode Intel PT in per-cpu mode, and potentially workload-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) mode too if the workload creates new processes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) Note also, that to use tracepoints, read-access to debugfs is required. So if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) debugfs is not mounted or the user does not have read-access, it will again not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) be possible to decode Intel PT in per-cpu mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) sched_switch tracepoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) ~~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) The sched_switch tracepoint is used to provide side-band data for Intel PT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) decoding in kernels where the PERF_RECORD_SWITCH metadata event isn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) The sched_switch events are automatically added. e.g. the second event shown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) below:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) $ perf record -vv -e intel_pt//u uname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) ------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) perf_event_attr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) type 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) size 112
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) config 0x400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) { sample_period, sample_freq } 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) sample_type IP|TID|TIME|CPU|IDENTIFIER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) read_format ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) disabled 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) inherit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) exclude_kernel 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) exclude_hv 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) enable_on_exec 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) sample_id_all 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) ------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) sys_perf_event_open: pid 31104 cpu 0 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) sys_perf_event_open: pid 31104 cpu 1 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) sys_perf_event_open: pid 31104 cpu 2 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) sys_perf_event_open: pid 31104 cpu 3 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) ------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) perf_event_attr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) type 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) size 112
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) config 0x108
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) { sample_period, sample_freq } 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) read_format ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) inherit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) sample_id_all 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) exclude_guest 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) ------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) sys_perf_event_open: pid -1 cpu 1 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) sys_perf_event_open: pid -1 cpu 2 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) sys_perf_event_open: pid -1 cpu 3 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) ------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) perf_event_attr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) type 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) size 112
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) config 0x9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) { sample_period, sample_freq } 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) sample_type IP|TID|TIME|IDENTIFIER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) read_format ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) disabled 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) inherit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) exclude_kernel 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) exclude_hv 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) mmap 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) comm 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) enable_on_exec 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) task 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) sample_id_all 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) mmap2 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) comm_exec 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) ------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) sys_perf_event_open: pid 31104 cpu 0 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) sys_perf_event_open: pid 31104 cpu 1 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) sys_perf_event_open: pid 31104 cpu 2 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) sys_perf_event_open: pid 31104 cpu 3 group_fd -1 flags 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) mmap size 528384B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) AUX area mmap length 4194304
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) perf event ring buffer mmapped per cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) Synthesizing auxtrace information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) [ perf record: Woken up 1 times to write data ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) [ perf record: Captured and wrote 0.042 MB perf.data ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) Note, the sched_switch event is only added if the user is permitted to use it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) and only in per-cpu mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) Note also, the sched_switch event is only added if TSC packets are requested.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) That is because, in the absence of timing information, the sched_switch events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) cannot be matched against the Intel PT trace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) perf script
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) By default, perf script will decode trace data found in the perf.data file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) This can be further controlled by new option --itrace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) New --itrace option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) ~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) Having no option is the same as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) --itrace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) which, in turn, is the same as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) --itrace=cepwx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) The letters are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) i synthesize "instructions" events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) b synthesize "branches" events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) x synthesize "transactions" events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) w synthesize "ptwrite" events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) p synthesize "power" events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) c synthesize branches events (calls only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) r synthesize branches events (returns only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) e synthesize tracing error events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) d create a debug log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) g synthesize a call chain (use with i or x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) G synthesize a call chain on existing event records
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) l synthesize last branch entries (use with i or x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) L synthesize last branch entries on existing event records
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) s skip initial number of events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) q quicker (less detailed) decoding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) "Instructions" events look like they were recorded by "perf record -e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) instructions".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) "Branches" events look like they were recorded by "perf record -e branches". "c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) and "r" can be combined to get calls and returns.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) "Transactions" events correspond to the start or end of transactions. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 'flags' field can be used in perf script to determine whether the event is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) tranasaction start, commit or abort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) Note that "instructions", "branches" and "transactions" events depend on code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) flow packets which can be disabled by using the config term "branch=0". Refer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) to the config terms section above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) "ptwrite" events record the payload of the ptwrite instruction and whether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) "fup_on_ptw" was used. "ptwrite" events depend on PTWRITE packets which are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) recorded only if the "ptw" config term was used. Refer to the config terms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) section above. perf script "synth" field displays "ptwrite" information like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) this: "ip: 0 payload: 0x123456789abcdef0" where "ip" is 1 if "fup_on_ptw" was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) "Power" events correspond to power event packets and CBR (core-to-bus ratio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) packets. While CBR packets are always recorded when tracing is enabled, power
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) event packets are recorded only if the "pwr_evt" config term was used. Refer to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) the config terms section above. The power events record information about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) C-state changes, whereas CBR is indicative of CPU frequency. perf script
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) "event,synth" fields display information like this:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) cbr: cbr: 22 freq: 2189 MHz (200%)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) mwait: hints: 0x60 extensions: 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) pwre: hw: 0 cstate: 2 sub-cstate: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) exstop: ip: 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) pwrx: deepest cstate: 2 last cstate: 2 wake reason: 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) Where:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) "cbr" includes the frequency and the percentage of maximum non-turbo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) "mwait" shows mwait hints and extensions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) "pwre" shows C-state transitions (to a C-state deeper than C0) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) whether initiated by hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) "exstop" indicates execution stopped and whether the IP was recorded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) exactly,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) "pwrx" indicates return to C0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) For more details refer to the Intel 64 and IA-32 Architectures Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) Developer Manuals.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) Error events show where the decoder lost the trace. Error events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) are quite important. Users must know if what they are seeing is a complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) picture or not. The "e" option may be followed by flags which affect what errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) will or will not be reported. Each flag must be preceded by either '+' or '-'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) The flags supported by Intel PT are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) -o Suppress overflow errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) -l Suppress trace data lost errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) For example, for errors but not overflow or data lost errors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) --itrace=e-o-l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) The "d" option will cause the creation of a file "intel_pt.log" containing all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) decoded packets and instructions. Note that this option slows down the decoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) and that the resulting file may be very large. The "d" option may be followed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) by flags which affect what debug messages will or will not be logged. Each flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) must be preceded by either '+' or '-'. The flags support by Intel PT are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) -a Suppress logging of perf events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) +a Log all perf events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) By default, logged perf events are filtered by any specified time ranges, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) flag +a overrides that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) In addition, the period of the "instructions" event can be specified. e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) --itrace=i10us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) sets the period to 10us i.e. one instruction sample is synthesized for each 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) microseconds of trace. Alternatives to "us" are "ms" (milliseconds),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) "ns" (nanoseconds), "t" (TSC ticks) or "i" (instructions).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) "ms", "us" and "ns" are converted to TSC ticks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) The timing information included with Intel PT does not give the time of every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) instruction. Consequently, for the purpose of sampling, the decoder estimates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) the time since the last timing packet based on 1 tick per instruction. The time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) on the sample is *not* adjusted and reflects the last known value of TSC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) For Intel PT, the default period is 100us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) Setting it to a zero period means "as often as possible".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) In the case of Intel PT that is the same as a period of 1 and a unit of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) 'instructions' (i.e. --itrace=i1i).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) Also the call chain size (default 16, max. 1024) for instructions or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) transactions events can be specified. e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) --itrace=ig32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) --itrace=xg32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) Also the number of last branch entries (default 64, max. 1024) for instructions or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) transactions events can be specified. e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) --itrace=il10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) --itrace=xl10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) Note that last branch entries are cleared for each sample, so there is no overlap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) from one sample to the next.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) The G and L options are designed in particular for sample mode, and work much
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) like g and l but add call chain and branch stack to the other selected events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) instead of synthesized events. For example, to record branch-misses events for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) 'ls' and then add a call chain derived from the Intel PT trace:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) perf record --aux-sample -e '{intel_pt//u,branch-misses:u}' -- ls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) perf report --itrace=Ge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) Although in fact G is a default for perf report, so that is the same as just:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) perf report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) One caveat with the G and L options is that they work poorly with "Large PEBS".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) Large PEBS means PEBS records will be accumulated by hardware and the written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) into the event buffer in one go. That reduces interrupts, but can give very
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) late timestamps. Because the Intel PT trace is synchronized by timestamps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) the PEBS events do not match the trace. Currently, Large PEBS is used only in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) certain circumstances:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) - hardware supports it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) - PEBS is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) - event period is specified, instead of frequency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) - the sample type is limited to the following flags:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_ADDR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_STREAM_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) PERF_SAMPLE_DATA_SRC | PERF_SAMPLE_IDENTIFIER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) PERF_SAMPLE_TRANSACTION | PERF_SAMPLE_PHYS_ADDR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) PERF_SAMPLE_REGS_INTR | PERF_SAMPLE_REGS_USER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) PERF_SAMPLE_PERIOD (and sometimes) | PERF_SAMPLE_TIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) Because Intel PT sample mode uses a different sample type to the list above,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) Large PEBS is not used with Intel PT sample mode. To avoid Large PEBS in other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) cases, avoid specifying the event period i.e. avoid the 'perf record' -c option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) --count option, or 'period' config term.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) To disable trace decoding entirely, use the option --no-itrace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) It is also possible to skip events generated (instructions, branches, transactions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) at the beginning. This is useful to ignore initialization code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) --itrace=i0nss1000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) skips the first million instructions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) The q option changes the way the trace is decoded. The decoding is much faster
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) but much less detailed. Specifically, with the q option, the decoder does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) decode TNT packets, and does not walk object code, but gets the ip from FUP and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) TIP packets. The q option can be used with the b and i options but the period
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) is not used. The q option decodes more quickly, but is useful only if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) control flow of interest is represented or indicated by FUP, TIP, TIP.PGE, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) TIP.PGD packets (refer below). However the q option could be used to find time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) ranges that could then be decoded fully using the --time option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) What will *not* be decoded with the (single) q option:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) - direct calls and jmps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) - conditional branches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) - non-branch instructions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) What *will* be decoded with the (single) q option:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) - asynchronous branches such as interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) - indirect branches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) - function return target address *if* the noretcomp config term (refer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) config terms section) was used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) - start of (control-flow) tracing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) - end of (control-flow) tracing, if it is not out of context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) - power events, ptwrite, transaction start and abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) - instruction pointer associated with PSB packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) Note the q option does not specify what events will be synthesized e.g. the p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) option must be used also to show power events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) Repeating the q option (double-q i.e. qq) results in even faster decoding and even
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) less detail. The decoder decodes only extended PSB (PSB+) packets, getting the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) instruction pointer if there is a FUP packet within PSB+ (i.e. between PSB and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) PSBEND). Note PSB packets occur regularly in the trace based on the psb_period
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) config term (refer config terms section). There will be a FUP packet if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) PSB+ occurs while control flow is being traced.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) What will *not* be decoded with the qq option:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) - everything except instruction pointer associated with PSB packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) What *will* be decoded with the qq option:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) - instruction pointer associated with PSB packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) dump option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) ~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) perf script has an option (-D) to "dump" the events i.e. display the binary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) When -D is used, Intel PT packets are displayed. The packet decoder does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) pay attention to PSB packets, but just decodes the bytes - so the packets seen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) by the actual decoder may not be identical in places where the data is corrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) One example of that would be when the buffer-switching interrupt has been too
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) slow, and the buffer has been filled completely. In that case, the last packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) in the buffer might be truncated and immediately followed by a PSB as the trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) continues in the next buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) To disable the display of Intel PT packets, combine the -D option with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) --no-itrace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) perf report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) By default, perf report will decode trace data found in the perf.data file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) This can be further controlled by new option --itrace exactly the same as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) perf script, with the exception that the default is --itrace=igxe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) perf inject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) perf inject also accepts the --itrace option in which case tracing data is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) removed and replaced with the synthesized events. e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) perf inject --itrace -i perf.data -o perf.data.new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) Below is an example of using Intel PT with autofdo. It requires autofdo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) (https://github.com/google/autofdo) and gcc version 5. The bubble
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) sort example is from the AutoFDO tutorial (https://gcc.gnu.org/wiki/AutoFDO/Tutorial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) amended to take the number of elements as a parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) $ gcc-5 -O3 sort.c -o sort_optimized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) $ ./sort_optimized 30000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) Bubble sorting array of 30000 elements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 2254 ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) $ cat ~/.perfconfig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) [intel-pt]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) mispred-all = on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) $ perf record -e intel_pt//u ./sort 3000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) Bubble sorting array of 3000 elements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 58 ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) [ perf record: Woken up 2 times to write data ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) [ perf record: Captured and wrote 3.939 MB perf.data ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) $ perf inject -i perf.data -o inj --itrace=i100usle --strip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) $ ./create_gcov --binary=./sort --profile=inj --gcov=sort.gcov -gcov_version=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) $ gcc-5 -O3 -fauto-profile=sort.gcov sort.c -o sort_autofdo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) $ ./sort_autofdo 30000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) Bubble sorting array of 30000 elements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 2155 ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) Note there is currently no advantage to using Intel PT instead of LBR, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) that may change in the future if greater use is made of the data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) PEBS via Intel PT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) -----------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) Some hardware has the feature to redirect PEBS records to the Intel PT trace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) Recording is selected by using the aux-output config term e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) perf record -c 10000 -e '{intel_pt/branch=0/,cycles/aux-output/ppp}' uname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) Note that currently, software only supports redirecting at most one PEBS event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) To display PEBS events from the Intel PT trace, use the itrace 'o' option e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) perf script --itrace=oe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) XED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) ---
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) include::build-xed.txt[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) SEE ALSO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) --------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) linkperf:perf-record[1], linkperf:perf-script[1], linkperf:perf-report[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) linkperf:perf-inject[1]