Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752016AbdIUGpu (ORCPT ); Thu, 21 Sep 2017 02:45:50 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6946 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751811AbdIUGps (ORCPT ); Thu, 21 Sep 2017 02:45:48 -0400 Subject: Re: [PATCH] rtc: interface: set the next alarm event appropriately To: Alexandre Belloni References: <1505877751-26566-1-git-send-email-xuyiping@hisilicon.com> <20170920091617.j7sie3mrncjkcj3m@piout.net> CC: , , , , , From: YiPing Xu Message-ID: Date: Thu, 21 Sep 2017 14:45:17 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170920091617.j7sie3mrncjkcj3m@piout.net> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.184.212.206] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.59C36004.00F6,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: d0582bc7581bfa18a34f0b8dbbd168b3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2078 Lines: 66 On 2017/9/20 17:16, Alexandre Belloni wrote: > Hi, > > On 20/09/2017 at 11:22:31 +0800, Xu Yiping wrote: >> From: Xu YiPing >> >> After commit 2b2f5ff00f63 ("rtc: interface: ignore expired timers when >> enqueuing new timers"), the rtc_timer_enqueue will not reprogram the RTC >> when there is any non-expired timers in the timerqueue. If we set a >> RTC_TIMER between now and the next non-expired timers, it won't go into >> effect in time. >> >> So, besides ignoring the expired timers, we should take the next effect >> timer into account, and reprogram the RTC timer appropriately. >> > > Can you try this patch instead? I think it solves this issue: > http://patchwork.ozlabs.org/patch/792482/ We've tested this patch, it works too. Will it be merged into the main tree? >> Signed-off-by: Xu YiPing >> Signed-off-by: Chen Jun >> --- >> drivers/rtc/interface.c | 9 ++++++--- >> 1 file changed, 6 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c >> index 8cec9a0..e237166 100644 >> --- a/drivers/rtc/interface.c >> +++ b/drivers/rtc/interface.c >> @@ -766,20 +766,23 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer) >> struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue); >> struct rtc_time tm; >> ktime_t now; >> + ktime_t next_effect = KTIME_MAX; >> >> timer->enabled = 1; >> __rtc_read_time(rtc, &tm); >> now = rtc_tm_to_ktime(tm); >> >> - /* Skip over expired timers */ >> + /* Skip over expired timers, get next effect timer */ >> while (next) { >> - if (next->expires >= now) >> + if (next->expires >= now) { >> + next_effect = next->expires; >> break; >> + } >> next = timerqueue_iterate_next(next); >> } >> >> timerqueue_add(&rtc->timerqueue, &timer->node); >> - if (!next) { >> + if (timer->node.expires < next_effect) { >> struct rtc_wkalrm alarm; >> int err; >> alarm.time = rtc_ktime_to_tm(timer->node.expires); >> -- >> 2.7.4 >> >