public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] open_posix/conformance/clock/1.1: Deterministic timing
Date: Thu, 26 Sep 2019 14:25:46 +0200	[thread overview]
Message-ID: <20190926122546.GA27993@rei> (raw)
In-Reply-To: <20190925092958.125325-1-lkml@jv-coder.de>

Hi!
> On some systems the loop with 8 million iterations takes a very long time.
> This patches changes it to busy loop for five seconds.
> 
> Signed-off-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
> ---
>  .../conformance/interfaces/clock/1-1.c                 | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c
> index 9c48cd979..cce5beea9 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c
> @@ -17,20 +17,22 @@
>  #include <time.h>
>  #include <stdio.h>
>  #include <unistd.h>
> +#include <time.h>
>  #include "posixtest.h"
>  
> -#define LARGENUMBER 8000000
> +#define BUSY_LOOP_SECONDS 5
>  int main(void)
>  {
>  	clock_t c1, c2;
>  	double sec1, sec2;
> -	int i;
> +	time_t end;
>  
>  	c1 = clock();
>  	sec1 = c1 / CLOCKS_PER_SEC;
>  
> -	for (i = 0; i < LARGENUMBER; i++) {
> -		// keep busy so CPU time increases
> +	end = time(NULL) + BUSY_LOOP_SECONDS;
> +
> +	while (end >= time(NULL)) {
>  		clock();
>  	}

clock_gettime() with CLOCK_MONOTONIC would be better fit there, since
the wall clock can be changed by ntp and generally is not guaranteed to
be monotonic...

>  
> -- 
> 2.20.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2019-09-26 12:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25  9:29 [LTP] [PATCH] open_posix/conformance/clock/1.1: Deterministic timing Joerg Vehlow
2019-09-26 12:25 ` Cyril Hrubis [this message]
2019-09-26 12:37   ` Joerg Vehlow
2019-10-03 13:49     ` Cyril Hrubis

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=20190926122546.GA27993@rei \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox