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