[PATCH v2 04/13] tools/nolibc/time: drop invocation of gettimeofday system call

Thomas Weißschuh posted 13 patches 1 week, 2 days ago
[PATCH v2 04/13] tools/nolibc/time: drop invocation of gettimeofday system call
Posted by Thomas Weißschuh 1 week, 2 days ago
This invocation uses libc types with a system call. While this works
now, upcoming changes to 'struct timeval' would require type
conversions. If types are converted anyways, the clock_gettime() based
fallback can be used everywhere, simplifying the code.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/sys/time.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/tools/include/nolibc/sys/time.h b/tools/include/nolibc/sys/time.h
index 33782a19aae9..171187836e6d 100644
--- a/tools/include/nolibc/sys/time.h
+++ b/tools/include/nolibc/sys/time.h
@@ -22,9 +22,6 @@ static int sys_clock_gettime(clockid_t clockid, struct timespec *tp);
 static __attribute__((unused))
 int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
 {
-#ifdef __NR_gettimeofday
-	return my_syscall2(__NR_gettimeofday, tv, tz);
-#else
 	(void) tz; /* Non-NULL tz is undefined behaviour */
 
 	struct timespec tp;
@@ -37,7 +34,6 @@ int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
 	}
 
 	return ret;
-#endif
 }
 
 static __attribute__((unused))

-- 
2.52.0

Re: [PATCH v2 04/13] tools/nolibc/time: drop invocation of gettimeofday system call
Posted by Willy Tarreau 1 day, 14 hours ago
On Sat, Nov 22, 2025 at 05:59:10PM +0100, Thomas Weißschuh wrote:
> This invocation uses libc types with a system call. While this works
> now, upcoming changes to 'struct timeval' would require type
> conversions. If types are converted anyways, the clock_gettime() based
> fallback can be used everywhere, simplifying the code.

I must confess I'm not happy to see the simple, lightweight and efficient
gettimeofday() quit, with the alternative being a bit bigger, but after
enough testing, aside the code size increase I cannot spot any problem.

> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Acked-by: Willy Tarreau <w@1wt.eu>

Willy