[Piglit] [PATCH 05/12] util: convert piglit_getmicroseconds to piglit_time_get_nano

Emil Velikov emil.l.velikov at gmail.com
Sat Nov 22 14:40:27 PST 2014


This way we can actually reuse it in {arb,ext}_timer_query

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 tests/spec/glx_oml_sync_control/timing.c | 8 ++++----
 tests/texturing/teximage-colors.c        | 6 +++---
 tests/util/piglit-util.c                 | 4 ++--
 tests/util/piglit-util.h                 | 6 ++++--
 4 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/tests/spec/glx_oml_sync_control/timing.c b/tests/spec/glx_oml_sync_control/timing.c
index 7fbcf44..b4d0302 100644
--- a/tests/spec/glx_oml_sync_control/timing.c
+++ b/tests/spec/glx_oml_sync_control/timing.c
@@ -64,7 +64,7 @@ draw(Display *dpy)
 {
 	enum piglit_result result = PIGLIT_PASS;
 	int64_t last_ust = 0xd0, last_msc = 0xd0, last_sbc = 0xd0;
-	int64_t last_timestamp = -1;
+	int64_t last_timestamp = -1; /* in nano seconds */
 	struct stats msc_wallclock_duration_stats = {};
 	struct stats msc_ust_duration_stats = {};
 	double expected_msc_wallclock_duration = 0.0;
@@ -98,7 +98,7 @@ draw(Display *dpy)
 	for (i = 0; i < loops; i++) {
 		int64_t new_ust = 0xd0, new_msc = 0xd0, new_sbc = 0xd0;
 		int64_t check_ust = 0xd0, check_msc = 0xd0, check_sbc = 0xd0;
-		int64_t new_timestamp;
+		int64_t new_timestamp; /* in nano seconds */
 		int64_t expected_msc, target_sbc;
 		int64_t target_msc = 0;
 
@@ -143,7 +143,7 @@ draw(Display *dpy)
 				result = PIGLIT_FAIL;
 			}
 		}
-		new_timestamp = piglit_get_microseconds();
+		new_timestamp = piglit_time_get_nano();
 
 		if (!glXGetSyncValuesOML(dpy, win,
 				&check_ust, &check_msc, &check_sbc))
@@ -219,7 +219,7 @@ draw(Display *dpy)
 					update_stats(
 						&msc_wallclock_duration_stats,
 						(new_timestamp - last_timestamp)
-							/ delta_msc);
+							/ (delta_msc*1000));
 				}
 			}
 		}
diff --git a/tests/texturing/teximage-colors.c b/tests/texturing/teximage-colors.c
index 649337a..001626d 100644
--- a/tests/texturing/teximage-colors.c
+++ b/tests/texturing/teximage-colors.c
@@ -732,13 +732,13 @@ run_test(GLenum test_format, GLenum test_type, float *time_out)
 			    expected + 4 * i);
 
 	if (benchmark) {
-		time = piglit_get_microseconds();
+		time = piglit_time_get_nano();
 		for (i = 0; i < BENCHMARK_ITERATIONS; ++i)
 			glTexImage2D(GL_TEXTURE_2D, 0, format->internal_format,
 				     texture_size, texture_size, 0,
 				     test_format, test_type, data);
-		time = piglit_get_microseconds() - time;
-		*time_out = (double)time / (double)BENCHMARK_ITERATIONS;
+		time = piglit_time_get_nano() - time;
+		*time_out = (double)time / (double)(BENCHMARK_ITERATIONS*1000);
 	} else {
 		glTexImage2D(GL_TEXTURE_2D, 0, format->internal_format,
 			     texture_size, texture_size, 0,
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index aa423d2..5180bb8 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -660,13 +660,13 @@ piglit_time_is_monotonic(void)
 }
 
 int64_t
-piglit_get_microseconds(void)
+piglit_time_get_nano(void)
 {
 #ifdef PIGLIT_HAS_POSIX_CLOCK_MONOTONIC
 	struct timespec t;
 	int r = clock_gettime(CLOCK_MONOTONIC, &t);
 	if (r >= 0)
-		return (t.tv_sec * 1000000) + (t.tv_nsec / 1000);
+		return (t.tv_sec * INT64_C(1000000000)) + t.tv_nsec;
 	else
 		return -1LL;
 #else
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 3a02334..89e6ef7 100755
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -247,14 +247,16 @@ bool
 piglit_time_is_monotonic();
 
 /**
- * \brief Get a monotonically increasing time in microseconds
+ * \brief Get the time in nanoseconds
  *
  * This time can be used for relative time measurements.
  *
  * A negative return value indicates an error.
+ *
+ * \sa piglit_time_is_monotonic
  */
 int64_t
-piglit_get_microseconds(void);
+piglit_time_get_nano(void);
 
 const char**
 piglit_split_string_to_array(const char *string, const char *separators);
-- 
2.1.3



More information about the Piglit mailing list