From: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
To: Thomas Wood <thomas.wood@intel.com>
Cc: Intel graphics driver community testing & development
<intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH i-g-t v6] lib/igt_core: Prefer CLOCK_MONOTONIC_RAW
Date: Mon, 23 Nov 2015 14:52:37 +0200 [thread overview]
Message-ID: <1448283157.4993.3.camel@linux.intel.com> (raw)
In-Reply-To: <1448020631-9763-1-git-send-email-joonas.lahtinen@linux.intel.com>
This could be merged?
On pe, 2015-11-20 at 13:57 +0200, Joonas Lahtinen wrote:
> 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
>
> Cc: Thomas Wood <thomas.wood@intel.com>
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> ---
> lib/igt_core.c | 54 +++++++++++++++++++++++++++++++++++++++++-------
> ------
> 1 file changed, 41 insertions(+), 13 deletions(-)
>
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index 04a0ab2..84cf8d2 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;
> @@ -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);
> }
>
--
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
prev parent reply other threads:[~2015-11-23 12:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-17 10:24 [PATCH i-g-t] lib/igt_core: Prefer CLOCK_MONOTONIC_RAW Joonas Lahtinen
2015-11-17 10:40 ` Chris Wilson
2015-11-17 12:18 ` [PATCH i-g-t v2] " Joonas Lahtinen
2015-11-17 14:02 ` Chris Wilson
2015-11-18 12:18 ` [PATCH i-g-t v3] " Joonas Lahtinen
2015-11-18 12:28 ` Chris Wilson
2015-11-18 12:54 ` Joonas Lahtinen
2015-11-18 13:07 ` Chris Wilson
2015-11-19 11:00 ` [PATCH i-g-t v4] " Joonas Lahtinen
2015-11-19 11:43 ` Chris Wilson
2015-11-20 11:26 ` [PATCH i-g-t v5] " Joonas Lahtinen
2015-11-20 11:38 ` Chris Wilson
2015-11-20 11:57 ` [PATCH i-g-t v6] " Joonas Lahtinen
2015-11-23 12:52 ` Joonas Lahtinen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448283157.4993.3.camel@linux.intel.com \
--to=joonas.lahtinen@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=thomas.wood@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.