[tip: timers/core] time: test: Avoid unnecessary divisions in time64_to_tm() test
From: tip-bot2 for Thomas Weißschuh (Schneider Electric)
Date: Mon Nov 30 2026 - 10:12:26 EST
The following commit has been merged into the timers/core branch of tip:
Commit-ID: ca365417bd492e605e21820730b63bc77dc8c7dc
Gitweb: https://git.kernel.org/tip/ca365417bd492e605e21820730b63bc77dc8c7dc
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@xxxxxxxxxxxxx>
AuthorDate: Mon, 30 Nov 2026 15:20:48 +01:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Mon, 30 Nov 2026 16:08:42 +01:00
time: test: Avoid unnecessary divisions in time64_to_tm() test
The time64_to_tm_test_date_range() test case is slow.
One big part of this slowness is the division done in the test loop to
calculate the current day from the current seconds. As each test loop
advances the time by one day, that division can be avoided.
Remove the division and instead increment the 'days' variable directly.
This brings the test's runtime from 30 seconds down to 15 seconds in an
emulated 32-bit ARM machine.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@xxxxxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Reviewed-by: Cassio Neri <cassio.neri@xxxxxxxxx>
Link: https://patch.msgid.link/20261130-time-time64-to-tm-v3-2-f68748ad4118@xxxxxxxxxxxxx
---
kernel/time/time_test.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/time/time_test.c b/kernel/time/time_test.c
index 8b71876..41e504a 100644
--- a/kernel/time/time_test.c
+++ b/kernel/time/time_test.c
@@ -69,12 +69,12 @@ static void time64_to_tm_test_date_range(struct kunit *test)
time64_t secs;
s64 days;
- for (secs = -total_secs; secs <= total_secs; secs += 86400) {
+ for (secs = -total_secs, days = div_s64(secs, 86400);
+ secs <= total_secs;
+ secs += 86400, days++) {
time64_to_tm(secs, 0, &result);
- days = div_s64(secs, 86400);
-
#define FAIL_MSG "%05ld/%02d/%02d (%2d) : %lld", \
year, month, mdday, yday, days