All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] alarmtimer: fix unexpected rtc interrupt when system resume from S3
@ 2015-11-17 12:08 zhuo-hao.lee
  2015-11-20 19:29 ` John Stultz
  0 siblings, 1 reply; 5+ messages in thread
From: zhuo-hao.lee @ 2015-11-17 12:08 UTC (permalink / raw)
  To: Thomas Gleixner, John Stultz; +Cc: linux-kernel, zhuohao.lee82

From: zhuo-hao <zhuo-hao.lee@intel.com>

Before the system go to suspend (S3), if user create a timer with clockid
CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM and set a "large" timeout value
to this timer. The function alarmtimer_suspend will be called to setup
a timeout value to RTC timer to avoid the system sleep over time. However,
if the system wakeup early than RTC timeout, the RTC timer will not be cleared.
And this will cause the hpet_rtc_interrupt come unexpectedly until the RTC
timeout. To fix this problem, just adding alarmtimer_resume to cancel the
RTC timer.

This was noticed because the HPET RTC emulation fires an interrupt every
16ms(=1/2^DEFAULT_RTC_SHIFT) up to the point where the alarm time is reached.
This program always hits this situation(https://lkml.org/lkml/2015/11/8/326),
if system wake up earlier than alarm time.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Signed-off-by: Zhuo-hao Lee <zhuo-hao.lee@intel.com>
---
 kernel/time/alarmtimer.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 7fbba63..e840ed8 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -271,11 +271,27 @@ static int alarmtimer_suspend(struct device *dev)
 		__pm_wakeup_event(ws, MSEC_PER_SEC);
 	return ret;
 }
+
+static int alarmtimer_resume(struct device *dev)
+{
+	struct rtc_device *rtc;
+
+	rtc = alarmtimer_get_rtcdev();
+	if (rtc)
+		rtc_timer_cancel(rtc, &rtctimer);
+	return 0;
+}
+
 #else
 static int alarmtimer_suspend(struct device *dev)
 {
 	return 0;
 }
+
+static int alarmtimer_resume(struct device *dev)
+{
+	return 0;
+}
 #endif
 
 static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type)
@@ -800,6 +816,7 @@ out:
 /* Suspend hook structures */
 static const struct dev_pm_ops alarmtimer_pm_ops = {
 	.suspend = alarmtimer_suspend,
+	.resume = alarmtimer_resume,
 };
 
 static struct platform_driver alarmtimer_driver = {
-- 
2.1.2


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

* Re: [PATCH v3] alarmtimer: fix unexpected rtc interrupt when system resume from S3
  2015-11-17 12:08 [PATCH v3] alarmtimer: fix unexpected rtc interrupt when system resume from S3 zhuo-hao.lee
@ 2015-11-20 19:29 ` John Stultz
  2015-11-23  1:57   ` Lee, Zhuo-hao
  2015-11-25 14:25   ` Thomas Gleixner
  0 siblings, 2 replies; 5+ messages in thread
From: John Stultz @ 2015-11-20 19:29 UTC (permalink / raw)
  To: zhuo-hao.lee; +Cc: Thomas Gleixner, lkml, zhuohao.lee82

