linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] some preparations for suspend on G5 powermac
@ 2006-12-13 12:38 Johannes Berg
  2006-12-13 12:38 ` [PATCH 1/3] windfarm: dont die on suspend thread signal Johannes Berg
                   ` (2 more replies)
  0 siblings, 3 replies; 36+ messages in thread
From: Johannes Berg @ 2006-12-13 12:38 UTC (permalink / raw)
  To: linuxppc-dev

These are some patches that I think are safe to apply now and I need them
for suspend on the powermac.

johannes

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

* [PATCH 1/3] windfarm: dont die on suspend thread signal
  2006-12-13 12:38 [PATCH 0/3] some preparations for suspend on G5 powermac Johannes Berg
@ 2006-12-13 12:38 ` Johannes Berg
  2007-01-24  6:32   ` Benjamin Herrenschmidt
  2006-12-13 12:38 ` [PATCH 2/3] powermac: proper time of day after resume Johannes Berg
  2006-12-13 12:38 ` [PATCH 3/3] powerpc: fix comment in kernel/irq.c Johannes Berg
  2 siblings, 1 reply; 36+ messages in thread
From: Johannes Berg @ 2006-12-13 12:38 UTC (permalink / raw)
  To: linuxppc-dev

When the windfarm thread gets a suspend signal it will die instead of
freezing. This fixes it.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>

--- linux-2.6-git.orig/drivers/macintosh/windfarm_core.c	2006-12-11 23:34:47.082716759 +0100
+++ linux-2.6-git/drivers/macintosh/windfarm_core.c	2006-12-11 23:37:58.181716759 +0100
@@ -93,8 +93,6 @@ static int wf_thread_func(void *data)
 	DBG("wf: thread started\n");
 
 	while(!kthread_should_stop()) {
-		try_to_freeze();
-
 		if (time_after_eq(jiffies, next)) {
 			wf_notify(WF_EVENT_TICK, NULL);
 			if (wf_overtemp) {
@@ -117,8 +115,8 @@ static int wf_thread_func(void *data)
 		if (delay <= HZ)
 			schedule_timeout_interruptible(delay);
 
-		/* there should be no signal, but oh well */
-		if (signal_pending(current)) {
+		/* there should be no non-suspend signal, but oh well */
+		if (signal_pending(current) && !try_to_freeze()) {
 			printk(KERN_WARNING "windfarm: thread got sigl !\n");
 			break;
 		}

--

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

* [PATCH 2/3] powermac: proper time of day after resume
  2006-12-13 12:38 [PATCH 0/3] some preparations for suspend on G5 powermac Johannes Berg
  2006-12-13 12:38 ` [PATCH 1/3] windfarm: dont die on suspend thread signal Johannes Berg
@ 2006-12-13 12:38 ` Johannes Berg
  2007-01-24  6:34   ` Benjamin Herrenschmidt
  2006-12-13 12:38 ` [PATCH 3/3] powerpc: fix comment in kernel/irq.c Johannes Berg
  2 siblings, 1 reply; 36+ messages in thread
From: Johannes Berg @ 2006-12-13 12:38 UTC (permalink / raw)
  To: linuxppc-dev

This patch converts the time restore code from a PMU notifier to a regular
sys device so I can profit from it even when I don't suspend through the
PMU, i.e. suspend to disk.

Also another step towards dropping pmu_sleep_notifier completely.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>

---
Tested on my powermac with my suspend code there but not yet on the
powerbook.

It seems that this could be done in the generic instead of the arch
dependent code since we have a machine op for getting the boot time...
Should we?

--- linux-2.6-git.orig/arch/powerpc/platforms/powermac/time.c	2006-12-12 16:54:10.573639512 +0100
+++ linux-2.6-git/arch/powerpc/platforms/powermac/time.c	2006-12-12 16:54:16.805639512 +0100
@@ -298,36 +298,56 @@ int __init via_calibrate_decr(void)
 #endif
 
 #ifdef CONFIG_PM
+
+static unsigned long time_diff;
+
 /*
  * Reset the time after a sleep.
  */
-static int
-time_sleep_notify(struct pmu_sleep_notifier *self, int when)
+static int timer_resume(struct sys_device *dev)
+{
+	struct timespec tv;
+
+	tv.tv_sec = pmac_get_boot_time() + time_diff;
+	tv.tv_nsec = 0;
+	do_settimeofday(&tv);
+
+	return 0;
+}
+
+static int timer_suspend(struct sys_device *dev, pm_message_t state)
 {
-	static unsigned long time_diff;
 	unsigned long flags;
 	unsigned long seq;
-	struct timespec tv;
 
-	switch (when) {
-	case PBOOK_SLEEP_NOW:
-		do {
-			seq = read_seqbegin_irqsave(&xtime_lock, flags);
-			time_diff = xtime.tv_sec - pmac_get_boot_time();
-		} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
-		break;
-	case PBOOK_WAKE:
-		tv.tv_sec = pmac_get_boot_time() + time_diff;
-		tv.tv_nsec = 0;
-		do_settimeofday(&tv);
-		break;
-	}
-	return PBOOK_SLEEP_OK;
+	do {
+		seq = read_seqbegin_irqsave(&xtime_lock, flags);
+		time_diff = xtime.tv_sec - pmac_get_boot_time();
+	} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
+
+	return 0;
 }
 
-static struct pmu_sleep_notifier time_sleep_notifier = {
-	time_sleep_notify, SLEEP_LEVEL_MISC,
+static struct sysdev_class timer_sysclass = {
+	.resume = timer_resume,
+	.suspend = timer_suspend,
+	set_kset_name("timer"),
+};
+
+static struct sys_device device_timer = {
+	.id = 0,
+	.cls = &timer_sysclass,
 };
+
+static int time_init_device(void)
+{
+	int error = sysdev_class_register(&timer_sysclass);
+	if (!error)
+		error = sysdev_register(&device_timer);
+	return error;
+}
+
+device_initcall(time_init_device);
 #endif /* CONFIG_PM */
 
 /*
@@ -335,11 +355,6 @@ static struct pmu_sleep_notifier time_sl
  */
 void __init pmac_calibrate_decr(void)
 {
-#if defined(CONFIG_PM) && defined(CONFIG_ADB_PMU)
-	/* XXX why here? */
-	pmu_register_sleep_notifier(&time_sleep_notifier);
-#endif
-
 	generic_calibrate_decr();
 
 #ifdef CONFIG_PPC32

--

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

* [PATCH 3/3] powerpc: fix comment in kernel/irq.c
  2006-12-13 12:38 [PATCH 0/3] some preparations for suspend on G5 powermac Johannes Berg
  2006-12-13 12:38 ` [PATCH 1/3] windfarm: dont die on suspend thread signal Johannes Berg
  2006-12-13 12:38 ` [PATCH 2/3] powermac: proper time of day after resume Johannes Berg
@ 2006-12-13 12:38 ` Johannes Berg
  2006-12-13 13:13   ` Johannes Berg
                     ` (2 more replies)
  2 siblings, 3 replies; 36+ messages in thread
From: Johannes Berg @ 2006-12-13 12:38 UTC (permalink / raw)
  To: linuxppc-dev

kernel/irq.c contains a comment that speaks of -1 and -2 as interrupt
numbers, but this is actually dependent on configuration options now.
Replace by NO_IRQ and NO_IRQ_ENABLED.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>

--- linux-2.6-git.orig/arch/powerpc/kernel/irq.c	2006-12-13 12:03:44.406144791 +0100
+++ linux-2.6-git/arch/powerpc/kernel/irq.c	2006-12-13 12:04:05.727144791 +0100
@@ -281,10 +281,10 @@ void do_IRQ(struct pt_regs *regs)
 
 	/*
 	 * Every platform is required to implement ppc_md.get_irq.
-	 * This function will either return an irq number or -1 to
+	 * This function will either return an irq number or NO_IRQ to
 	 * indicate there are no more pending.
-	 * The value -2 is for buggy hardware and means that this IRQ
-	 * has already been handled. -- Tom
+	 * The value NO_IRQ_IGNORE is for buggy hardware and means that this
+	 * IRQ has already been handled. -- Tom
 	 */
 	irq = ppc_md.get_irq();
 

--

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

* Re: [PATCH 3/3] powerpc: fix comment in kernel/irq.c
  2006-12-13 12:38 ` [PATCH 3/3] powerpc: fix comment in kernel/irq.c Johannes Berg
@ 2006-12-13 13:13   ` Johannes Berg
  2006-12-19  5:40   ` Paul Mackerras
  2007-01-24  6:35   ` Benjamin Herrenschmidt
  2 siblings, 0 replies; 36+ messages in thread
From: Johannes Berg @ 2006-12-13 13:13 UTC (permalink / raw)
  To: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 353 bytes --]

On Wed, 2006-12-13 at 13:38 +0100, Johannes Berg wrote:

> kernel/irq.c contains a comment that speaks of -1 and -2 as interrupt
> numbers, but this is actually dependent on configuration options now.
> Replace by NO_IRQ and NO_IRQ_ENABLED.

Humm, this got into this patchset by accident. That doesn't really make
it wrong though :)

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

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

* Re: [PATCH 3/3] powerpc: fix comment in kernel/irq.c
  2006-12-13 12:38 ` [PATCH 3/3] powerpc: fix comment in kernel/irq.c Johannes Berg
  2006-12-13 13:13   ` Johannes Berg
@ 2006-12-19  5:40   ` Paul Mackerras
  2006-12-19 18:29     ` Johannes Berg
  2007-01-24  6:35   ` Benjamin Herrenschmidt
  2 siblings, 1 reply; 36+ messages in thread
From: Paul Mackerras @ 2006-12-19  5:40 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linuxppc-dev

Johannes Berg writes:

> kernel/irq.c contains a comment that speaks of -1 and -2 as interrupt
> numbers, but this is actually dependent on configuration options now.
> Replace by NO_IRQ and NO_IRQ_ENABLED.

Hmmm, NO_IRQ has to be 0, if anything, per decree of the head penguin.

Paul.

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

* Re: [PATCH 3/3] powerpc: fix comment in kernel/irq.c
  2006-12-19  5:40   ` Paul Mackerras
@ 2006-12-19 18:29     ` Johannes Berg
  0 siblings, 0 replies; 36+ messages in thread
From: Johannes Berg @ 2006-12-19 18:29 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

On Tue, 2006-12-19 at 16:40 +1100, Paul Mackerras wrote:
> Johannes Berg writes:
> 
> > kernel/irq.c contains a comment that speaks of -1 and -2 as interrupt
> > numbers, but this is actually dependent on configuration options now.
> > Replace by NO_IRQ and NO_IRQ_ENABLED.
> 
> Hmmm, NO_IRQ has to be 0, if anything, per decree of the head penguin.

I thought so too but then I found that under some conditions it's
actually defined to -1, so I was confused. Maybe that is wrong then?

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

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

* Re: [PATCH 1/3] windfarm: dont die on suspend thread signal
  2006-12-13 12:38 ` [PATCH 1/3] windfarm: dont die on suspend thread signal Johannes Berg
@ 2007-01-24  6:32   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 36+ messages in thread
From: Benjamin Herrenschmidt @ 2007-01-24  6:32 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linuxppc-dev

On Wed, 2006-12-13 at 13:38 +0100, Johannes Berg wrote:
> plain text document attachment (windfarm-dont-die-on-signals.patch)
> When the windfarm thread gets a suspend signal it will die instead of
> freezing. This fixes it.
> 
> Signed-off-by: Johannes Berg <johannes@sipsolutions.net>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> --- linux-2.6-git.orig/drivers/macintosh/windfarm_core.c	2006-12-11 23:34:47.082716759 +0100
> +++ linux-2.6-git/drivers/macintosh/windfarm_core.c	2006-12-11 23:37:58.181716759 +0100
> @@ -93,8 +93,6 @@ static int wf_thread_func(void *data)
>  	DBG("wf: thread started\n");
>  
>  	while(!kthread_should_stop()) {
> -		try_to_freeze();
> -
>  		if (time_after_eq(jiffies, next)) {
>  			wf_notify(WF_EVENT_TICK, NULL);
>  			if (wf_overtemp) {
> @@ -117,8 +115,8 @@ static int wf_thread_func(void *data)
>  		if (delay <= HZ)
>  			schedule_timeout_interruptible(delay);
>  
> -		/* there should be no signal, but oh well */
> -		if (signal_pending(current)) {
> +		/* there should be no non-suspend signal, but oh well */
> +		if (signal_pending(current) && !try_to_freeze()) {
>  			printk(KERN_WARNING "windfarm: thread got sigl !\n");
>  			break;
>  		}
> 
> --

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2006-12-13 12:38 ` [PATCH 2/3] powermac: proper time of day after resume Johannes Berg
@ 2007-01-24  6:34   ` Benjamin Herrenschmidt
  2007-01-24  8:46     ` Johannes Berg
                       ` (3 more replies)
  0 siblings, 4 replies; 36+ messages in thread
From: Benjamin Herrenschmidt @ 2007-01-24  6:34 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linuxppc-dev

On Wed, 2006-12-13 at 13:38 +0100, Johannes Berg wrote:
> plain text document attachment (time-resume.patch)
> This patch converts the time restore code from a PMU notifier to a regular
> sys device so I can profit from it even when I don't suspend through the
> PMU, i.e. suspend to disk.
> 
> Also another step towards dropping pmu_sleep_notifier completely.

I'd rather do it differently: On suspend, read the RTC and save the
value. On resume, read it again, diff the values, and add that to the
current time.

Ben.

> Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> 
> ---
> Tested on my powermac with my suspend code there but not yet on the
> powerbook.
> 
> It seems that this could be done in the generic instead of the arch
> dependent code since we have a machine op for getting the boot time...
> Should we?
> 
> --- linux-2.6-git.orig/arch/powerpc/platforms/powermac/time.c	2006-12-12 16:54:10.573639512 +0100
> +++ linux-2.6-git/arch/powerpc/platforms/powermac/time.c	2006-12-12 16:54:16.805639512 +0100
> @@ -298,36 +298,56 @@ int __init via_calibrate_decr(void)
>  #endif
>  
>  #ifdef CONFIG_PM
> +
> +static unsigned long time_diff;
> +
>  /*
>   * Reset the time after a sleep.
>   */
> -static int
> -time_sleep_notify(struct pmu_sleep_notifier *self, int when)
> +static int timer_resume(struct sys_device *dev)
> +{
> +	struct timespec tv;
> +
> +	tv.tv_sec = pmac_get_boot_time() + time_diff;
> +	tv.tv_nsec = 0;
> +	do_settimeofday(&tv);
> +
> +	return 0;
> +}
> +
> +static int timer_suspend(struct sys_device *dev, pm_message_t state)
>  {
> -	static unsigned long time_diff;
>  	unsigned long flags;
>  	unsigned long seq;
> -	struct timespec tv;
>  
> -	switch (when) {
> -	case PBOOK_SLEEP_NOW:
> -		do {
> -			seq = read_seqbegin_irqsave(&xtime_lock, flags);
> -			time_diff = xtime.tv_sec - pmac_get_boot_time();
> -		} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
> -		break;
> -	case PBOOK_WAKE:
> -		tv.tv_sec = pmac_get_boot_time() + time_diff;
> -		tv.tv_nsec = 0;
> -		do_settimeofday(&tv);
> -		break;
> -	}
> -	return PBOOK_SLEEP_OK;
> +	do {
> +		seq = read_seqbegin_irqsave(&xtime_lock, flags);
> +		time_diff = xtime.tv_sec - pmac_get_boot_time();
> +	} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
> +
> +	return 0;
>  }
>  
> -static struct pmu_sleep_notifier time_sleep_notifier = {
> -	time_sleep_notify, SLEEP_LEVEL_MISC,
> +static struct sysdev_class timer_sysclass = {
> +	.resume = timer_resume,
> +	.suspend = timer_suspend,
> +	set_kset_name("timer"),
> +};
> +
> +static struct sys_device device_timer = {
> +	.id = 0,
> +	.cls = &timer_sysclass,
>  };
> +
> +static int time_init_device(void)
> +{
> +	int error = sysdev_class_register(&timer_sysclass);
> +	if (!error)
> +		error = sysdev_register(&device_timer);
> +	return error;
> +}
> +
> +device_initcall(time_init_device);
>  #endif /* CONFIG_PM */
>  
>  /*
> @@ -335,11 +355,6 @@ static struct pmu_sleep_notifier time_sl
>   */
>  void __init pmac_calibrate_decr(void)
>  {
> -#if defined(CONFIG_PM) && defined(CONFIG_ADB_PMU)
> -	/* XXX why here? */
> -	pmu_register_sleep_notifier(&time_sleep_notifier);
> -#endif
> -
>  	generic_calibrate_decr();
>  
>  #ifdef CONFIG_PPC32
> 
> --

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

* Re: [PATCH 3/3] powerpc: fix comment in kernel/irq.c
  2006-12-13 12:38 ` [PATCH 3/3] powerpc: fix comment in kernel/irq.c Johannes Berg
  2006-12-13 13:13   ` Johannes Berg
  2006-12-19  5:40   ` Paul Mackerras
@ 2007-01-24  6:35   ` Benjamin Herrenschmidt
  2 siblings, 0 replies; 36+ messages in thread
From: Benjamin Herrenschmidt @ 2007-01-24  6:35 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linuxppc-dev

On Wed, 2006-12-13 at 13:38 +0100, Johannes Berg wrote:
> plain text document attachment (irq-comment.patch)
> kernel/irq.c contains a comment that speaks of -1 and -2 as interrupt
> numbers, but this is actually dependent on configuration options now.
> Replace by NO_IRQ and NO_IRQ_ENABLED.
> 
> Signed-off-by: Johannes Berg <johannes@sipsolutions.net>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> --- linux-2.6-git.orig/arch/powerpc/kernel/irq.c	2006-12-13 12:03:44.406144791 +0100
> +++ linux-2.6-git/arch/powerpc/kernel/irq.c	2006-12-13 12:04:05.727144791 +0100
> @@ -281,10 +281,10 @@ void do_IRQ(struct pt_regs *regs)
>  
>  	/*
>  	 * Every platform is required to implement ppc_md.get_irq.
> -	 * This function will either return an irq number or -1 to
> +	 * This function will either return an irq number or NO_IRQ to
>  	 * indicate there are no more pending.
> -	 * The value -2 is for buggy hardware and means that this IRQ
> -	 * has already been handled. -- Tom
> +	 * The value NO_IRQ_IGNORE is for buggy hardware and means that this
> +	 * IRQ has already been handled. -- Tom
>  	 */
>  	irq = ppc_md.get_irq();
>  
> 
> --

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24  6:34   ` Benjamin Herrenschmidt
@ 2007-01-24  8:46     ` Johannes Berg
  2007-01-24  8:51       ` Benjamin Herrenschmidt
  2007-01-24  8:54     ` Gabriel Paubert
                       ` (2 subsequent siblings)
  3 siblings, 1 reply; 36+ messages in thread
From: Johannes Berg @ 2007-01-24  8:46 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 723 bytes --]

On Wed, 2007-01-24 at 17:34 +1100, Benjamin Herrenschmidt wrote:
> On Wed, 2006-12-13 at 13:38 +0100, Johannes Berg wrote:
> > plain text document attachment (time-resume.patch)
> > This patch converts the time restore code from a PMU notifier to a regular
> > sys device so I can profit from it even when I don't suspend through the
> > PMU, i.e. suspend to disk.
> > 
> > Also another step towards dropping pmu_sleep_notifier completely.
> 
> I'd rather do it differently: On suspend, read the RTC and save the
> value. On resume, read it again, diff the values, and add that to the
> current time.

Alright, I can do that too, this simply shuffled the old code around.
Will have a look at it.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24  8:46     ` Johannes Berg
@ 2007-01-24  8:51       ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 36+ messages in thread
From: Benjamin Herrenschmidt @ 2007-01-24  8:51 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linuxppc-dev

On Wed, 2007-01-24 at 09:46 +0100, Johannes Berg wrote:
> On Wed, 2007-01-24 at 17:34 +1100, Benjamin Herrenschmidt wrote:
> > On Wed, 2006-12-13 at 13:38 +0100, Johannes Berg wrote:
> > > plain text document attachment (time-resume.patch)
> > > This patch converts the time restore code from a PMU notifier to a regular
> > > sys device so I can profit from it even when I don't suspend through the
> > > PMU, i.e. suspend to disk.
> > > 
> > > Also another step towards dropping pmu_sleep_notifier completely.
> > 
> > I'd rather do it differently: On suspend, read the RTC and save the
> > value. On resume, read it again, diff the values, and add that to the
> > current time.
> 
> Alright, I can do that too, this simply shuffled the old code around.
> Will have a look at it.

Ok. I just don't like the pmac_get_boot_time() calls around all over the
place :-) That stuff is a hack I'd like to only call once at boot.

Ben.

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24  6:34   ` Benjamin Herrenschmidt
  2007-01-24  8:46     ` Johannes Berg
@ 2007-01-24  8:54     ` Gabriel Paubert
  2007-01-24  9:32       ` Benjamin Herrenschmidt
  2007-01-26 14:35     ` Johannes Berg
  2007-02-01 19:16     ` [PATCH] " Johannes Berg
  3 siblings, 1 reply; 36+ messages in thread
From: Gabriel Paubert @ 2007-01-24  8:54 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev, Johannes Berg

On Wed, Jan 24, 2007 at 05:34:04PM +1100, Benjamin Herrenschmidt wrote:
> On Wed, 2006-12-13 at 13:38 +0100, Johannes Berg wrote:
> > plain text document attachment (time-resume.patch)
> > This patch converts the time restore code from a PMU notifier to a regular
> > sys device so I can profit from it even when I don't suspend through the
> > PMU, i.e. suspend to disk.
> > 
> > Also another step towards dropping pmu_sleep_notifier completely.
> 
> I'd rather do it differently: On suspend, read the RTC and save the
> value. On resume, read it again, diff the values, and add that to the
> current time.
> 

Isn't there a way to obtain a better resolution? 

The RTC has a resolution on 1 second AFAIR. This means that there will
be an error of up to 1 second after resume. If you run NTP, it will
ultimately be corrected (I believe) but it may take a fairly long time
given the loop bandwidth of NTP, which will also probably write for a
while crap values into its drift file (/var/lib/ntp/ntp.drift on Debian 
but location varies with distribution).

	Regards,
	Gabriel

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24  8:54     ` Gabriel Paubert
@ 2007-01-24  9:32       ` Benjamin Herrenschmidt
  2007-01-24 10:36         ` Gabriel Paubert
  0 siblings, 1 reply; 36+ messages in thread
From: Benjamin Herrenschmidt @ 2007-01-24  9:32 UTC (permalink / raw)
  To: Gabriel Paubert; +Cc: linuxppc-dev, Johannes Berg

On Wed, 2007-01-24 at 09:54 +0100, Gabriel Paubert wrote:

> Isn't there a way to obtain a better resolution? 

Not that I know.

> The RTC has a resolution on 1 second AFAIR. This means that there will
> be an error of up to 1 second after resume. If you run NTP, it will
> ultimately be corrected (I believe) but it may take a fairly long time
> given the loop bandwidth of NTP, which will also probably write for a
> while crap values into its drift file (/var/lib/ntp/ntp.drift on Debian 
> but location varies with distribution).

But then, people suspending/resuming laptops know what to (or not to)
expect I suppose :-)

Ben.

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24  9:32       ` Benjamin Herrenschmidt
@ 2007-01-24 10:36         ` Gabriel Paubert
  2007-01-24 14:23           ` Segher Boessenkool
  0 siblings, 1 reply; 36+ messages in thread
From: Gabriel Paubert @ 2007-01-24 10:36 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev, Johannes Berg

On Wed, Jan 24, 2007 at 08:32:57PM +1100, Benjamin Herrenschmidt wrote:
> On Wed, 2007-01-24 at 09:54 +0100, Gabriel Paubert wrote:
> 
> > Isn't there a way to obtain a better resolution? 
> 
> Not that I know.
> 
> > The RTC has a resolution on 1 second AFAIR. This means that there will
> > be an error of up to 1 second after resume. If you run NTP, it will
> > ultimately be corrected (I believe) but it may take a fairly long time
> > given the loop bandwidth of NTP, which will also probably write for a
> > while crap values into its drift file (/var/lib/ntp/ntp.drift on Debian 
> > but location varies with distribution).
> 
> But then, people suspending/resuming laptops know what to (or not to)
> expect I suppose :-)
> 

I believed that the patch also worked on desktops. Of course, one
solution is to try to reset time from an NTP server on resume if you
are connected (if you are not, then an error of a fraction of a second
is less serious).

The best solution may require informing the user space ntp code of
such events. This requires very likely modifications to ntp itself
(I may be wrong, I've not looked at NTP code for 5 years or so).

	Gabriel

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24 10:36         ` Gabriel Paubert
@ 2007-01-24 14:23           ` Segher Boessenkool
  2007-01-24 21:44             ` Benjamin Herrenschmidt
  2007-01-25 11:09             ` Gabriel Paubert
  0 siblings, 2 replies; 36+ messages in thread
From: Segher Boessenkool @ 2007-01-24 14:23 UTC (permalink / raw)
  To: Gabriel Paubert; +Cc: Johannes Berg, linuxppc-dev

> I believed that the patch also worked on desktops. Of course, one
> solution is to try to reset time from an NTP server on resume if you
> are connected (if you are not, then an error of a fraction of a second
> is less serious).

A fraction of a second is *never* serious, except with
broken apps ;-)

> The best solution may require informing the user space ntp code of
> such events. This requires very likely modifications to ntp itself
> (I may be wrong, I've not looked at NTP code for 5 years or so).

Doesn't the kernel send signals to init on suspend/resume
events, just like with power fail events?  You can hook on
that.


Segher

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24 14:23           ` Segher Boessenkool
@ 2007-01-24 21:44             ` Benjamin Herrenschmidt
  2007-01-24 22:24               ` Segher Boessenkool
  2007-01-25  7:39               ` Michel Dänzer
  2007-01-25 11:09             ` Gabriel Paubert
  1 sibling, 2 replies; 36+ messages in thread
From: Benjamin Herrenschmidt @ 2007-01-24 21:44 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev, Johannes Berg

> > The best solution may require informing the user space ntp code of
> > such events. This requires very likely modifications to ntp itself
> > (I may be wrong, I've not looked at NTP code for 5 years or so).
> 
> Doesn't the kernel send signals to init on suspend/resume
> events, just like with power fail events?  You can hook on
> that.

I don't think it does... at least not on powerbooks.

Ben.

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24 21:44             ` Benjamin Herrenschmidt
@ 2007-01-24 22:24               ` Segher Boessenkool
  2007-01-24 22:35                 ` Benjamin Herrenschmidt
  2007-01-25  7:39               ` Michel Dänzer
  1 sibling, 1 reply; 36+ messages in thread
From: Segher Boessenkool @ 2007-01-24 22:24 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev, Johannes Berg

>>> The best solution may require informing the user space ntp code of
>>> such events. This requires very likely modifications to ntp itself
>>> (I may be wrong, I've not looked at NTP code for 5 years or so).
>>
>> Doesn't the kernel send signals to init on suspend/resume
>> events, just like with power fail events?  You can hook on
>> that.
>
> I don't think it does... at least not on powerbooks.

<Cpt. Picard voice>  Make it so.

:-)


Segher

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24 22:24               ` Segher Boessenkool
@ 2007-01-24 22:35                 ` Benjamin Herrenschmidt
  2007-01-24 23:21                   ` Segher Boessenkool
  0 siblings, 1 reply; 36+ messages in thread
From: Benjamin Herrenschmidt @ 2007-01-24 22:35 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev, Johannes Berg

On Wed, 2007-01-24 at 23:24 +0100, Segher Boessenkool wrote:
> >>> The best solution may require informing the user space ntp code of
> >>> such events. This requires very likely modifications to ntp itself
> >>> (I may be wrong, I've not looked at NTP code for 5 years or so).
> >>
> >> Doesn't the kernel send signals to init on suspend/resume
> >> events, just like with power fail events?  You can hook on
> >> that.
> >
> > I don't think it does... at least not on powerbooks.
> 
> <Cpt. Picard voice>  Make it so.
> 
> :-)

Do you know of any timer that is still running while the box is asleep ?
I doubt KL timer is and MPIC timers are long gone on Apple HW ...

Ben.

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24 22:35                 ` Benjamin Herrenschmidt
@ 2007-01-24 23:21                   ` Segher Boessenkool
  0 siblings, 0 replies; 36+ messages in thread
From: Segher Boessenkool @ 2007-01-24 23:21 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev, Johannes Berg

>> <Cpt. Picard voice>  Make it so.
>>
>> :-)
>
> Do you know of any timer that is still running while the box is  
> asleep ?
> I doubt KL timer is and MPIC timers are long gone on Apple HW ...

Only the PMU (SMU) timers run while the box is asleep (i.e.,
the RTC clock this patch is about).


Segher

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24 21:44             ` Benjamin Herrenschmidt
  2007-01-24 22:24               ` Segher Boessenkool
@ 2007-01-25  7:39               ` Michel Dänzer
  2007-01-25  8:06                 ` Benjamin Herrenschmidt
  1 sibling, 1 reply; 36+ messages in thread
From: Michel Dänzer @ 2007-01-25  7:39 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev, Johannes Berg

On Thu, 2007-01-25 at 08:44 +1100, Benjamin Herrenschmidt wrote:
> > > The best solution may require informing the user space ntp code of
> > > such events. This requires very likely modifications to ntp itself
> > > (I may be wrong, I've not looked at NTP code for 5 years or so).
> > 
> > Doesn't the kernel send signals to init on suspend/resume
> > events, just like with power fail events?  You can hook on
> > that.
> 
> I don't think it does... at least not on powerbooks.

It could be handled by scripts invoked from pbbuttonsd or pmud on wakeup
though, couldn't it? I thought there used to be one for that
in /etc/apm/, but I can't find it now...


-- 
Earthling Michel Dänzer           |          http://tungstengraphics.com
Libre software enthusiast         |          Debian, X and DRI developer

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-25  7:39               ` Michel Dänzer
@ 2007-01-25  8:06                 ` Benjamin Herrenschmidt
  2007-01-25  8:10                   ` Michel Dänzer
  0 siblings, 1 reply; 36+ messages in thread
From: Benjamin Herrenschmidt @ 2007-01-25  8:06 UTC (permalink / raw)
  To: Michel Dänzer; +Cc: linuxppc-dev, Johannes Berg

On Thu, 2007-01-25 at 08:39 +0100, Michel Dänzer wrote:
> On Thu, 2007-01-25 at 08:44 +1100, Benjamin Herrenschmidt wrote:
> > > > The best solution may require informing the user space ntp code of
> > > > such events. This requires very likely modifications to ntp itself
> > > > (I may be wrong, I've not looked at NTP code for 5 years or so).
> > > 
> > > Doesn't the kernel send signals to init on suspend/resume
> > > events, just like with power fail events?  You can hook on
> > > that.
> > 
> > I don't think it does... at least not on powerbooks.
> 
> It could be handled by scripts invoked from pbbuttonsd or pmud on wakeup
> though, couldn't it? I thought there used to be one for that
> in /etc/apm/, but I can't find it now...

Well, I'm not sure I've fully followed how these things changed over the
last couple of years but yes, there used to be one called by pmud and
possibly pbbuttonsd too in /etc/power/pwrctl but distro I think -also-
hook that top APM stuffs among others.

Ben.

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-25  8:06                 ` Benjamin Herrenschmidt
@ 2007-01-25  8:10                   ` Michel Dänzer
  0 siblings, 0 replies; 36+ messages in thread
From: Michel Dänzer @ 2007-01-25  8:10 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev, Johannes Berg

On Thu, 2007-01-25 at 19:06 +1100, Benjamin Herrenschmidt wrote:
> On Thu, 2007-01-25 at 08:39 +0100, Michel Dänzer wrote:
> > On Thu, 2007-01-25 at 08:44 +1100, Benjamin Herrenschmidt wrote:
> > > > > The best solution may require informing the user space ntp code of
> > > > > such events. This requires very likely modifications to ntp itself
> > > > > (I may be wrong, I've not looked at NTP code for 5 years or so).
> > > > 
> > > > Doesn't the kernel send signals to init on suspend/resume
> > > > events, just like with power fail events?  You can hook on
> > > > that.
> > > 
> > > I don't think it does... at least not on powerbooks.
> > 
> > It could be handled by scripts invoked from pbbuttonsd or pmud on wakeup
> > though, couldn't it? I thought there used to be one for that
> > in /etc/apm/, but I can't find it now...
> 
> Well, I'm not sure I've fully followed how these things changed over the
> last couple of years but yes, there used to be one called by pmud and
> possibly pbbuttonsd too in /etc/power/pwrctl but distro I think -also-
> hook that top APM stuffs among others.

FWIW, it seems to be handled indirectly here
via /etc/network/if-up.d/ntp, which is invoked whenever a network
interface goes up, which happens automatically on wakeup with
network-manager.


-- 
Earthling Michel Dänzer           |          http://tungstengraphics.com
Libre software enthusiast         |          Debian, X and DRI developer

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24 14:23           ` Segher Boessenkool
  2007-01-24 21:44             ` Benjamin Herrenschmidt
@ 2007-01-25 11:09             ` Gabriel Paubert
  2007-01-25 12:54               ` Johannes Berg
  1 sibling, 1 reply; 36+ messages in thread
From: Gabriel Paubert @ 2007-01-25 11:09 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: Johannes Berg, linuxppc-dev

On Wed, Jan 24, 2007 at 03:23:47PM +0100, Segher Boessenkool wrote:
> >I believed that the patch also worked on desktops. Of course, one
> >solution is to try to reset time from an NTP server on resume if you
> >are connected (if you are not, then an error of a fraction of a second
> >is less serious).
> 
> A fraction of a second is *never* serious, except with
> broken apps ;-)
> 

You've obviously never met people doing VLBI (Very Long Baseline 
Interferometry) ;-) 

Seriously, here we have a bunch of machines doing data acquisition
which are synchronized through timestamps taken at interrupt time.
They need an accuracy ot 5-10ms, which NTP easily provides (we have
our own redundant NTP servers connected to reference clocks: GPS
receivers and high precision clocks including an hydrogen maser).
Fortunately they never perform a suspend/resume cycle, because this
precision is not achievable even when trying to synchronize with the
second transition from the RTC.

If we did suspend the machines to save power, the only solution 
would be to tell NTP to synchronize with the master clock by 
stepping the time (not slewing) at resume time.

	Gabriel

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-25 11:09             ` Gabriel Paubert
@ 2007-01-25 12:54               ` Johannes Berg
  0 siblings, 0 replies; 36+ messages in thread
From: Johannes Berg @ 2007-01-25 12:54 UTC (permalink / raw)
  To: Gabriel Paubert; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

On Thu, 2007-01-25 at 12:09 +0100, Gabriel Paubert wrote:

> If we did suspend the machines to save power, the only solution 
> would be to tell NTP to synchronize with the master clock by 
> stepping the time (not slewing) at resume time.

You also know that you have such a requirement, and obviously also know
what you could do to fix it.

I see this as a non-issue. Even if we *try* to sync with the second
transition (which is likely rather hard to do) then we won't have the
required precision for a bunch of applications, so it's futile to try it
anyway.

Besides, if we don't do it at all the time just keeps running where it
was before suspend...

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

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

* Re: [PATCH 2/3] powermac: proper time of day after resume
  2007-01-24  6:34   ` Benjamin Herrenschmidt
  2007-01-24  8:46     ` Johannes Berg
  2007-01-24  8:54     ` Gabriel Paubert
@ 2007-01-26 14:35     ` Johannes Berg
  2007-02-01 19:16     ` [PATCH] " Johannes Berg
  3 siblings, 0 replies; 36+ messages in thread
From: Johannes Berg @ 2007-01-26 14:35 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 3907 bytes --]

On Wed, 2007-01-24 at 17:34 +1100, Benjamin Herrenschmidt wrote:
> On Wed, 2006-12-13 at 13:38 +0100, Johannes Berg wrote:
> > plain text document attachment (time-resume.patch)
> > This patch converts the time restore code from a PMU notifier to a regular
> > sys device so I can profit from it even when I don't suspend through the
> > PMU, i.e. suspend to disk.
> > 
> > Also another step towards dropping pmu_sleep_notifier completely.
> 
> I'd rather do it differently: On suspend, read the RTC and save the
> value. On resume, read it again, diff the values, and add that to the
> current time.

Alright, how about something like this? I still need to fill in the
actual calculations of course :)

--- mb-wireless.orig/arch/powerpc/platforms/powermac/time.c	2007-01-25 14:09:12.288927117 +0100
+++ mb-wireless/arch/powerpc/platforms/powermac/time.c	2007-01-26 14:16:18.598954773 +0100
@@ -297,49 +297,11 @@ int __init via_calibrate_decr(void)
 }
 #endif
 
-#ifdef CONFIG_PM
-/*
- * Reset the time after a sleep.
- */
-static int
-time_sleep_notify(struct pmu_sleep_notifier *self, int when)
-{
-	static unsigned long time_diff;
-	unsigned long flags;
-	unsigned long seq;
-	struct timespec tv;
-
-	switch (when) {
-	case PBOOK_SLEEP_NOW:
-		do {
-			seq = read_seqbegin_irqsave(&xtime_lock, flags);
-			time_diff = xtime.tv_sec - pmac_get_boot_time();
-		} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
-		break;
-	case PBOOK_WAKE:
-		tv.tv_sec = pmac_get_boot_time() + time_diff;
-		tv.tv_nsec = 0;
-		do_settimeofday(&tv);
-		break;
-	}
-	return PBOOK_SLEEP_OK;
-}
-
-static struct pmu_sleep_notifier time_sleep_notifier = {
-	time_sleep_notify, SLEEP_LEVEL_MISC,
-};
-#endif /* CONFIG_PM */
-
 /*
  * Query the OF and get the decr frequency.
  */
 void __init pmac_calibrate_decr(void)
 {
-#if defined(CONFIG_PM) && defined(CONFIG_ADB_PMU)
-	/* XXX why here? */
-	pmu_register_sleep_notifier(&time_sleep_notifier);
-#endif
-
 	generic_calibrate_decr();
 
 #ifdef CONFIG_PPC32
--- mb-wireless.orig/arch/powerpc/kernel/Makefile	2007-01-26 14:16:35.838954773 +0100
+++ mb-wireless/arch/powerpc/kernel/Makefile	2007-01-26 14:16:47.918954773 +0100
@@ -50,6 +50,7 @@ extra-y				+= vmlinux.lds
 
 obj-y				+= time.o prom.o traps.o setup-common.o \
 				   udbg.o misc.o io.o
+obj-$(CONFIG_PM)		+= time_suspend.o
 obj-$(CONFIG_PPC32)		+= entry_32.o setup_32.o misc_32.o
 obj-$(CONFIG_PPC64)		+= misc_64.o dma_64.o iommu.o
 obj-$(CONFIG_PPC_MULTIPLATFORM)	+= prom_init.o
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ mb-wireless/arch/powerpc/kernel/time_suspend.c	2007-01-26 15:33:55.879025345 +0100
@@ -0,0 +1,62 @@
+/*
+ * Common code to keep time when machine suspends.
+ *
+ * Copyright 2007	Johannes Berg <johannes@sipsolutions.net>
+ *
+ * GPLv2
+ */
+
+#include <linux/time.h>
+#include <asm/rtc.h>
+
+static struct rtc_time suspend_rtc_time;
+
+/*
+ * Reset the time after a sleep.
+ */
+static int timer_resume(struct sys_device *dev)
+{
+	struct timespec tv;
+	struct rtc_time cur_rtc_time;
+
+
+	get_rtc_time(&suspend_rtc_time);
+
+	do_gettimeofday(&tv);
+
+	/* FIXME: do something with tv here */
+
+	do_settimeofday(&tv);
+
+	return 0;
+}
+
+static int timer_suspend(struct sys_device *dev, pm_message_t state)
+{
+	WARN_ON(!ppc_md.get_rtc_time);
+
+	get_rtc_time(&suspend_rtc_time);
+
+	return 0;
+}
+
+static struct sysdev_class timer_sysclass = {
+	.resume = timer_resume,
+	.suspend = timer_suspend,
+	set_kset_name("timer"),
+};
+
+static struct sys_device device_timer = {
+	.id = 0,
+	.cls = &timer_sysclass,
+};
+
+static int time_init_device(void)
+{
+	int error = sysdev_class_register(&timer_sysclass);
+	if (!error)
+		error = sysdev_register(&device_timer);
+	return error;
+}
+
+device_initcall(time_init_device);


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

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

* [PATCH] powermac: proper time of day after resume
  2007-01-24  6:34   ` Benjamin Herrenschmidt
                       ` (2 preceding siblings ...)
  2007-01-26 14:35     ` Johannes Berg
@ 2007-02-01 19:16     ` Johannes Berg
  2007-02-02 12:19       ` Johannes Berg
                         ` (2 more replies)
  3 siblings, 3 replies; 36+ messages in thread
From: Johannes Berg @ 2007-02-01 19:16 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev

This patch converts the time restore code from a PMU notifier to a regular
sys device so any powerpc platform will use it.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>

---
 arch/powerpc/Kconfig                           |    5 +
 arch/powerpc/kernel/Makefile                   |    1
 arch/powerpc/platforms/powermac/time.c         |   38 -------------
 mb-wireless/arch/powerpc/kernel/time_suspend.c |   70 +++++++++++++++++++++++++
 4 files changed, 76 insertions(+), 38 deletions(-)

Tested on my powerbook.

The rtc library is necessary for rtc_tm_to_time, I could of course copy
it instead.

--- mb-wireless.orig/arch/powerpc/platforms/powermac/time.c	2007-01-25 14:09:12.288927117 +0100
+++ mb-wireless/arch/powerpc/platforms/powermac/time.c	2007-01-26 14:16:18.598954773 +0100
@@ -297,49 +297,11 @@ int __init via_calibrate_decr(void)
 }
 #endif
 
-#ifdef CONFIG_PM
-/*
- * Reset the time after a sleep.
- */
-static int
-time_sleep_notify(struct pmu_sleep_notifier *self, int when)
-{
-	static unsigned long time_diff;
-	unsigned long flags;
-	unsigned long seq;
-	struct timespec tv;
-
-	switch (when) {
-	case PBOOK_SLEEP_NOW:
-		do {
-			seq = read_seqbegin_irqsave(&xtime_lock, flags);
-			time_diff = xtime.tv_sec - pmac_get_boot_time();
-		} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
-		break;
-	case PBOOK_WAKE:
-		tv.tv_sec = pmac_get_boot_time() + time_diff;
-		tv.tv_nsec = 0;
-		do_settimeofday(&tv);
-		break;
-	}
-	return PBOOK_SLEEP_OK;
-}
-
-static struct pmu_sleep_notifier time_sleep_notifier = {
-	time_sleep_notify, SLEEP_LEVEL_MISC,
-};
-#endif /* CONFIG_PM */
-
 /*
  * Query the OF and get the decr frequency.
  */
 void __init pmac_calibrate_decr(void)
 {
-#if defined(CONFIG_PM) && defined(CONFIG_ADB_PMU)
-	/* XXX why here? */
-	pmu_register_sleep_notifier(&time_sleep_notifier);
-#endif
-
 	generic_calibrate_decr();
 
 #ifdef CONFIG_PPC32
--- mb-wireless.orig/arch/powerpc/kernel/Makefile	2007-01-26 14:16:35.838954773 +0100
+++ mb-wireless/arch/powerpc/kernel/Makefile	2007-01-26 14:16:47.918954773 +0100
@@ -50,6 +50,7 @@ extra-y				+= vmlinux.lds
 
 obj-y				+= time.o prom.o traps.o setup-common.o \
 				   udbg.o misc.o io.o
+obj-$(CONFIG_PM)		+= time_suspend.o
 obj-$(CONFIG_PPC32)		+= entry_32.o setup_32.o misc_32.o
 obj-$(CONFIG_PPC64)		+= misc_64.o dma_64.o iommu.o
 obj-$(CONFIG_PPC_MULTIPLATFORM)	+= prom_init.o
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ mb-wireless/arch/powerpc/kernel/time_suspend.c	2007-02-01 19:38:59.818907090 +0100
@@ -0,0 +1,70 @@
+/*
+ * Common code to keep time when machine suspends.
+ *
+ * Copyright 2007	Johannes Berg <johannes@sipsolutions.net>
+ *
+ * GPLv2
+ */
+
+#include <linux/time.h>
+#include <asm/rtc.h>
+
+static unsigned long suspend_rtc_time;
+
+/*
+ * Reset the time after a sleep.
+ */
+static int timer_resume(struct sys_device *dev)
+{
+	struct timeval tv;
+	struct timespec ts;
+	struct rtc_time cur_rtc_tm;
+	unsigned long cur_rtc_time, diff;
+
+	/* get current RTC time and convert to seconds */
+	get_rtc_time(&cur_rtc_tm);
+	rtc_tm_to_time(&cur_rtc_tm, &cur_rtc_time);
+
+	diff = cur_rtc_time - suspend_rtc_time;
+
+	/* adjust time of day by seconds that elapsed while
+	 * we were suspended */
+	do_gettimeofday(&tv);
+	ts.tv_sec = tv.tv_sec + diff;
+	ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC;
+	do_settimeofday(&ts);
+
+	return 0;
+}
+
+static int timer_suspend(struct sys_device *dev, pm_message_t state)
+{
+	struct rtc_time suspend_rtc_tm;
+	WARN_ON(!ppc_md.get_rtc_time);
+
+	get_rtc_time(&suspend_rtc_tm);
+	rtc_tm_to_time(&suspend_rtc_tm, &suspend_rtc_time);
+
+	return 0;
+}
+
+static struct sysdev_class timer_sysclass = {
+	.resume = timer_resume,
+	.suspend = timer_suspend,
+	set_kset_name("timer"),
+};
+
+static struct sys_device device_timer = {
+	.id = 0,
+	.cls = &timer_sysclass,
+};
+
+static int time_init_device(void)
+{
+	int error = sysdev_class_register(&timer_sysclass);
+	if (!error)
+		error = sysdev_register(&device_timer);
+	return error;
+}
+
+device_initcall(time_init_device);
--- mb-wireless.orig/arch/powerpc/Kconfig	2007-02-01 19:43:27.478907090 +0100
+++ mb-wireless/arch/powerpc/Kconfig	2007-02-01 19:44:09.138907090 +0100
@@ -11,6 +11,11 @@ config PPC64
 	  This option selects whether a 32-bit or a 64-bit kernel
 	  will be built.
 
+config PPC_PM_NEEDS_RTC_LIB
+	bool
+	select RTC_LIB
+	default y if PM
+
 config PPC32
 	bool
 	default y if !PPC64

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

* Re: [PATCH] powermac: proper time of day after resume
  2007-02-01 19:16     ` [PATCH] " Johannes Berg
@ 2007-02-02 12:19       ` Johannes Berg
  2007-02-03  2:41       ` Michael Ellerman
  2007-05-02  4:45       ` Paul Mackerras
  2 siblings, 0 replies; 36+ messages in thread
From: Johannes Berg @ 2007-02-02 12:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 133 bytes --]

On Thu, 2007-02-01 at 20:16 +0100, Johannes Berg wrote:

> Tested on my powerbook.

And now on my powermac as well.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

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

* Re: [PATCH] powermac: proper time of day after resume
  2007-02-01 19:16     ` [PATCH] " Johannes Berg
  2007-02-02 12:19       ` Johannes Berg
@ 2007-02-03  2:41       ` Michael Ellerman
  2007-02-03 17:37         ` Johannes Berg
  2007-05-02  4:45       ` Paul Mackerras
  2 siblings, 1 reply; 36+ messages in thread
From: Michael Ellerman @ 2007-02-03  2:41 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 910 bytes --]

On Thu, 2007-02-01 at 20:16 +0100, Johannes Berg wrote:
> This patch converts the time restore code from a PMU notifier to a regular
> sys device so any powerpc platform will use it.
> 
> Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> 
> ---
>  arch/powerpc/Kconfig                           |    5 +
>  arch/powerpc/kernel/Makefile                   |    1
>  arch/powerpc/platforms/powermac/time.c         |   38 -------------
>  mb-wireless/arch/powerpc/kernel/time_suspend.c |   70 +++++++++++++++++++++++++

Would it be better in arch/powerpc/sysdev perhaps? :)

cheers

-- 
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [PATCH] powermac: proper time of day after resume
  2007-02-03  2:41       ` Michael Ellerman
@ 2007-02-03 17:37         ` Johannes Berg
  0 siblings, 0 replies; 36+ messages in thread
From: Johannes Berg @ 2007-02-03 17:37 UTC (permalink / raw)
  To: michael; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 854 bytes --]

On Sat, 2007-02-03 at 13:41 +1100, Michael Ellerman wrote:
> On Thu, 2007-02-01 at 20:16 +0100, Johannes Berg wrote:
> > This patch converts the time restore code from a PMU notifier to a regular
> > sys device so any powerpc platform will use it.
> > 
> > Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
> > Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > 
> > ---
> >  arch/powerpc/Kconfig                           |    5 +
> >  arch/powerpc/kernel/Makefile                   |    1
> >  arch/powerpc/platforms/powermac/time.c         |   38 -------------
> >  mb-wireless/arch/powerpc/kernel/time_suspend.c |   70 +++++++++++++++++++++++++
> 
> Would it be better in arch/powerpc/sysdev perhaps? :)

