[igt-dev] [i-g-t 1/2] tests/kms_vrr: Add support to read Vblank event

Bhanuprakash Modem bhanuprakash.modem at intel.com
Mon Nov 20 08:24:58 UTC 2023


Add a helper support to read DRM_EVENT_VBLANK event from Kernel.

Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem at intel.com>
---
 tests/kms_vrr.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/tests/kms_vrr.c b/tests/kms_vrr.c
index f26adbccf..741a13be6 100644
--- a/tests/kms_vrr.c
+++ b/tests/kms_vrr.c
@@ -128,13 +128,31 @@ static uint64_t timespec_to_ns(struct timespec *ts)
 static uint64_t get_kernel_event_ns(data_t *data, uint32_t event)
 {
 	struct drm_event_vblank ev;
+	union drm_wait_vblank vbl;
+	uint32_t tv_sec, tv_usec;
 
 	igt_set_timeout(1, "Waiting for an event\n");
-	igt_assert_eq(read(data->drm_fd, &ev, sizeof(ev)), sizeof(ev));
-	igt_assert_eq(ev.base.type, event);
+
+	if (event == DRM_EVENT_VBLANK) {
+		memset(&vbl, 0, sizeof(vbl));
+		vbl.request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_NEXTONMISS;
+		igt_assert_eq(drmIoctl(data->drm_fd, DRM_IOCTL_WAIT_VBLANK, &vbl), 0);
+
+		tv_sec = vbl.reply.tval_sec;
+		tv_usec = vbl.reply.tval_usec;
+	} else if (event == DRM_EVENT_FLIP_COMPLETE) {
+		igt_assert_eq(read(data->drm_fd, &ev, sizeof(ev)), sizeof(ev));
+		igt_assert_eq(ev.base.type, event);
+
+		tv_sec = ev.tv_sec;
+		tv_usec = ev.tv_usec;
+	} else {
+		igt_assert_f(0, "Un recognized event.\n");
+	}
+
 	igt_reset_timeout();
 
-	return ev.tv_sec * NSECS_PER_SEC + ev.tv_usec * 1000ull;
+	return tv_sec * NSECS_PER_SEC + tv_usec * 1000ull;
 }
 
 /*
-- 
2.40.0



More information about the igt-dev mailing list