summaryrefslogtreecommitdiff
path: root/lib/igt_debugfs.c
diff options
context:
space:
mode:
authorMaarten Lankhorst <maarten.lankhorst@linux.intel.com>2018-07-24 15:59:25 +0200
committerMaarten Lankhorst <maarten.lankhorst@linux.intel.com>2018-08-14 17:34:58 +0200
commitdeead1d39368ac11a66f0d9def39f75d1db7e78b (patch)
treea55e799797e24380ad0db0e3a304f4bbf872dfcb /lib/igt_debugfs.c
parentb0263e5d0563a81a42cf66e7d3b84662d3222862 (diff)
lib/igt_debugfs: Add igt_pipe_crc_get_current() to get a crc.
A pair of igt_pipe_crc_drain() and igt_pipe_crc_get_single() has a bug in which you're not sure whether the new CRC is captured because the vblank irq may race against the CRC irq and delivered to userspace too soon. When receiving a vblank event, igt_pipe_crc_drain() will then drain all crc's, but not the new (stale) crc, which is then delivered and immediately returned by igt_pipe_crc_get_single(). Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'lib/igt_debugfs.c')
-rw-r--r--lib/igt_debugfs.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 4de6b247..14753a9e 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -917,7 +917,7 @@ void igt_pipe_crc_drain(igt_pipe_crc_t *pipe_crc)
* look at igt_pipe_crc_collect_crc().
*
* If capturing has been going on for a while and a fresh crc is required,
- * you will need to call igt_pipe_crc_drain() first to remove stale entries.
+ * you should use igt_pipe_crc_get_current() instead.
*
* Returns:
* Whether a crc is captured, only false in non-blocking mode.
@@ -940,6 +940,36 @@ igt_pipe_crc_get_single(igt_pipe_crc_t *pipe_crc, igt_crc_t *crc)
return found;
}
+/**
+ * igt_pipe_crc_get_current:
+ * @drm_fd: Pointer to drm fd for vblank counter
+ * @pipe_crc: pipe CRC object
+ * @crc: buffer pointer for the captured CRC value
+ *
+ * Same as igt_pipe_crc_get_single(), but will wait until a new CRC can be captured.
+ * This is useful for retrieving the current CRC in a more race free way than
+ * igt_pipe_crc_drain() + igt_pipe_crc_get_single().
+ */
+void
+igt_pipe_crc_get_current(int drm_fd, igt_pipe_crc_t *pipe_crc, igt_crc_t *crc)
+{
+ unsigned vblank = kmstest_get_vblank(drm_fd, pipe_crc->pipe, 0);
+
+ igt_assert(!(pipe_crc->flags & O_NONBLOCK));
+ do {
+ read_one_crc(pipe_crc, crc);
+
+ /* Only works with valid frame counter */
+ if (!crc->has_valid_frame) {
+ igt_pipe_crc_drain(pipe_crc);
+ igt_pipe_crc_get_single(pipe_crc, crc);
+ return;
+ }
+ } while (crc->frame <= vblank);
+
+ crc_sanity_checks(crc);
+}
+
/*
* Drop caches
*/