Well, I put it along with time.c :) But we can well put it into sysdev
as well, I don't really care.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

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

* Re: [PATCH] powermac: proper time of day after resume
  2007-02-01 19:16     ` [PATCH] " Johannes Berg
  2007-02-02 12:19       ` Johannes Berg
  2007-02-03  2:41       ` Michael Ellerman
@ 2007-05-02  4:45       ` Paul Mackerras
  2007-05-02  4:47         ` Paul Mackerras
                           ` (2 more replies)
  2 siblings, 3 replies; 36+ messages in thread
From: Paul Mackerras @ 2007-05-02  4:45 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linuxppc-dev

Johannes Berg writes:

> +static int timer_resume(struct sys_device *dev)
> +{
> +	struct timeval tv;
> +	struct timespec ts;
> +	struct rtc_time cur_rtc_tm;
> +	unsigned long cur_rtc_time, diff;
> +
> +	/* get current RTC time and convert to seconds */
> +	get_rtc_time(&cur_rtc_tm);
> +	rtc_tm_to_time(&cur_rtc_tm, &cur_rtc_time);

Why not just use get_boot_time() here?  Or if not that, then use
mktime() instead of rtc_tm_to_time().  Either way we don't need to
select RTC_LIB.

> +	diff = cur_rtc_time - suspend_rtc_time;
> +
> +	/* adjust time of day by seconds that elapsed while
> +	 * we were suspended */
> +	do_gettimeofday(&tv);
> +	ts.tv_sec = tv.tv_sec + diff;
> +	ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC;
> +	do_settimeofday(&ts);

This will fail if ts.tv_nsec ends up being >= NSEC_PER_SEC.

Paul.

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

* Re: [PATCH] powermac: proper time of day after resume
  2007-05-02  4:45       ` Paul Mackerras
@ 2007-05-02  4:47         ` Paul Mackerras
  2007-05-02  8:26         ` Johannes Berg
  2007-05-02 14:25         ` [PATCH] powerpc timer sysdev: use mktime Johannes Berg
  2 siblings, 0 replies; 36+ messages in thread
From: Paul Mackerras @ 2007-05-02  4:47 UTC (permalink / raw)
  To: Johannes Berg, Benjamin Herrenschmidt, linuxppc-dev

I wrote:

> This will fail if ts.tv_nsec ends up being >= NSEC_PER_SEC.

Sorry, silly comment, I didn't look at the code closely enough...

Paul.

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

* Re: [PATCH] powermac: proper time of day after resume
  2007-05-02  4:45       ` Paul Mackerras
  2007-05-02  4:47         ` Paul Mackerras
@ 2007-05-02  8:26         ` Johannes Berg
  2007-05-02 14:25         ` [PATCH] powerpc timer sysdev: use mktime Johannes Berg
  2 siblings, 0 replies; 36+ messages in thread
From: Johannes Berg @ 2007-05-02  8:26 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 646 bytes --]

