linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/12] rtc: handle alarms with a minute resolution
@ 2021-11-07 22:54 Alexandre Belloni
  2021-11-07 22:54 ` [PATCH 02/12] rtc: s35390a: let the core handle the alarm resolution Alexandre Belloni
                   ` (10 more replies)
  0 siblings, 11 replies; 13+ messages in thread
From: Alexandre Belloni @ 2021-11-07 22:54 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni; +Cc: linux-rtc, linux-kernel

Handle alarms with a minute resolution in the core. Until now drivers have
been open coding the seconds part removal and have been doing that wrongly.
Most of them are rounding up which means the allow the system to miss
deadlines. So, round down and let __rtc_set_alarm return immediately if the
time has already passed.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/interface.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index d005623e6eb3..d8e835798153 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -423,6 +423,7 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 	if (err)
 		return err;
 	now = rtc_tm_to_time64(&tm);
+
 	if (scheduled <= now)
 		return -ETIME;
 	/*
@@ -447,6 +448,7 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 
 int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 {
+	ktime_t alarm_time;
 	int err;
 
 	if (!rtc->ops)
@@ -468,7 +470,15 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 	if (rtc->aie_timer.enabled)
 		rtc_timer_remove(rtc, &rtc->aie_timer);
 
-	rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time);
+	alarm_time = rtc_tm_to_ktime(alarm->time);
+	/*
+	 * Round down so we never miss a deadline, checking for past deadline is
+	 * done in __rtc_set_alarm
+	 */
+	if (test_bit(RTC_FEATURE_ALARM_RES_MINUTE, rtc->features))
+		alarm_time = ktime_sub_ns(alarm_time, (u64)alarm->time.tm_sec * NSEC_PER_SEC);
+
+	rtc->aie_timer.node.expires = alarm_time;
 	rtc->aie_timer.period = 0;
 	if (alarm->enabled)
 		err = rtc_timer_enqueue(rtc, &rtc->aie_timer);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-11-09 11:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-07 22:54 [PATCH 01/12] rtc: handle alarms with a minute resolution Alexandre Belloni
2021-11-07 22:54 ` [PATCH 02/12] rtc: s35390a: let the core handle the alarm resolution Alexandre Belloni
2021-11-07 22:54 ` [PATCH 03/12] rtc: rv3032: " Alexandre Belloni
2021-11-07 22:54 ` [PATCH 04/12] rtc: ab-eoz9: use RTC_FEATURE_UPDATE_INTERRUPT Alexandre Belloni
2021-11-07 22:54 ` [PATCH 05/12] rtc: ab-eoz9: support UIE when available Alexandre Belloni
2021-11-07 22:54 ` [PATCH 06/12] rtc: ab8500: let the core handle the alarm resolution Alexandre Belloni
2021-11-09 11:47   ` Linus Walleij
2021-11-07 22:54 ` [PATCH 07/12] rtc: rx8025: switch to devm_rtc_allocate_device Alexandre Belloni
2021-11-07 22:54 ` [PATCH 08/12] rtc: rx8025: let the core handle the alarm resolution Alexandre Belloni
2021-11-07 22:54 ` [PATCH 09/12] rtc: rx8025: set range Alexandre Belloni
2021-11-07 22:54 ` [PATCH 10/12] rtc: rx8025: clear RTC_FEATURE_ALARM when alarm are not supported Alexandre Belloni
2021-11-07 22:54 ` [PATCH 11/12] rtc: rx8025: use rtc_add_group Alexandre Belloni
2021-11-07 22:54 ` [PATCH 12/12] rtc: rx8025: use .set_offset/.read_offset Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).