Todd Poynor | 9 Aug 2012 09:37
Picon
Favicon

[PATCH] alarmtimer: implement minimum alarm interval for allowing suspend

alarmtimer suspend return -EBUSY if the next alarm will fire in less
than 2 seconds.  This allows one RTC seconds tick to occur subsequent
to this check before the alarm wakeup time is set, ensuring the wakeup
time is still in the future (assuming the RTC does not tick one more
second prior to setting the alarm).

If suspend is rejected due to an imminent alarm, hold a wakeup source
for 2 seconds to process the alarm prior to reattempting suspend.

If setting the alarm incurs an -ETIME for an alarm set in the past,
or any other problem setting the alarm, abort suspend and hold a
wakelock for 1 second while the alarm is allowed to be serviced or
other hopefully transient conditions preventing the alarm clear up.

Signed-off-by: Todd Poynor <toddpoynor <at> google.com>
---
 kernel/time/alarmtimer.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index aa27d39..f979d85 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
 <at>  <at>  -46,6 +46,8  <at>  <at>  static struct alarm_base {
 static ktime_t freezer_delta;
 static DEFINE_SPINLOCK(freezer_delta_lock);

+static struct wakeup_source *ws;
+
 #ifdef CONFIG_RTC_CLASS
(Continue reading)

Rafael J. Wysocki | 9 Aug 2012 11:31
Picon
Gravatar

Re: [PATCH] alarmtimer: implement minimum alarm interval for allowing suspend

On Thursday, August 09, 2012, Todd Poynor wrote:
> alarmtimer suspend return -EBUSY if the next alarm will fire in less
> than 2 seconds.  This allows one RTC seconds tick to occur subsequent
> to this check before the alarm wakeup time is set, ensuring the wakeup
> time is still in the future (assuming the RTC does not tick one more
> second prior to setting the alarm).
> 
> If suspend is rejected due to an imminent alarm, hold a wakeup source
> for 2 seconds to process the alarm prior to reattempting suspend.
> 
> If setting the alarm incurs an -ETIME for an alarm set in the past,
> or any other problem setting the alarm, abort suspend and hold a
> wakelock for 1 second while the alarm is allowed to be serviced or
> other hopefully transient conditions preventing the alarm clear up.
> 
> Signed-off-by: Todd Poynor <toddpoynor <at> google.com>
> ---
>  kernel/time/alarmtimer.c |   18 +++++++++++++-----
>  1 files changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
> index aa27d39..f979d85 100644
> --- a/kernel/time/alarmtimer.c
> +++ b/kernel/time/alarmtimer.c
>  <at>  <at>  -46,6 +46,8  <at>  <at>  static struct alarm_base {
>  static ktime_t freezer_delta;
>  static DEFINE_SPINLOCK(freezer_delta_lock);
>  
> +static struct wakeup_source *ws;
> +
(Continue reading)

John Stultz | 9 Aug 2012 23:06
Favicon

Re: [PATCH] alarmtimer: implement minimum alarm interval for allowing suspend

On 08/09/2012 12:37 AM, Todd Poynor wrote:
>  <at>  <at>  -288,9 +293,11  <at>  <at>  static int alarmtimer_suspend(struct device *dev)
>   	now = rtc_tm_to_ktime(tm);
>   	now = ktime_add(now, min);
>
> -	rtc_timer_start(rtc, &rtctimer, now, ktime_set(0, 0));
> -
> -	return 0;
> +	/* Set alarm, if in the past reject suspend briefly to handle */
> +	ret = rtc_timer_start(rtc, &rtctimer, now, ktime_set(0, 0));
> +	if (ret < 0)
> +		__pm_wakeup_event(ws, 1 * MSEC_PER_SEC);
> +	return ret;

What if something other then -ETIME  is returned from rtc_timer_start?

thanks
-john

John Stultz | 9 Aug 2012 23:09
Picon
Favicon

Re: [PATCH] alarmtimer: implement minimum alarm interval for allowing suspend

On 08/09/2012 02:06 PM, John Stultz wrote:
> On 08/09/2012 12:37 AM, Todd Poynor wrote:
>>  <at>  <at>  -288,9 +293,11  <at>  <at>  static int alarmtimer_suspend(struct device *dev)
>>       now = rtc_tm_to_ktime(tm);
>>       now = ktime_add(now, min);
>>
>> -    rtc_timer_start(rtc, &rtctimer, now, ktime_set(0, 0));
>> -
>> -    return 0;
>> +    /* Set alarm, if in the past reject suspend briefly to handle */
>> +    ret = rtc_timer_start(rtc, &rtctimer, now, ktime_set(0, 0));
>> +    if (ret < 0)
>> +        __pm_wakeup_event(ws, 1 * MSEC_PER_SEC);
>> +    return ret;
>
> What if something other then -ETIME  is returned from rtc_timer_start?

Bah, sorry, too fast on the trigger there (enlightenment somehow only 
comes with clicking the send button).
I see the wakeup_source will expire after a second and the next suspend 
can try again.

thanks
-john

John Stultz | 9 Aug 2012 23:27
Favicon

Re: [PATCH] alarmtimer: implement minimum alarm interval for allowing suspend

On 08/09/2012 12:37 AM, Todd Poynor wrote:
> alarmtimer suspend return -EBUSY if the next alarm will fire in less
> than 2 seconds.  This allows one RTC seconds tick to occur subsequent
> to this check before the alarm wakeup time is set, ensuring the wakeup
> time is still in the future (assuming the RTC does not tick one more
> second prior to setting the alarm).
>
> If suspend is rejected due to an imminent alarm, hold a wakeup source
> for 2 seconds to process the alarm prior to reattempting suspend.
>
> If setting the alarm incurs an -ETIME for an alarm set in the past,
> or any other problem setting the alarm, abort suspend and hold a
> wakelock for 1 second while the alarm is allowed to be serviced or
> other hopefully transient conditions preventing the alarm clear up.
>
> Signed-off-by: Todd Poynor <toddpoynor <at> google.com>
> ---
>   kernel/time/alarmtimer.c |   18 +++++++++++++-----
>   1 files changed, 13 insertions(+), 5 deletions(-)

Thanks for sending this in!
I've gone ahead and queued it for 3.7 (with the minor tweak Rafael 
suggested). I'll try to do some further testing of the edge case this 
handles as well.

thanks again,
-john

Arve Hjønnevåg | 10 Aug 2012 01:41
Favicon

Re: [PATCH] alarmtimer: implement minimum alarm interval for allowing suspend

On Thu, Aug 9, 2012 at 2:27 PM, John Stultz <john.stultz <at> linaro.org> wrote:
> On 08/09/2012 12:37 AM, Todd Poynor wrote:
>>
>> alarmtimer suspend return -EBUSY if the next alarm will fire in less
>> than 2 seconds.  This allows one RTC seconds tick to occur subsequent
>> to this check before the alarm wakeup time is set, ensuring the wakeup
>> time is still in the future (assuming the RTC does not tick one more
>> second prior to setting the alarm).
>>
>> If suspend is rejected due to an imminent alarm, hold a wakeup source
>> for 2 seconds to process the alarm prior to reattempting suspend.
>>
>> If setting the alarm incurs an -ETIME for an alarm set in the past,
>> or any other problem setting the alarm, abort suspend and hold a
>> wakelock for 1 second while the alarm is allowed to be serviced or
>> other hopefully transient conditions preventing the alarm clear up.
>>
>> Signed-off-by: Todd Poynor <toddpoynor <at> google.com>
>> ---
>>   kernel/time/alarmtimer.c |   18 +++++++++++++-----
>>   1 files changed, 13 insertions(+), 5 deletions(-)
>
>
> Thanks for sending this in!
> I've gone ahead and queued it for 3.7 (with the minor tweak Rafael
> suggested). I'll try to do some further testing of the edge case this
> handles as well.
>

You may want to add a wakeupsource to the rtc_timer interface as well.
(Continue reading)


Gmane