diff mbox

[i-g-t,v2] lib/igt_core: Prefer CLOCK_MONOTONIC_RAW

Message ID 1447762689-3635-1-git-send-email-joonas.lahtinen@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Joonas Lahtinen Nov. 17, 2015, 12:18 p.m. UTC
CLOCK_MONOTONIC_RAW is not affected by NTP, so it should be THE clock
used for timing execution of tests.

v2:
- Cache the used clock (Chris)
- Do not change the clock during execution
- Spit out and error if monotonic time can not be read

Cc: Thomas Wood <thomas.wood@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 lib/igt_core.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

Comments

Chris Wilson Nov. 17, 2015, 2:02 p.m. UTC | #1
On Tue, Nov 17, 2015 at 02:18:09PM +0200, Joonas Lahtinen wrote:
> CLOCK_MONOTONIC_RAW is not affected by NTP, so it should be THE clock
> used for timing execution of tests.
> 
> v2:
> - Cache the used clock (Chris)
> - Do not change the clock during execution
> - Spit out and error if monotonic time can not be read
> 
> Cc: Thomas Wood <thomas.wood@intel.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> ---
>  lib/igt_core.c | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index 04a0ab2..c56bc15 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -220,6 +220,7 @@ static char *run_single_subtest = NULL;
>  static bool run_single_subtest_found = false;
>  static const char *in_subtest = NULL;
>  static struct timespec subtest_time;
> +static clockid_t igt_clock = (clockid_t)-1;
>  static bool in_fixture = false;
>  static bool test_with_subtests = false;
>  static bool in_atexit_handler = false;
> @@ -341,10 +342,25 @@ static void gettime(struct timespec *ts)
>  {
>  	memset(ts, 0, sizeof(*ts));
>  
> +	// Stay on the same clock for consistency.
> +	if (igt_clock != (clockid_t)-1) {
> +		clock_gettime(igt_clock, ts);
> +		return;
> +	}
> +
> +#ifdef CLOCK_MONOTONIC_RAW
> +	if (!clock_gettime(igt_clock = CLOCK_MONOTONIC_RAW, ts))
> +		return;
> +#endif
>  #ifdef CLOCK_MONOTONIC_COARSE
> -	if (clock_gettime(CLOCK_MONOTONIC_COARSE, ts))
> +	if (!clock_gettime(igt_clock = CLOCK_MONOTONIC_COARSE, ts))
> +		return;
>  #endif
> -		clock_gettime(CLOCK_MONOTONIC, ts);
> +	if (!clock_gettime(igt_clock = CLOCK_MONOTONIC, ts))
> +		return;
> +
> +	igt_warn("Unable to get monotonic time!\n");
> +	exit(IGT_EXIT_FAILURE);

Hmm. gettime is used inside the subtest execution, so I'm not too sure
what should be done here, but definitely not call exit() itself!

I think probably return -errno is best, and move the igt_assert() into
the callers (as whatever is appropriate).

A second patch to then export

void igt_gettime(struct timespec *ts)
{
	igt_assert_f(gettime(ts) == 0,
		     "Unable to get monotonic time\n");
}

and replace all of the mismash in the tests would be nice.
-Chris
diff mbox

Patch

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 04a0ab2..c56bc15 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -220,6 +220,7 @@  static char *run_single_subtest = NULL;
 static bool run_single_subtest_found = false;
 static const char *in_subtest = NULL;
 static struct timespec subtest_time;
+static clockid_t igt_clock = (clockid_t)-1;
 static bool in_fixture = false;
 static bool test_with_subtests = false;
 static bool in_atexit_handler = false;
@@ -341,10 +342,25 @@  static void gettime(struct timespec *ts)
 {
 	memset(ts, 0, sizeof(*ts));
 
+	// Stay on the same clock for consistency.
+	if (igt_clock != (clockid_t)-1) {
+		clock_gettime(igt_clock, ts);
+		return;
+	}
+
+#ifdef CLOCK_MONOTONIC_RAW
+	if (!clock_gettime(igt_clock = CLOCK_MONOTONIC_RAW, ts))
+		return;
+#endif
 #ifdef CLOCK_MONOTONIC_COARSE
-	if (clock_gettime(CLOCK_MONOTONIC_COARSE, ts))
+	if (!clock_gettime(igt_clock = CLOCK_MONOTONIC_COARSE, ts))
+		return;
 #endif
-		clock_gettime(CLOCK_MONOTONIC, ts);
+	if (!clock_gettime(igt_clock = CLOCK_MONOTONIC, ts))
+		return;
+
+	igt_warn("Unable to get monotonic time!\n");
+	exit(IGT_EXIT_FAILURE);
 }
 
 bool __igt_fixture(void)