All of lore.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Shuah Khan <shuah@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 08/12] tools/nolibc: gettimeofday(): avoid libgcc 64-bit divisions
Date: Sun, 2 Nov 2025 10:49:51 +0100	[thread overview]
Message-ID: <20251102094951.GB26041@1wt.eu> (raw)
In-Reply-To: <69c383ef-0d05-4f9a-bdd1-85dbf3d0100b@t-8ch.de>

On Sun, Nov 02, 2025 at 10:27:18AM +0100, Thomas Weißschuh wrote:
> On 2025-11-02 09:31:56+0100, Willy Tarreau wrote:
> > On Wed, Oct 29, 2025 at 05:02:58PM +0100, Thomas Weißschuh wrote:
> > > timespec::tv_nsec is going to be 64-bit wide even on 32-bit
> > > architectures. As not all architectures support 64-bit division
> > > instructions, calls to libgcc (__divdi3()) may be emitted by the
> > > compiler which are not provided by nolibc.
> > > 
> > > As tv_nsec is guaranteed to always fit into an uint32_t, perform a
> > > 32-bit division instead.
> > >
> > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > > ---
> > >  tools/include/nolibc/sys/time.h | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/tools/include/nolibc/sys/time.h b/tools/include/nolibc/sys/time.h
> > > index 33782a19aae9..6dd3705c6c9d 100644
> > > --- a/tools/include/nolibc/sys/time.h
> > > +++ b/tools/include/nolibc/sys/time.h
> > > @@ -33,7 +33,7 @@ int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
> > >  	ret = sys_clock_gettime(CLOCK_REALTIME, &tp);
> > >  	if (!ret && tv) {
> > >  		tv->tv_sec = tp.tv_sec;
> > > -		tv->tv_usec = tp.tv_nsec / 1000;
> > > +		tv->tv_usec = (uint32_t)tp.tv_nsec / 1000;
> > >  	}
> > 
> > Good catch! I'm wondering if this one shouldn't be marked as a build
> > fix for 5e7392dc82ed ("tools/nolibc: fall back to sys_clock_gettime()
> > in gettimeofday()") so that it can be backported.
> 
> Right now timespec::tv_nsec is of type 'long', so it should only be
> 64-bits on architectures which have native 64-bit division instructions. 
> But marking it as fix shouldn't hurt either.

Ah yeah you're right. Don't bother with that then.

Thanks!
Willy

  reply	other threads:[~2025-11-02  9:49 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-29 16:02 [PATCH 00/12] tools/nolibc: always use 64-bit ino_t, off_t and time-related types Thomas Weißschuh
2025-10-29 16:02 ` [PATCH 01/12] tools/nolibc: use 64-bit ino_t Thomas Weißschuh
2025-10-29 16:02 ` [PATCH 02/12] tools/nolibc: handle 64-bit off_t for llseek Thomas Weißschuh
2025-10-30 14:56   ` Arnd Bergmann
2025-10-29 16:02 ` [PATCH 03/12] tools/nolibc: prefer the llseek syscall Thomas Weißschuh
2025-10-29 16:02 ` [PATCH 04/12] tools/nolibc: use 64-bit off_t Thomas Weißschuh
2025-10-29 16:02 ` [PATCH 05/12] tools/nolibc: remove now superfluous overflow check in llseek Thomas Weißschuh
2025-10-30 14:58   ` Arnd Bergmann
2025-10-29 16:02 ` [PATCH 06/12] tools/nolibc: remove more __nolibc_enosys() fallbacks Thomas Weißschuh
2025-10-29 16:02 ` [PATCH 07/12] tools/nolibc: prefer explicit 64-bit time-related system calls Thomas Weißschuh
2025-10-30 14:44   ` Arnd Bergmann
2025-10-29 16:02 ` [PATCH 08/12] tools/nolibc: gettimeofday(): avoid libgcc 64-bit divisions Thomas Weißschuh
2025-10-30 14:57   ` Arnd Bergmann
2025-11-02  8:31   ` Willy Tarreau
2025-11-02  9:27     ` Thomas Weißschuh
2025-11-02  9:49       ` Willy Tarreau [this message]
2025-10-29 16:02 ` [PATCH 09/12] tools/nolibc: use a custom struct timespec Thomas Weißschuh
2025-10-30 14:46   ` Arnd Bergmann
2025-11-02  8:36     ` Willy Tarreau
2025-11-02  8:40       ` Willy Tarreau
2025-11-02  9:41       ` Thomas Weißschuh
2025-11-02  9:50         ` Willy Tarreau
2025-10-29 16:03 ` [PATCH 10/12] tools/nolibc: always use 64-bit time types Thomas Weißschuh
2025-10-29 16:03 ` [PATCH 11/12] selftests/nolibc: test compatibility of timespec and __kernel_timespec Thomas Weißschuh
2025-10-29 16:03 ` [PATCH 12/12] tools/nolibc: remove time conversions Thomas Weißschuh
2025-10-30 14:58   ` Arnd Bergmann
2025-11-02  8:44 ` [PATCH 00/12] tools/nolibc: always use 64-bit ino_t, off_t and 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=20251102094951.GB26041@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.