From nobody Sat Sep 26 08:38:52 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E36FD34F27F; Thu, 3 Sep 2026 07:46:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788421618; cv=none; b=b9mpdMAh2utEL2oXgNWWCza5PzZiUpHM4yPHVar7TkREYRwWbEkoOgB4WY/p6AVjqL2jglBaUPmRmJwmP+eB/BdDQtjpUIy/OkU9c+/XhdyQCkG0zJFO9Ab7BsdkePonFK03hmQi9730Gd16uYb+jtYrrry/v1nILPe71elafo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788421618; c=relaxed/simple; bh=spMD8vZ7M1VL4J8XbtU3xQnEOII+8rCIt1dRwSRZxDw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l0CKAObpBhzRfzFoR+gCoShAQ0yIzUOAlONcIBTQ6noWVcHEEKiDVMcAweVlC/ZnqGdHYXXjc/qoBLDu2t5r9bVLT27bHix0zg8/E9BfL5GBoab9RNEhTGCMAg1/+23ZkmkvL+yPF9/LH7CTe0oDL14AaRHXJYGMrV9Em4jopGY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=g+0ng5P1; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cYoZwfqG; arc=none smtp.client-ip=193.142.43.55 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.b="g+0ng5P1"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cYoZwfqG" 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=1788421615; 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=eDi9D7UWYmW+7+A4cGT4drFBnCH6B2iiSY+Aul2GqFM=; b=g+0ng5P1EHTqwg9xNtKdRNFd4/ydxGkmNeAqdiGWDtqPBXDkdKQkyBU2ahCu8+tx6rAZiq qhIg9ufPrm1CC8tK8O5Vw7A7eYOS7BwPIs1RLibnugY1CIflXUZk6Thqf3MPUUCFWWTJXm CEOT43CUvTiqYNFW9zc5neDG2JbLWdbeZtXXXpXzM8kzqzFPxT3eRRT/mwDaq/3Y6eEnNj wR9Yph7gyE2VTkepQ6SOEFwqwtIJ4p5V5+cr+oRrJabJStMamgedMFJHoZP3idZfOX8I9B WLQFYzUWXSsna/4D1pfIUKzsQCsgB/rYYD9y9U9H61TAs1UVNFhkTG2cxqY2PQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1788421615; 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=eDi9D7UWYmW+7+A4cGT4drFBnCH6B2iiSY+Aul2GqFM=; b=cYoZwfqGxPB0W+vYuqVJb6woLGUp2xzeUqZxpqnLWPwvFyp7KiFMufFxvRWGawo6SwS608 oA2neaf2HAImCnAw== Date: Thu, 03 Sep 2026 09:46:50 +0200 Subject: [PATCH 1/4] time: Avoid 64-bit by 64-bit division in time64_to_tm() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260903-time-time64-to-tm-v1-1-660be972adfc@linutronix.de> References: <20260903-time-time64-to-tm-v1-0-660be972adfc@linutronix.de> In-Reply-To: <20260903-time-time64-to-tm-v1-0-660be972adfc@linutronix.de> To: John Stultz , Thomas Gleixner , Stephen Boyd , Miroslav Lichvar , Alexandre Belloni 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=1788421614; l=1104; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=spMD8vZ7M1VL4J8XbtU3xQnEOII+8rCIt1dRwSRZxDw=; b=VcVocKPY9nygpEwwoJoJThN2jtRjwv13u8pqIh312YQdjtARz/i9MASjku5q9AdRPJvBqDf/+ lXHJVXmu/vWCI38Ws3zCVwRyYMLYgAPh3REYygGiDJ2lTfbnsnhN18h 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 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, 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.55.0 From nobody Sat Sep 26 08:38:52 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F9B8367B95; Thu, 3 Sep 2026 07:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788421619; cv=none; b=LsP1C7qViIY3md/JHUrXkDe90+LG0x7DQCU5ESwt9cLt17qqTVtizu1fcz2vfIvXhfHacQznWcmj8X7Ys2uFG8WcyKYHg+nFLM5qIyQSEFVCzCeTKvlWeNH1x//wR+h/oN2CEkwJelbXgs3AtxgYXBDWVa7c3HtApF1CjsGBfbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788421619; c=relaxed/simple; bh=c/r00Kc56rRp8nKCPC7Nq1p+PVKOYNpiEVhF/GQ11V4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u5jAzsaA/tFGokpQQ7oZmzTJZ6J997qwmqSJaHE3jqH05ZrLx+Uzo+DtKbzAR1HY3OOGB7efF+JFgR5yYL+O1GTkNzhArchr2szxUQrl+DDAzdvZC4WJZO/3rMXtpZ5owSP7jN4T6ANArDpP83IK8FYcR0md6a1tQ2qMcwsqPyA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ySimOkGK; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=P/ZkWrH2; arc=none smtp.client-ip=193.142.43.55 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.b="ySimOkGK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="P/ZkWrH2" 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=1788421615; 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=jovYjJSbPo3ySjvlgqdVO09m9BSHrSPSClOaS55PBy0=; b=ySimOkGKJbyb3ho9VXdgYeaqfygtg1gsDIOKBfEQEjf7LJ8MoQL8BdFCLLfvLclDcKeZgl SpkPLboxOHmMmjvN/K+55cdGVH1In8fOy2Rba6QU0Mjdf7DBe1dZttVc6hipgGklFU4zWm xJi92WeXcobnvajyQgZ4zAUqBtr+FRudQY3TlncSrFNTuD11XnnB7hiknfHt4Lg02PdhZw CAoVJpvTodZwfvmcRuCG5Pt+a9IdArJiX669Fc357AkJCxtNZTHDYrA/L19kF3/nXWSxKd ZnFBy8NkY5+k9JlDGQJg8uZboqjuSTINBczfysbyoYrjNsgJiLpsFlzbAsDs3w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1788421615; 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=jovYjJSbPo3ySjvlgqdVO09m9BSHrSPSClOaS55PBy0=; b=P/ZkWrH2NrSDxW016hfijKEwVzvDOLqVev0NNU+UC0IP2Bl/VwXM16N55O9xukF/ymXoO7 kNwXfd0F9aKuSvBQ== Date: Thu, 03 Sep 2026 09:46:51 +0200 Subject: [PATCH 2/4] time: test: Avoid unnecessary divisions in time64_to_tm() test Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260903-time-time64-to-tm-v1-2-660be972adfc@linutronix.de> References: <20260903-time-time64-to-tm-v1-0-660be972adfc@linutronix.de> In-Reply-To: <20260903-time-time64-to-tm-v1-0-660be972adfc@linutronix.de> To: John Stultz , Thomas Gleixner , Stephen Boyd , Miroslav Lichvar , Alexandre Belloni 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=1788421614; l=1277; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=c/r00Kc56rRp8nKCPC7Nq1p+PVKOYNpiEVhF/GQ11V4=; b=T9OHYtxuMVYzMXprMDavI7kUo53194cqI2Zqz3q/HlbUh8hsmHaORDs8XUs35xmVriSjT43aI mviIcwwV8/4C/jiYMIBWOBB2ZsN+Dvlx1THrWRcWL8JUvtq0zXnD6gz 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 1b99180da288..70b20c5c7336 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.55.0 From nobody Sat Sep 26 08:38:52 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7EA94398F5; Thu, 3 Sep 2026 07:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788421620; cv=none; b=bxllHhuWVEwRLXIQqt8/UQrm/p95nF3DJYSLcg1PRk12iIO+BJDB72OtJPSo6p8W6TJRewqVZrYj2aPlAbXNYMCdfkYVskJ9e+nAl08ifYgQYx8Ptl1mNctOY4olYZhJCgXds+pU7AEPANWTeviqnTit5+MxThESDKHlW1Wc+pA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788421620; c=relaxed/simple; bh=cR6f72Tfcuz3QSyNNEltgA9XJez2MtCdr8UsBuCs8+M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OWlplg9pYiQOZcJha5s2H2TYbwHSnS7wzdTq1kYNYsCYT2L8k4HqDME3Frm6Qr3OHDaTK26kGz9v13+AmJSo0kWKq+nA/q6andaa/cTTlqwFv/7ki0PIt7OxGdO6uMXX9KpQoYVmtwOr8Zq//gGDDpV2Pjt4VKQa2oU1dZD/eno= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yatAfVui; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yEkP2wY7; arc=none smtp.client-ip=193.142.43.55 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.b="yatAfVui"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yEkP2wY7" 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=1788421617; 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=SL5wPnj8borcXzUO1qzOBq1eWT6u2thlTBhYgpzs9/Y=; b=yatAfVuirbklpD3FyReIw0vAzqXmxHRansse+Y9ipyzRWSQ+csWar6+AELYv+jWwiOaeXZ +5fxuwsSibM1PJyU2nEbdtuL4s++JzCSM2QcBAhMY/wFMEALFomPFQobzmzEYmbFfvtLli 57lu3UYHsvIPJb0cPjfpLCphuZZR08GaYXv6s0N/AQFZVgGveN8G5zTZDN5zoXOGizTKKq LubjXGHtwhOIJIp9OROGi1rGOciHUOW1pTrWntIWybcO2tgG/o1mlutVdsF+owPJAbKtz8 nG69xEvsz0lJYdaXbpyAIlrwRihba/INm96VFIrZNb35MA+KeaaO7oBzKwGDXw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1788421617; 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=SL5wPnj8borcXzUO1qzOBq1eWT6u2thlTBhYgpzs9/Y=; b=yEkP2wY7Rt2WlKV91o9jdnk9JRlhGqiJPXnrPDhN+MtBVWb5o89O/hkk+FZ5nsQrXGTFjh 5i5V3YN5UO8XuGAw== Date: Thu, 03 Sep 2026 09:46:52 +0200 Subject: [PATCH 3/4] rtc: lib: Implement time64_to_tm() in terms of time64_to_tm() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260903-time-time64-to-tm-v1-3-660be972adfc@linutronix.de> References: <20260903-time-time64-to-tm-v1-0-660be972adfc@linutronix.de> In-Reply-To: <20260903-time-time64-to-tm-v1-0-660be972adfc@linutronix.de> To: John Stultz , Thomas Gleixner , Stephen Boyd , Miroslav Lichvar , Alexandre Belloni 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=1788421614; l=4923; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=cR6f72Tfcuz3QSyNNEltgA9XJez2MtCdr8UsBuCs8+M=; b=UB2hO3nHk5ZLbpGzks+4GiEJFWhz1oKnhav6hzSO8rTNB4VWy2EhdtuDGsciDwIUT7gf0VYiu 1YB9fLlVH9NBAKx9/DnYigNIdAlI+mkny9AkAjATAY7KYwxccDHST1u 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.55.0 From nobody Sat Sep 26 08:38:52 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F14D43B3DE; Thu, 3 Sep 2026 07:46:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788421620; cv=none; b=WQYMAeqBMyENsfRC6gVMQ3PtqNNPsildm7S45FGkT8i2pIB2N4zxpxoGyI2Dd+UY3qbIbsZrtkXRoTA5Luvb0YNSPMbtjSfCLu5mtykkc9rx0fbj1cOX2D3D4dsQUn6vZ7ZXe0km1Jq1sokFp8s95HF5iuHpFV2WEw6KaADxT2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788421620; c=relaxed/simple; bh=Cl0NZ3XpAP7HfxvIn/bTq7M/efP9DEVbCTug8RKQaHo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ajl3w27wy9GCgUG7BmjnqN9Une0N2IVfrkWp936sy5hkP4re3jET3BT77XIFWFw+rCKNA/E1wP0V4TMQfh3W3e16lRrpWfo++YNvZe3nxToF+Pt2esFAiloFMlTHZj5YZ06Oog+RdM0bw3+UtEIOK+NhB9nZTGCZvnWGQTuIaD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Jkg2wMsO; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=SDDldus3; arc=none smtp.client-ip=193.142.43.55 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.b="Jkg2wMsO"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="SDDldus3" 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=1788421617; 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=Q4R5tcvzIFsy/xQEdT5mJzi52ucmMu7YwKbCKoveVzY=; b=Jkg2wMsON1/8sRsHupBIMCoTq1VdSzHs2k2xOHeUOKINR1ncXNjkfIIdqaiOU0YYKIM9eI Rsn60txv9ulKbO7czvGfTA15JEq59w300G5ED6Heu1KXRSLispFCwkSd5M3SZRifAGKdhc 7o6AmlR2gviSEIlSeDPUmJ23a/DY5clmzfxX3scSI0MvJ/eawC0YrejqYLZy1Bc71Wp+He 6vY+KNVOJBd6Oun+FuzrRA7dRIrtAph/tNcS+AKY5DGO0o3jGtr0hqiRwunfeSKJEJEufD 2muYuDjq6S7J5XD59LdjZtZDTd6DLWNdb6UpuqT/v10Q9YdfEANOd6RSJmZEOA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1788421617; 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=Q4R5tcvzIFsy/xQEdT5mJzi52ucmMu7YwKbCKoveVzY=; b=SDDldus3VjMAxc51eHRue8WDB6/ESlzEWc1vCDCABIyXMdJLvRRL1iwriK568nscg1Nz3E Gj/wOahpWKnlJhCw== Date: Thu, 03 Sep 2026 09:46:53 +0200 Subject: [PATCH 4/4] rtc: test: Remove test_rtc_lib.c Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260903-time-time64-to-tm-v1-4-660be972adfc@linutronix.de> References: <20260903-time-time64-to-tm-v1-0-660be972adfc@linutronix.de> In-Reply-To: <20260903-time-time64-to-tm-v1-0-660be972adfc@linutronix.de> To: John Stultz , Thomas Gleixner , Stephen Boyd , Miroslav Lichvar , Alexandre Belloni 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=1788421614; l=4664; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=Cl0NZ3XpAP7HfxvIn/bTq7M/efP9DEVbCTug8RKQaHo=; b=BEdoLpCuJtsb3Ws4e141oeIV3LFNIv1TrQqDxWSijM/RkDSdN3Cylx1rtWb42fngJYqFmBSdf HCVvTxVlXZRArJiOycJBG4piURungwmhy+s7MCqJ04KkOe8vNuBcGzn 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 05b9233b9418..b507ed2f10e7 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -75,15 +75,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 0347645b021f..a3b336432df1 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.55.0