From 0cf3d67a5a96f0a913acd73034672b1f474922eb Mon Sep 17 00:00:00 2001 From: Ville Syrjälä Date: Tue, 6 Nov 2018 17:46:23 +0200 Subject: lib/debugfs: Fix wraparound handling for crc frame counter check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Cc: Daniel Vetter Signed-off-by: Ville Syrjälä Reviewed-by: Daniel Vetter #v1 Reviewed-by: Chris Wilson --- lib/igt_debugfs.c | 2 +- lib/igt_kms.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c index b0e5cfa5..d9e9ff7b 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 a29ad783..3c602576 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__ */ -- cgit v1.2.3