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