On Tue, Jun 9, 2026 at 12:56 AM Wake Liu <[email protected]> wrote:
>
> This reverts commit 80fa614e2fbcf11069f0995e1601fb2e5702e2f4.
>
> The reverted commit replaced local definitions of NSEC_PER_SEC and
> USEC_PER_SEC with inclusion of <include/vdso/time64.h>. However,
> NSEC_PER_SEC in vdso/time64.h is defined as 1000000000L, which is
> 32-bit on 32-bit architectures. This causes integer overflow warnings
> in several timer tests when doing arithmetic like NSEC_PER_SEC * 10.
>
> Reverting this change restores the local definitions which use
> unsigned long long (ULL) or long long (LL) suffixes, ensuring 64-bit
> multiplication and avoiding overflows on 32-bit systems.
> This also decouples the userspace selftests from internal kernel
> headers.

Hey Wake,
  Thanks for sending this out. While I agree reverting back to local
definitions to ensure we're using 64bit values is better then adding
lots of casting, I think a straight revert isn't maybe the best, since
the original patch did have value in cleaning up the inconsistencies
between tests.

Maybe a "partial" revert would be best, re-adding the local
definitions but avoiding the quirks and inconsistencies between the
tests.


> diff --git a/tools/testing/selftests/timers/adjtick.c 
> b/tools/testing/selftests/timers/adjtick.c
> index 5b3ef708d6e9..0053c6c5bfc0 100644
> --- a/tools/testing/selftests/timers/adjtick.c
> +++ b/tools/testing/selftests/timers/adjtick.c
> @@ -22,10 +22,12 @@
>  #include <sys/time.h>
>  #include <sys/timex.h>
>  #include <time.h>
> -#include <include/vdso/time64.h>
>
>  #include "kselftest.h"
>
> +#define NSEC_PER_SEC           1000000000LL
> +#define USEC_PER_SEC           1000000
> +
>  #define MILLION                        1000000
>
>  long systick;
> diff --git a/tools/testing/selftests/timers/alarmtimer-suspend.c 
> b/tools/testing/selftests/timers/alarmtimer-suspend.c
> index aa66c805f6a4..ba277a708aba 100644
> --- a/tools/testing/selftests/timers/alarmtimer-suspend.c
> +++ b/tools/testing/selftests/timers/alarmtimer-suspend.c
> @@ -28,10 +28,10 @@
>  #include <signal.h>
>  #include <stdlib.h>
>  #include <pthread.h>
> -#include <include/vdso/time64.h>
>  #include <errno.h>
>  #include "kselftest.h"
>
> +#define NSEC_PER_SEC 1000000000ULL


It seems like picking LL across the board would probably be a good idea.


> diff --git a/tools/testing/selftests/timers/posix_timers.c 
> b/tools/testing/selftests/timers/posix_timers.c
> index 38512623622a..6f78b6068589 100644
> --- a/tools/testing/selftests/timers/posix_timers.c
> +++ b/tools/testing/selftests/timers/posix_timers.c
> @@ -16,13 +16,14 @@
>  #include <string.h>
>  #include <unistd.h>
>  #include <time.h>
> -#include <include/vdso/time64.h>
>  #include <pthread.h>
>  #include <stdbool.h>
>
>  #include "kselftest.h"
>
>  #define DELAY 2
> +#define USECS_PER_SEC 1000000
> +#define NSECS_PER_SEC 1000000000
>
>  static void __fatal_error(const char *test, const char *name, const char 
> *what)
>  {
> @@ -87,9 +88,9 @@ static int check_diff(struct timeval start, struct timeval 
> end)
>         long long diff;
>
>         diff = end.tv_usec - start.tv_usec;
> -       diff += (end.tv_sec - start.tv_sec) * USEC_PER_SEC;
> +       diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC;
>
> -       if (llabs(diff - DELAY * USEC_PER_SEC) > USEC_PER_SEC / 2) {
> +       if (llabs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
>                 printf("Diff too high: %lld..", diff);
>                 return -1;
>         }

Similarly I don't think re-introducing the plural definitions to the
code here is useful. Lets keep the cleanups, but just re-add the local
definition.

thanks
-john

Reply via email to