rtc: interface: skip the RTC read in rtc_timer_do_work() on an empty queue
PATCH 1/1 rtc: interface: skip the RTC read in rtc_timer_do_work() on an empty queue
From: Li RongQing <[email protected]>
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.
--- drivers/rtc/interface.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/rtc/interface.c +5 -0
@@ -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) {
Signature · 1 line
2.9.4
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 11 lines
From: Li RongQing <[email protected]>
After
rtc_set_time(), the RTC core schedulesrtc->irqworkto 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.
Quoted 4 lines
Check whether the timer queue is empty under
ops_lockbefore reading the RTC. If it is empty, release the lock and return immediately.Signed-off-by Li RongQing <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1