Use clock_gettime to implement gettimeofday

System Internals / glibc - Adhemerval Zanella [] - 30 October 2019 20:11 UTC

Consolidate generic gettimeofday implementation to use clock_gettime. Linux ports that still provide gettimeofday through vDSO are not changed.

Remove sysdeps/unix/clock_gettime.c, which implemented clock_gettime using gettimeofday; new OS ports must provide a real implementation of clock_gettime.

Rename sysdeps/mach/gettimeofday.c to sysdeps/mach/clock_gettime.c and convert into an implementation of clock_gettime. It only supports CLOCK_REALTIME; Mach does not appear to have any support for monotonic clocks. It uses __host_get_time, which provides at best microsecond resolution. Hurd is currently using sysdeps/posix/clock_getres.c for clock_getres; its output for CLOCK_REALTIME is based on sysconf (_SC_CLK_TCK), and I do not know whether that gives the correct result.

Unlike settimeofday, there are no known uses of gettimeofday's
vestigial "get time zone" feature that are not bugs. (The per-process timezone support in localtime and friends is unrelated, and the programs that set the kernel's offset between the hardware clock and UTC do not need to read it back.) Therefore, this feature is dummied out. Henceforth, if gettimeofday's "struct timezone" argument is not NULL, it will write zeroes to both fields. Any program that is actually looking at this data will thus think it is running in UTC, which is probably more correct than whatever it was doing before.

[__]gettimeofday no longer has any internal callers, so we can now remove its internal prototype and PLT bypass aliases. The __gettimeofday@GLIBC_2.0 export remains, in case it is used by any third-party code.

It also allows to simplify the arch-specific implementation on x86 and powerpc to remove the hack to disable the internal route to non iFUNC
variant for internal symbol.

This patch also fixes a missing optimization on aarch64, powerpc, and x86 where the code used on static build do not use the vDSO.

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu, powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu.

5e46749c64 Use clock_gettime to implement gettimeofday.
NEWS | 13 ++++
include/sys/time.h | 2 -
sysdeps/{unix => mach}/clock_gettime.c | 37 +++++-------
sysdeps/mach/gettimeofday.c | 43 --------------
sysdeps/posix/gettimeofday.c | 67 ---------------------
sysdeps/unix/syscalls.list | 1 -
sysdeps/unix/sysv/linux/aarch64/gettimeofday.c | 34 +++++------
.../unix/sysv/linux/{i386 => alpha}/gettimeofday.c | 25 ++------
sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c | 11 +++-
sysdeps/unix/sysv/linux/alpha/tv32-compat.h | 6 ++
sysdeps/unix/sysv/linux/gettimeofday.c | 49 ---------------
sysdeps/unix/sysv/linux/powerpc/gettimeofday.c | 69 ++++++----------------
sysdeps/unix/sysv/linux/x86/gettimeofday.c | 43 ++++++--------
sysdeps/unix/sysv/linux/x86_64/x32/gettimeofday.c | 1 +
sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list | 1 -
time/gettimeofday.c | 32 ++++++----
16 files changed, 125 insertions(+), 309 deletions(-)


  • Share