public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] open_posix/conformance/clock/1.1: Deterministic timing
@ 2019-09-25  9:29 Joerg Vehlow
  2019-09-26 12:25 ` Cyril Hrubis
  0 siblings, 1 reply; 4+ messages in thread
From: Joerg Vehlow @ 2019-09-25  9:29 UTC (permalink / raw)
  To: ltp

From: Joerg Vehlow <joerg.vehlow@aox-tech.de>

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();
 	}
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH] open_posix/conformance/clock/1.1: Deterministic timing
  2019-09-25  9:29 [LTP] [PATCH] open_posix/conformance/clock/1.1: Deterministic timing Joerg Vehlow
@ 2019-09-26 12:25 ` Cyril Hrubis
  2019-09-26 12:37   ` Joerg Vehlow
  0 siblings, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2019-09-26 12:25 UTC (permalink / raw)
  To: ltp

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH] open_posix/conformance/clock/1.1: Deterministic timing
  2019-09-26 12:25 ` Cyril Hrubis
@ 2019-09-26 12:37   ` Joerg Vehlow
  2019-10-03 13:49     ` Cyril Hrubis
  0 siblings, 1 reply; 4+ messages in thread
From: Joerg Vehlow @ 2019-09-26 12:37 UTC (permalink / raw)
  To: ltp


Am 26.09.2019 um 14:25 schrieb Cyril Hrubis:
> 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...
I was actually thinking the same, but decided to use time() because of 
a) it doesn't matter much as long as some time passes by and b) 
monotonic clocks are an optional feature in posix.
>>   
>> -- 
>> 2.20.1
>>
>>
>> -- 
>> Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH] open_posix/conformance/clock/1.1: Deterministic timing
  2019-09-26 12:37   ` Joerg Vehlow
@ 2019-10-03 13:49     ` Cyril Hrubis
  0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2019-10-03 13:49 UTC (permalink / raw)
  To: ltp

Hi!
> I was actually thinking the same, but decided to use time() because of 
> a) it doesn't matter much as long as some time passes by and b) 
> monotonic clocks are an optional feature in posix.

Fair enough, applied, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-03 13:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-25  9:29 [LTP] [PATCH] open_posix/conformance/clock/1.1: Deterministic timing Joerg Vehlow
2019-09-26 12:25 ` Cyril Hrubis
2019-09-26 12:37   ` Joerg Vehlow
2019-10-03 13:49     ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox