* [RFC][PATCH] rtc: proc/sysfs: read actual alarm time from hardware
@ 2021-01-25 17:17 Christoph Fritz
0 siblings, 0 replies; only message in thread
From: Christoph Fritz @ 2021-01-25 17:17 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni; +Cc: linux-rtc
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 --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);
--
2.29.2
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-25 17:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25 17:17 [RFC][PATCH] rtc: proc/sysfs: read actual alarm time from hardware Christoph Fritz
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).