https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98507
Janne Blomqvist <jb at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jb at gcc dot gnu.org --- Comment #5 from Janne Blomqvist <jb at gcc dot gnu.org> --- (In reply to anlauf from comment #1) > Not a confirmation, just an observation: libgfortran/intrinsics/time_1.h > prefers gettimeofday over clock_gettime, whereas the Linux manpages have: > > GETTIMEOFDAY(2) Linux Programmer's Manual > GETTIMEOFDAY(2) > > CONFORMING TO > SVr4, 4.3BSD. POSIX.1-2001 describes gettimeofday() but not > settimeofday(). > POSIX.1-2008 marks gettimeofday() as obsolete, recommending the use > of clock_get- > time(2) instead. > > > Janne chose this prioritization in 2012, but there is no comment explaining > his choice. Should this be revisited? Usage of gettimeofday() was, and still is, ubiquitous. In find it hard to imagine any C library would remove it just because POSIX has deprecated it, unless they want a significant fraction of applications to stop working. That being said, my main motivation for preferring gettimeofday() was that back then clock_gettime was not found in the glibc libc.so but rather in librt (which is part of glibc, but not linked by default for single-threaded programs). See the weakref trickery in intrinsics/system_clock.c for how using clock_gettime on glibc < 2.17 was done, where there was a real motivation for using clock_gettime, namely to access the monotonic clock. So preferring gettimeofday() in time_1.h:gf_gettime() meant that as many targets as possible used the same code path as glibc targets, reducing the risk of target-specific bugs that I would have difficulty deciphering considering I was developing on Linux myself. However, this is all water under the bridge by now, as clock_gettime is part of glibc libc.so since glibc 2.17. So I think switching the order now in 2021 is perfectly fine. As an additional datapoint, per https://man7.org/linux/man-pages/man7/vdso.7.html all Linux targets that provide gettimeofday() as a VDSO also provide clock_gettime() as a VDSO, so no concerns there either. As a minor nit, now that clock_gettime() is the "main" implementation for gf_gettime() you might want to change it to return nanoseconds rather than microseconds, and update the callers.