coresight-perf.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ================
  3. CoreSight - Perf
  4. ================
  5. :Author: Carsten Haitzler <carsten.haitzler@arm.com>
  6. :Date: June 29th, 2022
  7. Perf is able to locally access CoreSight trace data and store it to the
  8. output perf data files. This data can then be later decoded to give the
  9. instructions that were traced for debugging or profiling purposes. You
  10. can log such data with a perf record command like::
  11. perf record -e cs_etm//u testbinary
  12. This would run some test binary (testbinary) until it exits and record
  13. a perf.data trace file. That file would have AUX sections if CoreSight
  14. is working correctly. You can dump the content of this file as
  15. readable text with a command like::
  16. perf report --stdio --dump -i perf.data
  17. You should find some sections of this file have AUX data blocks like::
  18. 0x1e78 [0x30]: PERF_RECORD_AUXTRACE size: 0x11dd0 offset: 0 ref: 0x1b614fc1061b0ad1 idx: 0 tid: 531230 cpu: -1
  19. . ... CoreSight ETM Trace data: size 73168 bytes
  20. Idx:0; ID:10; I_ASYNC : Alignment Synchronisation.
  21. Idx:12; ID:10; I_TRACE_INFO : Trace Info.; INFO=0x0 { CC.0 }
  22. Idx:17; ID:10; I_ADDR_L_64IS0 : Address, Long, 64 bit, IS0.; Addr=0x0000000000000000;
  23. Idx:26; ID:10; I_TRACE_ON : Trace On.
  24. Idx:27; ID:10; I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0x0000FFFFB6069140; Ctxt: AArch64,EL0, NS;
  25. Idx:38; ID:10; I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE
  26. Idx:39; ID:10; I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE
  27. Idx:40; ID:10; I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE
  28. Idx:41; ID:10; I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEN
  29. ...
  30. If you see these above, then your system is tracing CoreSight data
  31. correctly.
  32. To compile perf with CoreSight support in the tools/perf directory do::
  33. make CORESIGHT=1
  34. This requires OpenCSD to build. You may install distribution packages
  35. for the support such as libopencsd and libopencsd-dev or download it
  36. and build yourself. Upstream OpenCSD is located at:
  37. https://github.com/Linaro/OpenCSD
  38. For complete information on building perf with CoreSight support and
  39. more extensive usage look at:
  40. https://github.com/Linaro/OpenCSD/blob/master/HOWTO.md
  41. Kernel CoreSight Support
  42. ------------------------
  43. You will also want CoreSight support enabled in your kernel config.
  44. Ensure it is enabled with::
  45. CONFIG_CORESIGHT=y
  46. There are various other CoreSight options you probably also want
  47. enabled like::
  48. CONFIG_CORESIGHT_LINKS_AND_SINKS=y
  49. CONFIG_CORESIGHT_LINK_AND_SINK_TMC=y
  50. CONFIG_CORESIGHT_CATU=y
  51. CONFIG_CORESIGHT_SINK_TPIU=y
  52. CONFIG_CORESIGHT_SINK_ETBV10=y
  53. CONFIG_CORESIGHT_SOURCE_ETM4X=y
  54. CONFIG_CORESIGHT_CTI=y
  55. CONFIG_CORESIGHT_CTI_INTEGRATION_REGS=y
  56. Please refer to the kernel configuration help for more information.
  57. Perf test - Verify kernel and userspace perf CoreSight work
  58. -----------------------------------------------------------
  59. When you run perf test, it will do a lot of self tests. Some of those
  60. tests will cover CoreSight (only if enabled and on ARM64). You
  61. generally would run perf test from the tools/perf directory in the
  62. kernel tree. Some tests will check some internal perf support like:
  63. Check Arm CoreSight trace data recording and synthesized samples
  64. Check Arm SPE trace data recording and synthesized samples
  65. Some others will actually use perf record and some test binaries that
  66. are in tests/shell/coresight and will collect traces to ensure a
  67. minimum level of functionality is met. The scripts that launch these
  68. tests are in the same directory. These will all look like:
  69. CoreSight / ASM Pure Loop
  70. CoreSight / Memcpy 16k 10 Threads
  71. CoreSight / Thread Loop 10 Threads - Check TID
  72. etc.
  73. These perf record tests will not run if the tool binaries do not exist
  74. in tests/shell/coresight/\*/ and will be skipped. If you do not have
  75. CoreSight support in hardware then either do not build perf with
  76. CoreSight support or remove these binaries in order to not have these
  77. tests fail and have them skip instead.
  78. These tests will log historical results in the current working
  79. directory (e.g. tools/perf) and will be named stats-\*.csv like:
  80. stats-asm_pure_loop-out.csv
  81. stats-memcpy_thread-16k_10.csv
  82. ...
  83. These statistic files log some aspects of the AUX data sections in
  84. the perf data output counting some numbers of certain encodings (a
  85. good way to know that it's working in a very simple way). One problem
  86. with CoreSight is that given a large enough amount of data needing to
  87. be logged, some of it can be lost due to the processor not waking up
  88. in time to read out all the data from buffers etc.. You will notice
  89. that the amount of data collected can vary a lot per run of perf test.
  90. If you wish to see how this changes over time, simply run perf test
  91. multiple times and all these csv files will have more and more data
  92. appended to it that you can later examine, graph and otherwise use to
  93. figure out if things have become worse or better.
  94. This means sometimes these tests fail as they don't capture all the
  95. data needed. This is about tracking quality and amount of data
  96. produced over time and to see when changes to the Linux kernel improve
  97. quality of traces.
  98. Be aware that some of these tests take quite a while to run, specifically
  99. in processing the perf data file and dumping contents to then examine what
  100. is inside.
  101. You can change where these csv logs are stored by setting the
  102. PERF_TEST_CORESIGHT_STATDIR environment variable before running perf
  103. test like::
  104. export PERF_TEST_CORESIGHT_STATDIR=/var/tmp
  105. perf test
  106. They will also store resulting perf output data in the current
  107. directory for later inspection like::
  108. perf-asm_pure_loop-out.data
  109. perf-memcpy_thread-16k_10.data
  110. ...
  111. You can alter where the perf data files are stored by setting the
  112. PERF_TEST_CORESIGHT_DATADIR environment variable such as::
  113. PERF_TEST_CORESIGHT_DATADIR=/var/tmp
  114. perf test
  115. You may wish to set these above environment variables if you wish to
  116. keep the output of tests outside of the current working directory for
  117. longer term storage and examination.