[Gmp-commit] /home/hgfiles/gmp: Added rudimentary sanity check for clock_gett...

mercurial at gmplib.org mercurial at gmplib.org
Tue Feb 16 14:02:44 CET 2010


details:   /home/hgfiles/gmp/rev/188906a110ff
changeset: 13430:188906a110ff
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Tue Feb 16 14:02:38 2010 +0100
description:
Added rudimentary sanity check for clock_gettime working.

diffstat:

 ChangeLog   |   5 +++++
 tune/time.c |  40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)

diffs (69 lines):

diff -r ba631dd1c9b4 -r 188906a110ff ChangeLog
--- a/ChangeLog	Mon Feb 15 11:47:21 2010 +0100
+++ b/ChangeLog	Tue Feb 16 14:02:38 2010 +0100
@@ -1,3 +1,8 @@
+2010-02-16  Niels Möller  <nisse at lysator.liu.se>
+
+	* tune/time.c (cgt_works_p): Added rudimentary sanity check for
+	clock_gettime working.
+
 2010-02-15  Niels Möller  <nisse at lysator.liu.se>
 
 	* tune/time.c (speed_time_init): Make use of cycle counter
diff -r ba631dd1c9b4 -r 188906a110ff tune/time.c
--- a/tune/time.c	Mon Feb 15 11:47:21 2010 +0100
+++ b/tune/time.c	Tue Feb 16 14:02:38 2010 +0100
@@ -722,6 +722,8 @@
 # define CGT_ID       (ASSERT_FAIL (CGT_ID not determined), -1)
 #endif
 
+#define CGT_DELAY_COUNT 1000
+
 int
 cgt_works_p (void)
 {
@@ -763,6 +765,44 @@
   cgt_unittime = unit.tv_sec + unit.tv_nsec * 1e-9;
   printf ("clock_gettime is %s accurate\n",
 	  unittime_string (cgt_unittime));
+
+  if (cgt_unittime < 10e-9)
+    {
+      /* Do we believe this? */
+      struct timespec start, end;
+      static volatile int counter;
+      double duration;
+      if (clock_gettime (CGT_ID, &start))
+	{
+	  if (speed_option_verbose)
+	    printf ("clock_gettime id=%d error: %s\n", CGT_ID, strerror (errno));
+	  result = 0;
+	  return result;
+	}
+      /* Loop of at least 1000 memory accesses, ought to take at
+	 least 100 ns*/
+      for (counter = 0; counter < CGT_DELAY_COUNT; counter++)
+	;
+      if (clock_gettime (CGT_ID, &end))
+	{
+	  if (speed_option_verbose)
+	    printf ("clock_gettime id=%d error: %s\n", CGT_ID, strerror (errno));
+	  result = 0;
+	  return result;
+	}
+      duration = (end.tv_sec + end.tv_nsec * 1e-9
+		  - start.tv_sec - start.tv_nsec * 1e-9);
+      if (speed_option_verbose)
+	printf ("delay loop of %d rounds took %s (according to clock_get_time)\n",
+		CGT_DELAY_COUNT, unittime_string (duration));
+      if (duration < 100e-9)
+	{
+	  if (speed_option_verbose)
+	    printf ("clock_gettime id=%d not believable\n", CGT_ID);
+	  result = 0;
+	  return result;
+	}
+    }
   result = 1;
   return result;
 }


More information about the gmp-commit mailing list