229 lines · plain
1perf-arm-spe(1)2================3 4NAME5----6perf-arm-spe - Support for Arm Statistical Profiling Extension within Perf tools7 8SYNOPSIS9--------10[verse]11'perf record' -e arm_spe//12 13DESCRIPTION14-----------15 16The SPE (Statistical Profiling Extension) feature provides accurate attribution of latencies and17 events down to individual instructions. Rather than being interrupt-driven, it picks an18instruction to sample and then captures data for it during execution. Data includes execution time19in cycles. For loads and stores it also includes data address, cache miss events, and data origin.20 21The sampling has 5 stages:22 23 1. Choose an operation24 2. Collect data about the operation25 3. Optionally discard the record based on a filter26 4. Write the record to memory27 5. Interrupt when the buffer is full28 29Choose an operation30~~~~~~~~~~~~~~~~~~~31 32This is chosen from a sample population, for SPE this is an IMPLEMENTATION DEFINED choice of all33architectural instructions or all micro-ops. Sampling happens at a programmable interval. The34architecture provides a mechanism for the SPE driver to infer the minimum interval at which it should35sample. This minimum interval is used by the driver if no interval is specified. A pseudo-random36perturbation is also added to the sampling interval by default.37 38Collect data about the operation39~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~40 41Program counter, PMU events, timings and data addresses related to the operation are recorded.42Sampling ensures there is only one sampled operation is in flight.43 44Optionally discard the record based on a filter45~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~46 47Based on programmable criteria, choose whether to keep the record or discard it. If the record is48discarded then the flow stops here for this sample.49 50Write the record to memory51~~~~~~~~~~~~~~~~~~~~~~~~~~52 53The record is appended to a memory buffer54 55Interrupt when the buffer is full56~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~57 58When the buffer fills, an interrupt is sent and the driver signals Perf to collect the records.59Perf saves the raw data in the perf.data file.60 61Opening the file62----------------63 64Up until this point no decoding of the SPE data was done by either the kernel or Perf. Only when the65recorded file is opened with 'perf report' or 'perf script' does the decoding happen. When decoding66the data, Perf generates "synthetic samples" as if these were generated at the time of the67recording. These samples are the same as if normal sampling was done by Perf without using SPE,68although they may have more attributes associated with them. For example a normal sample may have69just the instruction pointer, but an SPE sample can have data addresses and latency attributes.70 71Why Sampling?72-------------73 74 - Sampling, rather than tracing, cuts down the profiling problem to something more manageable for75 hardware. Only one sampled operation is in flight at a time.76 77 - Allows precise attribution data, including: Full PC of instruction, data virtual and physical78 addresses.79 80 - Allows correlation between an instruction and events, such as TLB and cache miss. (Data source81 indicates which particular cache was hit, but the meaning is implementation defined because82 different implementations can have different cache configurations.)83 84However, SPE does not provide any call-graph information, and relies on statistical methods.85 86Collisions87----------88 89When an operation is sampled while a previous sampled operation has not finished, a collision90occurs. The new sample is dropped. Collisions affect the integrity of the data, so the sample rate91should be set to avoid collisions.92 93The 'sample_collision' PMU event can be used to determine the number of lost samples. Although this94count is based on collisions _before_ filtering occurs. Therefore this can not be used as an exact95number for samples dropped that would have made it through the filter, but can be a rough96guide.97 98The effect of microarchitectural sampling99-----------------------------------------100 101If an implementation samples micro-operations instead of instructions, the results of sampling must102be weighted accordingly.103 104For example, if a given instruction A is always converted into two micro-operations, A0 and A1, it105becomes twice as likely to appear in the sample population.106 107The coarse effect of conversions, and, if applicable, sampling of speculative operations, can be108estimated from the 'sample_pop' and 'inst_retired' PMU events.109 110Kernel Requirements111-------------------112 113The ARM_SPE_PMU config must be set to build as either a module or statically.114 115Depending on CPU model, the kernel may need to be booted with page table isolation disabled116(kpti=off). If KPTI needs to be disabled, this will fail with a console message "profiling buffer117inaccessible. Try passing 'kpti=off' on the kernel command line".118 119For the full criteria that determine whether KPTI needs to be forced off or not, see function120unmap_kernel_at_el0() in the kernel sources. Common cases where it's not required121are on the CPUs in kpti_safe_list, or on Arm v8.5+ where FEAT_E0PD is mandatory.122 123The SPE interrupt must also be described by the firmware. If the module is loaded and KPTI is124disabled (or isn't required to be disabled) but the SPE PMU still doesn't show in125/sys/bus/event_source/devices/, then it's possible that the SPE interrupt isn't described by126ACPI or DT. In this case no warning will be printed by the driver.127 128Capturing SPE with perf command-line tools129------------------------------------------130 131You can record a session with SPE samples:132 133 perf record -e arm_spe// -- ./mybench134 135The sample period is set from the -c option, and because the minimum interval is used by default136it's recommended to set this to a higher value. The value is written to PMSIRR.INTERVAL.137 138Config parameters139~~~~~~~~~~~~~~~~~140 141These are placed between the // in the event and comma separated. For example '-e142arm_spe/load_filter=1,min_latency=10/'143 144 branch_filter=1 - collect branches only (PMSFCR.B)145 event_filter=<mask> - filter on specific events (PMSEVFR) - see bitfield description below146 jitter=1 - use jitter to avoid resonance when sampling (PMSIRR.RND)147 load_filter=1 - collect loads only (PMSFCR.LD)148 min_latency=<n> - collect only samples with this latency or higher* (PMSLATFR)149 pa_enable=1 - collect physical address (as well as VA) of loads/stores (PMSCR.PA) - requires privilege150 pct_enable=1 - collect physical timestamp instead of virtual timestamp (PMSCR.PCT) - requires privilege151 store_filter=1 - collect stores only (PMSFCR.ST)152 ts_enable=1 - enable timestamping with value of generic timer (PMSCR.TS)153 154+++*+++ Latency is the total latency from the point at which sampling started on that instruction, rather155than only the execution latency.156 157Only some events can be filtered on; these include:158 159 bit 1 - instruction retired (i.e. omit speculative instructions)160 bit 3 - L1D refill161 bit 5 - TLB refill162 bit 7 - mispredict163 bit 11 - misaligned access164 165So to sample just retired instructions:166 167 perf record -e arm_spe/event_filter=2/ -- ./mybench168 169or just mispredicted branches:170 171 perf record -e arm_spe/event_filter=0x80/ -- ./mybench172 173Viewing the data174~~~~~~~~~~~~~~~~~175 176By default perf report and perf script will assign samples to separate groups depending on the177attributes/events of the SPE record. Because instructions can have multiple events associated with178them, the samples in these groups are not necessarily unique. For example perf report shows these179groups:180 181 Available samples182 0 arm_spe//183 0 dummy:u184 21 l1d-miss185 897 l1d-access186 5 llc-miss187 7 llc-access188 2 tlb-miss189 1K tlb-access190 36 branch-miss191 0 remote-access192 900 memory193 194The arm_spe// and dummy:u events are implementation details and are expected to be empty.195 196To get a full list of unique samples that are not sorted into groups, set the itrace option to197generate 'instruction' samples. The period option is also taken into account, so set it to 1198instruction unless you want to further downsample the already sampled SPE data:199 200 perf report --itrace=i1i201 202Memory access details are also stored on the samples and this can be viewed with:203 204 perf report --mem-mode205 206Common errors207~~~~~~~~~~~~~208 209 - "Cannot find PMU `arm_spe'. Missing kernel support?"210 211 Module not built or loaded, KPTI not disabled, interrupt not described by firmware,212 or running on a VM. See 'Kernel Requirements' above.213 214 - "Arm SPE CONTEXT packets not found in the traces."215 216 Root privilege is required to collect context packets. But these only increase the accuracy of217 assigning PIDs to kernel samples. For userspace sampling this can be ignored.218 219 - Excessively large perf.data file size220 221 Increase sampling interval (see above)222 223 224SEE ALSO225--------226 227linkperf:perf-record[1], linkperf:perf-script[1], linkperf:perf-report[1],228linkperf:perf-inject[1]229