Skip to contentSkip to conversation

some preparations for suspend on G5 powermac

PATCH In review Johannes Berg 7 participants 36 messages Dec 13, 2006 – May 28, 2007

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH 1/3 windfarm: dont die on suspend thread signal

In reply to Johannes Berg

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

Cc Benjamin Herrenschmidt <[email protected]>
drivers/macintosh/windfarm_core.c +2 -4
@@ -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;
 		}

--

#3 lore raw

PATCH 2/3 powermac: proper time of day after resume

In reply to Johannes Berg

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.

Cc Benjamin Herrenschmidt <[email protected]>

---
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?

arch/powerpc/platforms/powermac/time.c +40 -25
@@ -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

--

#31 lore raw

PATCH 3/3 powerpc: fix comment in kernel/irq.c

In reply to Johannes Berg

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.

Cc Benjamin Herrenschmidt <[email protected]>
arch/powerpc/kernel/irq.c +3 -3
@@ -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();
 

--

#0 lore raw

cover some preparations for suspend on G5 powermac

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

johannes

#32 lore raw

Re: [PATCH 3/3] powerpc: fix comment in kernel/irq.c

In reply to Johannes Berg
Quoted 3 lines · Johannes Berg

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

#33 lore raw

Re: [PATCH 3/3] powerpc: fix comment in kernel/irq.c

In reply to Johannes Berg
Quoted 3 lines · Johannes Berg

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.

#34 lore raw

Re: [PATCH 3/3] powerpc: fix comment in kernel/irq.c

Quoted 7 lines · Paul Mackerras
Quoted 3 lines · Johannes Berg

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

Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] windfarm: dont die on suspend thread signal

In reply to Johannes Berg
Quoted 5 lines · Johannes Berg

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.

Quoted 24 lines
drivers/macintosh/windfarm_core.c +2 -5
@@ -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;
 		}
 
--
#4 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

In reply to Johannes Berg
Quoted 6 lines · Johannes Berg

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.

Quoted 104 lines
Cc Benjamin Herrenschmidt <[email protected]>

---
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?

arch/powerpc/platforms/powermac/time.c +40 -26
@@ -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
 
--
Acked-by on v1 3/3
#35 lore raw

Re: [PATCH 3/3] powerpc: fix comment in kernel/irq.c

In reply to Johannes Berg
Quoted 6 lines · Johannes Berg

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.

Quoted 18 lines
arch/powerpc/kernel/irq.c +3 -4
@@ -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();
 
 
--
#5 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

In reply to Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines · Johannes Berg

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

#6 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

Quoted 7 lines · Johannes Berg
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines · Johannes Berg

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.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

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.

#7 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

In reply to Benjamin Herrenschmidt
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines · Johannes Berg

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.

Quoted 6 lines
Quoted 1 line

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

#8 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

Quoted 1 line · Gabriel Paubert

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

Not that I know.

Quoted 6 lines

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.

#9 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

Quoted 13 lines · Benjamin Herrenschmidt
Quoted 1 line · Gabriel Paubert

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

Not that I know.

Quoted 6 lines

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

Quoted 3 lines

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

#10 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

Quoted 4 lines

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

Quoted 3 lines

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

#11 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

Quoted 7 lines
Quoted 3 lines

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.

#12 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

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

#13 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

Quoted 8 lines · Segher Boessenkool
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

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.

Quoted 5 lines
Quoted 1 line

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.

#14 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

Quoted 6 lines
Quoted 3 lines

<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

#15 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 7 lines
Quoted 3 lines

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

Signature · 2 lines
Earthling Michel Dänzer           |          http://tungstengraphics.com
Libre software enthusiast         |          Debian, X and DRI developer
#16 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

Quoted 9 lines · Michel Dänzer
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines
Quoted 3 lines

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.

Quoted 5 lines
Quoted 1 line

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.

#17 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

Quoted 12 lines · Benjamin Herrenschmidt
Quoted 11 lines · Michel Dänzer
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 7 lines
Quoted 3 lines

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.

Quoted 8 lines
Quoted 3 lines

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.

Signature · 2 lines
Earthling Michel Dänzer           |          http://tungstengraphics.com
Libre software enthusiast         |          Debian, X and DRI developer
#18 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

In reply to Segher Boessenkool
Quoted 8 lines · Segher Boessenkool
Quoted 4 lines

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

#19 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

Quoted 3 lines · Gabriel Paubert

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

#20 lore raw

Re: [PATCH 2/3] powermac: proper time of day after resume

In reply to Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines · Johannes Berg

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

arch/powerpc/platforms/powermac/time.c +0 -38
@@ -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
arch/powerpc/kernel/Makefile +1 -0
@@ -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
arch/powerpc/kernel/time_suspend.c new file +62 -0

62 lines not on this page · raw message

#21 lore raw

PATCH 1/1 powermac: proper time of day after resume

In reply to Benjamin Herrenschmidt

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

Cc Benjamin Herrenschmidt <[email protected]>
---
 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.

arch/powerpc/platforms/powermac/time.c +0 -38
@@ -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
arch/powerpc/kernel/Makefile +1 -0
@@ -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
arch/powerpc/kernel/time_suspend.c new file +70 -0

70 lines not on this page · raw message

arch/powerpc/Kconfig +5 -0
@@ -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
#22 lore raw

Re: [PATCH] powermac: proper time of day after resume

Quoted 1 line · Johannes Berg

Tested on my powerbook.

And now on my powermac as well.

johannes

#23 lore raw

Re: [PATCH] powermac: proper time of day after resume

In reply to Johannes Berg
Quoted 11 lines · Johannes Berg

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

Cc Benjamin Herrenschmidt <[email protected]>
---
 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

Signature · 8 lines
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
#24 lore raw

Re: [PATCH] powermac: proper time of day after resume

Quoted 7 lines · Michael Ellerman
Quoted 6 lines · Johannes Berg

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

Cc Benjamin Herrenschmidt <[email protected]>
Quoted 7 lines
Quoted 5 lines
---
 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

#25 lore raw

Re: [PATCH] powermac: proper time of day after resume

In reply to Johannes Berg

arch/powerpc/kernel/time_suspend.c line 26

Quoted 10 lines · Johannes Berg
arch/powerpc/kernel/time_suspend.c new file +10 -0
+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.

arch/powerpc/kernel/time_suspend.c line 35

Quoted 8 lines
arch/powerpc/kernel/time_suspend.c new file +8 -0
+	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.

#26 lore raw

Re: [PATCH] powermac: proper time of day after resume

Quoted 1 line · 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.

#27 lore raw

Re: [PATCH] powermac: proper time of day after resume

In reply to Paul Mackerras
Quoted 5 lines · Paul Mackerras

arch/powerpc/kernel/time_suspend.c line 26

Quoted 3 lines
arch/powerpc/kernel/time_suspend.c new file +3 -0
+	/* 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.

Quoted 3 lines

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

#28 lore raw

PATCH 1/1 powerpc timer sysdev: use mktime

In reply to Paul Mackerras

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

arch/powerpc/sysdev/timer.c +12 -2
@@ -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;
 }
arch/powerpc/Kconfig +0 -5
@@ -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
#29 lore raw

Re: [PATCH] powerpc timer sysdev: use mktime

Quoted 2 lines · Johannes Berg

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?

Quoted 53 lines
arch/powerpc/sysdev/timer.c +12 -2
@@ -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;
 }
arch/powerpc/Kconfig +0 -5
@@ -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
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#30 lore raw

Re: [PATCH] powerpc timer sysdev: use mktime

Quoted 2 lines · Johannes Berg

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.