hisi-ptt.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ======================================
  3. HiSilicon PCIe Tune and Trace device
  4. ======================================
  5. Introduction
  6. ============
  7. HiSilicon PCIe tune and trace device (PTT) is a PCIe Root Complex
  8. integrated Endpoint (RCiEP) device, providing the capability
  9. to dynamically monitor and tune the PCIe link's events (tune),
  10. and trace the TLP headers (trace). The two functions are independent,
  11. but is recommended to use them together to analyze and enhance the
  12. PCIe link's performance.
  13. On Kunpeng 930 SoC, the PCIe Root Complex is composed of several
  14. PCIe cores. Each PCIe core includes several Root Ports and a PTT
  15. RCiEP, like below. The PTT device is capable of tuning and
  16. tracing the links of the PCIe core.
  17. ::
  18. +--------------Core 0-------+
  19. | | [ PTT ] |
  20. | | [Root Port]---[Endpoint]
  21. | | [Root Port]---[Endpoint]
  22. | | [Root Port]---[Endpoint]
  23. Root Complex |------Core 1-------+
  24. | | [ PTT ] |
  25. | | [Root Port]---[ Switch ]---[Endpoint]
  26. | | [Root Port]---[Endpoint] `-[Endpoint]
  27. | | [Root Port]---[Endpoint]
  28. +---------------------------+
  29. The PTT device driver registers one PMU device for each PTT device.
  30. The name of each PTT device is composed of 'hisi_ptt' prefix with
  31. the id of the SICL and the Core where it locates. The Kunpeng 930
  32. SoC encapsulates multiple CPU dies (SCCL, Super CPU Cluster) and
  33. IO dies (SICL, Super I/O Cluster), where there's one PCIe Root
  34. Complex for each SICL.
  35. ::
  36. /sys/devices/hisi_ptt<sicl_id>_<core_id>
  37. Tune
  38. ====
  39. PTT tune is designed for monitoring and adjusting PCIe link parameters (events).
  40. Currently we support events in 2 classes. The scope of the events
  41. covers the PCIe core to which the PTT device belongs.
  42. Each event is presented as a file under $(PTT PMU dir)/tune, and
  43. a simple open/read/write/close cycle will be used to tune the event.
  44. ::
  45. $ cd /sys/devices/hisi_ptt<sicl_id>_<core_id>/tune
  46. $ ls
  47. qos_tx_cpl qos_tx_np qos_tx_p
  48. tx_path_rx_req_alloc_buf_level
  49. tx_path_tx_req_alloc_buf_level
  50. $ cat qos_tx_dp
  51. 1
  52. $ echo 2 > qos_tx_dp
  53. $ cat qos_tx_dp
  54. 2
  55. Current value (numerical value) of the event can be simply read
  56. from the file, and the desired value written to the file to tune.
  57. 1. Tx Path QoS Control
  58. ------------------------
  59. The following files are provided to tune the QoS of the tx path of
  60. the PCIe core.
  61. - qos_tx_cpl: weight of Tx completion TLPs
  62. - qos_tx_np: weight of Tx non-posted TLPs
  63. - qos_tx_p: weight of Tx posted TLPs
  64. The weight influences the proportion of certain packets on the PCIe link.
  65. For example, for the storage scenario, increase the proportion
  66. of the completion packets on the link to enhance the performance as
  67. more completions are consumed.
  68. The available tune data of these events is [0, 1, 2].
  69. Writing a negative value will return an error, and out of range
  70. values will be converted to 2. Note that the event value just
  71. indicates a probable level, but is not precise.
  72. 2. Tx Path Buffer Control
  73. -------------------------
  74. Following files are provided to tune the buffer of tx path of the PCIe core.
  75. - rx_alloc_buf_level: watermark of Rx requested
  76. - tx_alloc_buf_level: watermark of Tx requested
  77. These events influence the watermark of the buffer allocated for each
  78. type. Rx means the inbound while Tx means outbound. The packets will
  79. be stored in the buffer first and then transmitted either when the
  80. watermark reached or when timed out. For a busy direction, you should
  81. increase the related buffer watermark to avoid frequently posting and
  82. thus enhance the performance. In most cases just keep the default value.
  83. The available tune data of above events is [0, 1, 2].
  84. Writing a negative value will return an error, and out of range
  85. values will be converted to 2. Note that the event value just
  86. indicates a probable level, but is not precise.
  87. Trace
  88. =====
  89. PTT trace is designed for dumping the TLP headers to the memory, which
  90. can be used to analyze the transactions and usage condition of the PCIe
  91. Link. You can choose to filter the traced headers by either Requester ID,
  92. or those downstream of a set of Root Ports on the same core of the PTT
  93. device. It's also supported to trace the headers of certain type and of
  94. certain direction.
  95. You can use the perf command `perf record` to set the parameters, start
  96. trace and get the data. It's also supported to decode the trace
  97. data with `perf report`. The control parameters for trace is inputted
  98. as event code for each events, which will be further illustrated later.
  99. An example usage is like
  100. ::
  101. $ perf record -e hisi_ptt0_2/filter=0x80001,type=1,direction=1,
  102. format=1/ -- sleep 5
  103. This will trace the TLP headers downstream root port 0000:00:10.1 (event
  104. code for event 'filter' is 0x80001) with type of posted TLP requests,
  105. direction of inbound and traced data format of 8DW.
  106. 1. Filter
  107. ---------
  108. The TLP headers to trace can be filtered by the Root Ports or the Requester ID
  109. of the Endpoint, which are located on the same core of the PTT device. You can
  110. set the filter by specifying the `filter` parameter which is required to start
  111. the trace. The parameter value is 20 bit. Bit 19 indicates the filter type.
  112. 1 for Root Port filter and 0 for Requester filter. Bit[15:0] indicates the
  113. filter value. The value for a Root Port is a mask of the core port id which is
  114. calculated from its PCI Slot ID as (slotid & 7) * 2. The value for a Requester
  115. is the Requester ID (Device ID of the PCIe function). Bit[18:16] is currently
  116. reserved for extension.
  117. For example, if the desired filter is Endpoint function 0000:01:00.1 the filter
  118. value will be 0x00101. If the desired filter is Root Port 0000:00:10.0 then
  119. then filter value is calculated as 0x80001.
  120. Note that multiple Root Ports can be specified at one time, but only one
  121. Endpoint function can be specified in one trace. Specifying both Root Port
  122. and function at the same time is not supported. Driver maintains a list of
  123. available filters and will check the invalid inputs.
  124. Currently the available filters are detected in driver's probe. If the supported
  125. devices are removed/added after probe, you may need to reload the driver to update
  126. the filters.
  127. 2. Type
  128. -------
  129. You can trace the TLP headers of certain types by specifying the `type`
  130. parameter, which is required to start the trace. The parameter value is
  131. 8 bit. Current supported types and related values are shown below:
  132. - 8'b00000001: posted requests (P)
  133. - 8'b00000010: non-posted requests (NP)
  134. - 8'b00000100: completions (CPL)
  135. You can specify multiple types when tracing inbound TLP headers, but can only
  136. specify one when tracing outbound TLP headers.
  137. 3. Direction
  138. ------------
  139. You can trace the TLP headers from certain direction, which is relative
  140. to the Root Port or the PCIe core, by specifying the `direction` parameter.
  141. This is optional and the default parameter is inbound. The parameter value
  142. is 4 bit. When the desired format is 4DW, directions and related values
  143. supported are shown below:
  144. - 4'b0000: inbound TLPs (P, NP, CPL)
  145. - 4'b0001: outbound TLPs (P, NP, CPL)
  146. - 4'b0010: outbound TLPs (P, NP, CPL) and inbound TLPs (P, NP, CPL B)
  147. - 4'b0011: outbound TLPs (P, NP, CPL) and inbound TLPs (CPL A)
  148. When the desired format is 8DW, directions and related values supported are
  149. shown below:
  150. - 4'b0000: reserved
  151. - 4'b0001: outbound TLPs (P, NP, CPL)
  152. - 4'b0010: inbound TLPs (P, NP, CPL B)
  153. - 4'b0011: inbound TLPs (CPL A)
  154. Inbound completions are classified into two types:
  155. - completion A (CPL A): completion of CHI/DMA/Native non-posted requests, except for CPL B
  156. - completion B (CPL B): completion of DMA remote2local and P2P non-posted requests
  157. 4. Format
  158. --------------
  159. You can change the format of the traced TLP headers by specifying the
  160. `format` parameter. The default format is 4DW. The parameter value is 4 bit.
  161. Current supported formats and related values are shown below:
  162. - 4'b0000: 4DW length per TLP header
  163. - 4'b0001: 8DW length per TLP header
  164. The traced TLP header format is different from the PCIe standard.
  165. When using the 8DW data format, the entire TLP header is logged
  166. (Header DW0-3 shown below). For example, the TLP header for Memory
  167. Reads with 64-bit addresses is shown in PCIe r5.0, Figure 2-17;
  168. the header for Configuration Requests is shown in Figure 2.20, etc.
  169. In addition, 8DW trace buffer entries contain a timestamp and
  170. possibly a prefix for a PASID TLP prefix (see Figure 6-20, PCIe r5.0).
  171. Otherwise this field will be all 0.
  172. The bit[31:11] of DW0 is always 0x1fffff, which can be
  173. used to distinguish the data format. 8DW format is like
  174. ::
  175. bits [ 31:11 ][ 10:0 ]
  176. |---------------------------------------|-------------------|
  177. DW0 [ 0x1fffff ][ Reserved (0x7ff) ]
  178. DW1 [ Prefix ]
  179. DW2 [ Header DW0 ]
  180. DW3 [ Header DW1 ]
  181. DW4 [ Header DW2 ]
  182. DW5 [ Header DW3 ]
  183. DW6 [ Reserved (0x0) ]
  184. DW7 [ Time ]
  185. When using the 4DW data format, DW0 of the trace buffer entry
  186. contains selected fields of DW0 of the TLP, together with a
  187. timestamp. DW1-DW3 of the trace buffer entry contain DW1-DW3
  188. directly from the TLP header.
  189. 4DW format is like
  190. ::
  191. bits [31:30] [ 29:25 ][24][23][22][21][ 20:11 ][ 10:0 ]
  192. |-----|---------|---|---|---|---|-------------|-------------|
  193. DW0 [ Fmt ][ Type ][T9][T8][TH][SO][ Length ][ Time ]
  194. DW1 [ Header DW1 ]
  195. DW2 [ Header DW2 ]
  196. DW3 [ Header DW3 ]
  197. 5. Memory Management
  198. --------------------
  199. The traced TLP headers will be written to the memory allocated
  200. by the driver. The hardware accepts 4 DMA address with same size,
  201. and writes the buffer sequentially like below. If DMA addr 3 is
  202. finished and the trace is still on, it will return to addr 0.
  203. ::
  204. +->[DMA addr 0]->[DMA addr 1]->[DMA addr 2]->[DMA addr 3]-+
  205. +---------------------------------------------------------+
  206. Driver will allocate each DMA buffer of 4MiB. The finished buffer
  207. will be copied to the perf AUX buffer allocated by the perf core.
  208. Once the AUX buffer is full while the trace is still on, driver
  209. will commit the AUX buffer first and then apply for a new one with
  210. the same size. The size of AUX buffer is default to 16MiB. User can
  211. adjust the size by specifying the `-m` parameter of the perf command.
  212. 6. Decoding
  213. -----------
  214. You can decode the traced data with `perf report -D` command (currently
  215. only support to dump the raw trace data). The traced data will be decoded
  216. according to the format described previously (take 8DW as an example):
  217. ::
  218. [...perf headers and other information]
  219. . ... HISI PTT data: size 4194304 bytes
  220. . 00000000: 00 00 00 00 Prefix
  221. . 00000004: 01 00 00 60 Header DW0
  222. . 00000008: 0f 1e 00 01 Header DW1
  223. . 0000000c: 04 00 00 00 Header DW2
  224. . 00000010: 40 00 81 02 Header DW3
  225. . 00000014: 33 c0 04 00 Time
  226. . 00000020: 00 00 00 00 Prefix
  227. . 00000024: 01 00 00 60 Header DW0
  228. . 00000028: 0f 1e 00 01 Header DW1
  229. . 0000002c: 04 00 00 00 Header DW2
  230. . 00000030: 40 00 81 02 Header DW3
  231. . 00000034: 02 00 00 00 Time
  232. . 00000040: 00 00 00 00 Prefix
  233. . 00000044: 01 00 00 60 Header DW0
  234. . 00000048: 0f 1e 00 01 Header DW1
  235. . 0000004c: 04 00 00 00 Header DW2
  236. . 00000050: 40 00 81 02 Header DW3
  237. [...]