History

drm/i915: Enable i915 perf stream for Haswell OA unit

Gen graphics hardware can be set up to periodically write snapshots of performance counters into a circular buffer via its Observation Architecture and this patch exposes that capability to userspace via the i915 perf interface. v2: Make sure to initialize ->specific_ctx_id when opening, without relying on _pin_notify hook, in case ctx already pinned. v3: Revert back to pinning ctx upfront when opening stream, removing need to hook in to pinning and to update OACONTROL on the fly.

Robert Bragg committed 10 years ago

Commit d7965151 parent 8a3003d4 files · +1482 −29Browse files

Unified · Split

4 files
  1. drivers/gpu/drm/i915/i915_drv.h +56 −10
  2. drivers/gpu/drm/i915/i915_perf.c +1019 −17
  3. drivers/gpu/drm/i915/i915_reg.h +338 −0
  4. include/uapi/drm/i915_drm.h +69 −2
drivers/gpu/drm/i915/i915_drv.h+56−10
@@ -1797,6 +1797,11 @@ struct intel_wm_config { · 1796 unmodified lines
1797 bool sprites_scaled;1797 bool sprites_scaled;
1798};1798};
1799 1799
1800struct i915_oa_format {
1801 u32 format;
1802 int size;
1803};
1804
1800struct i915_oa_reg {1805struct i915_oa_reg {
1801 i915_reg_t addr;1806 i915_reg_t addr;
1802 u32 value;1807 u32 value;
@@ -1817,11 +1822,6 @@ struct i915_perf_stream_ops { · 14 unmodified lines
1817 */1822 */
1818 void (*disable)(struct i915_perf_stream *stream);1823 void (*disable)(struct i915_perf_stream *stream);
1819 1824
1820 /* Return: true if any i915 perf records are ready to read()
1821 * for this stream.
1822 */
1823 bool (*can_read)(struct i915_perf_stream *stream);
1824
1825 /* Call poll_wait, passing a wait queue that will be woken1825 /* Call poll_wait, passing a wait queue that will be woken
1826 * once there is something ready to read() for the stream1826 * once there is something ready to read() for the stream
1827 */1827 */
@@ -1831,9 +1831,7 @@ struct i915_perf_stream_ops { · 3 unmodified lines
1831 1831
1832 /* For handling a blocking read, wait until there is something1832 /* For handling a blocking read, wait until there is something
1833 * to ready to read() for the stream. E.g. wait on the same1833 * to ready to read() for the stream. E.g. wait on the same
1834 * wait queue that would be passed to poll_wait() until1834 * wait queue that would be passed to poll_wait().
1835 * ->can_read() returns true (if its safe to call ->can_read()
1836 * without the i915 perf lock held).
1837 */1835 */
1838 int (*wait_unlocked)(struct i915_perf_stream *stream);1836 int (*wait_unlocked)(struct i915_perf_stream *stream);
1839 1837
@@ -1873,11 +1871,28 @@ struct i915_perf_stream { · 33 unmodified lines
1873 struct list_head link;1871 struct list_head link;
1874 1872
1875 u32 sample_flags;1873 u32 sample_flags;
1874 int sample_size;
1876 1875
1877 struct i915_gem_context *ctx;1876 struct i915_gem_context *ctx;
1878 bool enabled;1877 bool enabled;
1879 1878
1880 struct i915_perf_stream_ops *ops;1879 const struct i915_perf_stream_ops *ops;
1880};
1881
1882struct i915_oa_ops {
1883 void (*init_oa_buffer)(struct drm_i915_private *dev_priv);
1884 int (*enable_metric_set)(struct drm_i915_private *dev_priv);
1885 void (*disable_metric_set)(struct drm_i915_private *dev_priv);
1886 void (*oa_enable)(struct drm_i915_private *dev_priv);
1887 void (*oa_disable)(struct drm_i915_private *dev_priv);
1888 void (*update_oacontrol)(struct drm_i915_private *dev_priv);
1889 void (*update_hw_ctx_id_locked)(struct drm_i915_private *dev_priv,
1890 u32 ctx_id);
1891 int (*read)(struct i915_perf_stream *stream,
1892 char __user *buf,
1893 size_t count,
1894 size_t *offset);
1895 bool (*oa_buffer_is_empty)(struct drm_i915_private *dev_priv);
1881};1896};
1882 1897
1883struct drm_i915_private {1898struct drm_i915_private {
@@ -2177,16 +2192,47 @@ struct drm_i915_private { · 293 unmodified lines
2177 2192
2178 struct {2193 struct {
2179 bool initialized;2194 bool initialized;
2195
2180 struct mutex lock;2196 struct mutex lock;
2181 struct list_head streams;2197 struct list_head streams;
2182 2198
2199 spinlock_t hook_lock;
2200
2183 struct {2201 struct {
2184 u32 metrics_set;2202 struct i915_perf_stream *exclusive_stream;
2203
2204 u32 specific_ctx_id;
2205 struct i915_vma *pinned_rcs_vma;
2206
2207 struct hrtimer poll_check_timer;
2208 wait_queue_head_t poll_wq;
2209 bool pollin;
2210
2211 bool periodic;
2212 int period_exponent;
2213 int timestamp_frequency;
2214
2215 int tail_margin;
2216
2217 int metrics_set;
2185 2218
2186 const struct i915_oa_reg *mux_regs;2219 const struct i915_oa_reg *mux_regs;
2187 int mux_regs_len;2220 int mux_regs_len;
2188 const struct i915_oa_reg *b_counter_regs;2221 const struct i915_oa_reg *b_counter_regs;
2189 int b_counter_regs_len;2222 int b_counter_regs_len;
2223
2224 struct {
2225 struct i915_vma *vma;
2226 u8 *vaddr;
2227 int format;
2228 int format_size;
2229 } oa_buffer;
2230
2231 u32 gen7_latched_oastatus1;
2232
2233 struct i915_oa_ops ops;
2234 const struct i915_oa_format *oa_formats;
2235 int n_builtin_sets;
2190 } oa;2236 } oa;
2191 } perf;2237 } perf;
2192 2238
drivers/gpu/drm/i915/i915_perf.c+1019−17
@@ -25,16 +25,899 @@ · 24 unmodified lines
25 */25 */
26 26
27#include <linux/anon_inodes.h>27#include <linux/anon_inodes.h>
28#include <linux/sizes.h>
28 29
29#include "i915_drv.h"30#include "i915_drv.h"
31#include "i915_oa_hsw.h"
32
33/* HW requires this to be a power of two, between 128k and 16M, though driver
34 * is currently generally designed assuming the largest 16M size is used such
35 * that the overflow cases are unlikely in normal operation.
36 */
37#define OA_BUFFER_SIZE SZ_16M
38
39#define OA_TAKEN(tail, head) ((tail - head) & (OA_BUFFER_SIZE - 1))
40
41/* There's a HW race condition between OA unit tail pointer register updates and
42 * writes to memory whereby the tail pointer can sometimes get ahead of what's
43 * been written out to the OA buffer so far.
44 *
45 * Although this can be observed explicitly by checking for a zeroed report-id
46 * field in tail reports, it seems preferable to account for this earlier e.g.
47 * as part of the _oa_buffer_is_empty checks to minimize -EAGAIN polling cycles
48 * in this situation.
49 *
50 * To give time for the most recent reports to land before they may be copied to
51 * userspace, the driver operates as if the tail pointer effectively lags behind
52 * the HW tail pointer by 'tail_margin' bytes. The margin in bytes is calculated
53 * based on this constant in nanoseconds, the current OA sampling exponent
54 * and current report size.
55 *
56 * There is also a fallback check while reading to simply skip over reports with
57 * a zeroed report-id.
58 */
59#define OA_TAIL_MARGIN_NSEC 100000ULL
60
61/* frequency for checking whether the OA unit has written new reports to the
62 * circular OA buffer...
63 */
64#define POLL_FREQUENCY 200
65#define POLL_PERIOD (NSEC_PER_SEC / POLL_FREQUENCY)
66
67/* The maximum exponent the hardware accepts is 63 (essentially it selects one
68 * of the 64bit timestamp bits to trigger reports from) but there's currently
69 * no known use case for sampling as infrequently as once per 47 thousand years.
70 *
71 * Since the timestamps included in OA reports are only 32bits it seems
72 * reasonable to limit the OA exponent where it's still possible to account for
73 * overflow in OA report timestamps.
74 */
75#define OA_EXPONENT_MAX 31
76
77#define INVALID_CTX_ID 0xffffffff
78
79
80/* XXX: beware if future OA HW adds new report formats that the current
81 * code assumes all reports have a power-of-two size and ~(size - 1) can
82 * be used as a mask to align the OA tail pointer.
83 */
84static struct i915_oa_format hsw_oa_formats[I915_OA_FORMAT_MAX] = {
85 [I915_OA_FORMAT_A13] = { 0, 64 },
86 [I915_OA_FORMAT_A29] = { 1, 128 },
87 [I915_OA_FORMAT_A13_B8_C8] = { 2, 128 },
88 /* A29_B8_C8 Disallowed as 192 bytes doesn't factor into buffer size */
89 [I915_OA_FORMAT_B4_C8] = { 4, 64 },
90 [I915_OA_FORMAT_A45_B8_C8] = { 5, 256 },
91 [I915_OA_FORMAT_B4_C8_A16] = { 6, 128 },
92 [I915_OA_FORMAT_C4_B8] = { 7, 64 },
93};
94
95#define SAMPLE_OA_REPORT (1<<0)
30 96
31struct perf_open_properties {97struct perf_open_properties {
32 u32 sample_flags;98 u32 sample_flags;
33 99
34 u64 single_context:1;100 u64 single_context:1;
35 u64 ctx_handle;101 u64 ctx_handle;
102
103 /* OA sampling state */
104 int metrics_set;
105 int oa_format;
106 bool oa_periodic;
107 int oa_period_exponent;
108};
109
110/* NB: This is either called via fops or the poll check hrtimer (atomic ctx)
111 *
112 * It's safe to read OA config state here unlocked, assuming that this is only
113 * called while the stream is enabled, while the global OA configuration can't
114 * be modified.
115 *
116 * Note: we don't lock around the head/tail reads even though there's the slim
117 * possibility of read() fop errors forcing a re-init of the OA buffer
118 * pointers. A race here could result in a false positive !empty status which
119 * is acceptable.
120 */
121static bool gen7_oa_buffer_is_empty_fop_unlocked(struct drm_i915_private *dev_priv)
122{
123 int report_size = dev_priv->perf.oa.oa_buffer.format_size;
124 u32 oastatus2 = I915_READ(GEN7_OASTATUS2);
125 u32 oastatus1 = I915_READ(GEN7_OASTATUS1);
126 u32 head = oastatus2 & GEN7_OASTATUS2_HEAD_MASK;
127 u32 tail = oastatus1 & GEN7_OASTATUS1_TAIL_MASK;
128
129 return OA_TAKEN(tail, head) <
130 dev_priv->perf.oa.tail_margin + report_size;
131}
132
133/**
134 * Appends a status record to a userspace read() buffer.
135 */
136static int append_oa_status(struct i915_perf_stream *stream,
137 char __user *buf,
138 size_t count,
139 size_t *offset,
140 enum drm_i915_perf_record_type type)
141{
142 struct drm_i915_perf_record_header header = { type, 0, sizeof(header) };
143
144 if ((count - *offset) < header.size)
145 return -ENOSPC;
146
147 if (copy_to_user(buf + *offset, &header, sizeof(header)))
148 return -EFAULT;
149
150 (*offset) += header.size;
151
152 return 0;
153}
154
155/**
156 * Copies single OA report into userspace read() buffer.
157 */
158static int append_oa_sample(struct i915_perf_stream *stream,
159 char __user *buf,
160 size_t count,
161 size_t *offset,
162 const u8 *report)
163{
164 struct drm_i915_private *dev_priv = stream->dev_priv;
165 int report_size = dev_priv->perf.oa.oa_buffer.format_size;
166 struct drm_i915_perf_record_header header;
167 u32 sample_flags = stream->sample_flags;
168
169 header.type = DRM_I915_PERF_RECORD_SAMPLE;
170 header.pad = 0;
171 header.size = stream->sample_size;
172
173 if ((count - *offset) < header.size)
174 return -ENOSPC;
175
176 buf += *offset;
177 if (copy_to_user(buf, &header, sizeof(header)))
178 return -EFAULT;
179 buf += sizeof(header);
180
181 if (sample_flags & SAMPLE_OA_REPORT) {
182 if (copy_to_user(buf, report, report_size))
183 return -EFAULT;
184 }
185
186 (*offset) += header.size;
187
188 return 0;
189}
190
191/**
192 * Copies all buffered OA reports into userspace read() buffer.
193 * @stream: An i915-perf stream opened for OA metrics
194 * @buf: destination buffer given by userspace
195 * @count: the number of bytes userspace wants to read
196 * @offset: (inout): the current position for writing into @buf
197 * @head_ptr: (inout): the current oa buffer cpu read position
198 * @tail: the current oa buffer gpu write position
199 *
200 * Returns 0 on success, negative error code on failure.
201 *
202 * Notably any error condition resulting in a short read (-ENOSPC or
203 * -EFAULT) will be returned even though one or more records may
204 * have been successfully copied. In this case it's up to the caller
205 * to decide if the error should be squashed before returning to
206 * userspace.
207 *
208 * Note: reports are consumed from the head, and appended to the
209 * tail, so the head chases the tail?... If you think that's mad
210 * and back-to-front you're not alone, but this follows the
211 * Gen PRM naming convention.
212 */
213static int gen7_append_oa_reports(struct i915_perf_stream *stream,
214 char __user *buf,
215 size_t count,
216 size_t *offset,
217 u32 *head_ptr,
218 u32 tail)
219{
220 struct drm_i915_private *dev_priv = stream->dev_priv;
221 int report_size = dev_priv->perf.oa.oa_buffer.format_size;
222 u8 *oa_buf_base = dev_priv->perf.oa.oa_buffer.vaddr;
223 int tail_margin = dev_priv->perf.oa.tail_margin;
224 u32 gtt_offset = i915_ggtt_offset(dev_priv->perf.oa.oa_buffer.vma);
225 u32 mask = (OA_BUFFER_SIZE - 1);
226 u32 head;
227 u32 taken;
228 int ret = 0;
229
230 if (WARN_ON(!stream->enabled))
231 return -EIO;
232
233 head = *head_ptr - gtt_offset;
234 tail -= gtt_offset;
235
236 /* The OA unit is expected to wrap the tail pointer according to the OA
237 * buffer size and since we should never write a misaligned head
238 * pointer we don't expect to read one back either...
239 */
240 if (tail > OA_BUFFER_SIZE || head > OA_BUFFER_SIZE ||
241 head % report_size) {
242 DRM_ERROR("Inconsistent OA buffer pointer (head = %u, tail = %u): force restart\n",
243 head, tail);
244 dev_priv->perf.oa.ops.oa_disable(dev_priv);
245 dev_priv->perf.oa.ops.oa_enable(dev_priv);
246 *head_ptr = I915_READ(GEN7_OASTATUS2) &
247 GEN7_OASTATUS2_HEAD_MASK;
248 return -EIO;
249 }
250
251
252 /* The tail pointer increases in 64 byte increments, not in report_size
253 * steps...
254 */
255 tail &= ~(report_size - 1);
256
257 /* Move the tail pointer back by the current tail_margin to account for
258 * the possibility that the latest reports may not have really landed
259 * in memory yet...
260 */
261
262 if (OA_TAKEN(tail, head) < report_size + tail_margin)
263 return -EAGAIN;
264
265 tail -= tail_margin;
266 tail &= mask;
267
268 for (/* none */;
269 (taken = OA_TAKEN(tail, head));
270 head = (head + report_size) & mask) {
271 u8 *report = oa_buf_base + head;
272 u32 *report32 = (void *)report;
273
274 /* All the report sizes factor neatly into the buffer
275 * size so we never expect to see a report split
276 * between the beginning and end of the buffer.
277 *
278 * Given the initial alignment check a misalignment
279 * here would imply a driver bug that would result
280 * in an overrun.
281 */
282 if (WARN_ON((OA_BUFFER_SIZE - head) < report_size)) {
283 DRM_ERROR("Spurious OA head ptr: non-integral report offset\n");
284 break;
285 }
286
287 /* The report-ID field for periodic samples includes
288 * some undocumented flags related to what triggered
289 * the report and is never expected to be zero so we
290 * can check that the report isn't invalid before
291 * copying it to userspace...
292 */
293 if (report32[0] == 0) {
294 DRM_ERROR("Skipping spurious, invalid OA report\n");
295 continue;
296 }
297
298 ret = append_oa_sample(stream, buf, count, offset, report);
299 if (ret)
300 break;
301
302 /* The above report-id field sanity check is based on
303 * the assumption that the OA buffer is initially
304 * zeroed and we reset the field after copying so the
305 * check is still meaningful once old reports start
306 * being overwritten.
307 */
308 report32[0] = 0;
309 }
310
311 *head_ptr = gtt_offset + head;
312
313 return ret;
314}
315
316static int gen7_oa_read(struct i915_perf_stream *stream,
317 char __user *buf,
318 size_t count,
319 size_t *offset)
320{
321 struct drm_i915_private *dev_priv = stream->dev_priv;
322 int report_size = dev_priv->perf.oa.oa_buffer.format_size;
323 u32 oastatus2;
324 u32 oastatus1;
325 u32 head;
326 u32 tail;
327 int ret;
328
329 if (WARN_ON(!dev_priv->perf.oa.oa_buffer.vaddr))
330 return -EIO;
331
332 oastatus2 = I915_READ(GEN7_OASTATUS2);
333 oastatus1 = I915_READ(GEN7_OASTATUS1);
334
335 head = oastatus2 & GEN7_OASTATUS2_HEAD_MASK;
336 tail = oastatus1 & GEN7_OASTATUS1_TAIL_MASK;
337
338 /* XXX: On Haswell we don't have a safe way to clear oastatus1
339 * bits while the OA unit is enabled (while the tail pointer
340 * may be updated asynchronously) so we ignore status bits
341 * that have already been reported to userspace.
342 */
343 oastatus1 &= ~dev_priv->perf.oa.gen7_latched_oastatus1;
344
345 /* We treat OABUFFER_OVERFLOW as a significant error:
346 *
347 * - The status can be interpreted to mean that the buffer is
348 * currently full (with a higher precedence than OA_TAKEN()
349 * which will start to report a near-empty buffer after an
350 * overflow) but it's awkward that we can't clear the status
351 * on Haswell, so without a reset we won't be able to catch
352 * the state again.
353 *
354 * - Since it also implies the HW has started overwriting old
355 * reports it may also affect our sanity checks for invalid
356 * reports when copying to userspace that assume new reports
357 * are being written to cleared memory.
358 *
359 * - In the future we may want to introduce a flight recorder
360 * mode where the driver will automatically maintain a safe
361 * guard band between head/tail, avoiding this overflow
362 * condition, but we avoid the added driver complexity for
363 * now.
364 */
365 if (unlikely(oastatus1 & GEN7_OASTATUS1_OABUFFER_OVERFLOW)) {
366 ret = append_oa_status(stream, buf, count, offset,
367 DRM_I915_PERF_RECORD_OA_BUFFER_LOST);
368 if (ret)
369 return ret;
370
371 DRM_ERROR("OA buffer overflow: force restart\n");
372
373 dev_priv->perf.oa.ops.oa_disable(dev_priv);
374 dev_priv->perf.oa.ops.oa_enable(dev_priv);
375
376 oastatus2 = I915_READ(GEN7_OASTATUS2);
377 oastatus1 = I915_READ(GEN7_OASTATUS1);
378
379 head = oastatus2 & GEN7_OASTATUS2_HEAD_MASK;
380 tail = oastatus1 & GEN7_OASTATUS1_TAIL_MASK;
381 }
382
383 if (unlikely(oastatus1 & GEN7_OASTATUS1_REPORT_LOST)) {
384 ret = append_oa_status(stream, buf, count, offset,
385 DRM_I915_PERF_RECORD_OA_REPORT_LOST);
386 if (ret)
387 return ret;
388 dev_priv->perf.oa.gen7_latched_oastatus1 |=
389 GEN7_OASTATUS1_REPORT_LOST;
390 }
391
392 ret = gen7_append_oa_reports(stream, buf, count, offset,
393 &head, tail);
394
395 /* All the report sizes are a power of two and the
396 * head should always be incremented by some multiple
397 * of the report size.
398 *
399 * A warning here, but notably if we later read back a
400 * misaligned pointer we will treat that as a bug since
401 * it could lead to a buffer overrun.
402 */
403 WARN_ONCE(head & (report_size - 1),
404 "i915: Writing misaligned OA head pointer");
405
406 /* Note: we update the head pointer here even if an error
407 * was returned since the error may represent a short read
408 * where some some reports were successfully copied.
409 */
410 I915_WRITE(GEN7_OASTATUS2,
411 ((head & GEN7_OASTATUS2_HEAD_MASK) |
412 OA_MEM_SELECT_GGTT));
413
414 return ret;
415}
416
417static int i915_oa_wait_unlocked(struct i915_perf_stream *stream)
418{
419 struct drm_i915_private *dev_priv = stream->dev_priv;
420
421 /* We would wait indefinitely if periodic sampling is not enabled */
422 if (!dev_priv->perf.oa.periodic)
423 return -EIO;
424
425 /* Note: the oa_buffer_is_empty() condition is ok to run unlocked as it
426 * just performs mmio reads of the OA buffer head + tail pointers and
427 * it's assumed we're handling some operation that implies the stream
428 * can't be destroyed until completion (such as a read()) that ensures
429 * the device + OA buffer can't disappear
430 */
431 return wait_event_interruptible(dev_priv->perf.oa.poll_wq,
432 !dev_priv->perf.oa.ops.oa_buffer_is_empty(dev_priv));
433}
434
435static void i915_oa_poll_wait(struct i915_perf_stream *stream,
436 struct file *file,
437 poll_table *wait)
438{
439 struct drm_i915_private *dev_priv = stream->dev_priv;
440
441 poll_wait(file, &dev_priv->perf.oa.poll_wq, wait);
442}
443
444static int i915_oa_read(struct i915_perf_stream *stream,
445 char __user *buf,
446 size_t count,
447 size_t *offset)
448{
449 struct drm_i915_private *dev_priv = stream->dev_priv;
450
451 return dev_priv->perf.oa.ops.read(stream, buf, count, offset);
452}
453
454/* Determine the render context hw id, and ensure it remains fixed for the
455 * lifetime of the stream. This ensures that we don't have to worry about
456 * updating the context ID in OACONTROL on the fly.
457 */
458static int oa_get_render_ctx_id(struct i915_perf_stream *stream)
459{
460 struct drm_i915_private *dev_priv = stream->dev_priv;
461 struct i915_vma *vma;
462 int ret;
463
464 ret = i915_mutex_lock_interruptible(&dev_priv->drm);
465 if (ret)
466 return ret;
467
468 /* As the ID is the gtt offset of the context's vma we pin
469 * the vma to ensure the ID remains fixed.
470 *
471 * NB: implied RCS engine...
472 */
473 vma = i915_gem_context_pin_legacy(stream->ctx, 0);
474 if (IS_ERR(vma)) {
475 ret = PTR_ERR(vma);
476 goto unlock;
477 }
478
479 dev_priv->perf.oa.pinned_rcs_vma = vma;
480
481 /* Explicitly track the ID (instead of calling i915_ggtt_offset()
482 * on the fly) considering the difference with gen8+ and
483 * execlists
484 */
485 dev_priv->perf.oa.specific_ctx_id = i915_ggtt_offset(vma);
486
487unlock:
488 mutex_unlock(&dev_priv->drm.struct_mutex);
489
490 return ret;
491}
492
493static void oa_put_render_ctx_id(struct i915_perf_stream *stream)
494{
495 struct drm_i915_private *dev_priv = stream->dev_priv;
496
497 mutex_lock(&dev_priv->drm.struct_mutex);
498
499 i915_vma_unpin(dev_priv->perf.oa.pinned_rcs_vma);
500 dev_priv->perf.oa.pinned_rcs_vma = NULL;
501
502 dev_priv->perf.oa.specific_ctx_id = INVALID_CTX_ID;
503
504 mutex_unlock(&dev_priv->drm.struct_mutex);
505}
506
507static void
508free_oa_buffer(struct drm_i915_private *i915)
509{
510 mutex_lock(&i915->drm.struct_mutex);
511
512 i915_gem_object_unpin_map(i915->perf.oa.oa_buffer.vma->obj);
513 i915_vma_unpin(i915->perf.oa.oa_buffer.vma);
514 i915_gem_object_put(i915->perf.oa.oa_buffer.vma->obj);
515
516 i915->perf.oa.oa_buffer.vma = NULL;
517 i915->perf.oa.oa_buffer.vaddr = NULL;
518
519 mutex_unlock(&i915->drm.struct_mutex);
520}
521
522static void i915_oa_stream_destroy(struct i915_perf_stream *stream)
523{
524 struct drm_i915_private *dev_priv = stream->dev_priv;
525
526 BUG_ON(stream != dev_priv->perf.oa.exclusive_stream);
527
528 dev_priv->perf.oa.ops.disable_metric_set(dev_priv);
529
530 free_oa_buffer(dev_priv);
531
532 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
533 intel_runtime_pm_put(dev_priv);
534
535 if (stream->ctx)
536 oa_put_render_ctx_id(stream);
537
538 dev_priv->perf.oa.exclusive_stream = NULL;
539}
540
541static void gen7_init_oa_buffer(struct drm_i915_private *dev_priv)
542{
543 u32 gtt_offset = i915_ggtt_offset(dev_priv->perf.oa.oa_buffer.vma);
544
545 /* Pre-DevBDW: OABUFFER must be set with counters off,
546 * before OASTATUS1, but after OASTATUS2
547 */
548 I915_WRITE(GEN7_OASTATUS2, gtt_offset | OA_MEM_SELECT_GGTT); /* head */
549 I915_WRITE(GEN7_OABUFFER, gtt_offset);
550 I915_WRITE(GEN7_OASTATUS1, gtt_offset | OABUFFER_SIZE_16M); /* tail */
551
552 /* On Haswell we have to track which OASTATUS1 flags we've
553 * already seen since they can't be cleared while periodic
554 * sampling is enabled.
555 */
556 dev_priv->perf.oa.gen7_latched_oastatus1 = 0;
557
558 /* NB: although the OA buffer will initially be allocated
559 * zeroed via shmfs (and so this memset is redundant when
560 * first allocating), we may re-init the OA buffer, either
561 * when re-enabling a stream or in error/reset paths.
562 *
563 * The reason we clear the buffer for each re-init is for the
564 * sanity check in gen7_append_oa_reports() that looks at the
565 * report-id field to make sure it's non-zero which relies on
566 * the assumption that new reports are being written to zeroed
567 * memory...
568 */
569 memset(dev_priv->perf.oa.oa_buffer.vaddr, 0, OA_BUFFER_SIZE);
570
571 /* Maybe make ->pollin per-stream state if we support multiple
572 * concurrent streams in the future.
573 */
574 dev_priv->perf.oa.pollin = false;
575}
576
577static int alloc_oa_buffer(struct drm_i915_private *dev_priv)
578{
579 struct drm_i915_gem_object *bo;
580 struct i915_vma *vma;
581 int ret;
582
583 if (WARN_ON(dev_priv->perf.oa.oa_buffer.vma))
584 return -ENODEV;
585
586 ret = i915_mutex_lock_interruptible(&dev_priv->drm);
587 if (ret)
588 return ret;
589
590 BUILD_BUG_ON_NOT_POWER_OF_2(OA_BUFFER_SIZE);
591 BUILD_BUG_ON(OA_BUFFER_SIZE < SZ_128K || OA_BUFFER_SIZE > SZ_16M);
592
593 bo = i915_gem_object_create(&dev_priv->drm, OA_BUFFER_SIZE);
594 if (IS_ERR(bo)) {
595 DRM_ERROR("Failed to allocate OA buffer\n");
596 ret = PTR_ERR(bo);
597 goto unlock;
598 }
599
600 ret = i915_gem_object_set_cache_level(bo, I915_CACHE_LLC);
601 if (ret)
602 goto err_unref;
603
604 /* PreHSW required 512K alignment, HSW requires 16M */
605 vma = i915_gem_object_ggtt_pin(bo, NULL, 0, SZ_16M, 0);
606 if (IS_ERR(vma)) {
607 ret = PTR_ERR(vma);
608 goto err_unref;
609 }
610 dev_priv->perf.oa.oa_buffer.vma = vma;
611
612 dev_priv->perf.oa.oa_buffer.vaddr =
613 i915_gem_object_pin_map(bo, I915_MAP_WB);
614 if (IS_ERR(dev_priv->perf.oa.oa_buffer.vaddr)) {
615 ret = PTR_ERR(dev_priv->perf.oa.oa_buffer.vaddr);
616 goto err_unpin;
617 }
618
619 dev_priv->perf.oa.ops.init_oa_buffer(dev_priv);
620
621 DRM_DEBUG_DRIVER("OA Buffer initialized, gtt offset = 0x%x, vaddr = %p\n",
622 i915_ggtt_offset(dev_priv->perf.oa.oa_buffer.vma),
623 dev_priv->perf.oa.oa_buffer.vaddr);
624
625 goto unlock;
626
627err_unpin:
628 __i915_vma_unpin(vma);
629
630err_unref:
631 i915_gem_object_put(bo);
632
633 dev_priv->perf.oa.oa_buffer.vaddr = NULL;
634 dev_priv->perf.oa.oa_buffer.vma = NULL;
635
636unlock:
637 mutex_unlock(&dev_priv->drm.struct_mutex);
638 return ret;
639}
640
641static void config_oa_regs(struct drm_i915_private *dev_priv,
642 const struct i915_oa_reg *regs,
643 int n_regs)
644{
645 int i;
646
647 for (i = 0; i < n_regs; i++) {
648 const struct i915_oa_reg *reg = regs + i;
649
650 I915_WRITE(reg->addr, reg->value);
651 }
652}
653
654static int hsw_enable_metric_set(struct drm_i915_private *dev_priv)
655{
656 int ret = i915_oa_select_metric_set_hsw(dev_priv);
657
658 if (ret)
659 return ret;
660
661 I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) |
662 GT_NOA_ENABLE));
663
664 /* PRM:
665 *
666 * OA unit is using “crclk” for its functionality. When trunk
667 * level clock gating takes place, OA clock would be gated,
668 * unable to count the events from non-render clock domain.
669 * Render clock gating must be disabled when OA is enabled to
670 * count the events from non-render domain. Unit level clock
671 * gating for RCS should also be disabled.
672 */
673 I915_WRITE(GEN7_MISCCPCTL, (I915_READ(GEN7_MISCCPCTL) &
674 ~GEN7_DOP_CLOCK_GATE_ENABLE));
675 I915_WRITE(GEN6_UCGCTL1, (I915_READ(GEN6_UCGCTL1) |
676 GEN6_CSUNIT_CLOCK_GATE_DISABLE));
677
678 config_oa_regs(dev_priv, dev_priv->perf.oa.mux_regs,
679 dev_priv->perf.oa.mux_regs_len);
680
681 /* It apparently takes a fairly long time for a new MUX
682 * configuration to be be applied after these register writes.
683 * This delay duration was derived empirically based on the
684 * render_basic config but hopefully it covers the maximum
685 * configuration latency.
686 *
687 * As a fallback, the checks in _append_oa_reports() to skip
688 * invalid OA reports do also seem to work to discard reports
689 * generated before this config has completed - albeit not
690 * silently.
691 *
692 * Unfortunately this is essentially a magic number, since we
693 * don't currently know of a reliable mechanism for predicting
694 * how long the MUX config will take to apply and besides
695 * seeing invalid reports we don't know of a reliable way to
696 * explicitly check that the MUX config has landed.
697 *
698 * It's even possible we've miss characterized the underlying
699 * problem - it just seems like the simplest explanation why
700 * a delay at this location would mitigate any invalid reports.
701 */
702 usleep_range(15000, 20000);
703
704 config_oa_regs(dev_priv, dev_priv->perf.oa.b_counter_regs,
705 dev_priv->perf.oa.b_counter_regs_len);
706
707 return 0;
708}
709
710static void hsw_disable_metric_set(struct drm_i915_private *dev_priv)
711{
712 I915_WRITE(GEN6_UCGCTL1, (I915_READ(GEN6_UCGCTL1) &
713 ~GEN6_CSUNIT_CLOCK_GATE_DISABLE));
714 I915_WRITE(GEN7_MISCCPCTL, (I915_READ(GEN7_MISCCPCTL) |
715 GEN7_DOP_CLOCK_GATE_ENABLE));
716
717 I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) &
718 ~GT_NOA_ENABLE));
719}
720
721static void gen7_update_oacontrol_locked(struct drm_i915_private *dev_priv)
722{
723 assert_spin_locked(&dev_priv->perf.hook_lock);
724
725 if (dev_priv->perf.oa.exclusive_stream->enabled) {
726 struct i915_gem_context *ctx =
727 dev_priv->perf.oa.exclusive_stream->ctx;
728 u32 ctx_id = dev_priv->perf.oa.specific_ctx_id;
729
730 bool periodic = dev_priv->perf.oa.periodic;
731 u32 period_exponent = dev_priv->perf.oa.period_exponent;
732 u32 report_format = dev_priv->perf.oa.oa_buffer.format;
733
734 I915_WRITE(GEN7_OACONTROL,
735 (ctx_id & GEN7_OACONTROL_CTX_MASK) |
736 (period_exponent <<
737 GEN7_OACONTROL_TIMER_PERIOD_SHIFT) |
738 (periodic ? GEN7_OACONTROL_TIMER_ENABLE : 0) |
739 (report_format << GEN7_OACONTROL_FORMAT_SHIFT) |
740 (ctx ? GEN7_OACONTROL_PER_CTX_ENABLE : 0) |
741 GEN7_OACONTROL_ENABLE);
742 } else
743 I915_WRITE(GEN7_OACONTROL, 0);
744}
745
746static void gen7_oa_enable(struct drm_i915_private *dev_priv)
747{
748 unsigned long flags;
749
750 /* Reset buf pointers so we don't forward reports from before now.
751 *
752 * Think carefully if considering trying to avoid this, since it
753 * also ensures status flags and the buffer itself are cleared
754 * in error paths, and we have checks for invalid reports based
755 * on the assumption that certain fields are written to zeroed
756 * memory which this helps maintains.
757 */
758 gen7_init_oa_buffer(dev_priv);
759
760 spin_lock_irqsave(&dev_priv->perf.hook_lock, flags);
761 gen7_update_oacontrol_locked(dev_priv);
762 spin_unlock_irqrestore(&dev_priv->perf.hook_lock, flags);
763}
764
765static void i915_oa_stream_enable(struct i915_perf_stream *stream)
766{
767 struct drm_i915_private *dev_priv = stream->dev_priv;
768
769 dev_priv->perf.oa.ops.oa_enable(dev_priv);
770
771 if (dev_priv->perf.oa.periodic)
772 hrtimer_start(&dev_priv->perf.oa.poll_check_timer,
773 ns_to_ktime(POLL_PERIOD),
774 HRTIMER_MODE_REL_PINNED);
775}
776
777static void gen7_oa_disable(struct drm_i915_private *dev_priv)
778{
779 I915_WRITE(GEN7_OACONTROL, 0);
780}
781
782static void i915_oa_stream_disable(struct i915_perf_stream *stream)
783{
784 struct drm_i915_private *dev_priv = stream->dev_priv;
785
786 dev_priv->perf.oa.ops.oa_disable(dev_priv);
787
788 if (dev_priv->perf.oa.periodic)
789 hrtimer_cancel(&dev_priv->perf.oa.poll_check_timer);
790}
791
792static u64 oa_exponent_to_ns(struct drm_i915_private *dev_priv, int exponent)
793{
794 return 1000000000ULL * (2ULL << exponent) /
795 dev_priv->perf.oa.timestamp_frequency;
796}
797
798static const struct i915_perf_stream_ops i915_oa_stream_ops = {
799 .destroy = i915_oa_stream_destroy,
800 .enable = i915_oa_stream_enable,
801 .disable = i915_oa_stream_disable,
802 .wait_unlocked = i915_oa_wait_unlocked,
803 .poll_wait = i915_oa_poll_wait,
804 .read = i915_oa_read,
36};805};
37 806
807static int i915_oa_stream_init(struct i915_perf_stream *stream,
808 struct drm_i915_perf_open_param *param,
809 struct perf_open_properties *props)
810{
811 struct drm_i915_private *dev_priv = stream->dev_priv;
812 int format_size;
813 int ret;
814
815 if (!(props->sample_flags & SAMPLE_OA_REPORT)) {
816 DRM_ERROR("Only OA report sampling supported\n");
817 return -EINVAL;
818 }
819
820 if (!dev_priv->perf.oa.ops.init_oa_buffer) {
821 DRM_ERROR("OA unit not supported\n");
822 return -ENODEV;
823 }
824
825 /* To avoid the complexity of having to accurately filter
826 * counter reports and marshal to the appropriate client
827 * we currently only allow exclusive access
828 */
829 if (dev_priv->perf.oa.exclusive_stream) {
830 DRM_ERROR("OA unit already in use\n");
831 return -EBUSY;
832 }
833
834 if (!props->metrics_set) {
835 DRM_ERROR("OA metric set not specified\n");
836 return -EINVAL;
837 }
838
839 if (!props->oa_format) {
840 DRM_ERROR("OA report format not specified\n");
841 return -EINVAL;
842 }
843
844 stream->sample_size = sizeof(struct drm_i915_perf_record_header);
845
846 format_size = dev_priv->perf.oa.oa_formats[props->oa_format].size;
847
848 stream->sample_flags |= SAMPLE_OA_REPORT;
849 stream->sample_size += format_size;
850
851 dev_priv->perf.oa.oa_buffer.format_size = format_size;
852 if (WARN_ON(dev_priv->perf.oa.oa_buffer.format_size == 0))
853 return -EINVAL;
854
855 dev_priv->perf.oa.oa_buffer.format =
856 dev_priv->perf.oa.oa_formats[props->oa_format].format;
857
858 dev_priv->perf.oa.metrics_set = props->metrics_set;
859
860 dev_priv->perf.oa.periodic = props->oa_periodic;
861 if (dev_priv->perf.oa.periodic) {
862 u64 period_ns = oa_exponent_to_ns(dev_priv,
863 props->oa_period_exponent);
864
865 dev_priv->perf.oa.period_exponent = props->oa_period_exponent;
866
867 /* See comment for OA_TAIL_MARGIN_NSEC for details
868 * about this tail_margin...
869 */
870 dev_priv->perf.oa.tail_margin =
871 ((OA_TAIL_MARGIN_NSEC / period_ns) + 1) * format_size;
872 }
873
874 if (stream->ctx) {
875 ret = oa_get_render_ctx_id(stream);
876 if (ret)
877 return ret;
878 }
879
880 ret = alloc_oa_buffer(dev_priv);
881 if (ret)
882 goto err_oa_buf_alloc;
883
884 /* PRM - observability performance counters:
885 *
886 * OACONTROL, performance counter enable, note:
887 *
888 * "When this bit is set, in order to have coherent counts,
889 * RC6 power state and trunk clock gating must be disabled.
890 * This can be achieved by programming MMIO registers as
891 * 0xA094=0 and 0xA090[31]=1"
892 *
893 * In our case we are expecting that taking pm + FORCEWAKE
894 * references will effectively disable RC6.
895 */
896 intel_runtime_pm_get(dev_priv);
897 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
898
899 ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv);
900 if (ret)
901 goto err_enable;
902
903 stream->ops = &i915_oa_stream_ops;
904
905 dev_priv->perf.oa.exclusive_stream = stream;
906
907 return 0;
908
909err_enable:
910 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
911 intel_runtime_pm_put(dev_priv);
912 free_oa_buffer(dev_priv);
913
914err_oa_buf_alloc:
915 if (stream->ctx)
916 oa_put_render_ctx_id(stream);
917
918 return ret;
919}
920
38static ssize_t i915_perf_read_locked(struct i915_perf_stream *stream,921static ssize_t i915_perf_read_locked(struct i915_perf_stream *stream,
39 struct file *file,922 struct file *file,
40 char __user *buf,923 char __user *buf,
@@ -78,8 +961,20 @@ static ssize_t i915_perf_read(struct file *file, · 37 unmodified lines
78 struct drm_i915_private *dev_priv = stream->dev_priv;961 struct drm_i915_private *dev_priv = stream->dev_priv;
79 ssize_t ret;962 ssize_t ret;
80 963
964 /* To ensure it's handled consistently we simply treat all reads of a
965 * disabled stream as an error. In particular it might otherwise lead
966 * to a deadlock for blocking file descriptors...
967 */
968 if (!stream->enabled)
969 return -EIO;
970
81 if (!(file->f_flags & O_NONBLOCK)) {971 if (!(file->f_flags & O_NONBLOCK)) {
82 /* Allow false positives from stream->ops->wait_unlocked.972 /* There's the small chance of false positives from
973 * stream->ops->wait_unlocked.
974 *
975 * E.g. with single context filtering since we only wait until
976 * oabuffer has >= 1 report we don't immediately know whether
977 * any reports really belong to the current context
83 */978 */
84 do {979 do {
85 ret = stream->ops->wait_unlocked(stream);980 ret = stream->ops->wait_unlocked(stream);
@@ -97,21 +992,51 @@ static ssize_t i915_perf_read(struct file *file, · 11 unmodified lines
97 mutex_unlock(&dev_priv->perf.lock);992 mutex_unlock(&dev_priv->perf.lock);
98 }993 }
99 994
995 if (ret >= 0) {
996 /* Maybe make ->pollin per-stream state if we support multiple
997 * concurrent streams in the future.
998 */
999 dev_priv->perf.oa.pollin = false;
1000 }
1001
100 return ret;1002 return ret;
101}1003}
102 1004
103static unsigned int i915_perf_poll_locked(struct i915_perf_stream *stream,1005static enum hrtimer_restart oa_poll_check_timer_cb(struct hrtimer *hrtimer)
1006{
1007 struct drm_i915_private *dev_priv =
1008 container_of(hrtimer, typeof(*dev_priv),
1009 perf.oa.poll_check_timer);
1010
1011 if (!dev_priv->perf.oa.ops.oa_buffer_is_empty(dev_priv)) {
1012 dev_priv->perf.oa.pollin = true;
1013 wake_up(&dev_priv->perf.oa.poll_wq);
1014 }
1015
1016 hrtimer_forward_now(hrtimer, ns_to_ktime(POLL_PERIOD));
1017
1018 return HRTIMER_RESTART;
1019}
1020
1021static unsigned int i915_perf_poll_locked(struct drm_i915_private *dev_priv,
1022 struct i915_perf_stream *stream,
104 struct file *file,1023 struct file *file,
105 poll_table *wait)1024 poll_table *wait)
106{1025{
107 unsigned int streams = 0;1026 unsigned int events = 0;
108 1027
109 stream->ops->poll_wait(stream, file, wait);1028 stream->ops->poll_wait(stream, file, wait);
110 1029
111 if (stream->ops->can_read(stream))1030 /* Note: we don't explicitly check whether there's something to read
112 streams |= POLLIN;1031 * here since this path may be very hot depending on what else
1032 * userspace is polling, or on the timeout in use. We rely solely on
1033 * the hrtimer/oa_poll_check_timer_cb to notify us when there are
1034 * samples to read.
1035 */
1036 if (dev_priv->perf.oa.pollin)
1037 events |= POLLIN;
113 1038
114 return streams;1039 return events;
115}1040}
116 1041
117static unsigned int i915_perf_poll(struct file *file, poll_table *wait)1042static unsigned int i915_perf_poll(struct file *file, poll_table *wait)
@@ -121,7 +1046,7 @@ static unsigned int i915_perf_poll(struct file *file, poll_table *wait) · 3 unmodified lines
121 int ret;1046 int ret;
122 1047
123 mutex_lock(&dev_priv->perf.lock);1048 mutex_lock(&dev_priv->perf.lock);
124 ret = i915_perf_poll_locked(stream, file, wait);1049 ret = i915_perf_poll_locked(dev_priv, stream, file, wait);
125 mutex_unlock(&dev_priv->perf.lock);1050 mutex_unlock(&dev_priv->perf.lock);
126 1051
127 return ret;1052 return ret;
@@ -285,18 +1210,21 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv, · 157 unmodified lines
285 goto err_ctx;1210 goto err_ctx;
286 }1211 }
287 1212
288 stream->sample_flags = props->sample_flags;
289 stream->dev_priv = dev_priv;1213 stream->dev_priv = dev_priv;
290 stream->ctx = specific_ctx;1214 stream->ctx = specific_ctx;
291 1215
292 /*1216 ret = i915_oa_stream_init(stream, param, props);
293 * TODO: support sampling something1217 if (ret)
294 *1218 goto err_alloc;
295 * For now this is as far as we can go.1219
1220 /* we avoid simply assigning stream->sample_flags = props->sample_flags
1221 * to have _stream_init check the combination of sample flags more
1222 * thoroughly, but still this is the expected result at this point.
296 */1223 */
297 DRM_ERROR("Unsupported i915 perf stream configuration\n");1224 if (WARN_ON(stream->sample_flags != props->sample_flags)) {
298 ret = -EINVAL;1225 ret = -ENODEV;
299 goto err_alloc;1226 goto err_alloc;
1227 }
300 1228
301 list_add(&stream->link, &dev_priv->perf.streams);1229 list_add(&stream->link, &dev_priv->perf.streams);
302 1230
@@ -382,6 +1310,56 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv, · 79 unmodified lines
382 props->single_context = 1;1310 props->single_context = 1;
383 props->ctx_handle = value;1311 props->ctx_handle = value;
384 break;1312 break;
1313 case DRM_I915_PERF_PROP_SAMPLE_OA:
1314 props->sample_flags |= SAMPLE_OA_REPORT;
1315 break;
1316 case DRM_I915_PERF_PROP_OA_METRICS_SET:
1317 if (value == 0 ||
1318 value > dev_priv->perf.oa.n_builtin_sets) {
1319 DRM_ERROR("Unknown OA metric set ID");
1320 return -EINVAL;
1321 }
1322 props->metrics_set = value;
1323 break;
1324 case DRM_I915_PERF_PROP_OA_FORMAT:
1325 if (value == 0 || value >= I915_OA_FORMAT_MAX) {
1326 DRM_ERROR("Invalid OA report format\n");
1327 return -EINVAL;
1328 }
1329 if (!dev_priv->perf.oa.oa_formats[value].size) {
1330 DRM_ERROR("Invalid OA report format\n");
1331 return -EINVAL;
1332 }
1333 props->oa_format = value;
1334 break;
1335 case DRM_I915_PERF_PROP_OA_EXPONENT:
1336 if (value > OA_EXPONENT_MAX) {
1337 DRM_ERROR("OA timer exponent too high (> %u)\n",
1338 OA_EXPONENT_MAX);
1339 return -EINVAL;
1340 }
1341
1342 /* NB: The exponent represents a period as follows:
1343 *
1344 * 80ns * 2^(period_exponent + 1)
1345 *
1346 * Theoretically we can program the OA unit to sample
1347 * every 160ns but don't allow that by default unless
1348 * root.
1349 *
1350 * Referring to perf's
1351 * kernel.perf_event_max_sample_rate for a precedent
1352 * (100000 by default); with an OA exponent of 6 we get
1353 * a period of 10.240 microseconds -just under 100000Hz
1354 */
1355 if (value < 6 && !capable(CAP_SYS_ADMIN)) {
1356 DRM_ERROR("Minimum OA sampling exponent is 6 without root privileges\n");
1357 return -EACCES;
1358 }
1359
1360 props->oa_periodic = true;
1361 props->oa_period_exponent = value;
1362 break;
385 default:1363 default:
386 MISSING_CASE(id);1364 MISSING_CASE(id);
387 DRM_ERROR("Unknown i915 perf property ID");1365 DRM_ERROR("Unknown i915 perf property ID");
@@ -432,8 +1410,33 @@ int i915_perf_open_ioctl(struct drm_device *dev, void *data, · 44 unmodified lines
432 1410
433void i915_perf_init(struct drm_i915_private *dev_priv)1411void i915_perf_init(struct drm_i915_private *dev_priv)
434{1412{
1413 if (!IS_HASWELL(dev_priv))
1414 return;
1415
1416 hrtimer_init(&dev_priv->perf.oa.poll_check_timer,
1417 CLOCK_MONOTONIC, HRTIMER_MODE_REL);
1418 dev_priv->perf.oa.poll_check_timer.function = oa_poll_check_timer_cb;
1419 init_waitqueue_head(&dev_priv->perf.oa.poll_wq);
1420
435 INIT_LIST_HEAD(&dev_priv->perf.streams);1421 INIT_LIST_HEAD(&dev_priv->perf.streams);
436 mutex_init(&dev_priv->perf.lock);1422 mutex_init(&dev_priv->perf.lock);
1423 spin_lock_init(&dev_priv->perf.hook_lock);
1424
1425 dev_priv->perf.oa.ops.init_oa_buffer = gen7_init_oa_buffer;
1426 dev_priv->perf.oa.ops.enable_metric_set = hsw_enable_metric_set;
1427 dev_priv->perf.oa.ops.disable_metric_set = hsw_disable_metric_set;
1428 dev_priv->perf.oa.ops.oa_enable = gen7_oa_enable;
1429 dev_priv->perf.oa.ops.oa_disable = gen7_oa_disable;
1430 dev_priv->perf.oa.ops.read = gen7_oa_read;
1431 dev_priv->perf.oa.ops.oa_buffer_is_empty =
1432 gen7_oa_buffer_is_empty_fop_unlocked;
1433
1434 dev_priv->perf.oa.timestamp_frequency = 12500000;
1435
1436 dev_priv->perf.oa.oa_formats = hsw_oa_formats;
1437
1438 dev_priv->perf.oa.n_builtin_sets =
1439 i915_oa_n_builtin_metric_sets_hsw;
437 1440
438 dev_priv->perf.initialized = true;1441 dev_priv->perf.initialized = true;
439}1442}
@@ -443,7 +1446,6 @@ void i915_perf_fini(struct drm_i915_private *dev_priv) · 3 unmodified lines
443 if (!dev_priv->perf.initialized)1446 if (!dev_priv->perf.initialized)
444 return;1447 return;
445 1448
446 /* Currently nothing to clean up */1449 memset(&dev_priv->perf.oa.ops, 0, sizeof(dev_priv->perf.oa.ops));
447
448 dev_priv->perf.initialized = false;1450 dev_priv->perf.initialized = false;
449}1451}
drivers/gpu/drm/i915/i915_reg.h+338−0
@@ -616,6 +616,343 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg) · 615 unmodified lines
616#define HSW_CS_GPR_UDW(n) _MMIO(0x2600 + (n) * 8 + 4)616#define HSW_CS_GPR_UDW(n) _MMIO(0x2600 + (n) * 8 + 4)
617 617
618#define GEN7_OACONTROL _MMIO(0x2360)618#define GEN7_OACONTROL _MMIO(0x2360)
619#define GEN7_OACONTROL_CTX_MASK 0xFFFFF000
620#define GEN7_OACONTROL_TIMER_PERIOD_MASK 0x3F
621#define GEN7_OACONTROL_TIMER_PERIOD_SHIFT 6
622#define GEN7_OACONTROL_TIMER_ENABLE (1<<5)
623#define GEN7_OACONTROL_FORMAT_A13 (0<<2)
624#define GEN7_OACONTROL_FORMAT_A29 (1<<2)
625#define GEN7_OACONTROL_FORMAT_A13_B8_C8 (2<<2)
626#define GEN7_OACONTROL_FORMAT_A29_B8_C8 (3<<2)
627#define GEN7_OACONTROL_FORMAT_B4_C8 (4<<2)
628#define GEN7_OACONTROL_FORMAT_A45_B8_C8 (5<<2)
629#define GEN7_OACONTROL_FORMAT_B4_C8_A16 (6<<2)
630#define GEN7_OACONTROL_FORMAT_C4_B8 (7<<2)
631#define GEN7_OACONTROL_FORMAT_SHIFT 2
632#define GEN7_OACONTROL_PER_CTX_ENABLE (1<<1)
633#define GEN7_OACONTROL_ENABLE (1<<0)
634
635#define GEN8_OACTXID _MMIO(0x2364)
636
637#define GEN8_OACONTROL _MMIO(0x2B00)
638#define GEN8_OA_REPORT_FORMAT_A12 (0<<2)
639#define GEN8_OA_REPORT_FORMAT_A12_B8_C8 (2<<2)
640#define GEN8_OA_REPORT_FORMAT_A36_B8_C8 (5<<2)
641#define GEN8_OA_REPORT_FORMAT_C4_B8 (7<<2)
642#define GEN8_OA_REPORT_FORMAT_SHIFT 2
643#define GEN8_OA_SPECIFIC_CONTEXT_ENABLE (1<<1)
644#define GEN8_OA_COUNTER_ENABLE (1<<0)
645
646#define GEN8_OACTXCONTROL _MMIO(0x2360)
647#define GEN8_OA_TIMER_PERIOD_MASK 0x3F
648#define GEN8_OA_TIMER_PERIOD_SHIFT 2
649#define GEN8_OA_TIMER_ENABLE (1<<1)
650#define GEN8_OA_COUNTER_RESUME (1<<0)
651
652#define GEN7_OABUFFER _MMIO(0x23B0) /* R/W */
653#define GEN7_OABUFFER_OVERRUN_DISABLE (1<<3)
654#define GEN7_OABUFFER_EDGE_TRIGGER (1<<2)
655#define GEN7_OABUFFER_STOP_RESUME_ENABLE (1<<1)
656#define GEN7_OABUFFER_RESUME (1<<0)
657
658#define GEN8_OABUFFER _MMIO(0x2b14)
659
660#define GEN7_OASTATUS1 _MMIO(0x2364)
661#define GEN7_OASTATUS1_TAIL_MASK 0xffffffc0
662#define GEN7_OASTATUS1_COUNTER_OVERFLOW (1<<2)
663#define GEN7_OASTATUS1_OABUFFER_OVERFLOW (1<<1)
664#define GEN7_OASTATUS1_REPORT_LOST (1<<0)
665
666#define GEN7_OASTATUS2 _MMIO(0x2368)
667#define GEN7_OASTATUS2_HEAD_MASK 0xffffffc0
668
669#define GEN8_OASTATUS _MMIO(0x2b08)
670#define GEN8_OASTATUS_OVERRUN_STATUS (1<<3)
671#define GEN8_OASTATUS_COUNTER_OVERFLOW (1<<2)
672#define GEN8_OASTATUS_OABUFFER_OVERFLOW (1<<1)
673#define GEN8_OASTATUS_REPORT_LOST (1<<0)
674
675#define GEN8_OAHEADPTR _MMIO(0x2B0C)
676#define GEN8_OATAILPTR _MMIO(0x2B10)
677
678#define OABUFFER_SIZE_128K (0<<3)
679#define OABUFFER_SIZE_256K (1<<3)
680#define OABUFFER_SIZE_512K (2<<3)
681#define OABUFFER_SIZE_1M (3<<3)
682#define OABUFFER_SIZE_2M (4<<3)
683#define OABUFFER_SIZE_4M (5<<3)
684#define OABUFFER_SIZE_8M (6<<3)
685#define OABUFFER_SIZE_16M (7<<3)
686
687#define OA_MEM_SELECT_GGTT (1<<0)
688
689#define EU_PERF_CNTL0 _MMIO(0xe458)
690
691#define GDT_CHICKEN_BITS _MMIO(0x9840)
692#define GT_NOA_ENABLE 0x00000080
693
694/*
695 * OA Boolean state
696 */
697
698#define OAREPORTTRIG1 _MMIO(0x2740)
699#define OAREPORTTRIG1_THRESHOLD_MASK 0xffff
700#define OAREPORTTRIG1_EDGE_LEVEL_TRIGER_SELECT_MASK 0xffff0000 /* 0=level */
701
702#define OAREPORTTRIG2 _MMIO(0x2744)
703#define OAREPORTTRIG2_INVERT_A_0 (1<<0)
704#define OAREPORTTRIG2_INVERT_A_1 (1<<1)
705#define OAREPORTTRIG2_INVERT_A_2 (1<<2)
706#define OAREPORTTRIG2_INVERT_A_3 (1<<3)
707#define OAREPORTTRIG2_INVERT_A_4 (1<<4)
708#define OAREPORTTRIG2_INVERT_A_5 (1<<5)
709#define OAREPORTTRIG2_INVERT_A_6 (1<<6)
710#define OAREPORTTRIG2_INVERT_A_7 (1<<7)
711#define OAREPORTTRIG2_INVERT_A_8 (1<<8)
712#define OAREPORTTRIG2_INVERT_A_9 (1<<9)
713#define OAREPORTTRIG2_INVERT_A_10 (1<<10)
714#define OAREPORTTRIG2_INVERT_A_11 (1<<11)
715#define OAREPORTTRIG2_INVERT_A_12 (1<<12)
716#define OAREPORTTRIG2_INVERT_A_13 (1<<13)
717#define OAREPORTTRIG2_INVERT_A_14 (1<<14)
718#define OAREPORTTRIG2_INVERT_A_15 (1<<15)
719#define OAREPORTTRIG2_INVERT_B_0 (1<<16)
720#define OAREPORTTRIG2_INVERT_B_1 (1<<17)
721#define OAREPORTTRIG2_INVERT_B_2 (1<<18)
722#define OAREPORTTRIG2_INVERT_B_3 (1<<19)
723#define OAREPORTTRIG2_INVERT_C_0 (1<<20)
724#define OAREPORTTRIG2_INVERT_C_1 (1<<21)
725#define OAREPORTTRIG2_INVERT_D_0 (1<<22)
726#define OAREPORTTRIG2_THRESHOLD_ENABLE (1<<23)
727#define OAREPORTTRIG2_REPORT_TRIGGER_ENABLE (1<<31)
728
729#define OAREPORTTRIG3 _MMIO(0x2748)
730#define OAREPORTTRIG3_NOA_SELECT_MASK 0xf
731#define OAREPORTTRIG3_NOA_SELECT_8_SHIFT 0
732#define OAREPORTTRIG3_NOA_SELECT_9_SHIFT 4
733#define OAREPORTTRIG3_NOA_SELECT_10_SHIFT 8
734#define OAREPORTTRIG3_NOA_SELECT_11_SHIFT 12
735#define OAREPORTTRIG3_NOA_SELECT_12_SHIFT 16
736#define OAREPORTTRIG3_NOA_SELECT_13_SHIFT 20
737#define OAREPORTTRIG3_NOA_SELECT_14_SHIFT 24
738#define OAREPORTTRIG3_NOA_SELECT_15_SHIFT 28
739
740#define OAREPORTTRIG4 _MMIO(0x274c)
741#define OAREPORTTRIG4_NOA_SELECT_MASK 0xf
742#define OAREPORTTRIG4_NOA_SELECT_0_SHIFT 0
743#define OAREPORTTRIG4_NOA_SELECT_1_SHIFT 4
744#define OAREPORTTRIG4_NOA_SELECT_2_SHIFT 8
745#define OAREPORTTRIG4_NOA_SELECT_3_SHIFT 12
746#define OAREPORTTRIG4_NOA_SELECT_4_SHIFT 16
747#define OAREPORTTRIG4_NOA_SELECT_5_SHIFT 20
748#define OAREPORTTRIG4_NOA_SELECT_6_SHIFT 24
749#define OAREPORTTRIG4_NOA_SELECT_7_SHIFT 28
750
751#define OAREPORTTRIG5 _MMIO(0x2750)
752#define OAREPORTTRIG5_THRESHOLD_MASK 0xffff
753#define OAREPORTTRIG5_EDGE_LEVEL_TRIGER_SELECT_MASK 0xffff0000 /* 0=level */
754
755#define OAREPORTTRIG6 _MMIO(0x2754)
756#define OAREPORTTRIG6_INVERT_A_0 (1<<0)
757#define OAREPORTTRIG6_INVERT_A_1 (1<<1)
758#define OAREPORTTRIG6_INVERT_A_2 (1<<2)
759#define OAREPORTTRIG6_INVERT_A_3 (1<<3)
760#define OAREPORTTRIG6_INVERT_A_4 (1<<4)
761#define OAREPORTTRIG6_INVERT_A_5 (1<<5)
762#define OAREPORTTRIG6_INVERT_A_6 (1<<6)
763#define OAREPORTTRIG6_INVERT_A_7 (1<<7)
764#define OAREPORTTRIG6_INVERT_A_8 (1<<8)
765#define OAREPORTTRIG6_INVERT_A_9 (1<<9)
766#define OAREPORTTRIG6_INVERT_A_10 (1<<10)
767#define OAREPORTTRIG6_INVERT_A_11 (1<<11)
768#define OAREPORTTRIG6_INVERT_A_12 (1<<12)
769#define OAREPORTTRIG6_INVERT_A_13 (1<<13)
770#define OAREPORTTRIG6_INVERT_A_14 (1<<14)
771#define OAREPORTTRIG6_INVERT_A_15 (1<<15)
772#define OAREPORTTRIG6_INVERT_B_0 (1<<16)
773#define OAREPORTTRIG6_INVERT_B_1 (1<<17)
774#define OAREPORTTRIG6_INVERT_B_2 (1<<18)
775#define OAREPORTTRIG6_INVERT_B_3 (1<<19)
776#define OAREPORTTRIG6_INVERT_C_0 (1<<20)
777#define OAREPORTTRIG6_INVERT_C_1 (1<<21)
778#define OAREPORTTRIG6_INVERT_D_0 (1<<22)
779#define OAREPORTTRIG6_THRESHOLD_ENABLE (1<<23)
780#define OAREPORTTRIG6_REPORT_TRIGGER_ENABLE (1<<31)
781
782#define OAREPORTTRIG7 _MMIO(0x2758)
783#define OAREPORTTRIG7_NOA_SELECT_MASK 0xf
784#define OAREPORTTRIG7_NOA_SELECT_8_SHIFT 0
785#define OAREPORTTRIG7_NOA_SELECT_9_SHIFT 4
786#define OAREPORTTRIG7_NOA_SELECT_10_SHIFT 8
787#define OAREPORTTRIG7_NOA_SELECT_11_SHIFT 12
788#define OAREPORTTRIG7_NOA_SELECT_12_SHIFT 16
789#define OAREPORTTRIG7_NOA_SELECT_13_SHIFT 20
790#define OAREPORTTRIG7_NOA_SELECT_14_SHIFT 24
791#define OAREPORTTRIG7_NOA_SELECT_15_SHIFT 28
792
793#define OAREPORTTRIG8 _MMIO(0x275c)
794#define OAREPORTTRIG8_NOA_SELECT_MASK 0xf
795#define OAREPORTTRIG8_NOA_SELECT_0_SHIFT 0
796#define OAREPORTTRIG8_NOA_SELECT_1_SHIFT 4
797#define OAREPORTTRIG8_NOA_SELECT_2_SHIFT 8
798#define OAREPORTTRIG8_NOA_SELECT_3_SHIFT 12
799#define OAREPORTTRIG8_NOA_SELECT_4_SHIFT 16
800#define OAREPORTTRIG8_NOA_SELECT_5_SHIFT 20
801#define OAREPORTTRIG8_NOA_SELECT_6_SHIFT 24
802#define OAREPORTTRIG8_NOA_SELECT_7_SHIFT 28
803
804#define OASTARTTRIG1 _MMIO(0x2710)
805#define OASTARTTRIG1_THRESHOLD_COUNT_MASK_MBZ 0xffff0000
806#define OASTARTTRIG1_THRESHOLD_MASK 0xffff
807
808#define OASTARTTRIG2 _MMIO(0x2714)
809#define OASTARTTRIG2_INVERT_A_0 (1<<0)
810#define OASTARTTRIG2_INVERT_A_1 (1<<1)
811#define OASTARTTRIG2_INVERT_A_2 (1<<2)
812#define OASTARTTRIG2_INVERT_A_3 (1<<3)
813#define OASTARTTRIG2_INVERT_A_4 (1<<4)
814#define OASTARTTRIG2_INVERT_A_5 (1<<5)
815#define OASTARTTRIG2_INVERT_A_6 (1<<6)
816#define OASTARTTRIG2_INVERT_A_7 (1<<7)
817#define OASTARTTRIG2_INVERT_A_8 (1<<8)
818#define OASTARTTRIG2_INVERT_A_9 (1<<9)
819#define OASTARTTRIG2_INVERT_A_10 (1<<10)
820#define OASTARTTRIG2_INVERT_A_11 (1<<11)
821#define OASTARTTRIG2_INVERT_A_12 (1<<12)
822#define OASTARTTRIG2_INVERT_A_13 (1<<13)
823#define OASTARTTRIG2_INVERT_A_14 (1<<14)
824#define OASTARTTRIG2_INVERT_A_15 (1<<15)
825#define OASTARTTRIG2_INVERT_B_0 (1<<16)
826#define OASTARTTRIG2_INVERT_B_1 (1<<17)
827#define OASTARTTRIG2_INVERT_B_2 (1<<18)
828#define OASTARTTRIG2_INVERT_B_3 (1<<19)
829#define OASTARTTRIG2_INVERT_C_0 (1<<20)
830#define OASTARTTRIG2_INVERT_C_1 (1<<21)
831#define OASTARTTRIG2_INVERT_D_0 (1<<22)
832#define OASTARTTRIG2_THRESHOLD_ENABLE (1<<23)
833#define OASTARTTRIG2_START_TRIG_FLAG_MBZ (1<<24)
834#define OASTARTTRIG2_EVENT_SELECT_0 (1<<28)
835#define OASTARTTRIG2_EVENT_SELECT_1 (1<<29)
836#define OASTARTTRIG2_EVENT_SELECT_2 (1<<30)
837#define OASTARTTRIG2_EVENT_SELECT_3 (1<<31)
838
839#define OASTARTTRIG3 _MMIO(0x2718)
840#define OASTARTTRIG3_NOA_SELECT_MASK 0xf
841#define OASTARTTRIG3_NOA_SELECT_8_SHIFT 0
842#define OASTARTTRIG3_NOA_SELECT_9_SHIFT 4
843#define OASTARTTRIG3_NOA_SELECT_10_SHIFT 8
844#define OASTARTTRIG3_NOA_SELECT_11_SHIFT 12
845#define OASTARTTRIG3_NOA_SELECT_12_SHIFT 16
846#define OASTARTTRIG3_NOA_SELECT_13_SHIFT 20
847#define OASTARTTRIG3_NOA_SELECT_14_SHIFT 24
848#define OASTARTTRIG3_NOA_SELECT_15_SHIFT 28
849
850#define OASTARTTRIG4 _MMIO(0x271c)
851#define OASTARTTRIG4_NOA_SELECT_MASK 0xf
852#define OASTARTTRIG4_NOA_SELECT_0_SHIFT 0
853#define OASTARTTRIG4_NOA_SELECT_1_SHIFT 4
854#define OASTARTTRIG4_NOA_SELECT_2_SHIFT 8
855#define OASTARTTRIG4_NOA_SELECT_3_SHIFT 12
856#define OASTARTTRIG4_NOA_SELECT_4_SHIFT 16
857#define OASTARTTRIG4_NOA_SELECT_5_SHIFT 20
858#define OASTARTTRIG4_NOA_SELECT_6_SHIFT 24
859#define OASTARTTRIG4_NOA_SELECT_7_SHIFT 28
860
861#define OASTARTTRIG5 _MMIO(0x2720)
862#define OASTARTTRIG5_THRESHOLD_COUNT_MASK_MBZ 0xffff0000
863#define OASTARTTRIG5_THRESHOLD_MASK 0xffff
864
865#define OASTARTTRIG6 _MMIO(0x2724)
866#define OASTARTTRIG6_INVERT_A_0 (1<<0)
867#define OASTARTTRIG6_INVERT_A_1 (1<<1)
868#define OASTARTTRIG6_INVERT_A_2 (1<<2)
869#define OASTARTTRIG6_INVERT_A_3 (1<<3)
870#define OASTARTTRIG6_INVERT_A_4 (1<<4)
871#define OASTARTTRIG6_INVERT_A_5 (1<<5)
872#define OASTARTTRIG6_INVERT_A_6 (1<<6)
873#define OASTARTTRIG6_INVERT_A_7 (1<<7)
874#define OASTARTTRIG6_INVERT_A_8 (1<<8)
875#define OASTARTTRIG6_INVERT_A_9 (1<<9)
876#define OASTARTTRIG6_INVERT_A_10 (1<<10)
877#define OASTARTTRIG6_INVERT_A_11 (1<<11)
878#define OASTARTTRIG6_INVERT_A_12 (1<<12)
879#define OASTARTTRIG6_INVERT_A_13 (1<<13)
880#define OASTARTTRIG6_INVERT_A_14 (1<<14)
881#define OASTARTTRIG6_INVERT_A_15 (1<<15)
882#define OASTARTTRIG6_INVERT_B_0 (1<<16)
883#define OASTARTTRIG6_INVERT_B_1 (1<<17)
884#define OASTARTTRIG6_INVERT_B_2 (1<<18)
885#define OASTARTTRIG6_INVERT_B_3 (1<<19)
886#define OASTARTTRIG6_INVERT_C_0 (1<<20)
887#define OASTARTTRIG6_INVERT_C_1 (1<<21)
888#define OASTARTTRIG6_INVERT_D_0 (1<<22)
889#define OASTARTTRIG6_THRESHOLD_ENABLE (1<<23)
890#define OASTARTTRIG6_START_TRIG_FLAG_MBZ (1<<24)
891#define OASTARTTRIG6_EVENT_SELECT_4 (1<<28)
892#define OASTARTTRIG6_EVENT_SELECT_5 (1<<29)
893#define OASTARTTRIG6_EVENT_SELECT_6 (1<<30)
894#define OASTARTTRIG6_EVENT_SELECT_7 (1<<31)
895
896#define OASTARTTRIG7 _MMIO(0x2728)
897#define OASTARTTRIG7_NOA_SELECT_MASK 0xf
898#define OASTARTTRIG7_NOA_SELECT_8_SHIFT 0
899#define OASTARTTRIG7_NOA_SELECT_9_SHIFT 4
900#define OASTARTTRIG7_NOA_SELECT_10_SHIFT 8
901#define OASTARTTRIG7_NOA_SELECT_11_SHIFT 12
902#define OASTARTTRIG7_NOA_SELECT_12_SHIFT 16
903#define OASTARTTRIG7_NOA_SELECT_13_SHIFT 20
904#define OASTARTTRIG7_NOA_SELECT_14_SHIFT 24
905#define OASTARTTRIG7_NOA_SELECT_15_SHIFT 28
906
907#define OASTARTTRIG8 _MMIO(0x272c)
908#define OASTARTTRIG8_NOA_SELECT_MASK 0xf
909#define OASTARTTRIG8_NOA_SELECT_0_SHIFT 0
910#define OASTARTTRIG8_NOA_SELECT_1_SHIFT 4
911#define OASTARTTRIG8_NOA_SELECT_2_SHIFT 8
912#define OASTARTTRIG8_NOA_SELECT_3_SHIFT 12
913#define OASTARTTRIG8_NOA_SELECT_4_SHIFT 16
914#define OASTARTTRIG8_NOA_SELECT_5_SHIFT 20
915#define OASTARTTRIG8_NOA_SELECT_6_SHIFT 24
916#define OASTARTTRIG8_NOA_SELECT_7_SHIFT 28
917
918/* CECX_0 */
919#define OACEC_COMPARE_LESS_OR_EQUAL 6
920#define OACEC_COMPARE_NOT_EQUAL 5
921#define OACEC_COMPARE_LESS_THAN 4
922#define OACEC_COMPARE_GREATER_OR_EQUAL 3
923#define OACEC_COMPARE_EQUAL 2
924#define OACEC_COMPARE_GREATER_THAN 1
925#define OACEC_COMPARE_ANY_EQUAL 0
926
927#define OACEC_COMPARE_VALUE_MASK 0xffff
928#define OACEC_COMPARE_VALUE_SHIFT 3
929
930#define OACEC_SELECT_NOA (0<<19)
931#define OACEC_SELECT_PREV (1<<19)
932#define OACEC_SELECT_BOOLEAN (2<<19)
933
934/* CECX_1 */
935#define OACEC_MASK_MASK 0xffff
936#define OACEC_CONSIDERATIONS_MASK 0xffff
937#define OACEC_CONSIDERATIONS_SHIFT 16
938
939#define OACEC0_0 _MMIO(0x2770)
940#define OACEC0_1 _MMIO(0x2774)
941#define OACEC1_0 _MMIO(0x2778)
942#define OACEC1_1 _MMIO(0x277c)
943#define OACEC2_0 _MMIO(0x2780)
944#define OACEC2_1 _MMIO(0x2784)
945#define OACEC3_0 _MMIO(0x2788)
946#define OACEC3_1 _MMIO(0x278c)
947#define OACEC4_0 _MMIO(0x2790)
948#define OACEC4_1 _MMIO(0x2794)
949#define OACEC5_0 _MMIO(0x2798)
950#define OACEC5_1 _MMIO(0x279c)
951#define OACEC6_0 _MMIO(0x27a0)
952#define OACEC6_1 _MMIO(0x27a4)
953#define OACEC7_0 _MMIO(0x27a8)
954#define OACEC7_1 _MMIO(0x27ac)
955
619 956
620#define _GEN7_PIPEA_DE_LOAD_SL 0x70068957#define _GEN7_PIPEA_DE_LOAD_SL 0x70068
621#define _GEN7_PIPEB_DE_LOAD_SL 0x71068958#define _GEN7_PIPEB_DE_LOAD_SL 0x71068
@@ -6914,6 +7251,7 @@ enum { · 6292 unmodified lines
6914# define GEN6_RCCUNIT_CLOCK_GATE_DISABLE (1 << 11)7251# define GEN6_RCCUNIT_CLOCK_GATE_DISABLE (1 << 11)
6915 7252
6916#define GEN6_UCGCTL3 _MMIO(0x9408)7253#define GEN6_UCGCTL3 _MMIO(0x9408)
7254# define GEN6_OACSUNIT_CLOCK_GATE_DISABLE (1 << 20)
6917 7255
6918#define GEN7_UCGCTL4 _MMIO(0x940c)7256#define GEN7_UCGCTL4 _MMIO(0x940c)
6919#define GEN7_L3BANK2X_CLOCK_GATE_DISABLE (1<<25)7257#define GEN7_L3BANK2X_CLOCK_GATE_DISABLE (1<<25)
include/uapi/drm/i915_drm.h+69−2
@@ -1230,6 +1230,18 @@ struct drm_i915_gem_context_param { · 1229 unmodified lines
1230 __u64 value;1230 __u64 value;
1231};1231};
1232 1232
1233enum drm_i915_oa_format {
1234 I915_OA_FORMAT_A13 = 1,
1235 I915_OA_FORMAT_A29,
1236 I915_OA_FORMAT_A13_B8_C8,
1237 I915_OA_FORMAT_B4_C8,
1238 I915_OA_FORMAT_A45_B8_C8,
1239 I915_OA_FORMAT_B4_C8_A16,
1240 I915_OA_FORMAT_C4_B8,
1241
1242 I915_OA_FORMAT_MAX /* non-ABI */
1243};
1244
1233enum drm_i915_perf_property_id {1245enum drm_i915_perf_property_id {
1234 /**1246 /**
1235 * Open the stream for a specific context handle (as used with1247 * Open the stream for a specific context handle (as used with
@@ -1238,6 +1250,32 @@ enum drm_i915_perf_property_id { · 2 unmodified lines
1238 */1250 */
1239 DRM_I915_PERF_PROP_CTX_HANDLE = 1,1251 DRM_I915_PERF_PROP_CTX_HANDLE = 1,
1240 1252
1253 /**
1254 * A value of 1 requests the inclusion of raw OA unit reports as
1255 * part of stream samples.
1256 */
1257 DRM_I915_PERF_PROP_SAMPLE_OA,
1258
1259 /**
1260 * The value specifies which set of OA unit metrics should be
1261 * be configured, defining the contents of any OA unit reports.
1262 */
1263 DRM_I915_PERF_PROP_OA_METRICS_SET,
1264
1265 /**
1266 * The value specifies the size and layout of OA unit reports.
1267 */
1268 DRM_I915_PERF_PROP_OA_FORMAT,
1269
1270 /**
1271 * Specifying this property implicitly requests periodic OA unit
1272 * sampling and (at least on Haswell) the sampling frequency is derived
1273 * from this exponent as follows:
1274 *
1275 * 80ns * 2^(period_exponent + 1)
1276 */
1277 DRM_I915_PERF_PROP_OA_EXPONENT,
1278
1241 DRM_I915_PERF_PROP_MAX /* non-ABI */1279 DRM_I915_PERF_PROP_MAX /* non-ABI */
1242};1280};
1243 1281
@@ -1257,7 +1295,23 @@ struct drm_i915_perf_open_param { · 13 unmodified lines
1257 __u64 __user properties_ptr;1295 __u64 __user properties_ptr;
1258};1296};
1259 1297
1298/**
1299 * Enable data capture for a stream that was either opened in a disabled state
1300 * via I915_PERF_FLAG_DISABLED or was later disabled via
1301 * I915_PERF_IOCTL_DISABLE.
1302 *
1303 * It is intended to be cheaper to disable and enable a stream than it may be
1304 * to close and re-open a stream with the same configuration.
1305 *
1306 * It's undefined whether any pending data for the stream will be lost.
1307 */
1260#define I915_PERF_IOCTL_ENABLE _IO('i', 0x0)1308#define I915_PERF_IOCTL_ENABLE _IO('i', 0x0)
1309
1310/**
1311 * Disable data capture for a stream.
1312 *
1313 * It is an error to try and read a stream that is disabled.
1314 */
1261#define I915_PERF_IOCTL_DISABLE _IO('i', 0x1)1315#define I915_PERF_IOCTL_DISABLE _IO('i', 0x1)
1262 1316
1263/**1317/**
@@ -1281,17 +1335,30 @@ enum drm_i915_perf_record_type { · 17 unmodified lines
1281 * every sample.1335 * every sample.
1282 *1336 *
1283 * The order of these sample properties given by userspace has no1337 * The order of these sample properties given by userspace has no
1284 * affect on the ordering of data within a sample. The order will be1338 * affect on the ordering of data within a sample. The order is
1285 * documented here.1339 * documented here.
1286 *1340 *
1287 * struct {1341 * struct {
1288 * struct drm_i915_perf_record_header header;1342 * struct drm_i915_perf_record_header header;
1289 *1343 *
1290 * TODO: itemize extensible sample data here1344 * { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA
1291 * };1345 * };
1292 */1346 */
1293 DRM_I915_PERF_RECORD_SAMPLE = 1,1347 DRM_I915_PERF_RECORD_SAMPLE = 1,
1294 1348
1349 /*
1350 * Indicates that one or more OA reports were not written by the
1351 * hardware. This can happen for example if an MI_REPORT_PERF_COUNT
1352 * command collides with periodic sampling - which would be more likely
1353 * at higher sampling frequencies.
1354 */
1355 DRM_I915_PERF_RECORD_OA_REPORT_LOST = 2,
1356
1357 /**
1358 * An error occurred that resulted in all pending OA reports being lost.
1359 */
1360 DRM_I915_PERF_RECORD_OA_BUFFER_LOST = 3,
1361
1295 DRM_I915_PERF_RECORD_MAX /* non-ABI */1362 DRM_I915_PERF_RECORD_MAX /* non-ABI */
1296};1363};
1297 1364

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t