selftests: timers: Partially revert "Remove local NSEC_PER_SEC and USEC_PER_SEC defines"

This partially reverts commit 80fa614e2f ("selftests: timers: Remove
local NSEC_PER_SEC and USEC_PER_SEC defines").

The original commit removed local definitions of NSEC_PER_SEC and
USEC_PER_SEC in favor of including <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 on
32-bit systems.

To fix this, restore the local definitions of NSEC_PER_SEC and
USEC_PER_SEC in the test files, but use "LL" suffix consistently
(1000000000LL and 1000000LL) to ensure 64-bit arithmetic and avoid
overflows.

We keep the cleanup from the original commit that renamed plural
definitions (NSECS_PER_SEC/USECS_PER_SEC) to singular ones in
posix_timers.c, but we now define them locally there as well.
This also removes the dependency of the selftests on the internal
kernel header <include/vdso/time64.h>.

Signed-off-by: Wake Liu <wakel@google.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260610014721.718362-1-wakel@google.com
This commit is contained in:
Wake Liu
2026-07-10 09:20:55 +02:00
committed by Thomas Gleixner
parent 794ddd6e15
commit f44ce7fdbd
13 changed files with 28 additions and 14 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
CFLAGS += -O3 -Wl,-no-as-needed -Wall -I $(top_srcdir)
CFLAGS += -O3 -Wl,-no-as-needed -Wall
LDLIBS += -lrt -lpthread -lm
# these are all "safe" tests that don't modify
+3 -2
View File
@@ -22,10 +22,11 @@
#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 1000000LL
#define MILLION 1000000
long systick;
@@ -28,10 +28,11 @@
#include <signal.h>
#include <stdlib.h>
#include <pthread.h>
#include <include/vdso/time64.h>
#include <errno.h>
#include "kselftest.h"
#define NSEC_PER_SEC 1000000000LL
#define UNREASONABLE_LAT (NSEC_PER_SEC * 5) /* hopefully we resume in 5 secs */
#define SUSPEND_SECS 15
@@ -28,9 +28,10 @@
#include <sys/timex.h>
#include <string.h>
#include <signal.h>
#include <include/vdso/time64.h>
#include "kselftest.h"
#define NSEC_PER_SEC 1000000000LL
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
+2 -1
View File
@@ -51,9 +51,10 @@
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <include/vdso/time64.h>
#include "kselftest.h"
#define NSEC_PER_SEC 1000000000LL
#define CLOCK_TAI 11
time_t next_leap;
+2 -1
View File
@@ -29,9 +29,10 @@
#include <signal.h>
#include <errno.h>
#include <mqueue.h>
#include <include/vdso/time64.h>
#include "kselftest.h"
#define NSEC_PER_SEC 1000000000LL
#define TARGET_TIMEOUT 100000000 /* 100ms in nanoseconds */
#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
+2 -1
View File
@@ -27,9 +27,10 @@
#include <sys/timex.h>
#include <string.h>
#include <signal.h>
#include <include/vdso/time64.h>
#include "kselftest.h"
#define NSEC_PER_SEC 1000000000LL
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
+2 -1
View File
@@ -24,9 +24,10 @@
#include <sys/timex.h>
#include <string.h>
#include <signal.h>
#include <include/vdso/time64.h>
#include "kselftest.h"
#define NSEC_PER_SEC 1000000000LL
#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
@@ -16,12 +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 NSEC_PER_SEC 1000000000LL
#define USEC_PER_SEC 1000000LL
#define DELAY 2
static void __fatal_error(const char *test, const char *name, const char *what)
+2 -1
View File
@@ -25,9 +25,10 @@
#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 shift_right(x, s) ({ \
__typeof__(x) __x = (x); \
__typeof__(s) __s = (s); \
+2 -1
View File
@@ -27,9 +27,10 @@
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <include/vdso/time64.h>
#include "kselftest.h"
#define NSEC_PER_SEC 1000000000LL
#define KTIME_MAX ((long long)~((unsigned long long)1 << 63))
#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
@@ -28,9 +28,10 @@
#include <signal.h>
#include <stdlib.h>
#include <pthread.h>
#include <include/vdso/time64.h>
#include "kselftest.h"
#define NSEC_PER_SEC 1000000000LL
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
@@ -29,9 +29,11 @@
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <include/vdso/time64.h>
#include "kselftest.h"
#define NSEC_PER_SEC 1000000000LL
#define USEC_PER_SEC 1000000LL
#define ADJ_SETOFFSET 0x0100
#include <sys/syscall.h>