summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/gettimeofday.c
diff options
context:
space:
mode:
authorDmitry Chestnykh <dm.chestnykh@gmail.com>2024-04-15 15:31:58 +0300
committerWaldemar Brodkorb <wbx@openadk.org>2024-04-18 14:52:06 +0200
commit3a36a3100af2ee1cca69345af83228757e8c55fe (patch)
tree6ec6990dba241b65a925eb581ef59bcb3a74e843 /libc/sysdeps/linux/common/gettimeofday.c
parent0694e42c9c9789bd87fba7e6639b21d2f28e09d4 (diff)
Fix vDSO support for all supported architectures.
- Cleanup dl-vdso.c code. - Pass `void *` as first arg to `load_vdso()`, using 32-bit type is completely wrong on 64bit architectures. - Split libc code and vDSO-related code. Move arch-specific implementations into separate files. The performance improvement is for example 50-60 times on ARMv7 and about 4 times on x86_64. Signed-off-by: Dmitry Chestnykh <dm.chestnykh@gmail.com>
Diffstat (limited to 'libc/sysdeps/linux/common/gettimeofday.c')
-rwxr-xr-xlibc/sysdeps/linux/common/gettimeofday.c34
1 files changed, 11 insertions, 23 deletions
diff --git a/libc/sysdeps/linux/common/gettimeofday.c b/libc/sysdeps/linux/common/gettimeofday.c
index ed18b2be5..9b29fe5a0 100755
--- a/libc/sysdeps/linux/common/gettimeofday.c
+++ b/libc/sysdeps/linux/common/gettimeofday.c
@@ -14,30 +14,18 @@
#include "ldso.h"
#endif
-#ifdef __VDSO_SUPPORT__
-typedef int (*gettimeofday_func)(struct timeval * tv, __timezone_ptr_t tz);
-#endif
-
int gettimeofday(struct timeval * tv, __timezone_ptr_t tz) {
-
- #ifdef __VDSO_SUPPORT__
- if ( _dl__vdso_gettimeofday != 0 ){
- gettimeofday_func func= _dl__vdso_gettimeofday;
- return func( tv, tz );
-
- }else{
- _syscall2_body(int, gettimeofday, struct timeval *, tv, __timezone_ptr_t, tz)
- }
- #else
- if (!tv)
- return 0;
-
- struct timespec __ts;
- int __ret = clock_gettime(CLOCK_REALTIME, &__ts);
- tv->tv_sec = __ts.tv_sec;
- tv->tv_usec = (suseconds_t)__ts.tv_nsec / 1000;
- return __ret;
- #endif
+ if (!tv)
+ return 0;
+#if defined(__VDSO_SUPPORT__) && defined(ARCH_VDSO_GETTIMEOFDAY)
+ return ARCH_VDSO_GETTIMEOFDAY(tv, tz);
+#else
+ struct timespec __ts;
+ int __ret = clock_gettime(CLOCK_REALTIME, &__ts);
+ tv->tv_sec = __ts.tv_sec;
+ tv->tv_usec = (suseconds_t)__ts.tv_nsec / 1000;
+ return __ret;
+#endif
}