[igt-dev] [PATCH i-g-t 1/5] lib/debugfs: Fix wraparound handling for crc frame counter check

Ville Syrjala ville.syrjala at linux.intel.com
Thu Mar 7 21:39:22 UTC 2019


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

Deal with frame counter wraparound correcrtly.

v2: Make the comparison functions available for everyone (Chris)
    Add some docs (gtk-doc seems obtuse so not 100% warning free)

Cc: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
Cc: Daniel Vetter <daniel.vetter at ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
Reviewed-by: Daniel Vetter <daniel.vetter at ffwll.ch> #v1
Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk> #v1
---
 lib/igt_debugfs.c |  2 +-
 lib/igt_kms.h     | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 640c78e972e9..b782a2a88b03 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -971,7 +971,7 @@ igt_pipe_crc_get_current(int drm_fd, igt_pipe_crc_t *pipe_crc, igt_crc_t *crc)
 			igt_pipe_crc_get_single(pipe_crc, crc);
 			return;
 		}
-	} while (crc->frame <= vblank);
+	} while (igt_vblank_before_eq(crc->frame, vblank));
 
 	crc_sanity_checks(crc);
 }
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index a29ad7836465..3c602576db34 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -767,4 +767,64 @@ void igt_cleanup_hotplug(struct udev_monitor *mon);
 bool igt_display_has_format_mod(igt_display_t *display, uint32_t format, uint64_t modifier);
 bool igt_plane_has_format_mod(igt_plane_t *plane, uint32_t format, uint64_t modifier);
 
+/**
+ * igt_vblank_after_eq:
+ * @a: First vblank sequence number.
+ * @b: Second vblank sequence number.
+ *
+ * Compare vblank sequence numbers,
+ * handling wraparound correctly.
+ *
+ * Returns: @a >= @b
+ */
+static inline bool igt_vblank_after_eq(uint32_t a, uint32_t b)
+{
+	return (int32_t)(a - b) >= 0;
+}
+
+/**
+ * igt_vblank_before_eq:
+ * @a: First vblank sequence number.
+ * @b: Second vblank sequence number.
+ *
+ * Compare vblank sequence numbers,
+ * handling wraparound correctly.
+ *
+ * Returns: @a <= @b
+ */
+static inline bool igt_vblank_before_eq(uint32_t a, uint32_t b)
+{
+	return igt_vblank_after_eq(b, a);
+}
+
+/**
+ * igt_vblank_after:
+ * @a: First vblank sequence number.
+ * @b: Second vblank sequence number.
+ *
+ * Compare vblank sequence numbers,
+ * handling wraparound correctly.
+ *
+ * Returns: @a > @b
+ */
+static inline bool igt_vblank_after(uint32_t a, uint32_t b)
+{
+	return (int32_t)(b - a) < 0;
+}
+
+/**
+ * igt_vblank_before:
+ * @a: First vblank sequence number.
+ * @b: Second vblank sequence number.
+ *
+ * Compare vblank sequence numbers,
+ * handling wraparound correctly.
+ *
+ * Returns: @a < @b
+ */
+static inline bool igt_vblank_before(uint32_t a, uint32_t b)
+{
+	return igt_vblank_after(b, a);
+}
+
 #endif /* __IGT_KMS_H__ */
-- 
2.19.2



More information about the igt-dev mailing list