diff mbox

[i-g-t,4/4] flip_test: switch to using monotonic timestamps (v2)

Message ID 1353595596-11993-1-git-send-email-imre.deak@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Imre Deak Nov. 22, 2012, 2:46 p.m. UTC
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(-)

Comments

Daniel Vetter Nov. 22, 2012, 8:20 p.m. UTC | #1
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
diff mbox

Patch

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