drm-usage-stats.rst 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. .. _drm-client-usage-stats:
  2. ======================
  3. DRM client usage stats
  4. ======================
  5. DRM drivers can choose to export partly standardised text output via the
  6. `fops->show_fdinfo()` as part of the driver specific file operations registered
  7. in the `struct drm_driver` object registered with the DRM core.
  8. One purpose of this output is to enable writing as generic as practically
  9. feasible `top(1)` like userspace monitoring tools.
  10. Given the differences between various DRM drivers the specification of the
  11. output is split between common and driver specific parts. Having said that,
  12. wherever possible effort should still be made to standardise as much as
  13. possible.
  14. File format specification
  15. =========================
  16. - File shall contain one key value pair per one line of text.
  17. - Colon character (`:`) must be used to delimit keys and values.
  18. - All standardised keys shall be prefixed with `drm-`.
  19. - Driver-specific keys shall be prefixed with `driver_name-`, where
  20. driver_name should ideally be the same as the `name` field in
  21. `struct drm_driver`, although this is not mandatory.
  22. - Whitespace between the delimiter and first non-whitespace character shall be
  23. ignored when parsing.
  24. - Keys are not allowed to contain whitespace characters.
  25. - Numerical key value pairs can end with optional unit string.
  26. - Data type of the value is fixed as defined in the specification.
  27. Key types
  28. ---------
  29. 1. Mandatory, fully standardised.
  30. 2. Optional, fully standardised.
  31. 3. Driver specific.
  32. Data types
  33. ----------
  34. - <uint> - Unsigned integer without defining the maximum value.
  35. - <keystr> - String excluding any above defined reserved characters or whitespace.
  36. - <valstr> - String.
  37. Mandatory fully standardised keys
  38. ---------------------------------
  39. - drm-driver: <valstr>
  40. String shall contain the name this driver registered as via the respective
  41. `struct drm_driver` data structure.
  42. Optional fully standardised keys
  43. --------------------------------
  44. Identification
  45. ^^^^^^^^^^^^^^
  46. - drm-pdev: <aaaa:bb.cc.d>
  47. For PCI devices this should contain the PCI slot address of the device in
  48. question.
  49. - drm-client-id: <uint>
  50. Unique value relating to the open DRM file descriptor used to distinguish
  51. duplicated and shared file descriptors. Conceptually the value should map 1:1
  52. to the in kernel representation of `struct drm_file` instances.
  53. Uniqueness of the value shall be either globally unique, or unique within the
  54. scope of each device, in which case `drm-pdev` shall be present as well.
  55. Userspace should make sure to not double account any usage statistics by using
  56. the above described criteria in order to associate data to individual clients.
  57. - drm-client-name: <valstr>
  58. String optionally set by userspace using DRM_IOCTL_SET_CLIENT_NAME.
  59. Utilization
  60. ^^^^^^^^^^^
  61. - drm-engine-<keystr>: <uint> ns
  62. GPUs usually contain multiple execution engines. Each shall be given a stable
  63. and unique name (keystr), with possible values documented in the driver specific
  64. documentation.
  65. Value shall be in specified time units which the respective GPU engine spent
  66. busy executing workloads belonging to this client.
  67. Values are not required to be constantly monotonic if it makes the driver
  68. implementation easier, but are required to catch up with the previously reported
  69. larger value within a reasonable period. Upon observing a value lower than what
  70. was previously read, userspace is expected to stay with that larger previous
  71. value until a monotonic update is seen.
  72. - drm-engine-capacity-<keystr>: <uint>
  73. Engine identifier string must be the same as the one specified in the
  74. drm-engine-<keystr> tag and shall contain a greater than zero number in case the
  75. exported engine corresponds to a group of identical hardware engines.
  76. In the absence of this tag parser shall assume capacity of one. Zero capacity
  77. is not allowed.
  78. - drm-cycles-<keystr>: <uint>
  79. Engine identifier string must be the same as the one specified in the
  80. drm-engine-<keystr> tag and shall contain the number of busy cycles for the given
  81. engine.
  82. Values are not required to be constantly monotonic if it makes the driver
  83. implementation easier, but are required to catch up with the previously reported
  84. larger value within a reasonable period. Upon observing a value lower than what
  85. was previously read, userspace is expected to stay with that larger previous
  86. value until a monotonic update is seen.
  87. - drm-total-cycles-<keystr>: <uint>
  88. Engine identifier string must be the same as the one specified in the
  89. drm-cycles-<keystr> tag and shall contain the total number cycles for the given
  90. engine.
  91. This is a timestamp in GPU unspecified unit that matches the update rate
  92. of drm-cycles-<keystr>. For drivers that implement this interface, the engine
  93. utilization can be calculated entirely on the GPU clock domain, without
  94. considering the CPU sleep time between 2 samples.
  95. A driver may implement either this key or drm-maxfreq-<keystr>, but not both.
  96. - drm-maxfreq-<keystr>: <uint> [Hz|MHz|KHz]
  97. Engine identifier string must be the same as the one specified in the
  98. drm-engine-<keystr> tag and shall contain the maximum frequency for the given
  99. engine. Taken together with drm-cycles-<keystr>, this can be used to calculate
  100. percentage utilization of the engine, whereas drm-engine-<keystr> only reflects
  101. time active without considering what frequency the engine is operating as a
  102. percentage of its maximum frequency.
  103. A driver may implement either this key or drm-total-cycles-<keystr>, but not
  104. both.
  105. Memory
  106. ^^^^^^
  107. Each possible memory type which can be used to store buffer objects by the GPU
  108. in question shall be given a stable and unique name to be used as the "<region>"
  109. string.
  110. The region name "memory" is reserved to refer to normal system memory.
  111. The value shall reflect the amount of storage currently consumed by the buffer
  112. objects belong to this client, in the respective memory region.
  113. Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB'
  114. indicating kibi- or mebi-bytes.
  115. - drm-total-<region>: <uint> [KiB|MiB]
  116. The total size of all requested buffers, including both shared and private
  117. memory. The backing store for the buffers does not need to be currently
  118. instantiated to count under this category. To avoid double-counting, if a buffer
  119. has multiple regions where it can be allocated to, the implementation should
  120. consistently select a single region for accounting purposes.
  121. - drm-shared-<region>: <uint> [KiB|MiB]
  122. The total size of buffers that are shared with another file (i.e., have more
  123. than one handle). The same requirement to avoid double-counting that applies to
  124. drm-total-<region> also applies here.
  125. - drm-resident-<region>: <uint> [KiB|MiB]
  126. The total size of buffers that are resident (i.e., have their backing store
  127. present or instantiated) in the specified region.
  128. - drm-memory-<region>: <uint> [KiB|MiB]
  129. This key is deprecated and is only printed by amdgpu; it is an alias for
  130. drm-resident-<region>.
  131. - drm-purgeable-<region>: <uint> [KiB|MiB]
  132. The total size of buffers that are resident and purgeable.
  133. For example, drivers that implement functionality similar to 'madvise' can count
  134. buffers that have instantiated backing stores but have been marked with an
  135. equivalent of MADV_DONTNEED.
  136. - drm-active-<region>: <uint> [KiB|MiB]
  137. The total size of buffers that are active on one or more engines.
  138. One practical example of this could be the presence of unsignaled fences in a
  139. GEM buffer reservation object. Therefore, the active category is a subset of the
  140. resident category.
  141. Implementation Details
  142. ======================
  143. Drivers should use drm_show_fdinfo() in their `struct file_operations`, and
  144. implement &drm_driver.show_fdinfo if they wish to provide any stats which
  145. are not provided by drm_show_fdinfo(). But even driver specific stats should
  146. be documented above and where possible, aligned with other drivers.
  147. Driver specific implementations
  148. -------------------------------
  149. * :ref:`i915-usage-stats`
  150. * :ref:`panfrost-usage-stats`
  151. * :ref:`panthor-usage-stats`
  152. * :ref:`xe-usage-stats`