diff mbox series

[RFC] rtc: proc/sysfs: read actual alarm time from hardware

Message ID 9a4ff4654151823316f565adf9d651ccd39806a0.camel@googlemail.com
State New
Headers show
Series [RFC] rtc: proc/sysfs: read actual alarm time from hardware | expand

Commit Message

Christoph Fritz Jan. 25, 2021, 5:17 p.m. UTC
Show actual alarm time from hardware by using __rtc_read_alarm()
instead of rtc_read_alarm() because some hardware does not support
secounds and is therefore rounding up actually.

Test, set an alarm in 20 secounds:
    w="/sys/class/rtc/rtc0/wakealarm"; now=$(date +%s); \
    t=20; alarm=$(expr $now + $t); \
    echo 0 > $w; echo $alarm > $w; \
    echo $now; cat $w; \
    echo -n "off by: "; expr $(cat $w) - $now - 20

Test result without this patch applied:
    1579972610
    1579972630
    off by: 0

Test result with applied patch:
    1579972543
    1579972620
    off by: 57
---
My question here is: Should /proc/driver/rtc and
/sys/class/rtc/rtc0/wakealarm show the actual alarm time from hardware
or the alarm time set by the user? There may be other implications?
---
 drivers/rtc/proc.c  | 2 +-
 drivers/rtc/sysfs.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/rtc/proc.c b/drivers/rtc/proc.c
index 73344598fc1b..79f7969f9867 100644
--- a/drivers/rtc/proc.c
+++ b/drivers/rtc/proc.c
@@ -52,7 +52,7 @@  static int rtc_proc_show(struct seq_file *seq, void *offset)
 			   &tm, &tm);
 	}
 
-	err = rtc_read_alarm(rtc, &alrm);
+	err = __rtc_read_alarm(rtc, &alrm);
 	if (err == 0) {
 		seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time);
 		seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time);
diff --git a/drivers/rtc/sysfs.c b/drivers/rtc/sysfs.c
index 8a957d31a1a4..bb49c3544c2c 100644
--- a/drivers/rtc/sysfs.c
+++ b/drivers/rtc/sysfs.c
@@ -138,7 +138,7 @@  wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf)
 	 * exact YYYY-MM-DD HH:MM[:SS] date *must* disable their RTC
 	 * alarms after they trigger, to ensure one-shot semantics.
 	 */
-	retval = rtc_read_alarm(to_rtc_device(dev), &alm);
+	retval = __rtc_read_alarm(to_rtc_device(dev), &alm);
 	if (retval == 0 && alm.enabled) {
 		alarm = rtc_tm_to_time64(&alm.time);
 		retval = sprintf(buf, "%lld\n", alarm);