All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] sigtimedwait: use gtod instead of time
@ 2015-05-14 14:58 Jan Stancek
  2015-05-18  7:53 ` Cyril Hrubis
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Stancek @ 2015-05-14 14:58 UTC (permalink / raw)
  To: ltp-list

Quoting https://lkml.org/lkml/2015/2/19/384
  "The idea that time() would be ok as being HZ granular, and its
  been this way since 2.6.23.  Thus you have a < HZ sized window
  where gettimeofday() will return the next second before time()
  gets updated by the tick."

Use gettimeofday() rather than time() and also relax the error margin,
since man page says, that there may be small overrun.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 .../conformance/interfaces/sigtimedwait/1-1.c      | 24 ++++++++++++++--------
 .../conformance/interfaces/sigtimedwait/2-1.c      | 19 +++++++++++------
 2 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigtimedwait/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sigtimedwait/1-1.c
index 15f32a8..189644c 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigtimedwait/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigtimedwait/1-1.c
@@ -35,13 +35,14 @@
 #define SIGTOTEST SIGUSR2
 #define TIMERSEC 2
 #define SIGTIMEDWAITSEC 1
-#define ERRORMARGIN 0.01
+#define ERRORMARGIN 0.1
 
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
+#include <sys/time.h>
 #include <sys/wait.h>
 #include "posixtest.h"
 
@@ -57,7 +58,7 @@ int main(void)
 {
 	struct sigaction act;
 
-	time_t time1, time2;
+	struct timeval time1, time2;
 	double time_elapsed;
 
 	sigset_t selectset;
@@ -96,21 +97,28 @@ int main(void)
                 return PTS_UNRESOLVED;
         }
 */
-	time1 = time(NULL);
+	if (gettimeofday(&time1, NULL) == -1) {
+		perror("gettimeofday()");
+		return PTS_UNRESOLVED;
+	}
 	if (sigtimedwait(&selectset, NULL, &ts) != -1) {
 		perror
 		    ("sigtimedwait() did not return -1 even though signal was not pending\n");
 		return PTS_UNRESOLVED;
 	}
+	if (gettimeofday(&time2, NULL) == -1) {
+		perror("gettimeofday()");
+		return PTS_UNRESOLVED;
+	}
 
-	time2 = time(NULL);
-
-	time_elapsed = difftime(time2, time1);
+	time_elapsed = (time2.tv_sec - time1.tv_sec
+		+ (time2.tv_usec - time1.tv_usec) / 1000000.0);
 
 	if ((time_elapsed > SIGTIMEDWAITSEC + ERRORMARGIN)
 	    || (time_elapsed < SIGTIMEDWAITSEC - ERRORMARGIN)) {
-		printf
-		    ("Test FAILED: sigtimedwait() did not return in the required time\n");
+		printf("Test FAILED: sigtimedwait() did not return in "
+			"the required time\n");
+		printf("time_elapsed: %lf\n", time_elapsed);
 		return PTS_FAIL;
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigtimedwait/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sigtimedwait/2-1.c
index a0fcaca..c5ac7db 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigtimedwait/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigtimedwait/2-1.c
@@ -36,13 +36,14 @@
 #define SIGTOTEST SIGUSR2
 #define TIMERSEC 2
 #define SIGTIMEDWAITSEC 0
-#define ERRORMARGIN 0.01
+#define ERRORMARGIN 0.1
 
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
+#include <sys/time.h>
 #include <sys/wait.h>
 #include "posixtest.h"
 
@@ -58,7 +59,7 @@ int main(void)
 {
 	struct sigaction act;
 
-	time_t time1, time2;
+	struct timeval time1, time2;
 	double time_elapsed;
 
 	sigset_t selectset;
@@ -97,16 +98,22 @@ int main(void)
                 return PTS_UNRESOLVED;
         }
 */
-	time1 = time(NULL);
+	if (gettimeofday(&time1, NULL) == -1) {
+		perror("gettimeofday()");
+		return PTS_UNRESOLVED;
+	}
 	if (sigtimedwait(&selectset, NULL, &ts) != -1) {
 		printf
 		    ("Test FAILED: sigtimedwait() did not return with an error\n");
 		return PTS_FAIL;
 	}
+	if (gettimeofday(&time2, NULL) == -1) {
+		perror("gettimeofday()");
+		return PTS_UNRESOLVED;
+	}
 
-	time2 = time(NULL);
-
-	time_elapsed = difftime(time2, time1);
+	time_elapsed = (time2.tv_sec - time1.tv_sec
+		+ (time2.tv_usec - time1.tv_usec) / 1000000.0);
 
 	if ((time_elapsed > SIGTIMEDWAITSEC + ERRORMARGIN)
 	    || (time_elapsed < SIGTIMEDWAITSEC - ERRORMARGIN)) {
-- 
1.8.3.1


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] sigtimedwait: use gtod instead of time
  2015-05-14 14:58 [LTP] [PATCH] sigtimedwait: use gtod instead of time Jan Stancek
@ 2015-05-18  7:53 ` Cyril Hrubis
  0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2015-05-18  7:53 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

Hi!
> Quoting https://lkml.org/lkml/2015/2/19/384
>   "The idea that time() would be ok as being HZ granular, and its
>   been this way since 2.6.23.  Thus you have a < HZ sized window
>   where gettimeofday() will return the next second before time()
>   gets updated by the tick."

Looks good.

Using clock_gettime() with monotonic clock would be even better but for
that we would have to create an abstract time measuring interface that
falls back to gettimeofday() if timers could not be used...

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2015-05-18  7:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-14 14:58 [LTP] [PATCH] sigtimedwait: use gtod instead of time Jan Stancek
2015-05-18  7:53 ` Cyril Hrubis

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.