159 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3================4CoreSight - Perf5================6 7 :Author: Carsten Haitzler <carsten.haitzler@arm.com>8 :Date: June 29th, 20229 10Perf is able to locally access CoreSight trace data and store it to the11output perf data files. This data can then be later decoded to give the12instructions that were traced for debugging or profiling purposes. You13can log such data with a perf record command like::14 15 perf record -e cs_etm//u testbinary16 17This would run some test binary (testbinary) until it exits and record18a perf.data trace file. That file would have AUX sections if CoreSight19is working correctly. You can dump the content of this file as20readable text with a command like::21 22 perf report --stdio --dump -i perf.data23 24You should find some sections of this file have AUX data blocks like::25 26 0x1e78 [0x30]: PERF_RECORD_AUXTRACE size: 0x11dd0 offset: 0 ref: 0x1b614fc1061b0ad1 idx: 0 tid: 531230 cpu: -127 28 . ... CoreSight ETM Trace data: size 73168 bytes29 Idx:0; ID:10; I_ASYNC : Alignment Synchronisation.30 Idx:12; ID:10; I_TRACE_INFO : Trace Info.; INFO=0x0 { CC.0 }31 Idx:17; ID:10; I_ADDR_L_64IS0 : Address, Long, 64 bit, IS0.; Addr=0x0000000000000000;32 Idx:26; ID:10; I_TRACE_ON : Trace On.33 Idx:27; ID:10; I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0x0000FFFFB6069140; Ctxt: AArch64,EL0, NS;34 Idx:38; ID:10; I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE35 Idx:39; ID:10; I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE36 Idx:40; ID:10; I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE37 Idx:41; ID:10; I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEN38 ...39 40If you see these above, then your system is tracing CoreSight data41correctly.42 43To compile perf with CoreSight support in the tools/perf directory do::44 45 make CORESIGHT=146 47This requires OpenCSD to build. You may install distribution packages48for the support such as libopencsd and libopencsd-dev or download it49and build yourself. Upstream OpenCSD is located at:50 51 https://github.com/Linaro/OpenCSD52 53For complete information on building perf with CoreSight support and54more extensive usage look at:55 56 https://github.com/Linaro/OpenCSD/blob/master/HOWTO.md57 58 59Kernel CoreSight Support60------------------------61 62You will also want CoreSight support enabled in your kernel config.63Ensure it is enabled with::64 65 CONFIG_CORESIGHT=y66 67There are various other CoreSight options you probably also want68enabled like::69 70 CONFIG_CORESIGHT_LINKS_AND_SINKS=y71 CONFIG_CORESIGHT_LINK_AND_SINK_TMC=y72 CONFIG_CORESIGHT_CATU=y73 CONFIG_CORESIGHT_SINK_TPIU=y74 CONFIG_CORESIGHT_SINK_ETBV10=y75 CONFIG_CORESIGHT_SOURCE_ETM4X=y76 CONFIG_CORESIGHT_CTI=y77 CONFIG_CORESIGHT_CTI_INTEGRATION_REGS=y78 79Please refer to the kernel configuration help for more information.80 81Perf test - Verify kernel and userspace perf CoreSight work82-----------------------------------------------------------83 84When you run perf test, it will do a lot of self tests. Some of those85tests will cover CoreSight (only if enabled and on ARM64). You86generally would run perf test from the tools/perf directory in the87kernel tree. Some tests will check some internal perf support like:88 89 Check Arm CoreSight trace data recording and synthesized samples90 Check Arm SPE trace data recording and synthesized samples91 92Some others will actually use perf record and some test binaries that93are in tests/shell/coresight and will collect traces to ensure a94minimum level of functionality is met. The scripts that launch these95tests are in the same directory. These will all look like:96 97 CoreSight / ASM Pure Loop98 CoreSight / Memcpy 16k 10 Threads99 CoreSight / Thread Loop 10 Threads - Check TID100 etc.101 102These perf record tests will not run if the tool binaries do not exist103in tests/shell/coresight/\*/ and will be skipped. If you do not have104CoreSight support in hardware then either do not build perf with105CoreSight support or remove these binaries in order to not have these106tests fail and have them skip instead.107 108These tests will log historical results in the current working109directory (e.g. tools/perf) and will be named stats-\*.csv like:110 111 stats-asm_pure_loop-out.csv112 stats-memcpy_thread-16k_10.csv113 ...114 115These statistic files log some aspects of the AUX data sections in116the perf data output counting some numbers of certain encodings (a117good way to know that it's working in a very simple way). One problem118with CoreSight is that given a large enough amount of data needing to119be logged, some of it can be lost due to the processor not waking up120in time to read out all the data from buffers etc.. You will notice121that the amount of data collected can vary a lot per run of perf test.122If you wish to see how this changes over time, simply run perf test123multiple times and all these csv files will have more and more data124appended to it that you can later examine, graph and otherwise use to125figure out if things have become worse or better.126 127This means sometimes these tests fail as they don't capture all the128data needed. This is about tracking quality and amount of data129produced over time and to see when changes to the Linux kernel improve130quality of traces.131 132Be aware that some of these tests take quite a while to run, specifically133in processing the perf data file and dumping contents to then examine what134is inside.135 136You can change where these csv logs are stored by setting the137PERF_TEST_CORESIGHT_STATDIR environment variable before running perf138test like::139 140 export PERF_TEST_CORESIGHT_STATDIR=/var/tmp141 perf test142 143They will also store resulting perf output data in the current144directory for later inspection like::145 146 perf-asm_pure_loop-out.data147 perf-memcpy_thread-16k_10.data148 ...149 150You can alter where the perf data files are stored by setting the151PERF_TEST_CORESIGHT_DATADIR environment variable such as::152 153 PERF_TEST_CORESIGHT_DATADIR=/var/tmp154 perf test155 156You may wish to set these above environment variables if you wish to157keep the output of tests outside of the current working directory for158longer term storage and examination.159