igt-dev.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t 1/3] lib/igt_debugfs: Add igt_pipe_crc_get_current() to get a crc.
@ 2018-07-24 13:59 Maarten Lankhorst
  2018-07-24 13:59 ` [igt-dev] [PATCH i-g-t 2/3] tests: Replace calls to igt_pipe_crc_drain + get_single with igt_pipe_crc_get_current() Maarten Lankhorst
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Maarten Lankhorst @ 2018-07-24 13:59 UTC (permalink / raw)
  To: igt-dev

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>
---
 lib/igt_debugfs.c | 32 +++++++++++++++++++++++++++++++-
 lib/igt_debugfs.h |  2 ++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index f3196f4341f3..dc2c7df9da30 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -910,7 +910,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.
@@ -933,6 +933,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
  */
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index 8d25abfe43c1..db634a827290 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -132,6 +132,8 @@ int igt_pipe_crc_get_crcs(igt_pipe_crc_t *pipe_crc, int n_crcs,
 			  igt_crc_t **out_crcs);
 void igt_pipe_crc_drain(igt_pipe_crc_t *pipe_crc);
 bool igt_pipe_crc_get_single(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc);
+void igt_pipe_crc_get_current(int drm_fd, igt_pipe_crc_t *pipe_crc, igt_crc_t *crc);
+
 void igt_pipe_crc_collect_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc);
 
 void igt_hpd_storm_set_threshold(int fd, unsigned int threshold);
-- 
2.18.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-08-14 15:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-24 13:59 [igt-dev] [PATCH i-g-t 1/3] lib/igt_debugfs: Add igt_pipe_crc_get_current() to get a crc Maarten Lankhorst
2018-07-24 13:59 ` [igt-dev] [PATCH i-g-t 2/3] tests: Replace calls to igt_pipe_crc_drain + get_single with igt_pipe_crc_get_current() Maarten Lankhorst
2018-08-14 15:18   ` Daniel Vetter
2018-08-14 15:36     ` Maarten Lankhorst
2018-07-24 13:59 ` [igt-dev] [PATCH i-g-t 3/3] tests/kms_nv12: Add nv12 specific tests Maarten Lankhorst
2018-07-26  6:55   ` Petri Latvala
2018-07-26  8:57     ` Maarten Lankhorst
2018-07-24 15:17 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/3] lib/igt_debugfs: Add igt_pipe_crc_get_current() to get a crc Patchwork
2018-07-24 18:21 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).