[PATCH 1/4] time: Avoid 64-bit by 64-bit division in time64_to_tm()

From: Thomas Weißschuh (Schneider Electric)

Date: Thu Sep 03 2026 - 04:02:16 EST


As the divisor is static and known to fit into 32 bits, a 64/32 division
is enough. The 64/64 is unnecessary and very expensive on architectures
without native 64/64 division instructions.

This brings the time64_to_tm_test_date_range() runtime from 45 seconds
down to 30 seconds in an emulated 32-bit ARM machine.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@xxxxxxxxxxxxx>
---
kernel/time/timeconv.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/time/timeconv.c b/kernel/time/timeconv.c
index 59b922c826e7..779b91898276 100644
--- a/kernel/time/timeconv.c
+++ b/kernel/time/timeconv.c
@@ -105,8 +105,8 @@ void time64_to_tm(time64_t totalsecs, int offset, struct tm *result)
udays = ((u64) days) + 2305843009213814918ULL;

u64tmp = 4 * udays + 3;
- century = div64_u64_rem(u64tmp, 146097, &u64tmp);
- day_of_century = (u32) (u64tmp / 4);
+ century = div_u64_rem(u64tmp, 146097, &u32tmp);
+ day_of_century = u32tmp / 4;

u32tmp = 4 * day_of_century + 3;
u64tmp = 2939745ULL * u32tmp;

--
2.55.0