aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
authorIngo Molnar <mingo@kernel.org>2026-05-29 09:51:00 +0200
committerIngo Molnar <mingo@kernel.org>2026-05-29 09:51:01 +0200
commit83358dec92a4c05c1bbdefa29d677db8a2a2799f (patch)
tree4b59627eaa77b70bd42903886274e5e9afd40a68 /tools
parentee5ce6e9ef0dff9f58c182509212f26dd634b3f7 (diff)
parenta05ca50fc0b832753669ab68fbbb6dc352cf6699 (diff)
downloadlinux-next-history-83358dec92a4c05c1bbdefa29d677db8a2a2799f.tar.gz
Merge branch into tip/master: 'timers/merge'
# New commits in timers/merge: 3eb4923e6851 ("clocksource: Add devm_clocksource_register_*() helpers") c8d32a0389fb ("timers: Fix flseep() typo in kernel-doc comment") 5d330d652d7a ("hrtimer: Fix the bogus return type of __hrtimer_start_range_ns()") 3af1f49f415d ("hrtimer: Return ktime_t from hrtimer_get_next_event()/hrtimer_next_event_without()") 33d4bfc49613 ("clocksource: Clean up clocksource_update_freq() functions") ed3b3c497668 ("alarmtimer: Remove stale return description from alarm_handle_timer()") b00385b8d081 ("selftests/posix_timers: Use CLOCK_THREAD_CPUTIME_ID for ITIMER_PROF measurements") cab0cd0130eb ("scripts/timers: Add timer_migration_tree.py") 5a7dfbcbbdb6 ("timers/migration: Handle capacity in connect tracepoints") 098cbaad8e57 ("timers/migration: Split per-capacity hierarchies") 3ba25488380f ("timers/migration: Track CPUs in a hierarchy") ff65875f80d1 ("timers/migration: Abstract out hierarchy to prepare for CPU capacity awareness") ed78a7019419 ("alarmtimer: Remove unused interfaces") 12e4311aa5b2 ("netfilter: xt_IDLETIMER: Switch to alarm_start_timer()") 9fa2e38ab749 ("power: supply: charger-manager: Switch to alarm_start_timer()") 7dda99952ced ("fs/timerfd: Use the new alarm/hrtimer functions") f4b58f61da79 ("alarmtimer: Convert posix timer functions to alarm_start_timer()") 183d00b72713 ("alarmtimer: Provide alarm_start_timer()") acc071343d29 ("posix-timers: Switch to hrtimer_start_expires_user()") cfb7fe3fdd4c ("posix-timers: Handle the timer_[re]arm() return value") 6fdb2677a594 ("posix-timers: Expand timer_[re]arm() callbacks with a boolean return value") b40c927345a9 ("hrtimer: Use hrtimer_start_expires_user() for hrtimer sleepers") bd5956166d20 ("hrtimer: Provide hrtimer_start_range_ns_user()") 68ed094971b0 ("clocksource/drivers/timer-of: Make the code compatible with modules") 2423405880c2 ("clocksource/drivers/mmio: Make the code compatible with modules") fed9f727cc3f ("clocksource/drivers/sun5i: Handle error returns from devm_reset_control_get_optional_exclusive()") 045a9dac7eb7 ("clocksource/drivers/timer-rtl-otto: Make rttm_cs variable static") b385caf91868 ("dt-bindings: timer: fsl,imxgpt: add compatible string fsl,imx25-epit") Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/timers/posix_timers.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index 38512623622a5..2f3bac9fc6e87 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -78,19 +78,25 @@ static void sig_handler(int nr)
done = 1;
}
+static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2)
+{
+ int64_t diff;
+
+ diff = NSEC_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec);
+ diff += ((int) t1.tv_nsec - (int) t2.tv_nsec);
+ return diff;
+}
+
/*
* Check the expected timer expiration matches the GTOD elapsed delta since
* we armed the timer. Keep a 0.5 sec error margin due to various jitter.
*/
-static int check_diff(struct timeval start, struct timeval end)
+static int check_diff(struct timespec start, struct timespec end)
{
- long long diff;
-
- diff = end.tv_usec - start.tv_usec;
- diff += (end.tv_sec - start.tv_sec) * USEC_PER_SEC;
+ long long diff = calcdiff_ns(end, start);
- if (llabs(diff - DELAY * USEC_PER_SEC) > USEC_PER_SEC / 2) {
- printf("Diff too high: %lld..", diff);
+ if (llabs(diff - DELAY * NSEC_PER_SEC) > NSEC_PER_SEC / 2) {
+ printf("Diff too high: %lld ns..", diff);
return -1;
}
@@ -99,22 +105,25 @@ static int check_diff(struct timeval start, struct timeval end)
static void check_itimer(int which, const char *name)
{
- struct timeval start, end;
+ struct timespec start, end;
struct itimerval val = {
.it_value.tv_sec = DELAY,
};
+ int clock_id = CLOCK_REALTIME;
done = 0;
if (which == ITIMER_VIRTUAL)
signal(SIGVTALRM, sig_handler);
- else if (which == ITIMER_PROF)
+ else if (which == ITIMER_PROF) {
+ clock_id = CLOCK_THREAD_CPUTIME_ID;
signal(SIGPROF, sig_handler);
+ }
else if (which == ITIMER_REAL)
signal(SIGALRM, sig_handler);
- if (gettimeofday(&start, NULL) < 0)
- fatal_error(name, "gettimeofday()");
+ if (clock_gettime(clock_id, &start))
+ fatal_error(name, "clock_gettime()");
if (setitimer(which, &val, NULL) < 0)
fatal_error(name, "setitimer()");
@@ -126,18 +135,19 @@ static void check_itimer(int which, const char *name)
else if (which == ITIMER_REAL)
idle_loop();
- if (gettimeofday(&end, NULL) < 0)
- fatal_error(name, "gettimeofday()");
+ if (clock_gettime(clock_id, &end))
+ fatal_error(name, "clock_gettime()");
ksft_test_result(check_diff(start, end) == 0, "%s\n", name);
}
static void check_timer_create(int which, const char *name)
{
- struct timeval start, end;
+ struct timespec start, end;
struct itimerspec val = {
.it_value.tv_sec = DELAY,
};
+ int clock_id = CLOCK_REALTIME;
timer_t id;
done = 0;
@@ -148,16 +158,16 @@ static void check_timer_create(int which, const char *name)
if (signal(SIGALRM, sig_handler) == SIG_ERR)
fatal_error(name, "signal()");
- if (gettimeofday(&start, NULL) < 0)
- fatal_error(name, "gettimeofday()");
+ if (clock_gettime(clock_id, &start))
+ fatal_error(name, "clock_gettime()");
if (timer_settime(id, 0, &val, NULL) < 0)
fatal_error(name, "timer_settime()");
user_loop();
- if (gettimeofday(&end, NULL) < 0)
- fatal_error(name, "gettimeofday()");
+ if (clock_gettime(clock_id, &end))
+ fatal_error(name, "clock_gettime()");
ksft_test_result(check_diff(start, end) == 0,
"timer_create() per %s\n", name);
@@ -445,15 +455,6 @@ static void check_delete(void)
ksft_test_result(!tsig.signals, "check_delete\n");
}
-static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2)
-{
- int64_t diff;
-
- diff = NSEC_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec);
- diff += ((int) t1.tv_nsec - (int) t2.tv_nsec);
- return diff;
-}
-
static void check_sigev_none(int which, const char *name)
{
struct timespec start, now;