intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [i-g-t PATCH 0/4] flip_test: support for monotonic timestamps
@ 2012-11-22 13:25 Imre Deak
  2012-11-22 13:25 ` [i-g-t PATCH 1/4] flip_test: add wf-vblank test for expired sequence Imre Deak
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Imre Deak @ 2012-11-22 13:25 UTC (permalink / raw)
  To: intel-gfx

The first patch isn't related, just a left-over from the previous
patchset.

Imre Deak (4):
  flip_test: add wf-vblank test for expired sequence
  flip_test: skip check for last_received_ts for the first event
  flip_test: use monotonic time to measure the test duration
  flip_test: switch to using monotonic timestamps

 tests/flip_test.c |  132 +++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 104 insertions(+), 28 deletions(-)

-- 
1.7.9.5

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

* [i-g-t PATCH 1/4] flip_test: add wf-vblank test for expired sequence
  2012-11-22 13:25 [i-g-t PATCH 0/4] flip_test: support for monotonic timestamps Imre Deak
@ 2012-11-22 13:25 ` Imre Deak
  2012-11-22 13:25 ` [i-g-t PATCH 2/4] flip_test: skip check for last_received_ts for the first event Imre Deak
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: Imre Deak @ 2012-11-22 13:25 UTC (permalink / raw)
  To: intel-gfx

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 tests/flip_test.c |   58 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 48 insertions(+), 10 deletions(-)

diff --git a/tests/flip_test.c b/tests/flip_test.c
index 7fed2f1..3dfce8e 100644
--- a/tests/flip_test.c
+++ b/tests/flip_test.c
@@ -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" },
-- 
1.7.9.5

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

* [i-g-t PATCH 2/4] flip_test: skip check for last_received_ts for the first event
  2012-11-22 13:25 [i-g-t PATCH 0/4] flip_test: support for monotonic timestamps Imre Deak
  2012-11-22 13:25 ` [i-g-t PATCH 1/4] flip_test: add wf-vblank test for expired sequence Imre Deak