On Wed, 2007-05-02 at 14:45 +1000, Paul Mackerras wrote:

> > +	/* get current RTC time and convert to seconds */
> > +	get_rtc_time(&cur_rtc_tm);
> > +	rtc_tm_to_time(&cur_rtc_tm, &cur_rtc_time);
> 
> Why not just use get_boot_time() here?

Hm, I don't quite remember. I think I originally had it that way and Ben
asked me to do this, but I may be wrong. Ben, can you remember anything
of that? If not I'll dig through my old mail.

>   Or if not that, then use
> mktime() instead of rtc_tm_to_time().  Either way we don't need to
> select RTC_LIB.

Hm, I'll have to look into mktime() and see if I can change that.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

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

* [PATCH] powerpc timer sysdev: use mktime
  2007-05-02  4:45       ` Paul Mackerras
  2007-05-02  4:47         ` Paul Mackerras
  2007-05-02  8:26         ` Johannes Berg
@ 2007-05-02 14:25         ` Johannes Berg
  2007-05-23 15:28           ` Johannes Berg
  2 siblings, 1 reply; 36+ messages in thread
From: Johannes Berg @ 2007-05-02 14:25 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: linuxppc-dev

This patch makes the timer sysdev use mktime instead of rtc_tm_to_time
by simply copying the function to avoid using rtc-lib.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>

--- wireless-dev.orig/arch/powerpc/sysdev/timer.c	2007-05-02 16:16:52.639177080 +0200
+++ wireless-dev/arch/powerpc/sysdev/timer.c	2007-05-02 16:21:56.429177080 +0200
@@ -24,7 +24,12 @@ static int timer_resume(struct sys_devic
 
 	/* get current RTC time and convert to seconds */
 	get_rtc_time(&cur_rtc_tm);
-	rtc_tm_to_time(&cur_rtc_tm, &cur_rtc_time);
+	cur_rtc_time = mktime(cur_rtc_tm.tm_year + 1900,
+			      cur_rtc_tm.tm_mon + 1,
+			      cur_rtc_tm.tm_mday,
+			      cur_rtc_tm.tm_hour,
+			      cur_rtc_tm.tm_min,
+			      cur_rtc_tm.tm_sec);
 
 	diff = cur_rtc_time - suspend_rtc_time;
 
@@ -44,7 +49,12 @@ static int timer_suspend(struct sys_devi
 	WARN_ON(!ppc_md.get_rtc_time);
 
 	get_rtc_time(&suspend_rtc_tm);
-	rtc_tm_to_time(&suspend_rtc_tm, &suspend_rtc_time);
+	suspend_rtc_time = mktime(suspend_rtc_tm.tm_year + 1900,
+				  suspend_rtc_tm.tm_mon + 1,
+				  suspend_rtc_tm.tm_mday,
+				  suspend_rtc_tm.tm_hour,
+				  suspend_rtc_tm.tm_min,
+				  suspend_rtc_tm.tm_sec);
 
 	return 0;
 }
--- wireless-dev.orig/arch/powerpc/Kconfig	2007-05-02 16:22:07.619177080 +0200
+++ wireless-dev/arch/powerpc/Kconfig	2007-05-02 16:22:12.759177080 +0200
@@ -11,11 +11,6 @@ config PPC64
 	  This option selects whether a 32-bit or a 64-bit kernel
 	  will be built.
 
-config PPC_PM_NEEDS_RTC_LIB
-	bool
-	select RTC_LIB
-	default y if PM
-
 config PPC32
 	bool
 	default y if !PPC64

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

* Re: [PATCH] powerpc timer sysdev: use mktime
  2007-05-02 14:25         ` [PATCH] powerpc timer sysdev: use mktime Johannes Berg
