From: Willy Tarreau <w@1wt.eu>
To: Arnd Bergmann <arnd@arndb.de>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
shuah <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2 09/13] tools/nolibc: always use 64-bit time types
Date: Mon, 1 Dec 2025 11:35:05 +0100 [thread overview]
Message-ID: <20251201103505.GA23859@1wt.eu> (raw)
In-Reply-To: <75e632e3-3353-414d-9b8a-8bf9ca46b5a4@app.fastmail.com>
Hi Arnd,
On Mon, Dec 01, 2025 at 08:45:00AM +0100, Arnd Bergmann wrote:
> On Sun, Nov 30, 2025, at 11:58, Willy Tarreau wrote:
> > On Sat, Nov 22, 2025 at 05:59:15PM +0100, Thomas Weißschuh wrote:
>
> >> struct timespec {
> >> - __kernel_old_time_t tv_sec;
> >> - long tv_nsec;
> >> + time_t tv_sec;
> >> + int64_t tv_nsec;
> >> };
> >> #define _STRUCT_TIMESPEC
> >>
> >> +/* Never use with system calls */
> >> struct timeval {
> >> - __kernel_old_time_t tv_sec;
> >> - __kernel_suseconds_t tv_usec;
> >> + time_t tv_sec;
> >> + int64_t tv_usec;
> >> };
> >
> > It seems to me that glibc continues to make the effort of using a long
> > for tv_usec and tv_nsec. At least I'm seeing how that can make a
> > difference for application code given that these fields are constantly
> > multiplied or divided, forcing them to 64-bit when we know they'll never
> > be larger than 1 billion is extra burden for the application. Another
> > reason might be that the definition really changed from long to suseconds_t
> > in timeval a while ago, it's possible that it's used as a long in various
> > APIs (or even just printf formats).
> >
> > IMHO it would be cleaner to keep it as a long here, or do you have a
> > particular reason for wanting int64_t (which BTW already forced a cast
> > in sys_gettimeofday()) ?
>
> As far as I can tell, it's the other way round for suseconds_t,
> which in glibc is defined as
>
> #if __TIMESIZE == 64 && __WORDSIZE == 32
> # define __TIME_T_TYPE __SQUAD_TYPE
> # define __SUSECONDS_T_TYPE __SQUAD_TYPE
> #else
> # define __TIME_T_TYPE __SLONGWORD_TYPE
> # define __SUSECONDS_T_TYPE __SLONGWORD_TYPE
> #endif
>
> so this one is explicitly the same width as tv_sec, which has all
> the issues you listed, but avoids the need for padding.
Ah we seem to just have checked different versions then,
as in mine there was still some extra padding left depending
on the endianness :-)
> As far as I remember, the one reason for having a 'long tv_nsec'
> with complex padding in glibc and musl is that this is actually
> required by both Unix[1] and C11/C11 [2] standards.
That's what I found as well and was my initial compatibility
concern (e.g. referencing &tv->tv_nsec as a long).
> C23 has updated the definition and does allow int64_t tv_nsec.
So it purposely breaks existing apps or does it apply only to those
compiled with -mstd=c23 ?
> I think it makes sense for nolibc to just follow the kernel's
> definition here.
Given the very narrow range of existing code that can be impacted,
I'm fine, but in general I try to remain extremely cautious about
portability: as a general rule, ifdefs needed to address possible
incompatibilities, if any, should rather be in the libc code itself
and not in the user application. I just ran a quick check and don't
have code using &tv_usec nor &tv_nsec so here the risk remains quite
low.
Thanks,
Willy
next prev parent reply other threads:[~2025-12-01 10:35 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-22 16:59 [PATCH v2 00/13] tools/nolibc: always use 64-bit time-related types Thomas Weißschuh
2025-11-22 16:59 ` [PATCH v2 01/13] tools/nolibc/poll: use kernel types for system call invocations Thomas Weißschuh
2025-11-22 16:59 ` [PATCH v2 02/13] tools/nolibc/poll: drop __NR_poll fallback Thomas Weißschuh
2025-11-22 16:59 ` [PATCH v2 03/13] tools/nolibc/select: drop non-pselect based implementations Thomas Weißschuh
2025-11-22 16:59 ` [PATCH v2 04/13] tools/nolibc/time: drop invocation of gettimeofday system call Thomas Weißschuh
2025-11-30 10:42 ` Willy Tarreau
2025-11-22 16:59 ` [PATCH v2 05/13] tools/nolibc: prefer explicit 64-bit time-related system calls Thomas Weißschuh
2025-11-22 16:59 ` [PATCH v2 06/13] tools/nolibc/gettimeofday: avoid libgcc 64-bit divisions Thomas Weißschuh
2025-11-22 16:59 ` [PATCH v2 07/13] tools/nolibc/select: avoid libgcc 64-bit multiplications Thomas Weißschuh
2025-11-22 16:59 ` [PATCH v2 08/13] tools/nolibc: use custom structs timespec and timeval Thomas Weißschuh
2025-11-22 16:59 ` [PATCH v2 09/13] tools/nolibc: always use 64-bit time types Thomas Weißschuh
2025-11-30 10:58 ` Willy Tarreau
2025-12-01 7:45 ` Arnd Bergmann
2025-12-01 10:35 ` Willy Tarreau [this message]
2025-12-01 10:53 ` Arnd Bergmann
2025-11-22 16:59 ` [PATCH v2 10/13] selftests/nolibc: test compatibility of nolibc and kernel " Thomas Weißschuh
2025-11-22 16:59 ` [PATCH v2 11/13] tools/nolibc: remove time conversions Thomas Weißschuh
2025-11-22 16:59 ` [PATCH v2 12/13] tools/nolibc: add __nolibc_static_assert() Thomas Weißschuh
2025-11-30 11:08 ` Willy Tarreau
2025-12-03 19:19 ` Thomas Weißschuh
2025-12-03 19:23 ` Willy Tarreau
2025-12-03 20:08 ` Thomas Weißschuh
2025-11-22 16:59 ` [PATCH v2 13/13] selftests/nolibc: add static assertions around time types handling Thomas Weißschuh
2025-11-30 11:10 ` [PATCH v2 00/13] tools/nolibc: always use 64-bit time-related types Willy Tarreau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251201103505.GA23859@1wt.eu \
--to=w@1wt.eu \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox