Skip to contentSkip to conversation

open_posix/conformance/clock/1.1: Deterministic timing

PATCH New Joerg Vehlow 2 participants 4 messages Sep 25, 2019 – Oct 3, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 open_posix/conformance/clock/1.1: Deterministic timing

From: Joerg Vehlow <[email protected]>

On some systems the loop with 8 million iterations takes a very long time. This patches changes it to busy loop for five seconds.

---
 .../conformance/interfaces/clock/1-1.c                 | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c +6 -4
index 9c48cd979..cce5beea9 100644
@@ -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();
 	}
 
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 open_posix/conformance/clock/1.1: Deterministic timing

Hi!

Quoted 28 lines

On some systems the loop with 8 million iterations takes a very long time. This patches changes it to busy loop for five seconds.

---
 .../conformance/interfaces/clock/1-1.c                 | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c +3 -2
index 9c48cd979..cce5beea9 100644
@@ -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;
 

testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c line 37

Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c +3 -2
 	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...

Quoted 7 lines
Signature · 6 lines
-- 
2.20.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 open_posix/conformance/clock/1.1: Deterministic timing

Am 26.09.2019 um 14:25 schrieb Cyril Hrubis:

Quoted 32 lines

Hi!

Quoted 31 lines

On some systems the loop with 8 million iterations takes a very long time. This patches changes it to busy loop for five seconds.

---
  .../conformance/interfaces/clock/1-1.c                 | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c +3 -2
index 9c48cd979..cce5beea9 100644
@@ -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;
 
Quoted 10 lines

testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c line 37

Quoted 7 lines
testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c +3 -2
-	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.

Quoted 7 lines
Quoted 7 lines
Signature · 6 lines
-- 
2.20.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH 1/1 open_posix/conformance/clock/1.1: Deterministic timing

Hi!

Quoted 3 lines

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.

Signature · 2 lines
Cyril Hrubis
[email protected]