On Tue, Nov 17, 2015 at 4:08 AM,  <zhuo-hao.lee@intel.com> wrote:
> From: zhuo-hao <zhuo-hao.lee@intel.com>
>
> Before the system go to suspend (S3), if user create a timer with clockid
> CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM and set a "large" timeout value
> to this timer. The function alarmtimer_suspend will be called to setup
> a timeout value to RTC timer to avoid the system sleep over time. However,
> if the system wakeup early than RTC timeout, the RTC timer will not be cleared.
> And this will cause the hpet_rtc_interrupt come unexpectedly until the RTC
> timeout. To fix this problem, just adding alarmtimer_resume to cancel the
> RTC timer.
>
> This was noticed because the HPET RTC emulation fires an interrupt every
> 16ms(=1/2^DEFAULT_RTC_SHIFT) up to the point where the alarm time is reached.
> This program always hits this situation(https://lkml.org/lkml/2015/11/8/326),
> if system wake up earlier than alarm time.

So thanks for the extra context here, and again I don't have an
objection to this patch.

Although from the earlier discussion it still isn't quite clear to me:
Why must the HPET RTC emulation need to fire the alarm every 16ms? Is
that not something that can be fixed?

I just want to make sure we're not hiding a deeper issue.

thanks
-john

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

* RE: [PATCH v3] alarmtimer: fix unexpected rtc interrupt when system resume from S3
  2015-11-20 19:29 ` John Stultz
@ 2015-11-23  1:57   ` Lee, Zhuo-hao
  2015-11-25 14:25   ` Thomas Gleixner
  1 sibling, 0 replies; 5+ messages in thread
From: Lee, Zhuo-hao @ 2015-11-23  1:57 UTC (permalink / raw)
  To: John Stultz; +Cc: Thomas Gleixner, lkml, zhuohao.lee82

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 1670 bytes --]

>Although from the earlier discussion it still isn't quite clear to me:
>Why must the HPET RTC emulation need to fire the alarm every 16ms? Is that not something that can be fixed?

This is hpet driver's behavior. Please check the following comment which is copied from the file hpet.c

/* HPET in LegacyReplacement Mode eats up RTC interrupt line. When, HPET
 * is enabled, we support RTC interrupt functionality in software.
 * RTC has 3 kinds of interrupts:
 * 1) Update Interrupt - generate an interrupt, every sec, when RTC clock
 *    is updated
 * 2) Alarm Interrupt - generate an interrupt at a specific time of day
 * 3) Periodic Interrupt - generate periodic interrupt, with frequencies
 *    2Hz-8192Hz (2Hz-64Hz for non-root user) (all freqs in powers of 2)
 * (1) and (2) above are implemented using polling at a frequency of
 * 64 Hz. The exact frequency is a tradeoff between accuracy and interrupt
 * overhead. (DEFAULT_RTC_INT_FREQ)
 * For (3), we use interrupts at 64Hz or user specified periodic
 * frequency, whichever is higher.
 */
 
The alarm interrupt have a frequency of 64Hz. This is a tradeoff between accuracy and interrupt overhead. 
So that, I think 16ms(1/64s) interrupt is expected unless we change the driver's design.
However, changing the driver's behavior is a huge modification. This driver already exists for a long time
(starting from  commit id :1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 or ealier).
So, I tend not to modify this driver's behavior.

Thanks
Lee, Zhuo-hao
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

* Re: [PATCH v3] alarmtimer: fix unexpected rtc interrupt when system resume from S3
  2015-11-20 19:29 ` John Stultz
  2015-11-23  1:57   ` Lee, Zhuo-hao
@ 2015-11-25 14:25   ` Thomas Gleixner
  2015-11-25 21:47     ` John Stultz
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas Gleixner @ 2015-11-25 14:25 UTC (permalink / raw)
  To: John Stultz; +Cc: zhuo-hao.lee, lkml, zhuohao.lee82

On Fri, 20 Nov 2015, John Stultz wrote:

> On Tue, Nov 17, 2015 at 4:08 AM,  <zhuo-hao.lee@intel.com> wrote:
> > From: zhuo-hao <zhuo-hao.lee@intel.com>
> >
> > Before the system go to suspend (S3), if user create a timer with clockid
> > CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM and set a "large" timeout value
> > to this timer. The function alarmtimer_suspend will be called to setup
> > a timeout value to RTC timer to avoid the system sleep over time. However,
> > if the system wakeup early than RTC timeout, the RTC timer will not be cleared.
> > And this will cause the hpet_rtc_interrupt come unexpectedly until the RTC
> > timeout. To fix this problem, just adding alarmtimer_resume to cancel the
> > RTC timer.
> >
> > This was noticed because the HPET RTC emulation fires an interrupt every
> > 16ms(=1/2^DEFAULT_RTC_SHIFT) up to the point where the alarm time is reached.
> > This program always hits this situation(https://lkml.org/lkml/2015/11/8/326),
> > if system wake up earlier than alarm time.
> 
> So thanks for the extra context here, and again I don't have an
> objection to this patch.
> 
> Although from the earlier discussion it still isn't quite clear to me:
> Why must the HPET RTC emulation need to fire the alarm every 16ms? Is
> that not something that can be fixed?

We probably can fix it with some surgery. OTOH that stuff is fragile
as hell and I rather avoid touching it, but I won't hinder someone
brave enough doing it :)
 
> I just want to make sure we're not hiding a deeper issue.

It's not a deeper issue. It's a - admittedly dumb - implementation
detail.

Thanks,

	tglx

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

* Re: [PATCH v3] alarmtimer: fix unexpected rtc interrupt when system resume from S3
  2015-11-25 14:25   ` Thomas Gleixner
@ 2015-11-25 21:47     ` John Stultz
  0 siblings, 0 replies; 5+ messages in thread
From: John Stultz @ 2015-11-25 21:47 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: zhuo-hao.lee, lkml, Zhuohao Lee

On Wed, Nov 25, 2015 at 6:25 AM, Thomas Gleixner <tglx@linutronix.de> wrote:
> On Fri, 20 Nov 2015, John Stultz wrote:
>
>> On Tue, Nov 17, 2015 at 4:08 AM,  <zhuo-hao.lee@intel.com> wrote:
>> > From: zhuo-hao <zhuo-hao.lee@intel.com>
>> >
>> > Before the system go to suspend (S3), if user create a timer with clockid
>> > CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM and set a "large" timeout value
>> > to this timer. The function alarmtimer_suspend will be called to setup
>> > a timeout value to RTC timer to avoid the system sleep over time. However,
>> > if the system wakeup early than RTC timeout, the RTC timer will not be cleared.
>> > And this will cause the hpet_rtc_interrupt come unexpectedly until the RTC
>> > timeout. To fix this problem, just adding alarmtimer_resume to cancel the
>> > RTC timer.
>> >
>> > This was noticed because the HPET RTC emulation fires an interrupt every
>> > 16ms(=1/2^DEFAULT_RTC_SHIFT) up to the point where the alarm time is reached.
>> > This program always hits this situation(https://lkml.org/lkml/2015/11/8/326),
>> > if system wake up earlier than alarm time.
>>
>> So thanks for the extra context here, and again I don't have an
>> objection to this patch.
>>
>> Although from the earlier discussion it still isn't quite clear to me:
>> Why must the HPET RTC emulation need to fire the alarm every 16ms? Is
>> that not something that can be fixed?
>
> We probably can fix it with some surgery. OTOH that stuff is fragile
> as hell and I rather avoid touching it, but I won't hinder someone
> brave enough doing it :)
>
>> I just want to make sure we're not hiding a deeper issue.
>
> It's not a deeper issue. It's a - admittedly dumb - implementation
> detail.

Fair enough.. I've got it queued up for testing.

thanks
-john

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

end of thread, other threads:[~2015-11-25 21:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17 12:08 [PATCH v3] alarmtimer: fix unexpected rtc interrupt when system resume from S3 zhuo-hao.lee
2015-11-20 19:29 ` John Stultz
2015-11-23  1:57   ` Lee, Zhuo-hao
2015-11-25 14:25   ` Thomas Gleixner
2015-11-25 21:47     ` John Stultz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.