lib/igt_core: Prefer CLOCK_MONOTONIC_RAW
PATCH 1/1 lib/igt_core: Prefer CLOCK_MONOTONIC_RAW
CLOCK_MONOTONIC_RAW is not affected by NTP, so it should be THE clock used for timing execution of tests.
--- lib/igt_core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
lib/igt_core.c +7 -2
@@ -341,10 +341,15 @@ static void gettime(struct timespec *ts) {memset (ts,0 ,sizeof (*ts)); +#ifdef CLOCK_MONOTONIC_RAW +if (!clock_gettime (CLOCK_MONOTONIC_RAW , ts)) +return ; +#endif #ifdef CLOCK_MONOTONIC_COARSE - if (clock_gettime(CLOCK_MONOTONIC_COARSE, ts)) +if (!clock_gettime (CLOCK_MONOTONIC_COARSE , ts)) +return ;#endif -clock_gettime (CLOCK_MONOTONIC , ts); +clock_gettime (CLOCK_MONOTONIC , ts); }bool __igt_fixture (void )
Signature · 6 lines
2.4.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 19 lines · Joonas Lahtinen
CLOCK_MONOTONIC_RAWis not affected by NTP, so it should be THE clock used for timing execution of tests.Cc Thomas Wood <[email protected]>Cc Chris Wilson <[email protected]>Signed-off-by Joonas Lahtinen <[email protected]>--- lib/igt_core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)lib/igt_core.c +1
-0@@ -341,10 +341,15 @@ static void gettime(struct timespec *ts) {memset (ts,0 ,sizeof (*ts)); +#ifdef CLOCK_MONOTONIC_RAW
lib/igt_core.c static void gettime(struct timespec *ts) · line 352
Quoted 10 lines
lib/igt_core.c +6
-2+if (!clock_gettime (CLOCK_MONOTONIC_RAW , ts)) +return ; +#endif #ifdef CLOCK_MONOTONIC_COARSE - if (clock_gettime(CLOCK_MONOTONIC_COARSE, ts)) +if (!clock_gettime (CLOCK_MONOTONIC_COARSE , ts)) +return ;#endif -clock_gettime (CLOCK_MONOTONIC , ts); +clock_gettime (CLOCK_MONOTONIC , ts);
Would it be worth doing
static clock_t clock = -1;
if (clock_gettime(clock, ts) == 0)
return;
#ifdef CLOCK_MONOTONIC_RAW if (clock_gettime(clock = CLOCK_MONOTONIC_RAW, ts) == 0) return;
#endif
...
?
Anyway,
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 1/1 lib/igt_core: Prefer CLOCK_MONOTONIC_RAW
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
--- lib/igt_core.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
lib/igt_core.c +18 -2
@@ -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 )
Signature · 6 lines
2.4.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 42 lines · Joonas Lahtinen
CLOCK_MONOTONIC_RAWis 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 readCc Thomas Wood <[email protected]>Cc Chris Wilson <[email protected]>Signed-off-by Joonas Lahtinen <[email protected]>--- lib/igt_core.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)lib/igt_core.c +11
-0@@ -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
lib/igt_core.c static void gettime(struct timespec *ts) · line 363
Quoted 10 lines
lib/igt_core.c +7
-2- 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
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 1/1 lib/igt_core: Prefer CLOCK_MONOTONIC_RAW
CLOCK_MONOTONIC_RAW is not affected by NTP, so it should be THE clock used for timing execution of tests.
When fetching either the starting or ending time of a test, show the time as -1.000s.
v3:
- Do not exit directly from handler (Chris)
- Show elapsed time as -1 if it is not calculable
v2:
- Cache the used clock (Chris)
- Do not change the clock during execution
- Spit out and error if monotonic time can not be read
--- lib/igt_core.c | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-)
lib/igt_core.c +41 -10
@@ -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;
@@ -337,14 +338,32 @@ static void kmsg(const char *format, ...)fclose (file); } -static void gettime (struct timespec *ts) +static int gettime (struct timespec *ts) {memset (ts,0 ,sizeof (*ts)); + errno =0 ; +// Stay on the same clock for consistency. +if (igt_clock != (clockid_t)-1 ) { +if (clock_gettime (igt_clock, ts)) + goto error; +return 0 ; + } + +#ifdef CLOCK_MONOTONIC_RAW +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC_RAW , ts)) +return 0 ; +#endif #ifdef CLOCK_MONOTONIC_COARSE - if (clock_gettime(CLOCK_MONOTONIC_COARSE, ts)) +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC_COARSE , ts)) +return 0 ;#endif -clock_gettime (CLOCK_MONOTONIC , ts); +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC , ts)) +return 0 ; +error: +igt_warn ("Could not read monotonic time: %s\n" , +strerror (errno)); +return -errno; }bool __igt_fixture (void )
@@ -832,10 +851,16 @@ static void exit_subtest(const char *result) {struct timespec now;double elapsed; +int err; -gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; + err =gettime (&now); +if (!err && subtest_time.tv_sec !=0 && + subtest_time.tv_nsec !=0 ) { + elapsed = now.tv_sec - subtest_time.tv_sec; + elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; + }else { + elapsed =-1. ; + } printf("%sSubtest %s: %s (%.3fs)%s\n", (!__igt_plain_output) ? "\x1b[1m" : "",
@@ -1090,10 +1115,17 @@ void igt_exit(void)struct timespec now;double elapsed;const char *result; +int err; -gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; + err =gettime (&now); + +if (!err && subtest_time.tv_sec !=0 && + subtest_time.tv_nsec !=0 ) { + elapsed = now.tv_sec - subtest_time.tv_sec; + elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; + }else { + elapsed =-1. ; + }switch (igt_exitcode) {case IGT_EXIT_SUCCESS :
@@ -1109,7 +1141,6 @@ void igt_exit(void) result ="FAIL" ; } -printf ("%s (%.3fs)\n" , result, elapsed);exit (igt_exitcode); }
Signature · 6 lines
2.4.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 9 lines · Joonas Lahtinen
CLOCK_MONOTONIC_RAWis not affected by NTP, so it should be THE clock used for timing execution of tests.When fetching either the starting or ending time of a test, show the time as -1.000s.
v3:
- Do not exit directly from handler (Chris)
- Show elapsed time as -1 if it is not calculable
Aye, that's better for the subtest handling.
lib/igt_core.c static void exit_subtest(const char *result) · line 858
Quoted 12 lines
lib/igt_core.c +4
-3@@ -832,10 +851,16 @@ static void exit_subtest(const char *result) {struct timespec now;double elapsed; +int err; -gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; + err =gettime (&now); +if (!err && subtest_time.tv_sec !=0 && + subtest_time.tv_nsec !=0 ) {
A little paranoid? If we want the paranoia perhaps move it to gettime and return an error?
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 21 lines · Chris Wilson
Quoted 11 lines · Joonas Lahtinen
CLOCK_MONOTONIC_RAWis not affected by NTP, so it should be THE clock
used for timing execution of tests.When fetching either the starting or ending time of a test, show the
time as -1.000s.v3:
- Do not exit directly from handler (Chris)
- Show elapsed time as -1 if it is not calculableAye, that's better for the subtest handling.
Quoted 6 lines
lib/igt_core.c +1
-0@@ -832,10 +851,16 @@ static void exit_subtest(const char *result) {struct timespec now;double elapsed; +int err;
Quoted 10 lines
lib/igt_core.c static void exit_subtest(const char *result) · line 858
Quoted 6 lines
lib/igt_core.c +3
-3-gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; + err =gettime (&now); +if (!err && subtest_time.tv_sec !=0 && + subtest_time.tv_nsec !=0 ) {A little paranoid? If we want the paranoia perhaps move it to gettime and return an error?
I'm just checking that the starting time which is in the subtest_time did not fail (which leads to both being zero). I'm not looking at the now values :)
Regards, Joonas
Quoted 2 lines
-Chris
Signature · 8 lines
Joonas Lahtinen Open Source Technology Center Intel Corporation _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 33 lines · Joonas Lahtinen
Quoted 21 lines · Chris Wilson
Quoted 11 lines · Joonas Lahtinen
CLOCK_MONOTONIC_RAWis not affected by NTP, so it should be THE clock
used for timing execution of tests.When fetching either the starting or ending time of a test, show the
time as -1.000s.v3:
- Do not exit directly from handler (Chris)
- Show elapsed time as -1 if it is not calculableAye, that's better for the subtest handling.
Quoted 6 lines
lib/igt_core.c +1
-0@@ -832,10 +851,16 @@ static void exit_subtest(const char *result) {struct timespec now;double elapsed; +int err;Quoted 10 lines
lib/igt_core.c static void exit_subtest(const char *result) · line 858
Quoted 6 lines
lib/igt_core.c +3
-3-gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; + err =gettime (&now); +if (!err && subtest_time.tv_sec !=0 && + subtest_time.tv_nsec !=0 ) {A little paranoid? If we want the paranoia perhaps move it to gettime and return an error?
Quoted 3 lines
I'm just checking that the starting time which is in the
subtest_timedid not fail (which leads to both being zero). I'm not looking at the now values :)
Ok, now I see.
#define time_valid(ts) ((ts)->tv_sec || (ts)->tv_nsec)
gettime(&now);
if (time_valid(&now) && time_valid(&subtest_time)) {
elapsed = ...;
} else {
elapsed = -1;
}Perhaps?
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v4 1/1 lib/igt_core: Prefer CLOCK_MONOTONIC_RAW
CLOCK_MONOTONIC_RAW is not affected by NTP, so it should be THE clock used for timing execution of tests.
When fetching either the starting or ending time of a test, show the time as -1.000s.
v4:
- Introduce time_valid macro (Chris)
- Reduce amount of boilerplate code for calculating elapsed time
v3:
- Do not exit directly from handler (Chris)
- Show elapsed time as -1 if it is not calculable
v2:
- Cache the used clock (Chris)
- Do not change the clock during execution
- Spit out and error if monotonic time can not be read
--- lib/igt_core.c | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-)
lib/igt_core.c +40 -13
@@ -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;
@@ -337,14 +338,48 @@ static void kmsg(const char *format, ...)fclose (file); } -static void gettime (struct timespec *ts) +#define time_valid (ts) ((ts)->tv_sec || (ts)->tv_nsec) + +static double +time_elapsed (struct timespec *then, +struct timespec * now) { +double elapsed =-1. ; + +if (time_valid (then) &&time_valid (now)) { + elapsed = now->tv_sec - then->tv_sec; + elapsed += (now->tv_nsec - then->tv_nsec) *1e-9 ; + } + +return elapsed; +} + +static int gettime (struct timespec *ts) {memset (ts,0 ,sizeof (*ts)); + errno =0 ; +// Stay on the same clock for consistency. +if (igt_clock != (clockid_t)-1 ) { +if (clock_gettime (igt_clock, ts)) + goto error; +return 0 ; + } + +#ifdef CLOCK_MONOTONIC_RAW +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC_RAW , ts)) +return 0 ; +#endif #ifdef CLOCK_MONOTONIC_COARSE - if (clock_gettime(CLOCK_MONOTONIC_COARSE, ts)) +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC_COARSE , ts)) +return 0 ;#endif -clock_gettime (CLOCK_MONOTONIC , ts); +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC , ts)) +return 0 ; +error: +igt_warn ("Could not read monotonic time: %s\n" , +strerror (errno)); + +return -errno; }bool __igt_fixture (void )
@@ -831,15 +866,11 @@ static void exit_subtest(const char *) __attribute__((noreturn));static void exit_subtest (const char *result) {struct timespec now; -double elapsed;gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; -printf ("%sSubtest %s: %s (%.3fs)%s\n" , (!__igt_plain_output) ?"\x1b[1m" :"" , - in_subtest, result, elapsed, + in_subtest, result,time_elapsed (&subtest_time, &now), (!__igt_plain_output) ?"\x1b[0m" :"" );fflush (stdout);
@@ -1088,12 +1119,9 @@ void igt_exit(void)if (!test_with_subtests) {struct timespec now; -double elapsed;const char *result;gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ;switch (igt_exitcode) {case IGT_EXIT_SUCCESS :
@@ -1109,8 +1137,7 @@ void igt_exit(void) result ="FAIL" ; } - -printf ("%s (%.3fs)\n" , result, elapsed); +printf ("%s (%.3fs)\n" , result,time_elapsed (&subtest_time, &now));exit (igt_exitcode); }
Signature · 6 lines
2.4.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 14 lines · Joonas Lahtinen
CLOCK_MONOTONIC_RAWis not affected by NTP, so it should be THE clock used for timing execution of tests.When fetching either the starting or ending time of a test, show the time as -1.000s.
v4:
- Introducetime_validmacro (Chris)
- Reduce amount of boilerplate code for calculating elapsed timev3:
- Do not exit directly from handler (Chris)
- Show elapsed time as -1 if it is not calculable
Quoted 8 lines
v2:
- Cache the used clock (Chris)
- Do not change the clock during execution
- Spit out and error if monotonic time can not be readCc Thomas Wood <[email protected]>Cc Chris Wilson <[email protected]>Signed-off-by Joonas Lahtinen <[email protected]>
lib/igt_core.c static void kmsg(const char *format, ...) · line 361
Quoted 6 lines
lib/igt_core.c +3
-0+static int gettime (struct timespec *ts) {memset (ts,0 ,sizeof (*ts)); + errno =0 ; +// Stay on the same clock for consistency.
We avoid using "//" for comments, even for single lines. -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 1/1 lib/igt_core: Prefer CLOCK_MONOTONIC_RAW
CLOCK_MONOTONIC_RAW is not affected by NTP, so it should be THE clock used for timing execution of tests.
When fetching either the starting or ending time of a test, show the time as -1.000s.
v5:
- Do not use C99 style comments (Chris)
v4:
- Introduce time_valid macro (Chris)
- Reduce amount of boilerplate code for calculating elapsed time
v3:
- Do not exit directly from handler (Chris)
- Show elapsed time as -1 if it is not calculable
v2:
- Cache the used clock (Chris)
- Do not change the clock during execution
- Spit out and error if monotonic time can not be read
--- lib/igt_core.c | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-)
lib/igt_core.c +40 -13
@@ -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;
@@ -337,14 +338,48 @@ static void kmsg(const char *format, ...)fclose (file); } -static void gettime (struct timespec *ts) +#define time_valid (ts) ((ts)->tv_sec || (ts)->tv_nsec) + +static double +time_elapsed (struct timespec *then, +struct timespec * now) { +double elapsed =-1. ; + +if (time_valid (then) &&time_valid (now)) { + elapsed = now->tv_sec - then->tv_sec; + elapsed += (now->tv_nsec - then->tv_nsec) *1e-9 ; + } + +return elapsed; +} + +static int gettime (struct timespec *ts) {memset (ts,0 ,sizeof (*ts)); + errno =0 ; +/* Stay on the same clock for consistency. */ +if (igt_clock != (clockid_t)-1 ) { +if (clock_gettime (igt_clock, ts)) + goto error; +return 0 ; + } + +#ifdef CLOCK_MONOTONIC_RAW +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC_RAW , ts)) +return 0 ; +#endif #ifdef CLOCK_MONOTONIC_COARSE - if (clock_gettime(CLOCK_MONOTONIC_COARSE, ts)) +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC_COARSE , ts)) +return 0 ;#endif -clock_gettime (CLOCK_MONOTONIC , ts); +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC , ts)) +return 0 ; +error: +igt_warn ("Could not read monotonic time: %s\n" , +strerror (errno)); + +return -errno; }bool __igt_fixture (void )
@@ -831,15 +866,11 @@ static void exit_subtest(const char *) __attribute__((noreturn));static void exit_subtest (const char *result) {struct timespec now; -double elapsed;gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; -printf ("%sSubtest %s: %s (%.3fs)%s\n" , (!__igt_plain_output) ?"\x1b[1m" :"" , - in_subtest, result, elapsed, + in_subtest, result,time_elapsed (&subtest_time, &now), (!__igt_plain_output) ?"\x1b[0m" :"" );fflush (stdout);
@@ -1088,12 +1119,9 @@ void igt_exit(void)if (!test_with_subtests) {struct timespec now; -double elapsed;const char *result;gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ;switch (igt_exitcode) {case IGT_EXIT_SUCCESS :
@@ -1109,8 +1137,7 @@ void igt_exit(void) result ="FAIL" ; } - -printf ("%s (%.3fs)\n" , result, elapsed); +printf ("%s (%.3fs)\n" , result,time_elapsed (&subtest_time, &now));exit (igt_exitcode); }
Signature · 6 lines
2.4.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
lib/igt_core.c static void kmsg(const char *format, ...) · line 345
Quoted 3 lines · Joonas Lahtinen
lib/igt_core.c +3
-0+static double +time_elapsed (struct timespec *then, +struct timespec * now) {
I can't stop myself... ^
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 1/1 lib/igt_core: Prefer CLOCK_MONOTONIC_RAW
CLOCK_MONOTONIC_RAW is not affected by NTP, so it should be THE clock used for timing execution of tests.
When fetching either the starting or ending time of a test, show the time as -1.000s.
v6:
- Whitespace corrections (Chris)
v5:
- Do not use C99 style comments (Chris)
v4:
- Introduce time_valid macro (Chris)
- Reduce amount of boilerplate code for calculating elapsed time
v3:
- Do not exit directly from handler (Chris)
- Show elapsed time as -1 if it is not calculable
v2:
- Cache the used clock (Chris)
- Do not change the clock during execution
- Spit out and error if monotonic time can not be read
--- lib/igt_core.c | 54 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-)
lib/igt_core.c +41 -13
@@ -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;
@@ -337,14 +338,49 @@ static void kmsg(const char *format, ...)fclose (file); } -static void gettime (struct timespec *ts) +#define time_valid (ts) ((ts)->tv_sec || (ts)->tv_nsec) + +static double +time_elapsed (struct timespec *then, +struct timespec * now) +{ +double elapsed =-1. ; + +if (time_valid (then) &&time_valid (now)) { + elapsed = now->tv_sec - then->tv_sec; + elapsed += (now->tv_nsec - then->tv_nsec) *1e-9 ; + } + +return elapsed; +} + +static int gettime (struct timespec *ts) {memset (ts,0 ,sizeof (*ts)); + errno =0 ; +/* Stay on the same clock for consistency. */ +if (igt_clock != (clockid_t)-1 ) { +if (clock_gettime (igt_clock, ts)) + goto error; +return 0 ; + } + +#ifdef CLOCK_MONOTONIC_RAW +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC_RAW , ts)) +return 0 ; +#endif #ifdef CLOCK_MONOTONIC_COARSE - if (clock_gettime(CLOCK_MONOTONIC_COARSE, ts)) +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC_COARSE , ts)) +return 0 ;#endif -clock_gettime (CLOCK_MONOTONIC , ts); +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC , ts)) +return 0 ; +error: +igt_warn ("Could not read monotonic time: %s\n" , +strerror (errno)); + +return -errno; }bool __igt_fixture (void )
@@ -831,15 +867,11 @@ static void exit_subtest(const char *) __attribute__((noreturn));static void exit_subtest (const char *result) {struct timespec now; -double elapsed;gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; -printf ("%sSubtest %s: %s (%.3fs)%s\n" , (!__igt_plain_output) ?"\x1b[1m" :"" , - in_subtest, result, elapsed, + in_subtest, result,time_elapsed (&subtest_time, &now), (!__igt_plain_output) ?"\x1b[0m" :"" );fflush (stdout);
@@ -1088,12 +1120,9 @@ void igt_exit(void)if (!test_with_subtests) {struct timespec now; -double elapsed;const char *result;gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ;switch (igt_exitcode) {case IGT_EXIT_SUCCESS :
@@ -1109,8 +1138,7 @@ void igt_exit(void) result ="FAIL" ; } - -printf ("%s (%.3fs)\n" , result, elapsed); +printf ("%s (%.3fs)\n" , result,time_elapsed (&subtest_time, &now));exit (igt_exitcode); }
Signature · 6 lines
2.4.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
This could be merged?
Quoted 142 lines · Joonas Lahtinen
CLOCK_MONOTONIC_RAWis not affected by NTP, so it should be THE clock used for timing execution of tests.When fetching either the starting or ending time of a test, show the time as -1.000s.
v6:
- Whitespace corrections (Chris)v5:
- Do not use C99 style comments (Chris)v4:
- Introducetime_validmacro (Chris)
- Reduce amount of boilerplate code for calculating elapsed timev3:
- Do not exit directly from handler (Chris)
- Show elapsed time as -1 if it is not calculablev2:
- Cache the used clock (Chris)
- Do not change the clock during execution
- Spit out and error if monotonic time can not be readCc Thomas Wood <[email protected]>Reviewed-by Chris Wilson <[email protected]>Signed-off-by Joonas Lahtinen <[email protected]>--- lib/igt_core.c | 54 +++++++++++++++++++++++++++++++++++++++++------- ------ 1 file changed, 41 insertions(+), 13 deletions(-)lib/igt_core.c +40
-8@@ -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;@@ -337,14 +338,49 @@ static void kmsg(const char *format, ...)fclose (file); } -static void gettime (struct timespec *ts) +#define time_valid (ts) ((ts)->tv_sec || (ts)->tv_nsec) + +static double +time_elapsed (struct timespec *then, +struct timespec * now) +{ +double elapsed =-1. ; + +if (time_valid (then) &&time_valid (now)) { + elapsed = now->tv_sec - then->tv_sec; + elapsed += (now->tv_nsec - then->tv_nsec) *1e-9 ; + } + +return elapsed; +} + +static int gettime (struct timespec *ts) {memset (ts,0 ,sizeof (*ts)); + errno =0 ; +/* Stay on the same clock for consistency. */ +if (igt_clock != (clockid_t)-1 ) { +if (clock_gettime (igt_clock, ts)) + goto error; +return 0 ; + } + +#ifdef CLOCK_MONOTONIC_RAW +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC_RAW , ts)) +return 0 ; +#endif #ifdef CLOCK_MONOTONIC_COARSE - if (clock_gettime(CLOCK_MONOTONIC_COARSE, ts)) +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC_COARSE , ts)) +return 0 ;#endif -clock_gettime (CLOCK_MONOTONIC , ts); +if (!clock_gettime (igt_clock =CLOCK_MONOTONIC , ts)) +return 0 ; +error: +igt_warn ("Could not read monotonic time: %s\n" , +strerror (errno)); + +return -errno; }bool __igt_fixture (void )@@ -831,15 +867,11 @@ static void exit_subtest(const char *) __attribute__((noreturn));static void exit_subtest (const char *result) {struct timespec now; -double elapsed;gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e-9 ; -printf ("%sSubtest %s: %s (%.3fs)%s\n" , (!__igt_plain_output) ?"\x1b[1m" :"" , - in_subtest, result, elapsed, + in_subtest, result,time_elapsed (&subtest_time, &now), (!__igt_plain_output) ?"\x1b[0m" :"" );lib/igt_core.c +1
-6fflush (stdout);@@ -1088,12 +1120,9 @@ void igt_exit(void)if (!test_with_subtests) {struct timespec now; -double elapsed;const char *result;gettime (&now); - elapsed = now.tv_sec - subtest_time.tv_sec; - elapsed += (now.tv_nsec - subtest_time.tv_nsec) *1e -9;switch (igt_exitcode) {case IGT_EXIT_SUCCESS :@@ -1109,8 +1138,7 @@ void igt_exit(void) result ="FAIL" ; } - -printf ("%s (%.3fs)\n" , result, elapsed); +printf ("%s (%.3fs)\n" , result,time_elapsed (&subtest_time, &now));exit (igt_exitcode); }
Signature · 8 lines
Joonas Lahtinen Open Source Technology Center Intel Corporation _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx