Linux RTC
 help / color / mirror / Atom feed
* [PATCH] rtc: interface: skip the RTC read in rtc_timer_do_work() on an empty queue
@ 2026-11-05  7:37 lirongqing
  2026-11-05  7:47 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: lirongqing @ 2026-11-05  7:37 UTC (permalink / raw)
  To: Alexandre Belloni, linux-rtc, linux-kernel; +Cc: Li RongQing

From: Li RongQing <lirongqing@baidu.com>

After rtc_set_time(), the RTC core schedules rtc->irqwork to re-read
the clock and reprocess the timer queue.

When the timer queue is empty, there is no timer to expire and no
next alarm to program, so reading the RTC is unnecessary. However,
an RTC read can take up to 3ms on some systems, blocking the CPU for
a significant amount of time. Even on faster systems, it can still
take around 50us.

Check whether the timer queue is empty under ops_lock before reading
the RTC. If it is empty, release the lock and return immediately.

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 drivers/rtc/interface.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 96626f8..a65b594 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -977,6 +977,11 @@ void rtc_timer_do_work(struct work_struct *work)
 		container_of(work, struct rtc_device, irqwork);
 
 	mutex_lock(&rtc->ops_lock);
+	if (!timerqueue_getnext(&rtc->timerqueue)) {
+		pm_relax(rtc->dev.parent);
+		mutex_unlock(&rtc->ops_lock);
+		return;
+	}
 again:
 	err = __rtc_read_time(rtc, &tm);
 	if (err) {
-- 
2.9.4


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

* Re: [PATCH] rtc: interface: skip the RTC read in rtc_timer_do_work() on an empty queue
  2026-11-05  7:37 [PATCH] rtc: interface: skip the RTC read in rtc_timer_do_work() on an empty queue lirongqing
@ 2026-11-05  7:47 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-05  7:47 UTC (permalink / raw)
  To: lirongqing, linux-rtc; +Cc: Alexandre Belloni

> From: Li RongQing <lirongqing@baidu.com>
> 
> After rtc_set_time(), the RTC core schedules rtc->irqwork to re-read
> the clock and reprocess the timer queue.
> 
> When the timer queue is empty, there is no timer to expire and no
> next alarm to program, so reading the RTC is unnecessary. However,
> an RTC read can take up to 3ms on some systems, blocking the CPU for
> a significant amount of time. Even on faster systems, it can still
> take around 50us.
> 
> Check whether the timer queue is empty under ops_lock before reading
> the RTC. If it is empty, release the lock and return immediately.
> 
> Signed-off-by: Li RongQing <lirongqing@baidu.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261105073742.2193-1-lirongqing@baidu.com?part=1


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

end of thread, other threads:[~2026-11-05  7:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-05  7:37 [PATCH] rtc: interface: skip the RTC read in rtc_timer_do_work() on an empty queue lirongqing
2026-11-05  7:47 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox