Skip to contentSkip to conversation

flip_test: increase duration for vbl+flip tests with ts check

PATCH In review Imre Deak 2 participants 9 messages Oct 22, 2012 – Oct 23, 2012

lore
Share & tools
lore

Imre Deak

author
#0 lore raw

PATCH 1/5 flip_test: increase duration for vbl+flip tests with ts check

We need a big enough duration, so the hotplug event's affect doesn't distort our final frame count too much.

Without this these tests will exit with a "dropped frames" error.

---
 tests/flip_test.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/flip_test.c +3 -3
index 3d52305..81a7afe 100644
@@ -866,11 +866,11 @@ int main(int argc, char **argv)
 		{ 30, TEST_FLIP | TEST_MODESET | TEST_EINVAL, "flip vs modeset" },
 		{ 30, TEST_FLIP | TEST_MODESET | TEST_WITH_DUMMY_LOAD, "delayed flip vs modeset" },
 
-		{ 5, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_ABSOLUTE |
+		{ 15, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_ABSOLUTE |
 		      TEST_CHECK_TS, "flip vs absolute wf-vblank" },
-		{ 5, TEST_FLIP | TEST_VBLANK | TEST_CHECK_TS,
+		{ 15, TEST_FLIP | TEST_VBLANK | TEST_CHECK_TS,
 					"flip vs wf-vblank" },
-		{ 5, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_BLOCK |
+		{ 15, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_BLOCK |
 			TEST_CHECK_TS, "flip vs blocking wf-vblank" },
 	};
 	int i;
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 2/5 flip_test: fixup zero timestamp for premature vblanks

---
 tests/flip_test.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tests/flip_test.c +25 -0
index 81a7afe..00f98ce 100644
@@ -291,6 +291,30 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,
 	event_handler(&o->flip_state, frame, sec, usec);
 }
 
+static void fixup_premature_vblank_ts(struct test_output *o,
+				      struct event_state *es)
+{
+	/*
+	 * In case a power off event preempts the completion of a
+	 * wait-for-vblank event the kernel will return a wf-vblank event with
+	 * a zeroed-out timestamp. In order that check_state() doesn't
+	 * complain replace this ts with a valid ts. As we can't calculate the
+	 * exact timestamp, just use the time we received the event.
+	 */
+	struct timeval tv;
+
+	if (!(o->flags & (TEST_DPMS | TEST_MODESET)))
+		return;
+
+	if (o->vblank_state.current_ts.tv_sec != 0 ||
+	    o->vblank_state.current_ts.tv_usec != 0)
+		return;
+
+	tv.tv_sec = 0;
+	tv.tv_usec = 1;
+	timersub(&es->current_received_ts, &tv, &es->current_ts);
+}
+
 static void vblank_handler(int fd, unsigned int frame, unsigned int sec,
 			      unsigned int usec, void *data)
 {
@@ -298,6 +322,7 @@ static void vblank_handler(int fd, unsigned int frame, unsigned int sec,
 
 	clear_flag(&o->pending_events, EVENT_VBLANK);
 	event_handler(&o->vblank_state, frame, sec, usec);
+	fixup_premature_vblank_ts(o, &o->vblank_state);
 }
 
 static void check_state(struct test_output *o, struct event_state *es)
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH 3/5 flip_test: check if the vblank and flip states correlate

In reply to Imre Deak
---
 tests/flip_test.c |   47 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 4 deletions(-)
tests/flip_test.c +43 -4
index 00f98ce..b387bf5 100644
@@ -291,6 +291,11 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,
 	event_handler(&o->flip_state, frame, sec, usec);
 }
 
+static double frame_time(struct test_output *o)
+{
+	return 1000.0 * 1000.0 / o->mode.vrefresh;
+}
+
 static void fixup_premature_vblank_ts(struct test_output *o,
 				      struct event_state *es)
 {
@@ -359,8 +364,7 @@ static void check_state(struct test_output *o, struct event_state *es)
 
 	if ((o->flags & TEST_CHECK_TS) && (!analog_tv_connector(o))) {
 		timersub(&es->current_ts, &es->last_ts, &diff);
-		usec_interflip = (double)es->seq_step /
-				 ((double)o->mode.vrefresh) * 1000.0 * 1000.0;
+		usec_interflip = (double)es->seq_step * frame_time(o);
 		if (fabs((((double) diff.tv_usec) - usec_interflip) /
 		    usec_interflip) > 0.005) {
 			fprintf(stderr, "inter-%s ts jitter: %is, %ius\n",
@@ -380,13 +384,48 @@ static void check_state(struct test_output *o, struct event_state *es)
 	}
 }
 
+static void check_state_correlation(struct test_output *o,
+				    struct event_state *es1,
+				    struct event_state *es2)
+{
+	struct timeval tv_diff;
+	double ftime;
+	double usec_diff;
+	int seq_diff;
+
+	if (es1->count == 0 || es2->count == 0)
+		return;
+
+	timersub(&es2->current_ts, &es1->current_ts, &tv_diff);
+	usec_diff = tv_diff.tv_sec * 1000 * 1000 + tv_diff.tv_usec;
+
+	seq_diff = es2->current_seq - es1->current_seq;
+	ftime = frame_time(o);
+	usec_diff -= seq_diff * ftime;
+
+	if (fabs(usec_diff) / ftime > 0.005) {
+		fprintf(stderr,
+			"timestamp mismatch between %s and %s (diff %.4f sec)\n",
+			es1->name, es2->name, usec_diff / 1000 / 1000);
+		exit(14);
+	}
+}
+
 static void check_all_state(struct test_output *o,
 			    unsigned int completed_events)
 {
-	if (completed_events & EVENT_FLIP)
+	bool flip, vblank;
+
+	flip = completed_events & EVENT_FLIP;
+	vblank = completed_events & EVENT_VBLANK;
+
+	if (flip)
 		check_state(o, &o->flip_state);
-	if (completed_events & EVENT_VBLANK)
+	if (vblank)
 		check_state(o, &o->vblank_state);
+
+	if (flip && vblank)
+		check_state_correlation(o, &o->flip_state, &o->vblank_state);
 }
 
 /* Return mask of completed events. */
Signature · 1 line
1.7.9.5
author
#3 lore raw

PATCH 4/5 flip_test: add comment about the race between flip vs. vblank events

In reply to Imre Deak
---
 tests/flip_test.c |    5 +++++
 1 file changed, 5 insertions(+)
tests/flip_test.c +5 -0
index b387bf5..7fed2f1 100644
@@ -444,6 +444,11 @@ static unsigned int run_test_step(struct test_output *o)
 	if (o->flags & TEST_VBLANK_ABSOLUTE)
 		target_seq += o->vblank_state.last_seq;
 
+	/*
+	 * It's possible that we don't have a pending flip here, in case both
+	 * wf-vblank and flip were scheduled and the wf-vblank event was
+	 * delivered earlier. The same applies to vblank events w.r.t flip.
+	 */
 	do_flip = (o->flags & TEST_FLIP) && !(o->pending_events & EVENT_FLIP);
 	do_vblank = (o->flags & TEST_VBLANK) &&
 		    !(o->pending_events & EVENT_VBLANK);
Signature · 1 line
1.7.9.5
author
#4 lore raw

PATCH 5/5 flip_test: add wf-vblank test for expired sequence

In reply to Imre Deak
---
 tests/flip_test.c |   61 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 49 insertions(+), 12 deletions(-)
tests/flip_test.c +49 -12
index 7fed2f1..bffd5b4 100644
@@ -52,6 +52,7 @@
 #define TEST_VBLANK		(1 << 8)
 #define TEST_VBLANK_BLOCK	(1 << 9)
 #define TEST_VBLANK_ABSOLUTE	(1 << 10)
+#define TEST_VBLANK_EXPIRED_SEQ	(1 << 11)
 
 #define EVENT_FLIP		(1 << 0)
 #define EVENT_VBLANK		(1 << 1)
@@ -221,13 +222,14 @@ struct vblank_reply {
 	struct timeval ts;
 };
 
-static int do_wait_for_vblank(struct test_output *o, int crtc_idx,
-			      int target_seq, struct vblank_reply *reply)
+static int __wait_for_vblank(unsigned int flags, int crtc_idx,
+			      int target_seq, unsigned long ret_data,
+			      struct vblank_reply *reply)
 {
 	drmVBlank wait_vbl;
 	int ret;
 	unsigned crtc_idx_mask;
-	bool event = !(o->flags & TEST_VBLANK_BLOCK);
+	bool event = !(flags & TEST_VBLANK_BLOCK);
 
 	memset(&wait_vbl, 0, sizeof(wait_vbl));
 
@@ -235,13 +237,13 @@ static int do_wait_for_vblank(struct test_output *o, int crtc_idx,
 	assert(!(crtc_idx_mask & ~DRM_VBLANK_HIGH_CRTC_MASK));
 
 	wait_vbl.request.type = crtc_idx_mask;
-	if (o->flags & TEST_VBLANK_ABSOLUTE)
+	if (flags & TEST_VBLANK_ABSOLUTE)
 		wait_vbl.request.type |= DRM_VBLANK_ABSOLUTE;
 	else
 		wait_vbl.request.type |= DRM_VBLANK_RELATIVE;
 	if (event) {
 		wait_vbl.request.type |= DRM_VBLANK_EVENT;
-		wait_vbl.request.signal = (unsigned long)o;
+		wait_vbl.request.signal = ret_data;
 	}
 	wait_vbl.request.sequence = target_seq;
 
@@ -251,17 +253,25 @@ static int do_wait_for_vblank(struct test_output *o, int crtc_idx,
 		reply->ts.tv_sec = wait_vbl.reply.tval_sec;
 		reply->ts.tv_usec = wait_vbl.reply.tval_usec;
 		reply->sequence = wait_vbl.reply.sequence;
-
-		if (event) {
-			assert(!(o->pending_events & EVENT_VBLANK));
-			o->pending_events |= EVENT_VBLANK;
-		}
 	} else
 		ret = -errno;
 
 	return ret;
 }
 
+static int do_wait_for_vblank(struct test_output *o, int pipe_id,
+			      int target_seq, struct vblank_reply *reply)
+{
+	int ret;
+
+	ret = __wait_for_vblank(o->flags, pipe_id, target_seq, (unsigned long)o,
+				reply);
+	if (ret == 0 && !(o->flags & TEST_VBLANK_BLOCK))
+		set_flag(&o->pending_events, EVENT_VBLANK);
+
+	return ret;
+}
+
 static bool
 analog_tv_connector(struct test_output *o)
 {
@@ -330,6 +340,12 @@ static void vblank_handler(int fd, unsigned int frame, unsigned int sec,
 	fixup_premature_vblank_ts(o, &o->vblank_state);
 }
 
+static bool seq_before(unsigned int s1, unsigned int s2)
+{
+	/* This bounding matches the one in DRM_IOCTL_WAIT_VBLANK. */
+	return s1 - s2 > 1UL << 23;
+}
+
 static void check_state(struct test_output *o, struct event_state *es)
 {
 	struct timeval diff;
@@ -355,8 +371,7 @@ static void check_state(struct test_output *o, struct event_state *es)
 	if (es->count == 0)
 		return;
 
-	/* This bounding matches the one in DRM_IOCTL_WAIT_VBLANK. */
-	if (es->current_seq - (es->last_seq + es->seq_step) > 1UL << 23) {
+	if (seq_before(es->current_seq, es->last_seq + es->seq_step)) {
 		fprintf(stderr, "unexpected %s seq %u, should be >= %u\n",
 			es->name, es->current_seq, es->last_seq + es->seq_step);
 		exit(10);
@@ -460,6 +475,26 @@ static unsigned int run_test_step(struct test_output *o)
 	o->current_fb_id = !o->current_fb_id;
 	new_fb_id = o->fb_ids[o->current_fb_id];
 
+	if ((o->flags & TEST_VBLANK_EXPIRED_SEQ) &&
+	    !(o->pending_events & EVENT_VBLANK) &&
+	    (o->vblank_state.count > 0 || o->flip_state.count > 0)) {
+		struct event_state *es;
+		struct vblank_reply reply;
+		unsigned int exp_seq;
+
+		if (o->vblank_state.count > 0)
+			es = &o->vblank_state;
+		else
+			es = &o->flip_state;
+
+		exp_seq = es->last_seq - 1;
+		do_or_die(__wait_for_vblank(TEST_VBLANK_ABSOLUTE |
+					    TEST_VBLANK_BLOCK, o->pipe, exp_seq,
+					    0, &reply));
+		assert(!seq_before(reply.sequence, exp_seq));
+		assert(!timercmp(&reply.ts, &es->last_ts, <));
+	}
+
 	if (do_flip && (o->flags & TEST_EINVAL) && o->flip_state.count > 0)
 		assert(do_page_flip(o, new_fb_id) == expected_einval);
 
@@ -934,6 +969,8 @@ int main(int argc, char **argv)
 		{ 30, TEST_FLIP | TEST_PAN | TEST_WITH_DUMMY_LOAD, "delayed flip vs panning" },
 		{ 30, TEST_FLIP | TEST_MODESET | TEST_EINVAL, "flip vs modeset" },
 		{ 30, TEST_FLIP | TEST_MODESET | TEST_WITH_DUMMY_LOAD, "delayed flip vs modeset" },
+		{ 5,  TEST_FLIP | TEST_VBLANK_EXPIRED_SEQ,
+					"flip vs. expired vblank" },
 
 		{ 15, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_ABSOLUTE |
 		      TEST_CHECK_TS, "flip vs absolute wf-vblank" },
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [PATCH 5/5] flip_test: add wf-vblank test for expired sequence

Quoted 1 line · Imre Deak

As discussed on irc, I still have a few whishlists items for this one here left. Patches 1-4 are merged, thanks.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
author
#6 lore raw

PATCH v2 1/1 flip_test: add wf-vblank test for expired sequence

In reply to Imre Deak
---
 tests/flip_test.c |   58 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 48 insertions(+), 10 deletions(-)

In v2:
- Wait for the seq that just completed (current_seq) not last_seq - 1.
- Do an equality check for ts and seq instead of >=. The previous issue didn't let us do this before.
- Simplify the condition when we do an "expired sequence" check by only using the last flip event as a reference.

tests/flip_test.c +48 -10
index 7fed2f1..3dfce8e 100644
@@ -52,6 +52,7 @@
 #define TEST_VBLANK		(1 << 8)
 #define TEST_VBLANK_BLOCK	(1 << 9)
 #define TEST_VBLANK_ABSOLUTE	(1 << 10)
+#define TEST_VBLANK_EXPIRED_SEQ	(1 << 11)
 
 #define EVENT_FLIP		(1 << 0)
 #define EVENT_VBLANK		(1 << 1)
@@ -116,6 +117,16 @@ struct test_output {
 	unsigned int pending_events;
 };
 
+
+static unsigned long gettime_us(void)
+{
+	struct timespec ts;
+
+	clock_gettime(CLOCK_MONOTONIC, &ts);
+
+	return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
+}
+
 static void emit_dummy_load(struct test_output *o)
 {
 	int i, limit;
@@ -221,13 +232,14 @@ struct vblank_reply {
 	struct timeval ts;
 };
 
-static int do_wait_for_vblank(struct test_output *o, int crtc_idx,
-			      int target_seq, struct vblank_reply *reply)
+static int __wait_for_vblank(unsigned int flags, int crtc_idx,
+			      int target_seq, unsigned long ret_data,
+			      struct vblank_reply *reply)
 {
 	drmVBlank wait_vbl;
 	int ret;
 	unsigned crtc_idx_mask;
-	bool event = !(o->flags & TEST_VBLANK_BLOCK);
+	bool event = !(flags & TEST_VBLANK_BLOCK);
 
 	memset(&wait_vbl, 0, sizeof(wait_vbl));
 
@@ -235,13 +247,13 @@ static int do_wait_for_vblank(struct test_output *o, int crtc_idx,
 	assert(!(crtc_idx_mask & ~DRM_VBLANK_HIGH_CRTC_MASK));
 
 	wait_vbl.request.type = crtc_idx_mask;
-	if (o->flags & TEST_VBLANK_ABSOLUTE)
+	if (flags & TEST_VBLANK_ABSOLUTE)
 		wait_vbl.request.type |= DRM_VBLANK_ABSOLUTE;
 	else
 		wait_vbl.request.type |= DRM_VBLANK_RELATIVE;
 	if (event) {
 		wait_vbl.request.type |= DRM_VBLANK_EVENT;
-		wait_vbl.request.signal = (unsigned long)o;
+		wait_vbl.request.signal = ret_data;
 	}
 	wait_vbl.request.sequence = target_seq;
 
@@ -251,17 +263,25 @@ static int do_wait_for_vblank(struct test_output *o, int crtc_idx,
 		reply->ts.tv_sec = wait_vbl.reply.tval_sec;
 		reply->ts.tv_usec = wait_vbl.reply.tval_usec;
 		reply->sequence = wait_vbl.reply.sequence;
-
-		if (event) {
-			assert(!(o->pending_events & EVENT_VBLANK));
-			o->pending_events |= EVENT_VBLANK;
-		}
 	} else
 		ret = -errno;
 
 	return ret;
 }
 
+static int do_wait_for_vblank(struct test_output *o, int pipe_id,
+			      int target_seq, struct vblank_reply *reply)
+{
+	int ret;
+
+	ret = __wait_for_vblank(o->flags, pipe_id, target_seq, (unsigned long)o,
+				reply);
+	if (ret == 0 && !(o->flags & TEST_VBLANK_BLOCK))
+		set_flag(&o->pending_events, EVENT_VBLANK);
+
+	return ret;
+}
+
 static bool
 analog_tv_connector(struct test_output *o)
 {
@@ -460,6 +480,22 @@ static unsigned int run_test_step(struct test_output *o)
 	o->current_fb_id = !o->current_fb_id;
 	new_fb_id = o->fb_ids[o->current_fb_id];
 
+	if ((o->flags & TEST_VBLANK_EXPIRED_SEQ) &&
+	    !(o->pending_events & EVENT_VBLANK) && o->flip_state.count > 0) {
+		struct vblank_reply reply;
+		unsigned int exp_seq;
+		unsigned long start;
+
+		exp_seq = o->flip_state.current_seq;
+		start = gettime_us();
+		do_or_die(__wait_for_vblank(TEST_VBLANK_ABSOLUTE |
+					    TEST_VBLANK_BLOCK, o->pipe, exp_seq,
+					    0, &reply));
+		assert(gettime_us() - start < 500);
+		assert(reply.sequence == exp_seq);
+		assert(timercmp(&reply.ts, &o->flip_state.last_ts, ==));
+	}
+
 	if (do_flip && (o->flags & TEST_EINVAL) && o->flip_state.count > 0)
 		assert(do_page_flip(o, new_fb_id) == expected_einval);
 
@@ -934,6 +970,8 @@ int main(int argc, char **argv)
 		{ 30, TEST_FLIP | TEST_PAN | TEST_WITH_DUMMY_LOAD, "delayed flip vs panning" },
 		{ 30, TEST_FLIP | TEST_MODESET | TEST_EINVAL, "flip vs modeset" },
 		{ 30, TEST_FLIP | TEST_MODESET | TEST_WITH_DUMMY_LOAD, "delayed flip vs modeset" },
+		{ 5,  TEST_FLIP | TEST_VBLANK_EXPIRED_SEQ,
+					"flip vs. expired vblank" },
 
 		{ 15, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_ABSOLUTE |
 		      TEST_CHECK_TS, "flip vs absolute wf-vblank" },
Signature · 1 line
1.7.9.5
#7 lore raw

Re: [PATCH v2] flip_test: add wf-vblank test for expired sequence

Quoted 11 lines · Imre Deak
---
 tests/flip_test.c |   58 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 48 insertions(+), 10 deletions(-)

In v2:
- Wait for the seq that just completed (current_seq) not last_seq - 1.
- Do an equality check for ts and seq instead of >=. The previous issue didn't let us do this before.
- Simplify the condition when we do an "expired sequence" check by only using the last flip event as a reference.

Patch style comment: I prefer the changelog above the --- so that it's included in the commit message. Safe obviously when the new patch has abosulutely nothing to do with previous versions.

Patch applied, thanks.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
author
#8 lore raw

Re: [PATCH v2] flip_test: add wf-vblank test for expired sequence

Quoted 13 lines · Daniel Vetter
Quoted 11 lines · Imre Deak
---
 tests/flip_test.c |   58 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 48 insertions(+), 10 deletions(-)

In v2:
- Wait for the seq that just completed (current_seq) not last_seq - 1.
- Do an equality check for ts and seq instead of >=. The previous issue didn't let us do this before.
- Simplify the condition when we do an "expired sequence" check by only using the last flip event as a reference.

Quoted 3 lines

Patch style comment: I prefer the changelog above the --- so that it's included in the commit message. Safe obviously when the new patch has abosulutely nothing to do with previous versions.

Ok, noted. So far I thought the only benefit of the history here is to make the reviewer's life easier, but I agree it may be useful even later to understand the context.

--Imre