From nobody Tue Nov 24 11:17:57 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795421161; b=YusV0REAC3KhIse9OgqiN+67Z3nyZKUIUzddC8m0Xd7UUN7Sh10aGTK6hfu6vMG3R0m5 Irwe0b/UsYrZOtTj90dCIn51AEHmHYVatmRPUeYL7o0HtO4t3M+xTwjq2IrMzkaEJIVu2 Wwuxo6Kl+tSjN7ShZNVSuivWVxsry6VypzVYxHcOfh21U/McKpkQr8U7fIkUBRPtes/aa zXNsi3hTAJl9xKUuEOuzDzoMrYP6ttzEmhpc8jsDGRKrfI+TS2zTfn3oVveG6anT6NX7t oqloeWgQnmixWSPJEgnGDUpzTRZ+ZE88XG3Ni14pu8NQaPgqEryKmpF7WiUF+T3DBmg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795421161; h=DMARC-Filter:From:DKIM-Signature:DKIM-Signature:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Developer-Signature:X-Developer-Key; bh=S+DkpgM/f1BqR3wKUmIV5ajih0kouMUjo0kYGu1jT0k=; b=EJHZL7XVa0sj+zqI+Rn1G8o5xauZFQFaYD6yyg8M4Hce5nAiSXQA2HVFgxtDp+bwA4Km 0Ec9d8HHTo3MftYoB2oYKPVqPhRUN500w4rVu5y2hw/7AL6rqQofgfV4zYs6Ki7QQIO2s /7wXkf1bU+VQIHZTF+p28xFA+vN5iMXePl+yEGq0y7HSLgSRDI02b2dzn9QFuHRvw8GjG ZWXjTGFsfw01dYKkW5IyEelFke2qXByLeZzC26KiZV59IlpN+UX3hxWaBZFGHlV2rHWk0 caT/UU4gSB/LSUzyf6/H9LwRz/xzNzQk6rgXoIVUOh2uKVjKzBBefTa6mCDGnxaphSQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=xfA18C18; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=GJ1CFMw9; arc=none smtp.remote-ip=193.142.43.55 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C682606DB77; Mon, 23 Nov 2026 08:06:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8C682606DB77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=xfA18C18; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=GJ1CFMw9 From: =?utf-8?q?Thomas_Wei=C3=9Fschuh_=28Schneider_Electric=29?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1795421159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S+DkpgM/f1BqR3wKUmIV5ajih0kouMUjo0kYGu1jT0k=; b=xfA18C189GoXJtY7yiDb2e125DcFrLlebB/xo89fTpEW758VpYsLYa297IoR91uQSTVqW3 6dwPXo/q0Wv1GrqOpsCr6F5CHsuTxSnRw5/4AZHF8ZAIwddFlpsiIcHkwJrOb1vA14TWEU 8zugvjh4piQOQUPGNtcPzE3oS+8rCgpLM4htE99/4HHEPRFxqWiidpbcwwUxlqlWX83tDC sGegi8ZZ+eIiXN1WPkdNH+QhrkH1/U9CGlglo5izU0AJ69rThEnQeo7kHosLsdlorR3LEP 0Y49b7WuANSJKM+Nh06q/kciNFS+bYALta+3JdSSKsb6DucHaV94h157P5jH2g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1795421159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S+DkpgM/f1BqR3wKUmIV5ajih0kouMUjo0kYGu1jT0k=; b=GJ1CFMw9VNXn4I/An3+XxZs1+/8/iK+WGZOsNjNjZmoyJaqkOoopDCqOpaJ4QL0uzJjZWx mBhaXSG2USBOy1DQ== Date: Mon, 23 Nov 2026 09:05:09 +0100 Subject: [PATCH v2 1/4] time: Avoid 64-bit by 64-bit division in time64_to_tm() X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261123-time-time64-to-tm-v2-1-117cf8afebce@linutronix.de> References: <20261123-time-time64-to-tm-v2-0-117cf8afebce@linutronix.de> In-Reply-To: <20261123-time-time64-to-tm-v2-0-117cf8afebce@linutronix.de> To: John Stultz , Thomas Gleixner , Stephen Boyd , Miroslav Lichvar , Alexandre Belloni , Cassio Neri Cc: linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1795421157; l=1104; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=Su6vtivmDdtDqpZXHC9ufYwCuQh7ogCQMpovA+8YW00=; b=Mw/GgNbA8sQpnopd1zpBs/rM5iI79EEP9Clio42OAZmYtZkP0TV3OVcAJbskgxyNfXoO790qv 3SH/2fwtZDlD3BwpuaHFbHt69zV6aOShyUTafaRAzD89CfZtQqDnQkO X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= 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=C3=9Fschuh (Schneider Electric) --- 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 aed3af950fa0..d6ae53f67521 100644 --- a/kernel/time/timeconv.c +++ b/kernel/time/timeconv.c @@ -107,8 +107,8 @@ void time64_to_tm(time64_t totalsecs, int offset, struc= t tm *result) udays =3D ((u64) days) + 2305843009213814918ULL; =20 u64tmp =3D 4 * udays + 3; - century =3D div64_u64_rem(u64tmp, 146097, &u64tmp); - day_of_century =3D (u32) (u64tmp / 4); + century =3D div_u64_rem(u64tmp, 146097, &u32tmp); + day_of_century =3D u32tmp / 4; =20 u32tmp =3D 4 * day_of_century + 3; u64tmp =3D 2939745ULL * u32tmp; --=20 2.56.1 From nobody Tue Nov 24 11:17:57 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795421161; b=kUcAyGSYpzikt8wNQwi77Pxi2KWg2ppcTD8OSvqWX5mQtghfgF7xeFxNLo191CQw8Vv7 BihrS+dnMqzMhT5QzUfXmhEvw3H8WI4j17nSx4tYhn5/5uNBZAej7CsYTPDVlyf5W83Bq czPL4bAkLLdJUDtPsp394tPnhjta/TkMYPY+c5dyT0mY74OEPQ1x5UOOzRsqLbXcKsRuK B39d7kKgHXKX7qDxtQvLbrjWkVPuLHe8ONRqKkgq+9Ol5t1BIRRUA2kH6pjSGp9m8+57e EyYm4DQV0+OJvbCFN33RXeAOZeyI4Mz15KlwrIvms+I3+sGpZMaJM+fk1DL+GMuZk3g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795421161; h=DMARC-Filter:From:DKIM-Signature:DKIM-Signature:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Developer-Signature:X-Developer-Key; bh=/6xKh0Y76+vQBXTX9pxqtoDemLDsQ1nSGr83z7rX4JM=; b=aDaPs4pqs8D+cFCws6YLFQiPNYxeI/tF8fBJy3GZm88SqB5FmGknuW8hQUTSinGZyWrP RLk+YzeJf7C+wYsg+K6oNeWvlKNV6Juys6Xhpt8gZzX02W43n2cQIFiv7J+S8C06WEmfx 2c7BBnJO3JxirgyStmUusYyeS/7DWwggiRCab1QUFuc3NMsL91MVOyPsoA03B8AxW6WY+ UVAoCf/DCmh31XusgOKoQfjC+nbQLu3g6pdQsqjVHrQgVQgqAEjat2WIQ/2Ek+l5fAPCV VqRkzR1VpgoxGqzOlnlsRJ0TUPJ26zgZPGgrMnfFHzvLI+j5pT9mYXpsW2Qq2P9l6LA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b="LL/yONXR"; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=nkKZHq7S; arc=none smtp.remote-ip=193.142.43.55 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DDFC606DB7B; Mon, 23 Nov 2026 08:06:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2DDFC606DB7B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=LL/yONXR; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=nkKZHq7S From: =?utf-8?q?Thomas_Wei=C3=9Fschuh_=28Schneider_Electric=29?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1795421159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/6xKh0Y76+vQBXTX9pxqtoDemLDsQ1nSGr83z7rX4JM=; b=LL/yONXRwlGJx9yD5dYoJs6M8Txm/mGSpGRYH/bLP0KMfiuyAjKVD67f+K+rz4u7au73A8 cOJTWRS1mWi6r0hsJLgYuuRilhAP0utx4auS3L7CcaHYvbCj5SM34KKxM/0dLwgziY/+nA V0bwnWeJy9sPd+I2xxFA8htc/Ux8cF4azJmpJZF/y7nz2QCC7FIu3MXsG1XwNDlAaCh2iG UpQpZ6VgSYPg6vyRpNBSHZdP1sW8kM9muxAKv21Dic5LEfJueQyKR2miqn53u9MF0FKVPd vohpEKqdpsmssPbPRtIfL0OqtjjPd/a3i57K8dpCXwOLTG8fsp+uqSAq8NhLwg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1795421159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/6xKh0Y76+vQBXTX9pxqtoDemLDsQ1nSGr83z7rX4JM=; b=nkKZHq7SGxP0nHhvjnBSQ7kNNjIj5I/a41Hrb/+FGVIAr0lumPzEWLVo82/KYVWZn0ISsl a37wCXbmPAGmH/Bw== Date: Mon, 23 Nov 2026 09:05:10 +0100 Subject: [PATCH v2 2/4] time: test: Avoid unnecessary divisions in time64_to_tm() test X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261123-time-time64-to-tm-v2-2-117cf8afebce@linutronix.de> References: <20261123-time-time64-to-tm-v2-0-117cf8afebce@linutronix.de> In-Reply-To: <20261123-time-time64-to-tm-v2-0-117cf8afebce@linutronix.de> To: John Stultz , Thomas Gleixner , Stephen Boyd , Miroslav Lichvar , Alexandre Belloni , Cassio Neri Cc: linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1795421157; l=1277; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=ta5/U3sTyAE1woCYesMyeJ0BDSsJ99j4RW/hkwicfpo=; b=J0kOxXMLgpAsEhrIfl3X6owaJZauGaT+4sDXbZx0iGcJ8+t5SPyHOGL4YWHbDOk4vVPtuyB6F mINPRmyXEnyCw5yMkC+6UzCb+wZo3QtqhP+iXQuyQlrHLR1gXDBnh/u X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= 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=C3=9Fschuh (Schneider Electric) --- 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; =20 - for (secs =3D -total_secs; secs <=3D total_secs; secs +=3D 86400) { + for (secs =3D -total_secs, days =3D div_s64(secs, 86400); + secs <=3D total_secs; + secs +=3D 86400, days++) { =20 time64_to_tm(secs, 0, &result); =20 - days =3D div_s64(secs, 86400); - #define FAIL_MSG "%05ld/%02d/%02d (%2d) : %lld", \ year, month, mdday, yday, days =20 --=20 2.56.1 From nobody Tue Nov 24 11:17:57 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795421162; b=j/YA2Dh5F8WCrU7FAs4vHBD2vukE93fBo5Ce9v3LDxFG16kpXC8NjP1MAqBTvtRXPlcX FQ0qvChXgD+IhuLgPh+lS96yIhO1RV5xJAoZsglyDzfyv4tgdr1RPBtX2cVkEYr+tyrov 2opQFvvjH1pypbOO+g9H9Tb7Rqf5QKzOZMQ20dBf6uyMmqiIdj8x2BUog/rbXkCMs48gw +ws+Fmq+nqXJLgD6iuW7i4N9pKc0wGgw58aptRqIotBUaGf7S6vvfQ71y25wmBwAe6+U4 rYo1uMcBBAuqKoCnqlou3JQMWGQ/ue7NPEn8zG7IOug9lGX8DR2xH/yiC2yvLSmdJ8g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795421162; h=DMARC-Filter:From:DKIM-Signature:DKIM-Signature:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Developer-Signature:X-Developer-Key; bh=2/WyowuDlwU3Vpqir6oMz1t4kUoGoxQnAwVtqFAIOS4=; b=Wef1XOzrNePzFhhyREODD4WpCuTEMQfC/PNbVizVmyQdp6y6oJuEEgqkCF+qkSoZkxgZ cEiQj3+ZOfjBAn9DsK6ey8OpYXXP1ZktG/x3KBhSb/RM87u5ZtGTAjOvjRyusyxLvPWiH K6qKwv29WgYTs36V1k/L/JmG6v2j4tl0xTkpKO/zjAndyvuvRLnGGM3q1Ixu5sf+N28f1 alJM7pI8FOeqOVOEltOrrDhtShM5+s9rhT3Ae/VJNFQeh/OgcFSzhgXfRdMK/pphFMKUT QJjaKOQClBVHOO9TWw4/VFOwDl34NVdqUogNPV4L74hAKhKRLC+ZCb56CTYCUJU+jEw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=JE6ZAxmJ; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=Mju+JCal; arc=none smtp.remote-ip=193.142.43.55 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAA72606DB7C; Mon, 23 Nov 2026 08:06:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AAA72606DB7C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=JE6ZAxmJ; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=Mju+JCal From: =?utf-8?q?Thomas_Wei=C3=9Fschuh_=28Schneider_Electric=29?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1795421160; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2/WyowuDlwU3Vpqir6oMz1t4kUoGoxQnAwVtqFAIOS4=; b=JE6ZAxmJgy8V/S+ycHXkPv4cFMrWsmihW4hZ3NPhdReG+ZxZAo9/u8mEjPY2ApH18X0V48 52vDZm2Eb9INY1UpLxDPn+pzvPkmDhM6mdOYpF4QLp1dsUwarfEvkuJw0NLrfFKwV0M3HK EZdryHPbqJTNxvO+cUaSEwOmy469clhD8eY4/LEUZwAu3GjF77YBIEQMMNEoMKvgkwT/77 yNySvia+D0c9br1B7TOYTIjehbUGXRGDbNRVBdoSkYxnjts5bBdT+jfzGdzMvHFA98WWE0 D0QQ8TGHYeM88XeVHr/z6y4PCy4ilkcpLgKDfBQBRABhzXIs1fDOKaCxE4oKfw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1795421160; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2/WyowuDlwU3Vpqir6oMz1t4kUoGoxQnAwVtqFAIOS4=; b=Mju+JCalhH+LE9n+atxBvlimCKzDu8kLQ4RZjUCwuqrUxi9Hn3HSeMaeWuigTUHtriRM5e 9Uvs/rfX+FIkF8AQ== Date: Mon, 23 Nov 2026 09:05:11 +0100 Subject: [PATCH v2 3/4] rtc: lib: Implement time64_to_tm() in terms of time64_to_tm() X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261123-time-time64-to-tm-v2-3-117cf8afebce@linutronix.de> References: <20261123-time-time64-to-tm-v2-0-117cf8afebce@linutronix.de> In-Reply-To: <20261123-time-time64-to-tm-v2-0-117cf8afebce@linutronix.de> To: John Stultz , Thomas Gleixner , Stephen Boyd , Miroslav Lichvar , Alexandre Belloni , Cassio Neri Cc: linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1795421157; l=4923; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=b5ErLZJMYDTYspIHmjRMR0gIi9U0Wye2qhnQtgSLhV0=; b=UlZFI7OMcwapjio7M3G92kG560gUKh6YESaUVDb4BcG17gyHoJNBCciiS22Zb0LVza2+DSq1v bcwNwfMTWRLB1SfI1DnRM94NywTuq4fOQ6hmIIFvp0jib6v145uva3Z X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The core timekeeping code already provides a function to convert seconds since the epoch to a 'struct tm'. This can be reused for a the 'struct rtc_time' conversion. time64_to_tm() can handle a larger range of dates. It is also 20% slower, but this function is not a hot-path anyways. On the other hand this saves ~600 bytes of .text. Signed-off-by: Thomas Wei=C3=9Fschuh (Schneider Electric) --- drivers/rtc/lib.c | 117 +++++++-------------------------------------------= ---- 1 file changed, 15 insertions(+), 102 deletions(-) diff --git a/drivers/rtc/lib.c b/drivers/rtc/lib.c index f7051592a6e3..48a26b579b4c 100644 --- a/drivers/rtc/lib.c +++ b/drivers/rtc/lib.c @@ -46,110 +46,23 @@ EXPORT_SYMBOL(rtc_year_days); * rtc_time64_to_tm - converts time64_t to rtc_time. * * @time: The number of seconds since 01-01-1970 00:00:00. - * Works for values since at least 1900 - * @tm: Pointer to the struct rtc_time. + * @rtc_tm: Pointer to the struct rtc_time. */ -void rtc_time64_to_tm(time64_t time, struct rtc_time *tm) +noinline void rtc_time64_to_tm(time64_t time, struct rtc_time *rtc_tm) { - int secs; - - u64 u64tmp; - u32 u32tmp, udays, century, day_of_century, year_of_century, year, - day_of_year, month, day; - bool is_Jan_or_Feb, is_leap_year; - - /* - * The time represented by `time` is given in seconds since 1970-01-01 - * (UTC). As the division done below might misbehave for negative - * values, we convert it to seconds since 0000-03-01 and then assume it - * will be non-negative. - * Below we do 4 * udays + 3 which should fit into a 32 bit unsigned - * variable. So the latest date this algorithm works for is 1073741823 - * days after 0000-03-01 which is in the year 2939805. - */ - time +=3D (u64)719468 * 86400; - - udays =3D div_s64_rem(time, 86400, &secs); - - /* - * day of the week, 0000-03-01 was a Wednesday (in the proleptic - * Gregorian calendar) - */ - tm->tm_wday =3D (udays + 3) % 7; - - /* - * The following algorithm is, basically, Figure 12 of Neri - * and Schneider [1]. In a few words: it works on the computational - * (fictitious) calendar where the year starts in March, month =3D 2 - * (*), and finishes in February, month =3D 13. This calendar is - * mathematically convenient because the day of the year does not - * depend on whether the year is leap or not. For instance: - * - * March 1st 0-th day of the year; - * ... - * April 1st 31-st day of the year; - * ... - * January 1st 306-th day of the year; (Important!) - * ... - * February 28th 364-th day of the year; - * February 29th 365-th day of the year (if it exists). - * - * After having worked out the date in the computational calendar - * (using just arithmetics) it's easy to convert it to the - * corresponding date in the Gregorian calendar. - * - * [1] Neri C, Schneider L. Euclidean affine functions and their - * application to calendar algorithms. Softw Pract Exper. - * 2023;53(4):937-970. doi: 10.1002/spe.3172 - * https://doi.org/10.1002/spe.3172 - * - * (*) The numbering of months follows rtc_time more closely and - * thus, is slightly different from [1]. - */ - - u32tmp =3D 4 * udays + 3; - century =3D u32tmp / 146097; - day_of_century =3D u32tmp % 146097 / 4; - - u32tmp =3D 4 * day_of_century + 3; - u64tmp =3D 2939745ULL * u32tmp; - year_of_century =3D upper_32_bits(u64tmp); - day_of_year =3D lower_32_bits(u64tmp) / 2939745 / 4; - - year =3D 100 * century + year_of_century; - is_leap_year =3D year_of_century !=3D 0 ? - year_of_century % 4 =3D=3D 0 : century % 4 =3D=3D 0; - - u32tmp =3D 2141 * day_of_year + 132377; - month =3D u32tmp >> 16; - day =3D ((u16) u32tmp) / 2141; - - /* - * Recall that January 01 is the 306-th day of the year in the - * computational (not Gregorian) calendar. - */ - is_Jan_or_Feb =3D day_of_year >=3D 306; - - /* Converts to the Gregorian calendar. */ - year =3D year + is_Jan_or_Feb; - month =3D is_Jan_or_Feb ? month - 12 : month; - day =3D day + 1; - - day_of_year =3D is_Jan_or_Feb ? - day_of_year - 306 : day_of_year + 31 + 28 + is_leap_year; - - /* Converts to rtc_time's format. */ - tm->tm_year =3D (int) (year - 1900); - tm->tm_mon =3D (int) month; - tm->tm_mday =3D (int) day; - tm->tm_yday =3D (int) day_of_year + 1; - - tm->tm_hour =3D secs / 3600; - secs -=3D tm->tm_hour * 3600; - tm->tm_min =3D secs / 60; - tm->tm_sec =3D secs - tm->tm_min * 60; - - tm->tm_isdst =3D 0; + struct tm tm; + + time64_to_tm(time, 0, &tm); + + rtc_tm->tm_wday =3D tm.tm_wday; + rtc_tm->tm_year =3D tm.tm_year; + rtc_tm->tm_mon =3D tm.tm_mon; + rtc_tm->tm_mday =3D tm.tm_mday; + rtc_tm->tm_yday =3D tm.tm_yday + 1; + rtc_tm->tm_hour =3D tm.tm_hour; + rtc_tm->tm_min =3D tm.tm_min; + rtc_tm->tm_sec =3D tm.tm_sec; + rtc_tm->tm_isdst =3D 0; } EXPORT_SYMBOL(rtc_time64_to_tm); =20 --=20 2.56.1 From nobody Tue Nov 24 11:17:57 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795421163; b=0Cw7TNih2yRRYRPyGvhimToJ9PQq/DPbjU2R/+EbeTVJUMZHW4rChVW2fswuP8YaxGlf LsQz4hueXmhL08pIdAj0xOHyqVnFFPn8TKFm+hNieFrcxbtsVYaJTUiWh8pUxsT2rz3/n fLBM5urHCOpHQUE6y/A+RTbjQwVabfF+rIJ4MKrzsHQuGUtp3pEdx9Y2540SANK7UN5Y5 5hDLKMt1Yo8i/nZUrZ7vDkApPQZgs8BvxoJ3yZSkUua4Y1NYKewfKe6MUji22cGh1KR21 hyUpOzj/EEYFeqW1Q+MfRQvBDlatNl2IqBpVhrzr8NJJOXqDH+XRq2cOMk2gBKNUUBw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795421163; h=DMARC-Filter:From:DKIM-Signature:DKIM-Signature:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Developer-Signature:X-Developer-Key; bh=saRGmW0YdaPOf9B38hsjs9ddd9rhpPBqExqDY8kvRlk=; b=tqxVf8ZKI45taJwZzVQuXY4/lYGcPkMt4Bo1AtRS/i0Bxlyk8ruRkzn4wrZ+CbShR306 SRARgadMrWZd49vafIueeQJ+osgZE/Yw3FrVwXX8rWqBcueedRNvHFSKmP8O+hJOjUfyr +NXVYyJ+yl1xUn4UKfmqKjRPkBPLtYgmf7pGG9GaRcw48c2qHqqrxNemgeiCbjRKC89PH lqooLur+0XIrk8ddOtnjvFN6UeP9IDiMC19RE+swoXtTxms9SGNtF+MaOJf0Zh+iZjwQ0 29tRNvsonM+p42oqpBw1eFANwoaQkbYaGYCCNqIFTC6lSlvtl5vcepMfQnMPm6lnZ/g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=pL0IIQpG; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b="MX0MH/kJ"; arc=none smtp.remote-ip=193.142.43.55 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EC1F6070A0C; Mon, 23 Nov 2026 08:06:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7EC1F6070A0C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=pL0IIQpG; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=MX0MH/kJ From: =?utf-8?q?Thomas_Wei=C3=9Fschuh_=28Schneider_Electric=29?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1795421160; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=saRGmW0YdaPOf9B38hsjs9ddd9rhpPBqExqDY8kvRlk=; b=pL0IIQpGW6RGKxvEjbj559GaC+94KefHpITKEKpOSHIHOmeAmIRwlGm4u1MtF3YLgP+PFv f0f54JhTrjLep4dK2ozpgi4TW2UtoNqM8LFM9miMPFbuuf0knH8NyRv/2Nf6mxAymfLICY WryEk4NMYLD5TSMgLsELmALOuTsSlWKxuJCsLjIWIYrTl7jXq/W6vlvJIxxtjh8TeycE1h 79MoQqMkCwnrtc3bo/QnKXJwmhYP+afhRXFBR/6hK200NAXBKpbGwjWvyrMqCR0MApPY6s fNSSOyBMtsIK2+azCZcErzk7HGXVUcDHXJeY8DaXuC1qunnfV351FL3RJEsjjg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1795421160; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=saRGmW0YdaPOf9B38hsjs9ddd9rhpPBqExqDY8kvRlk=; b=MX0MH/kJWzPwwpekIHeTeOTlfSas/vdKILMvnnId8WsY7f6kuMiNyTHSHPFRL+Sx7DY/pL ETKkQ/nmWppDmpBg== Date: Mon, 23 Nov 2026 09:05:12 +0100 Subject: [PATCH v2 4/4] rtc: test: Remove test_rtc_lib.c X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261123-time-time64-to-tm-v2-4-117cf8afebce@linutronix.de> References: <20261123-time-time64-to-tm-v2-0-117cf8afebce@linutronix.de> In-Reply-To: <20261123-time-time64-to-tm-v2-0-117cf8afebce@linutronix.de> To: John Stultz , Thomas Gleixner , Stephen Boyd , Miroslav Lichvar , Alexandre Belloni , Cassio Neri Cc: linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1795421157; l=4664; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=lpLdoqurV8Q9KUZahlozvSDnmTawZdmVljIkY0BOJYU=; b=1wACDgoJITvKsWM2M4Ud8BBPebJ/N9M++3W6fCKobHLXpa6s1FSoQDYIll81cvWbSBGKFzoT8 9X3UC9hDGmvDojh08WaEnJlhFkRMDHHDTk355+96ddBrJY8Gi9XKQkp X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Now that rtc_time64_to_tm() is only a thin wrapper around time64_to_tm() the dedicated test is not necessary anymore. time64_to_tm() is already tested with a similar test in kernel/time/time_test.c Remove it. Signed-off-by: Thomas Wei=C3=9Fschuh (Schneider Electric) --- drivers/rtc/Kconfig | 9 ---- drivers/rtc/Makefile | 2 - drivers/rtc/test_rtc_lib.c | 106 -----------------------------------------= ---- 3 files changed, 117 deletions(-) diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 73ec9230edfd..3fd586aef1ec 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -96,15 +96,6 @@ config RTC_DEBUG Say yes here to enable debugging support in the RTC framework and individual RTC drivers. =20 -config RTC_LIB_KUNIT_TEST - tristate "KUnit test for RTC lib functions" if !KUNIT_ALL_TESTS - depends on KUNIT - default KUNIT_ALL_TESTS - help - Enable this option to test RTC library functions. - - If unsure, say N. - config RTC_NVMEM bool "RTC non volatile storage support" select NVMEM diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 46f1a0fc2416..51e2ca2d2a57 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -15,8 +15,6 @@ rtc-core-$(CONFIG_RTC_INTF_DEV) +=3D dev.o rtc-core-$(CONFIG_RTC_INTF_PROC) +=3D proc.o rtc-core-$(CONFIG_RTC_INTF_SYSFS) +=3D sysfs.o =20 -obj-$(CONFIG_RTC_LIB_KUNIT_TEST) +=3D test_rtc_lib.o - # Keep the list ordered. =20 obj-$(CONFIG_RTC_DRV_88PM80X) +=3D rtc-88pm80x.o diff --git a/drivers/rtc/test_rtc_lib.c b/drivers/rtc/test_rtc_lib.c deleted file mode 100644 index 0eebad1fe2a0..000000000000 --- a/drivers/rtc/test_rtc_lib.c +++ /dev/null @@ -1,106 +0,0 @@ -// SPDX-License-Identifier: LGPL-2.1+ - -#include -#include - -/* - * Advance a date by one day. - */ -static void advance_date(int *year, int *month, int *mday, int *yday, int = *wday) -{ - *wday =3D (*wday + 1) % 7; - - if (*mday !=3D rtc_month_days(*month - 1, *year)) { - ++*mday; - ++*yday; - return; - } - - *mday =3D 1; - if (*month !=3D 12) { - ++*month; - ++*yday; - return; - } - - *month =3D 1; - *yday =3D 1; - ++*year; -} - -/* - * Check every day in specified number of years interval starting on 1970-= 01-01 - * against the expected result. - */ -static void rtc_time64_to_tm_test_date_range(struct kunit *test, int years) -{ - /* - * years =3D (years / 400) * 400 years - * =3D (years / 400) * 146097 days - * =3D (years / 400) * 146097 * 86400 seconds - */ - time64_t total_secs =3D ((time64_t)years) / 400 * 146097 * 86400; - - int year =3D 1900; - int month =3D 1; - int mday =3D 1; - int yday =3D 1; - int wday =3D 1; /* Jan 1st 1900 was a Monday */ - - struct rtc_time result; - time64_t secs; - const time64_t sec_offset =3D RTC_TIMESTAMP_BEGIN_1900 + ((1 * 60) + 2) *= 60 + 3; - - for (secs =3D 0; secs <=3D total_secs; secs +=3D 86400) { - - rtc_time64_to_tm(secs + sec_offset, &result); - - #define FAIL_MSG "%d/%02d/%02d (%2d, %d) : %lld", \ - year, month, mday, yday, wday, secs + sec_offset - - KUNIT_ASSERT_EQ_MSG(test, year - 1900, result.tm_year, FAIL_MSG); - KUNIT_ASSERT_EQ_MSG(test, month - 1, result.tm_mon, FAIL_MSG); - KUNIT_ASSERT_EQ_MSG(test, mday, result.tm_mday, FAIL_MSG); - KUNIT_ASSERT_EQ_MSG(test, yday, result.tm_yday, FAIL_MSG); - KUNIT_ASSERT_EQ_MSG(test, 1, result.tm_hour, FAIL_MSG); - KUNIT_ASSERT_EQ_MSG(test, 2, result.tm_min, FAIL_MSG); - KUNIT_ASSERT_EQ_MSG(test, 3, result.tm_sec, FAIL_MSG); - KUNIT_ASSERT_EQ_MSG(test, wday, result.tm_wday, FAIL_MSG); - - advance_date(&year, &month, &mday, &yday, &wday); - } -} - -/* - * Checks every day in a 160000 years interval starting on 1900-01-01 - * against the expected result. - */ -static void rtc_time64_to_tm_test_date_range_160000(struct kunit *test) -{ - rtc_time64_to_tm_test_date_range(test, 160000); -} - -/* - * Checks every day in a 1000 years interval starting on 1900-01-01 - * against the expected result. - */ -static void rtc_time64_to_tm_test_date_range_1000(struct kunit *test) -{ - rtc_time64_to_tm_test_date_range(test, 1000); -} - -static struct kunit_case rtc_lib_test_cases[] =3D { - KUNIT_CASE(rtc_time64_to_tm_test_date_range_1000), - KUNIT_CASE_SLOW(rtc_time64_to_tm_test_date_range_160000), - {} -}; - -static struct kunit_suite rtc_lib_test_suite =3D { - .name =3D "rtc_lib_test_cases", - .test_cases =3D rtc_lib_test_cases, -}; - -kunit_test_suite(rtc_lib_test_suite); - -MODULE_DESCRIPTION("KUnit test for RTC lib functions"); -MODULE_LICENSE("GPL"); --=20 2.56.1