Skip to contentSkip to conversation

rtc: proc/sysfs: read actual alarm time from hardware

RFC PATCH New Christoph Fritz 1 participant 1 message Jan 25, 2021 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 rtc: proc/sysfs: read actual alarm time from hardware

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(-)
drivers/rtc/proc.c +1 -1
index 73344598fc1b..79f7969f9867 100644
@@ -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);
drivers/rtc/sysfs.c +1 -1
index 8a957d31a1a4..bb49c3544c2c 100644
@@ -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);
Signature · 1 line
2.29.2