@ 2007-05-23 15:28           ` Johannes Berg
  2007-05-28  4:33             ` Paul Mackerras
  0 siblings, 1 reply; 36+ messages in thread
From: Johannes Berg @ 2007-05-23 15:28 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 2072 bytes --]

On Wed, 2007-05-02 at 16:25 +0200, Johannes Berg wrote:
> This patch makes the timer sysdev use mktime instead of rtc_tm_to_time
> by simply copying the function to avoid using rtc-lib.

I think you asked for this, any reason you then didn't take it? Just
missed? Or is something wrong with it?

> Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
> 
> --- wireless-dev.orig/arch/powerpc/sysdev/timer.c	2007-05-02 16:16:52.639177080 +0200
> +++ wireless-dev/arch/powerpc/sysdev/timer.c	2007-05-02 16:21:56.429177080 +0200
> @@ -24,7 +24,12 @@ static int timer_resume(struct sys_devic
>  
>  	/* get current RTC time and convert to seconds */
>  	get_rtc_time(&cur_rtc_tm);
> -	rtc_tm_to_time(&cur_rtc_tm, &cur_rtc_time);
> +	cur_rtc_time = mktime(cur_rtc_tm.tm_year + 1900,
> +			      cur_rtc_tm.tm_mon + 1,
> +			      cur_rtc_tm.tm_mday,
> +			      cur_rtc_tm.tm_hour,
> +			      cur_rtc_tm.tm_min,
> +			      cur_rtc_tm.tm_sec);
>  
>  	diff = cur_rtc_time - suspend_rtc_time;
>  
> @@ -44,7 +49,12 @@ static int timer_suspend(struct sys_devi
>  	WARN_ON(!ppc_md.get_rtc_time);
>  
>  	get_rtc_time(&suspend_rtc_tm);
> -	rtc_tm_to_time(&suspend_rtc_tm, &suspend_rtc_time);
> +	suspend_rtc_time = mktime(suspend_rtc_tm.tm_year + 1900,
> +				  suspend_rtc_tm.tm_mon + 1,
> +				  suspend_rtc_tm.tm_mday,
> +				  suspend_rtc_tm.tm_hour,
> +				  suspend_rtc_tm.tm_min,
> +				  suspend_rtc_tm.tm_sec);
>  
>  	return 0;
>  }
> --- wireless-dev.orig/arch/powerpc/Kconfig	2007-05-02 16:22:07.619177080 +0200
> +++ wireless-dev/arch/powerpc/Kconfig	2007-05-02 16:22:12.759177080 +0200
> @@ -11,11 +11,6 @@ config PPC64
>  	  This option selects whether a 32-bit or a 64-bit kernel
>  	  will be built.
>  
> -config PPC_PM_NEEDS_RTC_LIB
> -	bool
> -	select RTC_LIB
> -	default y if PM
> -
>  config PPC32
>  	bool
>  	default y if !PPC64
> 
> 
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev
> 

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

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

* Re: [PATCH] powerpc timer sysdev: use mktime
  2007-05-23 15:28           ` Johannes Berg
@ 2007-05-28  4:33             ` Paul Mackerras
  0 siblings, 0 replies; 36+ messages in thread
From: Paul Mackerras @ 2007-05-28  4:33 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linuxppc-dev

Johannes Berg writes:

> I think you asked for this, any reason you then didn't take it? Just
> missed? Or is something wrong with it?

Sorry, just missed.  It doesn't look essential for 2.6.22, so I'll
queue it for 2.6.23.

Paul.

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

end of thread, other threads:[~2007-05-28  4:33 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-13 12:38 [PATCH 0/3] some preparations for suspend on G5 powermac Johannes Berg
2006-12-13 12:38 ` [PATCH 1/3] windfarm: dont die on suspend thread signal Johannes Berg
2007-01-24  6:32   ` Benjamin Herrenschmidt
2006-12-13 12:38 ` [PATCH 2/3] powermac: proper time of day after resume Johannes Berg
2007-01-24  6:34   ` Benjamin Herrenschmidt
2007-01-24  8:46     ` Johannes Berg
2007-01-24  8:51       ` Benjamin Herrenschmidt
2007-01-24  8:54     ` Gabriel Paubert
2007-01-24  9:32       ` Benjamin Herrenschmidt
2007-01-24 10:36         ` Gabriel Paubert
2007-01-24 14:23           ` Segher Boessenkool
2007-01-24 21:44             ` Benjamin Herrenschmidt
2007-01-24 22:24               ` Segher Boessenkool
2007-01-24 22:35                 ` Benjamin Herrenschmidt
2007-01-24 23:21                   ` Segher Boessenkool
2007-01-25  7:39               ` Michel Dänzer
2007-01-25  8:06                 ` Benjamin Herrenschmidt
2007-01-25  8:10                   ` Michel Dänzer
2007-01-25 11:09             ` Gabriel Paubert
2007-01-25 12:54               ` Johannes Berg
2007-01-26 14:35     ` Johannes Berg
2007-02-01 19:16     ` [PATCH] " Johannes Berg
2007-02-02 12:19       ` Johannes Berg
2007-02-03  2:41       ` Michael Ellerman
2007-02-03 17:37         ` Johannes Berg
2007-05-02  4:45       ` Paul Mackerras
2007-05-02  4:47         ` Paul Mackerras
2007-05-02  8:26         ` Johannes Berg
2007-05-02 14:25         ` [PATCH] powerpc timer sysdev: use mktime Johannes Berg
2007-05-23 15:28           ` Johannes Berg
2007-05-28  4:33             ` Paul Mackerras
2006-12-13 12:38 ` [PATCH 3/3] powerpc: fix comment in kernel/irq.c Johannes Berg
2006-12-13 13:13   ` Johannes Berg
2006-12-19  5:40   ` Paul Mackerras
2006-12-19 18:29     ` Johannes Berg
2007-01-24  6:35   ` Benjamin Herrenschmidt

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).