From: "Thomas Weißschuh (Schneider Electric)" <thomas.weissschuh@linutronix.de>
To: John Stultz <jstultz@google.com>,
Thomas Gleixner <tglx@kernel.org>,
Stephen Boyd <sboyd@kernel.org>,
Miroslav Lichvar <mlichvar@redhat.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Cassio Neri <cassio.neri@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Subject: [PATCH v2 2/4] time: test: Avoid unnecessary divisions in time64_to_tm() test
Date: Mon, 23 Nov 2026 09:05:10 +0100 [thread overview]
Message-ID: <20261123-time-time64-to-tm-v2-2-117cf8afebce@linutronix.de> (raw)
In-Reply-To: <20261123-time-time64-to-tm-v2-0-117cf8afebce@linutronix.de>
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@linutronix.de>
---
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 8b718767b3ba..41e504aa2883 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
--
2.56.1
next prev parent reply other threads:[~2026-11-23 8:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 8:05 [PATCH v2 0/4] time: time64_to_tm() cleanups Thomas Weißschuh (Schneider Electric)
2026-11-23 8:05 ` [PATCH v2 1/4] time: Avoid 64-bit by 64-bit division in time64_to_tm() Thomas Weißschuh (Schneider Electric)
2026-11-23 8:05 ` Thomas Weißschuh (Schneider Electric) [this message]
2026-11-23 8:05 ` [PATCH v2 3/4] rtc: lib: Implement time64_to_tm() in terms of time64_to_tm() Thomas Weißschuh (Schneider Electric)
2026-11-23 8:05 ` [PATCH v2 4/4] rtc: test: Remove test_rtc_lib.c Thomas Weißschuh (Schneider Electric)
-- strict thread matches above, loose matches on Subject: below --
2026-09-03 7:46 [PATCH 2/4] time: test: Avoid unnecessary divisions in time64_to_tm() test Thomas Weißschuh (Schneider Electric)
2026-11-27 16:56 ` [PATCH v2 " Cassio Neri
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=20261123-time-time64-to-tm-v2-2-117cf8afebce@linutronix.de \
--to=thomas.weissschuh@linutronix.de \
--cc=alexandre.belloni@bootlin.com \
--cc=cassio.neri@gmail.com \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=mlichvar@redhat.com \
--cc=sboyd@kernel.org \
--cc=tglx@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®