@ 2012-11-22 13:25 ` Imre Deak
  2012-11-22 13:25 ` [i-g-t PATCH 3/4] flip_test: use monotonic time to measure the test duration Imre Deak
  2012-11-22 13:25 ` [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps Imre Deak
  3 siblings, 0 replies; 12+ messages in thread
From: Imre Deak @ 2012-11-22 13:25 UTC (permalink / raw)
  To: intel-gfx

The old way worked too, but just skipping the test for the first event
is more logical/simpler thing to do.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 tests/flip_test.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/tests/flip_test.c b/tests/flip_test.c
index 3dfce8e..e2af358 100644
--- a/tests/flip_test.c
+++ b/tests/flip_test.c
@@ -362,6 +362,9 @@ static void check_state(struct test_output *o, struct event_state *es)
 		exit(5);
 	}
 
+	if (es->count == 0)
+		return;
+
 	if (!timercmp(&es->last_received_ts, &es->current_ts, <)) {
 		fprintf(stderr, "%s ts before the %s was issued!\n",
 				es->name, es->name);
@@ -372,9 +375,6 @@ static void check_state(struct test_output *o, struct event_state *es)
 		exit(6);
 	}
 
-	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) {
 		fprintf(stderr, "unexpected %s seq %u, should be >= %u\n",
@@ -862,9 +862,6 @@ static void run_test_on_crtc(struct test_output *o, int crtc, int duration)
 	if (o->flags & TEST_CHECK_TS)
 		sleep(1);
 
-	gettimeofday(&o->flip_state.last_ts, NULL);
-	gettimeofday(&o->vblank_state.last_ts, NULL);
-
 	if (do_page_flip(o, o->fb_ids[1])) {
 		fprintf(stderr, "failed to page flip: %s\n", strerror(errno));
 		exit(4);
-- 
1.7.9.5

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

* [i-g-t PATCH 3/4] flip_test: use monotonic time to measure the test duration
  2012-11-22 13:25 [i-g-t PATCH 0/4] flip_test: support for monotonic timestamps Imre Deak
  2012-11-22 13:25 ` [i-g-t PATCH 1/4] flip_test: add wf-vblank test for expired sequence Imre Deak
  2012-11-22 13:25 ` [i-g-t PATCH 2/4] flip_test: skip check for last_received_ts for the first event Imre Deak
@ 2012-11-22 13:25 ` Imre Deak
  2012-11-22 13:52   ` Daniel Vetter
  2012-11-22 13:25 ` [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps Imre Deak
  3 siblings, 1 reply; 12+ messages in thread
From: Imre Deak @ 2012-11-22 13:25 UTC (permalink / raw)
  To: intel-gfx

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 tests/flip_test.c |   16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/tests/flip_test.c b/tests/flip_test.c
index e2af358..d88f81c 100644
--- a/tests/flip_test.c
+++ b/tests/flip_test.c
@@ -786,15 +786,11 @@ static unsigned int wait_for_events(struct test_output *o)
 /* Returned the ellapsed time in us */
 static unsigned event_loop(struct test_output *o, unsigned duration_sec)
 {
-	struct timeval start, end;
-	struct timeval tv_dur;
+	unsigned long start, end;
 
-	gettimeofday(&start, NULL);
-	end.tv_sec = start.tv_sec + duration_sec;
-	end.tv_usec = start.tv_usec;
+	start = gettime_us();
 
 	while (1) {
-		struct timeval now;
 		unsigned int completed_events;
 
 		completed_events = run_test_step(o);
@@ -803,19 +799,17 @@ static unsigned event_loop(struct test_output *o, unsigned duration_sec)
 		check_all_state(o, completed_events);
 		update_all_state(o, completed_events);
 
-		gettimeofday(&now, NULL);
-		if (!timercmp(&now, &end, <))
+		if ((gettime_us() - start) / 1000000 >= duration_sec)
 			break;
 	}
 
-	gettimeofday(&end, NULL);
-	timersub(&end, &start, &tv_dur);
+	end = gettime_us();
 
 	/* Flush any remaining events */
 	if (o->pending_events)
 		wait_for_events(o);
 
-	return tv_dur.tv_sec * 1000 * 1000 + tv_dur.tv_usec;
+	return end - start;
 }
 
 static void run_test_on_crtc(struct test_output *o, int crtc, int duration)
-- 
1.7.9.5

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

* [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps
  2012-11-22 13:25 [i-g-t PATCH 0/4] flip_test: support for monotonic timestamps Imre Deak
                   ` (2 preceding siblings ...)
  2012-11-22 13:25 ` [i-g-t PATCH 3/4] flip_test: use monotonic time to measure the test duration Imre Deak
@ 2012-11-22 13:25 ` Imre Deak
  2012-11-22 13:46   ` Daniel Vetter
  2012-11-22 14:46   ` [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps (v2) Imre Deak
  3 siblings, 2 replies; 12+ messages in thread
From: Imre Deak @ 2012-11-22 13:25 UTC (permalink / raw)
  To: intel-gfx

Since monotonic timestamps are now the preferred time format, change
timestamps checks to compare against monotonic instead of real time.
Also add two tests for DRM's compatibility mode where it returns real
timestamps.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 tests/flip_test.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/tests/flip_test.c b/tests/flip_test.c
index d88f81c..258d727 100644
--- a/tests/flip_test.c
+++ b/tests/flip_test.c
@@ -53,6 +53,7 @@
 #define TEST_VBLANK_BLOCK	(1 << 9)
 #define TEST_VBLANK_ABSOLUTE	(1 << 10)
 #define TEST_VBLANK_EXPIRED_SEQ	(1 << 11)
+#define TEST_TIMESTAMP_REAL	(1 << 12)
 
 #define EVENT_FLIP		(1 << 0)
 #define EVENT_VBLANK		(1 << 1)
@@ -63,6 +64,7 @@ static drm_intel_bufmgr *bufmgr;
 struct intel_batchbuffer *batch;
 uint32_t devid;
 int test_time = 3;
+static bool monotonic_timestamp;
 
 uint32_t *fb_ptr;
 
@@ -296,7 +298,19 @@ analog_tv_connector(struct test_output *o)
 static void event_handler(struct event_state *es, unsigned int frame,
 			  unsigned int sec, unsigned int usec)
 {
-	gettimeofday(&es->current_received_ts, NULL);
+	struct timeval now;
+
+	if (monotonic_timestamp) {
+		struct timespec ts;
+
+		clock_gettime(CLOCK_MONOTONIC, &ts);
+		now.tv_sec = ts.tv_sec;
+		now.tv_usec = ts.tv_nsec / 1000;
+	} else {
+		gettimeofday(&now, NULL);
+	}
+	es->current_received_ts = now;
+
 	es->current_ts.tv_sec = sec;
 	es->current_ts.tv_usec = usec;
 	es->current_seq = frame;
@@ -899,6 +913,28 @@ static int get_pipe_from_crtc_id(int crtc_id)
 	return pfci.pipe;
 }
 
+static void enable_monotonic_timestamp(bool enable)
+{
+	static const char *sysfs_mono_path =
+		"/sys/module/drm/parameters/timestamp_monotonic";
+	int mono_ts_enabled;
+	int scanned;
+	FILE *f;
+
+	f = fopen(sysfs_mono_path, "r+");
+	assert(f);
+
+	scanned = fscanf(f, "%d", &mono_ts_enabled);
+	assert(scanned == 1 && (mono_ts_enabled == 1 || mono_ts_enabled == 0));
+
+	if (mono_ts_enabled != enable)
+		fprintf(f, "%d", enable);
+
+	fclose(f);
+
+	monotonic_timestamp = enable;
+}
+
 static int run_test(int duration, int flags, const char *test_name)
 {
 	struct test_output o;
@@ -911,6 +947,8 @@ static int run_test(int duration, int flags, const char *test_name)
 		exit(5);
 	}
 
+	enable_monotonic_timestamp(!(flags & TEST_TIMESTAMP_REAL));
+
 	/* Find any connected displays */
 	for (c = 0; c < resources->count_connectors; c++) {
 		for (i = 0; i < resources->count_crtcs; i++) {
@@ -941,6 +979,8 @@ int main(int argc, char **argv)
 		const char *name;
 	} tests[] = {
 		{ 15, TEST_VBLANK | TEST_CHECK_TS, "wf-vblank" },
+		{ 15, TEST_VBLANK | TEST_TIMESTAMP_REAL | TEST_CHECK_TS,
+					"wf-vblank with real timestamps" },
 		{ 15, TEST_VBLANK | TEST_VBLANK_BLOCK | TEST_CHECK_TS,
 					"blocking wf-vblank" },
 		{ 5,  TEST_VBLANK | TEST_VBLANK_ABSOLUTE,
@@ -955,6 +995,8 @@ int main(int argc, char **argv)
 					"delayed wf-vblank vs modeset" },
 
 		{ 15, TEST_FLIP | TEST_CHECK_TS | TEST_EBUSY , "plain flip" },
+		{ 5,  TEST_FLIP | TEST_TIMESTAMP_REAL | TEST_CHECK_TS,
+					"flip with real timestamps" },
 		{ 30, TEST_FLIP | TEST_DPMS | TEST_EINVAL, "flip vs dpms" },
 		{ 30, TEST_FLIP | TEST_DPMS | TEST_WITH_DUMMY_LOAD, "delayed flip vs dpms" },
 		{ 5,  TEST_FLIP | TEST_PAN, "flip vs panning" },
@@ -973,6 +1015,11 @@ int main(int argc, char **argv)
 	};
 	int i;
 
+	if (geteuid() != 0) {
+		fprintf(stderr, "you must run this as root\n");
+		exit(EXIT_FAILURE);
+	}
+
 	drm_fd = drm_open_any();
 
 	bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
-- 
1.7.9.5

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

* Re: [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps
  2012-11-22 13:25 ` [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps Imre Deak
@ 2012-11-22 13:46   ` Daniel Vetter
  2012-11-22 13:50     ` Imre Deak
  2012-11-22 14:46   ` [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps (v2) Imre Deak
  1 sibling, 1 reply; 12+ messages in thread
From: Daniel Vetter @ 2012-11-22 13:46 UTC (permalink / raw)
  To: Imre Deak; +Cc: intel-gfx

On Thu, Nov 22, 2012 at 03:25:06PM +0200, Imre Deak wrote:
> Since monotonic timestamps are now the preferred time format, change
> timestamps checks to compare against monotonic instead of real time.
> Also add two tests for DRM's compatibility mode where it returns real
> timestamps.
> 
> Signed-off-by: Imre Deak <imre.deak@intel.com>

A few comments below.
-Daniel

> ---
>  tests/flip_test.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 48 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/flip_test.c b/tests/flip_test.c
> index d88f81c..258d727 100644
> --- a/tests/flip_test.c
> +++ b/tests/flip_test.c
> @@ -53,6 +53,7 @@
>  #define TEST_VBLANK_BLOCK	(1 << 9)
>  #define TEST_VBLANK_ABSOLUTE	(1 << 10)
>  #define TEST_VBLANK_EXPIRED_SEQ	(1 << 11)
> +#define TEST_TIMESTAMP_REAL	(1 << 12)
>  
>  #define EVENT_FLIP		(1 << 0)
>  #define EVENT_VBLANK		(1 << 1)
> @@ -63,6 +64,7 @@ static drm_intel_bufmgr *bufmgr;
>  struct intel_batchbuffer *batch;
>  uint32_t devid;
>  int test_time = 3;
> +static bool monotonic_timestamp;
>  
>  uint32_t *fb_ptr;
>  
> @@ -296,7 +298,19 @@ analog_tv_connector(struct test_output *o)
>  static void event_handler(struct event_state *es, unsigned int frame,
>  			  unsigned int sec, unsigned int usec)
>  {
> -	gettimeofday(&es->current_received_ts, NULL);
> +	struct timeval now;
> +
> +	if (monotonic_timestamp) {
> +		struct timespec ts;
> +
> +		clock_gettime(CLOCK_MONOTONIC, &ts);
> +		now.tv_sec = ts.tv_sec;
> +		now.tv_usec = ts.tv_nsec / 1000;
> +	} else {
> +		gettimeofday(&now, NULL);
> +	}
> +	es->current_received_ts = now;
> +
>  	es->current_ts.tv_sec = sec;
>  	es->current_ts.tv_usec = usec;
>  	es->current_seq = frame;
> @@ -899,6 +913,28 @@ static int get_pipe_from_crtc_id(int crtc_id)
>  	return pfci.pipe;
>  }
>  
> +static void enable_monotonic_timestamp(bool enable)
> +{
> +	static const char *sysfs_mono_path =
> +		"/sys/module/drm/parameters/timestamp_monotonic";
> +	int mono_ts_enabled;
> +	int scanned;
> +	FILE *f;
> +
> +	f = fopen(sysfs_mono_path, "r+");
> +	assert(f);
> +
> +	scanned = fscanf(f, "%d", &mono_ts_enabled);
> +	assert(scanned == 1 && (mono_ts_enabled == 1 || mono_ts_enabled == 0));
> +
> +	if (mono_ts_enabled != enable)
> +		fprintf(f, "%d", enable);

I think it'd be better to use the drm getcap ioctl here (and default to
disabled if it returns -EINVAL), since that's the officially blessed
interface to figure this out.


> +
> +	fclose(f);
> +
> +	monotonic_timestamp = enable;
> +}
> +
>  static int run_test(int duration, int flags, const char *test_name)
>  {
>  	struct test_output o;
> @@ -911,6 +947,8 @@ static int run_test(int duration, int flags, const char *test_name)
>  		exit(5);
>  	}
>  
> +	enable_monotonic_timestamp(!(flags & TEST_TIMESTAMP_REAL));

I don't follow why we should enable monotonic timestamps for some tests
and not for some others? Shouldn't all tests with TEST_CHECK_TS just use
the same clock the kernel uses?

> +
>  	/* Find any connected displays */
>  	for (c = 0; c < resources->count_connectors; c++) {
>  		for (i = 0; i < resources->count_crtcs; i++) {
> @@ -941,6 +979,8 @@ int main(int argc, char **argv)
>  		const char *name;
>  	} tests[] = {
>  		{ 15, TEST_VBLANK | TEST_CHECK_TS, "wf-vblank" },
> +		{ 15, TEST_VBLANK | TEST_TIMESTAMP_REAL | TEST_CHECK_TS,
> +					"wf-vblank with real timestamps" },
>  		{ 15, TEST_VBLANK | TEST_VBLANK_BLOCK | TEST_CHECK_TS,
>  					"blocking wf-vblank" },
>  		{ 5,  TEST_VBLANK | TEST_VBLANK_ABSOLUTE,
> @@ -955,6 +995,8 @@ int main(int argc, char **argv)
>  					"delayed wf-vblank vs modeset" },
>  
>  		{ 15, TEST_FLIP | TEST_CHECK_TS | TEST_EBUSY , "plain flip" },
> +		{ 5,  TEST_FLIP | TEST_TIMESTAMP_REAL | TEST_CHECK_TS,
> +					"flip with real timestamps" },
>  		{ 30, TEST_FLIP | TEST_DPMS | TEST_EINVAL, "flip vs dpms" },
>  		{ 30, TEST_FLIP | TEST_DPMS | TEST_WITH_DUMMY_LOAD, "delayed flip vs dpms" },
>  		{ 5,  TEST_FLIP | TEST_PAN, "flip vs panning" },
> @@ -973,6 +1015,11 @@ int main(int argc, char **argv)
>  	};
>  	int i;
>  
> +	if (geteuid() != 0) {
> +		fprintf(stderr, "you must run this as root\n");
> +		exit(EXIT_FAILURE);
> +	}

If you want this, I think we should have a common function to check for
master capability ... Imo you can drop this.

> +
>  	drm_fd = drm_open_any();
>  
>  	bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
> -- 
> 1.7.9.5
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

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

* Re: [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps
  2012-11-22 13:46   ` Daniel Vetter
@ 2012-11-22 13:50     ` Imre Deak
  2012-11-22 14:04       ` Daniel Vetter
  0 siblings, 1 reply; 12+ messages in thread
From: Imre Deak @ 2012-11-22 13:50 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

On Thu, 2012-11-22 at 14:46 +0100, Daniel Vetter wrote:
> On Thu, Nov 22, 2012 at 03:25:06PM +0200, Imre Deak wrote:
> > Since monotonic timestamps are now the preferred time format, change
> > timestamps checks to compare against monotonic instead of real time.
> > Also add two tests for DRM's compatibility mode where it returns real
> > timestamps.
> > 
> > Signed-off-by: Imre Deak <imre.deak@intel.com>
> 
> A few comments below.
> -Daniel
> 
> > ---
> >  tests/flip_test.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 48 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tests/flip_test.c b/tests/flip_test.c
> > index d88f81c..258d727 100644
> > --- a/tests/flip_test.c
> > +++ b/tests/flip_test.c
> > @@ -53,6 +53,7 @@
> >  #define TEST_VBLANK_BLOCK	(1 << 9)
> >  #define TEST_VBLANK_ABSOLUTE	(1 << 10)
> >  #define TEST_VBLANK_EXPIRED_SEQ	(1 << 11)
> > +#define TEST_TIMESTAMP_REAL	(1 << 12)
> >  
> >  #define EVENT_FLIP		(1 << 0)
> >  #define EVENT_VBLANK		(1 << 1)
> > @@ -63,6 +64,7 @@ static drm_intel_bufmgr *bufmgr;
> >  struct intel_batchbuffer *batch;
> >  uint32_t devid;
> >  int test_time = 3;
> > +static bool monotonic_timestamp;
> >  
> >  uint32_t *fb_ptr;
> >  
> > @@ -296,7 +298,19 @@ analog_tv_connector(struct test_output *o)
> >  static void event_handler(struct event_state *es, unsigned int frame,
> >  			  unsigned int sec, unsigned int usec)
> >  {
> > -	gettimeofday(&es->current_received_ts, NULL);
> > +	struct timeval now;
> > +
> > +	if (monotonic_timestamp) {
> > +		struct timespec ts;
> > +
> > +		clock_gettime(CLOCK_MONOTONIC, &ts);
> > +		now.tv_sec = ts.tv_sec;
> > +		now.tv_usec = ts.tv_nsec / 1000;
> > +	} else {
> > +		gettimeofday(&now, NULL);
> > +	}
> > +	es->current_received_ts = now;
> > +
> >  	es->current_ts.tv_sec = sec;
> >  	es->current_ts.tv_usec = usec;
> >  	es->current_seq = frame;
> > @@ -899,6 +913,28 @@ static int get_pipe_from_crtc_id(int crtc_id)
> >  	return pfci.pipe;
> >  }
> >  
> > +static void enable_monotonic_timestamp(bool enable)
> > +{
> > +	static const char *sysfs_mono_path =
> > +		"/sys/module/drm/parameters/timestamp_monotonic";
> > +	int mono_ts_enabled;
> > +	int scanned;
> > +	FILE *f;
> > +
> > +	f = fopen(sysfs_mono_path, "r+");
> > +	assert(f);
> > +
> > +	scanned = fscanf(f, "%d", &mono_ts_enabled);
> > +	assert(scanned == 1 && (mono_ts_enabled == 1 || mono_ts_enabled == 0));
> > +
> > +	if (mono_ts_enabled != enable)
> > +		fprintf(f, "%d", enable);
> 
> I think it'd be better to use the drm getcap ioctl here (and default to
> disabled if it returns -EINVAL), since that's the officially blessed
> interface to figure this out.
> 
> 
> > +
> > +	fclose(f);
> > +
> > +	monotonic_timestamp = enable;
> > +}
> > +
> >  static int run_test(int duration, int flags, const char *test_name)
> >  {
> >  	struct test_output o;
> > @@ -911,6 +947,8 @@ static int run_test(int duration, int flags, const char *test_name)
> >  		exit(5);
> >  	}
> >  
> > +	enable_monotonic_timestamp(!(flags & TEST_TIMESTAMP_REAL));
> 
> I don't follow why we should enable monotonic timestamps for some tests
> and not for some others? Shouldn't all tests with TEST_CHECK_TS just use
> the same clock the kernel uses?

The idea was to also test the compatibility mode, where we get real
timestamps.

> 
> > +
> >  	/* Find any connected displays */
> >  	for (c = 0; c < resources->count_connectors; c++) {
> >  		for (i = 0; i < resources->count_crtcs; i++) {
> > @@ -941,6 +979,8 @@ int main(int argc, char **argv)
> >  		const char *name;
> >  	} tests[] = {
> >  		{ 15, TEST_VBLANK | TEST_CHECK_TS, "wf-vblank" },
> > +		{ 15, TEST_VBLANK | TEST_TIMESTAMP_REAL | TEST_CHECK_TS,
> > +					"wf-vblank with real timestamps" },
> >  		{ 15, TEST_VBLANK | TEST_VBLANK_BLOCK | TEST_CHECK_TS,
> >  					"blocking wf-vblank" },
> >  		{ 5,  TEST_VBLANK | TEST_VBLANK_ABSOLUTE,
> > @@ -955,6 +995,8 @@ int main(int argc, char **argv)
> >  					"delayed wf-vblank vs modeset" },
> >  
> >  		{ 15, TEST_FLIP | TEST_CHECK_TS | TEST_EBUSY , "plain flip" },
> > +		{ 5,  TEST_FLIP | TEST_TIMESTAMP_REAL | TEST_CHECK_TS,
> > +					"flip with real timestamps" },
> >  		{ 30, TEST_FLIP | TEST_DPMS | TEST_EINVAL, "flip vs dpms" },
> >  		{ 30, TEST_FLIP | TEST_DPMS | TEST_WITH_DUMMY_LOAD, "delayed flip vs dpms" },
> >  		{ 5,  TEST_FLIP | TEST_PAN, "flip vs panning" },
> > @@ -973,6 +1015,11 @@ int main(int argc, char **argv)
> >  	};
> >  	int i;
> >  
> > +	if (geteuid() != 0) {
> > +		fprintf(stderr, "you must run this as root\n");
> > +		exit(EXIT_FAILURE);
> > +	}
> 
> If you want this, I think we should have a common function to check for
> master capability ... Imo you can drop this.

I added this early check since accessing timestamp_monotonic needs it.
Otherwise you get some error only later when switching to compatibility
mode, which I thought was confusing.

> 
> > +
> >  	drm_fd = drm_open_any();
> >  
> >  	bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
> > -- 
> > 1.7.9.5
> > 
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/intel-gfx
> 

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

* Re: [i-g-t PATCH 3/4] flip_test: use monotonic time to measure the test duration
  2012-11-22 13:25 ` [i-g-t PATCH 3/4] flip_test: use monotonic time to measure the test duration Imre Deak
@ 2012-11-22 13:52   ` Daniel Vetter
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Vetter @ 2012-11-22 13:52 UTC (permalink / raw)
  To: Imre Deak; +Cc: intel-gfx

On Thu, Nov 22, 2012 at 03:25:05PM +0200, Imre Deak wrote:
> Signed-off-by: Imre Deak <imre.deak@intel.com>

Merged patches 1-3, thanks.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

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

* Re: [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps
  2012-11-22 13:50     ` Imre Deak
@ 2012-11-22 14:04       ` Daniel Vetter
  2012-11-22 14:07         ` Imre Deak
  0 siblings, 1 reply; 12+ messages in thread
From: Daniel Vetter @ 2012-11-22 14:04 UTC (permalink / raw)
  To: Imre Deak; +Cc: intel-gfx

On Thu, Nov 22, 2012 at 2:50 PM, Imre Deak <imre.deak@intel.com> wrote:
>> > +   enable_monotonic_timestamp(!(flags & TEST_TIMESTAMP_REAL));
>>
>> I don't follow why we should enable monotonic timestamps for some tests
>> and not for some others? Shouldn't all tests with TEST_CHECK_TS just use
>> the same clock the kernel uses?
>
> The idea was to also test the compatibility mode, where we get real
> timestamps.

Oh, I've missed that you write back the desired value. I don't think
we need to test the compat mode if it's not enabled, just test
whatever mode is enabled. That way we also check whether the getcap
interface works.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

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

* Re: [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps
  2012-11-22 14:04       ` Daniel Vetter
@ 2012-11-22 14:07         ` Imre Deak
  0 siblings, 0 replies; 12+ messages in thread
From: Imre Deak @ 2012-11-22 14:07 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

On Thu, 2012-11-22 at 15:04 +0100, Daniel Vetter wrote:
> On Thu, Nov 22, 2012 at 2:50 PM, Imre Deak <imre.deak@intel.com> wrote:
> >> > +   enable_monotonic_timestamp(!(flags & TEST_TIMESTAMP_REAL));
> >>
> >> I don't follow why we should enable monotonic timestamps for some tests
> >> and not for some others? Shouldn't all tests with TEST_CHECK_TS just use
> >> the same clock the kernel uses?
> >
> > The idea was to also test the compatibility mode, where we get real
> > timestamps.
> 
> Oh, I've missed that you write back the desired value. I don't think
> we need to test the compat mode if it's not enabled, just test
> whatever mode is enabled. That way we also check whether the getcap
> interface works.

Ok, will do so. We have to wait though until DRM_CAP_TIMESTAMP_MONOTONIC
is added to libdrm. I've sent already a patch for this.

--Imre

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

* [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps (v2)
  2012-11-22 13:25 ` [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps Imre Deak
  2012-11-22 13:46   ` Daniel Vetter
@ 2012-11-22 14:46   ` Imre Deak
  2012-11-22 20:20     ` Daniel Vetter
  1 sibling, 1 reply; 12+ messages in thread
From: Imre Deak @ 2012-11-22 14:46 UTC (permalink / raw)
  To: intel-gfx

Since monotonic timestamps are now the preferred time format, change
timestamps checks to compare against monotonic instead of real time.
Also add two tests for DRM's compatibility mode where it returns real
timestamps.

v2: drop the tests for the compatibilty mode (Daniel)

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 tests/flip_test.c |   33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/tests/flip_test.c b/tests/flip_test.c
index d88f81c..5214da9 100644
--- a/tests/flip_test.c
+++ b/tests/flip_test.c
@@ -57,12 +57,17 @@
 #define EVENT_FLIP		(1 << 0)
 #define EVENT_VBLANK		(1 << 1)
 
+#ifndef DRM_CAP_TIMESTAMP_MONOTONIC
+#define DRM_CAP_TIMESTAMP_MONOTONIC 6
+#endif
+
 drmModeRes *resources;
 int drm_fd;
 static drm_intel_bufmgr *bufmgr;
 struct intel_batchbuffer *batch;
 uint32_t devid;
 int test_time = 3;
+static bool monotonic_timestamp;
 
 uint32_t *fb_ptr;
 
@@ -296,7 +301,19 @@ analog_tv_connector(struct test_output *o)
 static void event_handler(struct event_state *es, unsigned int frame,
 			  unsigned int sec, unsigned int usec)
 {
-	gettimeofday(&es->current_received_ts, NULL);
+	struct timeval now;
+
+	if (monotonic_timestamp) {
+		struct timespec ts;
+
+		clock_gettime(CLOCK_MONOTONIC, &ts);
+		now.tv_sec = ts.tv_sec;
+		now.tv_usec = ts.tv_nsec / 1000;
+	} else {
+		gettimeofday(&now, NULL);
+	}
+	es->current_received_ts = now;
+
 	es->current_ts.tv_sec = sec;
 	es->current_ts.tv_usec = usec;
 	es->current_seq = frame;
@@ -933,6 +950,18 @@ static int run_test(int duration, int flags, const char *test_name)
 	return 1;
 }
 
+static void get_timestamp_format(void)
+{
+	uint64_t cap_mono;
+	int ret;
+
+	ret = drmGetCap(drm_fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap_mono);
+	assert(ret == 0 || errno == EINVAL);
+	monotonic_timestamp = ret == 0 && cap_mono == 1;
+	printf("Using %s timestamps\n",
+		monotonic_timestamp ? "monotonic" : "real");
+}
+
 int main(int argc, char **argv)
 {
 	struct {
@@ -975,6 +1004,8 @@ int main(int argc, char **argv)
 
 	drm_fd = drm_open_any();
 
+	get_timestamp_format();
+
 	bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
 	devid = intel_get_drm_devid(drm_fd);
 	batch = intel_batchbuffer_alloc(bufmgr, devid);
-- 
1.7.9.5

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

* Re: [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps (v2)
  2012-11-22 14:46   ` [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps (v2) Imre Deak
@ 2012-11-22 20:20     ` Daniel Vetter
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Vetter @ 2012-11-22 20:20 UTC (permalink / raw)
  To: Imre Deak; +Cc: intel-gfx

On Thu, Nov 22, 2012 at 04:46:36PM +0200, Imre Deak wrote:
> Since monotonic timestamps are now the preferred time format, change
> timestamps checks to compare against monotonic instead of real time.
> Also add two tests for DRM's compatibility mode where it returns real
> timestamps.
> 
> v2: drop the tests for the compatibilty mode (Daniel)
> 
> Signed-off-by: Imre Deak <imre.deak@intel.com>

Applied, thanks for the patch.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

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

end of thread, other threads:[~2012-11-22 20:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-22 13:25 [i-g-t PATCH 0/4] flip_test: support for monotonic timestamps Imre Deak
2012-11-22 13:25 ` [i-g-t PATCH 1/4] flip_test: add wf-vblank test for expired sequence Imre Deak
2012-11-22 13:25 ` [i-g-t PATCH 2/4] flip_test: skip check for last_received_ts for the first event Imre Deak
2012-11-22 13:25 ` [i-g-t PATCH 3/4] flip_test: use monotonic time to measure the test duration Imre Deak
2012-11-22 13:52   ` Daniel Vetter
2012-11-22 13:25 ` [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps Imre Deak
2012-11-22 13:46   ` Daniel Vetter
2012-11-22 13:50     ` Imre Deak
2012-11-22 14:04       ` Daniel Vetter
2012-11-22 14:07         ` Imre Deak
2012-11-22 14:46   ` [i-g-t PATCH 4/4] flip_test: switch to using monotonic timestamps (v2) Imre Deak
2012-11-22 20:20     ` Daniel Vetter

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).