From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Michael <michael@mipisi.de>
Cc: linux-rtc@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>,
John Stultz <john.stultz@linaro.org>,
Stephen Boyd <sboyd@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: Problem when function alarmtimer_suspend returns 0 if time delta is zero
Date: Mon, 2 Sep 2019 09:49:17 +0200 [thread overview]
Message-ID: <20190902074917.GA21922@piout.net> (raw)
In-Reply-To: <08fbdf25-faa1-aa13-4f13-d30acbf27dda@mipisi.de>
Hello Michael,
This code is maintained by the timekeeping maintainers, now in Cc and I
think John will be able to answer.
On 31/08/2019 20:32:06+0200, Michael wrote:
> Dear members of the linux-rtc list,
>
> currently I have a problem with the alarmtimer i'm using to cyclically wake
> up my i.MX6 ULL board from suspend to RAM.
>
> The problem is that in principle the timer wake ups work fine but seem to be
> not 100% stable. In about 1 percent the wake up alarm from suspend is
> missing.
>
> When I look at the code of alarmtimer in function alarmtimer_suspend
> (kernel/time/alarmtimer.c)
> I find the following:
>
> ....
>
> /* Find the soonest timer to expire*/
>
> for (i = 0; i < ALARM_NUMTYPE; i++) {
> struct alarm_base *base = &alarm_bases[i];
> struct timerqueue_node *next;
> ktime_t delta;
>
> spin_lock_irqsave(&base->lock, flags);
> next = timerqueue_getnext(&base->timerqueue);
> spin_unlock_irqrestore(&base->lock, flags);
> if (!next)
> continue;
> delta = ktime_sub(next->expires, base->gettime());
> if (!min || (delta < min)) {
> expires = next->expires;
> min = delta;
> type = i;
> }
> }
> if (min == 0)
> return 0;
>
> if (ktime_to_ns(min) < 2 * NSEC_PER_SEC) {
> __pm_wakeup_event(ws, 2 * MSEC_PER_SEC);
> return -EBUSY;
> }
>
> In my error case the alarm wake up always fails if the path "if(min==0)" is
> entered. If I understand this code correctly that means that
> when ever one of the timers in the list has a remaining tick time of zero,
> the function just returns 0 and continues the suspend process until
> it reaches suspend mode.
>
> If I implement a hack here "if(min == 0) {min = 1;}" and do not return, my
> system runs 100% ok, as the following -EBUSY path is hit.
>
> So my question to you is: Why is there a check if min < 2 seconds and do a
> return -EBUSY here, but handle (min==0) differently?
> Could there be some race condition here, where the function
> alarmtimer_suspend just returns 0 and shortly after this the alarmtimer
> expires
> right before the RTC driver was able to allow the wake up interrupt?
>
> If I look through the kernel versions I found the alarmtimer_suspend to be a
> very stable function, so I don't think there is anything wrong here.
>
> But do you have a hint for me where else I could have a look to encircle the
> error?
>
> Thank you very much!
>
> Br,
> Michael
>
--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2019-09-02 7:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <S1728511AbfHaSEm/20190831180442Z+580@vger.kernel.org>
2019-08-31 18:32 ` Problem when function alarmtimer_suspend returns 0 if time delta is zero Michael
2019-09-02 7:49 ` Alexandre Belloni [this message]
2019-09-02 10:57 ` Thomas Gleixner
2019-09-03 18:48 ` Michael
2019-09-03 22:49 ` Thomas Gleixner
2023-02-08 15:23 ` Michael Trimarchi
2023-02-08 18:06 ` Thomas Gleixner
2023-02-09 11:19 ` Michael Nazzareno Trimarchi
2023-02-09 15:40 ` Thomas Gleixner
2023-02-11 1:04 ` John Stultz
2023-02-11 1:18 ` John Stultz
2023-02-11 6:25 ` Michael Nazzareno Trimarchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190902074917.GA21922@piout.net \
--to=alexandre.belloni@bootlin.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=michael@mipisi.de \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).