This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] PR 53456 Improve time resolution on targets without gettimeofday


Hi,

some targets such as VXWorks don't provide gettimeofday but do provide
clock_gettime. The attached patch allows such targets to get better
resolution for the DATE_AND_TIME (up to the 1 millisecond limit of the
API) intrinsic than the 1 second resolution provided by the current
fallback of using the C standard time().

(SYSTEM_CLOCK already uses clock_gettime if available and thus
nanosecond resultion has been available to vxworks also before this
patch.)

Ok for trunk? (Patch both inline below and as an attachment)

2012-05-23  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/53456
	* intrinsics/time_1.h (gf_gettime): Fallback for clock_gettime.


diff --git a/libgfortran/intrinsics/time_1.h b/libgfortran/intrinsics/time_1.h
index aaca56a..ca5b26b 100644
--- a/libgfortran/intrinsics/time_1.h
+++ b/libgfortran/intrinsics/time_1.h
@@ -181,8 +181,8 @@ gf_cputime (long *user_sec, long *user_usec, long
*system_sec, long *system_usec
 #endif


-/* Realtime clock with microsecond resolution, falling back to less
-   precise functions if the target does not support gettimeofday().
+/* Realtime clock with microsecond resolution, falling back to other
+   functions if the target does not support gettimeofday().

    Arguments:
    secs     - OUTPUT, seconds
@@ -204,6 +204,12 @@ gf_gettime (time_t * secs, long * usecs)
   *secs = tv.tv_sec;
   *usecs = tv.tv_usec;
   return err;
+#elif defined(HAVE_CLOCK_GETTIME)
+  struct timespec ts;
+  int err = clock_gettime (CLOCK_REALTIME, &ts);
+  *secs = ts.tv_sec;
+  *usecs = ts.tv_nsec / 1000;
+  return err;
 #else
   time_t t = time (NULL);
   *secs = t;


-- 
Janne Blomqvist

Attachment: vxtime.diff
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]