]> Savannah Git Hosting - gnulib.git/commitdiff
gettime-res: Fix test failure on Solaris 11.4/SPARC.
authorBruno Haible <bruno@clisp.org>
Tue, 26 Mar 2024 11:12:23 +0000 (12:12 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 26 Mar 2024 11:12:23 +0000 (12:12 +0100)
* lib/gettime-res.c (gettime_res): On Solaris/SPARC, just return 1 ns.

ChangeLog
lib/gettime-res.c

index 73379f0c1bdfa58859b7650c1d3d5e365be4665d..94fc26fb449fb7459a709d9964c0c9bea1031dd4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-03-26  Bruno Haible  <bruno@clisp.org>
+
+       gettime-res: Fix test failure on Solaris 11.4/SPARC.
+       * lib/gettime-res.c (gettime_res): On Solaris/SPARC, just return 1 ns.
+
 2024-03-25  Bruno Haible  <bruno@clisp.org>
 
        jit/cache: Fix a compilation error on Solaris 11.4/SPARC.
index afc828a5fb8ae5bfd69cecccabfd305dfe858d82..8bde4122a78297dc1fa88d33e84f805dea9e0925 100644 (file)
@@ -38,16 +38,28 @@ gcd (long int a, long int b)
 long int
 gettime_res (void)
 {
+#if defined __sun && defined __sparc
+  /* On Solaris 11.4/SPARC (with a SPARC-M8 CPU)
+     clock_getres (CLOCK_REALTIME, ...) returns a resolution of 1000000 ns,
+     and clock_gettime (CLOCK_REALTIME) returns a multiple of 5 ns with a
+     probability of ca. 1 - 1/300000.  Thus the heuristic below with the
+     32 samples guesses a resolution of 5 ns with a probability of ca.
+     1 - 1/10000.  But occasionally clock_gettime (CLOCK_REALTIME) returns
+     only a multiple of 1 ns.
+     Simple guesswork is not enough to cope with this irregular behaviour.
+     Therefore, here is an override.  */
+  return 1;
+#else
   struct timespec res;
-#if defined CLOCK_REALTIME && HAVE_CLOCK_GETRES
+# if defined CLOCK_REALTIME && HAVE_CLOCK_GETRES
   clock_getres (CLOCK_REALTIME, &res);
-#elif defined HAVE_TIMESPEC_GETRES
+# elif defined HAVE_TIMESPEC_GETRES
   timespec_getres (&res, TIME_UTC);
-#else
+# else
   /* Guess high and let the later code deduce better.  */
   res.tv_sec = 1;
   res.tv_nsec = 0;
-#endif
+# endif
 
   /* On all Gnulib platforms the following calculations do not overflow.  */
 
@@ -83,6 +95,7 @@ gettime_res (void)
     }
 
   return r;
+#endif
 }
 
 /*