Skip to contentSkip to conversation

software suspend for ppc.]

[email protected]: [email protected] 3 participants 9 messages Jan 3, 2005 – Jan 7, 2005 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

----- Forwarded message from [email protected] -----

Date: Mon, 3 Jan 2005 20:25:57 +0800
To: [email protected]
Subject: [PATH]software suspend for ppc.

Hi Benjamin Herrenschmidt:

Here is a patch to make ppc32 support suspend, Test passed in my PowerBook, against with 2.6.10-mm1. Have a look. :)

I'm also someone can do more test with it.

thanks.

/arch/ppc/Kconfig renamed from arch/ppc/Kconfig +2 -0
@@ -1062,6 +1062,8 @@ config PROC_HARDWARE
 
 source "drivers/zorro/Kconfig"
 
+source "kernel/power/Kconfig"
+
 endmenu
 
 menu "Bus options"
/arch/ppc/kernel/Makefile renamed from arch/ppc/kernel/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-y				:= entry.o traps.o irq.o idle.o
 					semaphore.o syscalls.o setup.o \
 					cputable.o ppc_htab.o perfmon.o
 obj-$(CONFIG_6xx)		+= l2cr.o cpu_setup_6xx.o
+obj-$(CONFIG_SOFTWARE_SUSPEND) += swsusp.o
 obj-$(CONFIG_POWER4)		+= cpu_setup_power4.o
 obj-$(CONFIG_MODULES)		+= module.o ppc_ksyms.o
 obj-$(CONFIG_NOT_COHERENT_CACHE)	+= dma-mapping.o
/arch/ppc/kernel/signal.c renamed from arch/ppc/kernel/signal.c +10 -0
@@ -28,6 +28,7 @@
 #include <linux/elf.h>
 #include <linux/tty.h>
 #include <linux/binfmts.h>
+#include <linux/suspend.h>
 #include <asm/ucontext.h>
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
@@ -704,6 +705,14 @@ int do_signal(sigset_t *oldset, struct p
 	unsigned long frame, newsp;
 	int signr, ret;
 
+	if (current->flags & PF_FREEZE) {
+		refrigerator(PF_FREEZE);
+		signr = 0;
+		ret = regs->gpr[3];
+		if (!signal_pending(current))
+			goto no_signal;
+	}
+
 	if (!oldset)
 		oldset = &current->blocked;
 
@@ -726,6 +735,7 @@ int do_signal(sigset_t *oldset, struct p
 			regs->gpr[3] = EINTR;
 			/* note that the cr0.SO bit is already set */
 		} else {
+no_signal:
 			regs->nip -= 4;	/* Back up & retry system call */
 			regs->result = 0;
 			regs->trap = 0;
/arch/ppc/kernel/swsusp.c new file +88 -0

88 lines not on this page · raw message

/arch/ppc/kernel/cpu_context.h new file +89 -0

89 lines not on this page · raw message

/arch/ppc/kernel/vmlinux.lds.S renamed from arch/ppc/kernel/vmlinux.lds.S +6 -0
@@ -74,6 +74,12 @@ SECTIONS
     CONSTRUCTORS
   }
 
+  . = ALIGN(4096);
+  __nosave_begin = .;
+  .data_nosave : { *(.data.nosave) }
+  . = ALIGN(4096);
+  __nosave_end = .;
+
   . = ALIGN(32);
   .data.cacheline_aligned : { *(.data.cacheline_aligned) }
 
/include/asm-ppc/suspend.h new file +28 -0
@@ -0,0 +1,28 @@
+/*
+ * Written by Hu Gang ([email protected])
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _ASM_PPC_SUSPEND_H_
+#define _ASM_PPC_SUSPEND_H_
+
+static inline int
+arch_prepare_suspend(void)
+{
+
+	return 0;
+}
+
+/* image of the saved processor states */
+struct saved_context {
+	u32 lr, cr, sp, r2;
+	u64 r12;
+	u32 sprg[4];
+	u32 msr, sdr1, tb1, tb2;
+} __attribute__((packed));
+
+#endif
/include/linux/suspend.h renamed from include/linux/suspend.h +1 -1
@@ -1,7 +1,7 @@
 #ifndef _LINUX_SWSUSP_H
 #define _LINUX_SWSUSP_H
 
-#if defined(CONFIG_X86) || defined(CONFIG_FRV)
+#if defined(CONFIG_X86) || defined(CONFIG_FRV) || defined(CONFIG_PPC32)
 #include <asm/suspend.h>
 #endif
 #include <linux/swap.h>
Signature · 14 lines
Hu Gang       .-.
              /v\
             // \\ 
Linux User  /(   )\  [204016]
GPG Key ID   ^^-^^   http://soulinfo.com/~hugang/hugang.asc

----- End forwarded message -----

-- 
Hu Gang       .-.
              /v\
             // \\ 
Linux User  /(   )\  [204016]
GPG Key ID   ^^-^^   http://soulinfo.com/~hugang/hugang.asc
#1 lore raw

Hi!

Quoted 10 lines

Date: Mon, 3 Jan 2005 20:25:57 +0800
To: [email protected]
Subject: [PATH]software suspend for ppc.

Hi Benjamin Herrenschmidt:

Here is a patch to make ppc32 support suspend, Test passed in my PowerBook, against with 2.6.10-mm1. Have a look. :)

I'm also someone can do more test with it.

swsusp_arch_{suspend,resume} should really be written in assembly. Just compile this, disassemble it and put it into source file. Otherwise it looks OK.
Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#2 lore raw
Quoted 2 lines · Pavel Machek

Hi!

...

Quoted 5 lines

swsusp_arch_{suspend,resume} should really be written in assembly. Just compile this, disassemble it and put it into source file. Otherwise it looks OK.
Pavel

After do more test, I have to drop my last patch, That's unstable. Current I using this one from
http://honk.physik.uni-konstanz.de/~agx/linux-ppc/kernel/

Here is another patch try make software suspend work well. This idea base on swsusp2.

adding a option to freeze/thaw_processes, first freeze all user processess, from now only kernel processess running, Now we can shrink more memory than current version, after that freeze all processes. that's mean if your swap space enough, swsusp will not fail.

/include/linux/sched.h renamed from include/linux/sched.h +2 -2
@@ -1172,8 +1172,8 @@ extern void normalize_rt_tasks(void);
  */
 #ifdef CONFIG_PM
 extern void refrigerator(unsigned long);
-extern int freeze_processes(void);
-extern void thaw_processes(void);
+extern int freeze_processes(int);
+extern void thaw_processes(int);
 
 static inline int try_to_freeze(unsigned long refrigerator_flags)
 {
/kernel/power/disk.c renamed from kernel/power/disk.c +5 -3
@@ -116,7 +116,7 @@ static void finish(void)
 	device_resume();
 	platform_finish();
 	enable_nonboot_cpus();
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 }
 
@@ -128,7 +128,7 @@ static int prepare(void)
 	pm_prepare_console();
 
 	sys_sync();
-	if (freeze_processes()) {
+	if (freeze_processes(0)) {
 		error = -EBUSY;
 		goto Thaw;
 	}
@@ -142,6 +142,8 @@ static int prepare(void)
 
 	/* Free memory before shutting down devices. */
 	free_some_memory();
+	
+	freeze_processes(1);
 
 	disable_nonboot_cpus();
 	if ((error = device_suspend(PM_SUSPEND_DISK)))
@@ -152,7 +154,7 @@ static int prepare(void)
 	platform_finish();
  Thaw:
 	enable_nonboot_cpus();
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 	return error;
 }
/kernel/power/main.c renamed from kernel/power/main.c +3 -3
@@ -55,7 +55,7 @@ static int suspend_prepare(suspend_state
 
 	pm_prepare_console();
 
-	if (freeze_processes()) {
+	if (freeze_processes(1)) {
 		error = -EAGAIN;
 		goto Thaw;
 	}
@@ -72,7 +72,7 @@ static int suspend_prepare(suspend_state
 	if (pm_ops->finish)
 		pm_ops->finish(state);
  Thaw:
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 	return error;
 }
@@ -107,7 +107,7 @@ static void suspend_finish(suspend_state
 	device_resume();
 	if (pm_ops && pm_ops->finish)
 		pm_ops->finish(state);
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 }
 
/kernel/power/power.h renamed from kernel/power/power.h +0 -3
@@ -45,8 +45,5 @@ static struct subsys_attribute _name##_a
 
 extern struct subsystem power_subsys;
 
-extern int freeze_processes(void);
-extern void thaw_processes(void);
-
 extern int pm_prepare_console(void);
 extern void pm_restore_console(void);
/kernel/power/process.c renamed from kernel/power/process.c +7 -5
@@ -19,7 +19,7 @@
 #define TIMEOUT	(6 * HZ)
 
 
-static inline int freezeable(struct task_struct * p)
+static inline int freezeable(struct task_struct * p, int all)
 {
 	if ((p == current) || 
 	    (p->flags & PF_NOFREEZE) ||
@@ -28,6 +28,8 @@ static inline int freezeable(struct task
 	    (p->state == TASK_STOPPED) ||
 	    (p->state == TASK_TRACED))
 		return 0;
+	if (all == 0 && p->mm == NULL) 
+		return 0;
 	return 1;
 }
 
@@ -55,7 +57,7 @@ void refrigerator(unsigned long flag)
 }
 
 /* 0 = success, else # of processes that we failed to stop */
-int freeze_processes(void)
+int freeze_processes(int all)
 {
        int todo;
        unsigned long start_time;
@@ -68,7 +70,7 @@ int freeze_processes(void)
 		read_lock(&tasklist_lock);
 		do_each_thread(g, p) {
 			unsigned long flags;
-			if (!freezeable(p))
+			if (!freezeable(p, all))
 				continue;
 			if ((p->flags & PF_FROZEN) ||
 			    (p->state == TASK_TRACED) ||
@@ -97,14 +99,14 @@ int freeze_processes(void)
 	return 0;
 }
 
-void thaw_processes(void)
+void thaw_processes(int all)
 {
 	struct task_struct *g, *p;
 
 	printk( "Restarting tasks..." );
 	read_lock(&tasklist_lock);
 	do_each_thread(g, p) {
-		if (!freezeable(p))
+		if (!freezeable(p, all))
 			continue;
 		if (p->flags & PF_FROZEN) {
 			p->flags &= ~PF_FROZEN;
Signature · 5 lines
Hu Gang       .-.
              /v\
             // \\ 
Linux User  /(   )\  [204016]
GPG Key ID   ^^-^^   http://soulinfo.com/~hugang/hugang.asc
#3 lore raw

Hi!

Quoted 9 lines
Quoted 4 lines

swsusp_arch_{suspend,resume} should really be written in assembly. Just compile this, disassemble it and put it into source file. Otherwise it looks OK.
Pavel

After do more test, I have to drop my last patch, That's unstable. Current I using this one from
http://honk.physik.uni-konstanz.de/~agx/linux-ppc/kernel/

Quoted 7 lines

Here is another patch try make software suspend work well. This idea base on swsusp2.

adding a option to freeze/thaw_processes, first freeze all user processess, from now only kernel processess running, Now we can shrink more memory than current version, after that freeze all processes. that's mean if your swap space enough, swsusp will not fail.

Thanks for the port... ...what is the test case this fixes?

Patch is pretty pretty simple, that's good...

Pavel

Quoted 147 lines
/include/linux/sched.h renamed from include/linux/sched.h +2 -2
@@ -1172,8 +1172,8 @@ extern void normalize_rt_tasks(void);
  */
 #ifdef CONFIG_PM
 extern void refrigerator(unsigned long);
-extern int freeze_processes(void);
-extern void thaw_processes(void);
+extern int freeze_processes(int);
+extern void thaw_processes(int);
 
 static inline int try_to_freeze(unsigned long refrigerator_flags)
 {
/kernel/power/disk.c renamed from kernel/power/disk.c +5 -3
@@ -116,7 +116,7 @@ static void finish(void)
 	device_resume();
 	platform_finish();
 	enable_nonboot_cpus();
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 }
 
@@ -128,7 +128,7 @@ static int prepare(void)
 	pm_prepare_console();
 
 	sys_sync();
-	if (freeze_processes()) {
+	if (freeze_processes(0)) {
 		error = -EBUSY;
 		goto Thaw;
 	}
@@ -142,6 +142,8 @@ static int prepare(void)
 
 	/* Free memory before shutting down devices. */
 	free_some_memory();
+	
+	freeze_processes(1);
 
 	disable_nonboot_cpus();
 	if ((error = device_suspend(PM_SUSPEND_DISK)))
@@ -152,7 +154,7 @@ static int prepare(void)
 	platform_finish();
  Thaw:
 	enable_nonboot_cpus();
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 	return error;
 }
/kernel/power/main.c renamed from kernel/power/main.c +3 -3
@@ -55,7 +55,7 @@ static int suspend_prepare(suspend_state
 
 	pm_prepare_console();
 
-	if (freeze_processes()) {
+	if (freeze_processes(1)) {
 		error = -EAGAIN;
 		goto Thaw;
 	}
@@ -72,7 +72,7 @@ static int suspend_prepare(suspend_state
 	if (pm_ops->finish)
 		pm_ops->finish(state);
  Thaw:
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 	return error;
 }
@@ -107,7 +107,7 @@ static void suspend_finish(suspend_state
 	device_resume();
 	if (pm_ops && pm_ops->finish)
 		pm_ops->finish(state);
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 }
 
/kernel/power/power.h renamed from kernel/power/power.h +0 -3
@@ -45,8 +45,5 @@ static struct subsys_attribute _name##_a
 
 extern struct subsystem power_subsys;
 
-extern int freeze_processes(void);
-extern void thaw_processes(void);
-
 extern int pm_prepare_console(void);
 extern void pm_restore_console(void);
/kernel/power/process.c renamed from kernel/power/process.c +7 -5
@@ -19,7 +19,7 @@
 #define TIMEOUT	(6 * HZ)
 
 
-static inline int freezeable(struct task_struct * p)
+static inline int freezeable(struct task_struct * p, int all)
 {
 	if ((p == current) || 
 	    (p->flags & PF_NOFREEZE) ||
@@ -28,6 +28,8 @@ static inline int freezeable(struct task
 	    (p->state == TASK_STOPPED) ||
 	    (p->state == TASK_TRACED))
 		return 0;
+	if (all == 0 && p->mm == NULL) 
+		return 0;
 	return 1;
 }
 
@@ -55,7 +57,7 @@ void refrigerator(unsigned long flag)
 }
 
 /* 0 = success, else # of processes that we failed to stop */
-int freeze_processes(void)
+int freeze_processes(int all)
 {
        int todo;
        unsigned long start_time;
@@ -68,7 +70,7 @@ int freeze_processes(void)
 		read_lock(&tasklist_lock);
 		do_each_thread(g, p) {
 			unsigned long flags;
-			if (!freezeable(p))
+			if (!freezeable(p, all))
 				continue;
 			if ((p->flags & PF_FROZEN) ||
 			    (p->state == TASK_TRACED) ||
@@ -97,14 +99,14 @@ int freeze_processes(void)
 	return 0;
 }
 
-void thaw_processes(void)
+void thaw_processes(int all)
 {
 	struct task_struct *g, *p;
 
 	printk( "Restarting tasks..." );
 	read_lock(&tasklist_lock);
 	do_each_thread(g, p) {
-		if (!freezeable(p))
+		if (!freezeable(p, all))
 			continue;
 		if (p->flags & PF_FROZEN) {
 			p->flags &= ~PF_FROZEN;
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#4 lore raw

Hi.

Quoted 14 lines · Pavel Machek

Hi!

Quoted 12 lines
Quoted 4 lines

swsusp_arch_{suspend,resume} should really be written in assembly. Just compile this, disassemble it and put it into source file. Otherwise it looks OK.
Pavel

After do more test, I have to drop my last patch, That's unstable. Current I using this one from
http://honk.physik.uni-konstanz.de/~agx/linux-ppc/kernel/

Here is another patch try make software suspend work well. This idea base on swsusp2.

Quoted 6 lines
Quoted 4 lines

adding a option to freeze/thaw_processes, first freeze all user processess, from now only kernel processess running, Now we can shrink more memory than current version, after that freeze all processes. that's mean if your swap space enough, swsusp will not fail.

Thanks for the port... ...what is the test case this fixes?

I don't know what Steve wants it for, but I use it for freezing userspace, then syncing, then freezing kernelspace.. and I use a couple of #defines to make the argument more readable.

Regards,

Nigel

Quoted 153 lines

Patch is pretty pretty simple, that's good...

Pavel

Quoted 147 lines
/include/linux/sched.h renamed from include/linux/sched.h +2 -2
@@ -1172,8 +1172,8 @@ extern void normalize_rt_tasks(void);
  */
 #ifdef CONFIG_PM
 extern void refrigerator(unsigned long);
-extern int freeze_processes(void);
-extern void thaw_processes(void);
+extern int freeze_processes(int);
+extern void thaw_processes(int);
 
 static inline int try_to_freeze(unsigned long refrigerator_flags)
 {
/kernel/power/disk.c renamed from kernel/power/disk.c +5 -3
@@ -116,7 +116,7 @@ static void finish(void)
 	device_resume();
 	platform_finish();
 	enable_nonboot_cpus();
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 }
 
@@ -128,7 +128,7 @@ static int prepare(void)
 	pm_prepare_console();
 
 	sys_sync();
-	if (freeze_processes()) {
+	if (freeze_processes(0)) {
 		error = -EBUSY;
 		goto Thaw;
 	}
@@ -142,6 +142,8 @@ static int prepare(void)
 
 	/* Free memory before shutting down devices. */
 	free_some_memory();
+	
+	freeze_processes(1);
 
 	disable_nonboot_cpus();
 	if ((error = device_suspend(PM_SUSPEND_DISK)))
@@ -152,7 +154,7 @@ static int prepare(void)
 	platform_finish();
  Thaw:
 	enable_nonboot_cpus();
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 	return error;
 }
/kernel/power/main.c renamed from kernel/power/main.c +3 -3
@@ -55,7 +55,7 @@ static int suspend_prepare(suspend_state
 
 	pm_prepare_console();
 
-	if (freeze_processes()) {
+	if (freeze_processes(1)) {
 		error = -EAGAIN;
 		goto Thaw;
 	}
@@ -72,7 +72,7 @@ static int suspend_prepare(suspend_state
 	if (pm_ops->finish)
 		pm_ops->finish(state);
  Thaw:
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 	return error;
 }
@@ -107,7 +107,7 @@ static void suspend_finish(suspend_state
 	device_resume();
 	if (pm_ops && pm_ops->finish)
 		pm_ops->finish(state);
-	thaw_processes();
+	thaw_processes(1);
 	pm_restore_console();
 }
 
/kernel/power/power.h renamed from kernel/power/power.h +0 -3
@@ -45,8 +45,5 @@ static struct subsys_attribute _name##_a
 
 extern struct subsystem power_subsys;
 
-extern int freeze_processes(void);
-extern void thaw_processes(void);
-
 extern int pm_prepare_console(void);
 extern void pm_restore_console(void);
/kernel/power/process.c renamed from kernel/power/process.c +7 -5
@@ -19,7 +19,7 @@
 #define TIMEOUT	(6 * HZ)
 
 
-static inline int freezeable(struct task_struct * p)
+static inline int freezeable(struct task_struct * p, int all)
 {
 	if ((p == current) || 
 	    (p->flags & PF_NOFREEZE) ||
@@ -28,6 +28,8 @@ static inline int freezeable(struct task
 	    (p->state == TASK_STOPPED) ||
 	    (p->state == TASK_TRACED))
 		return 0;
+	if (all == 0 && p->mm == NULL) 
+		return 0;
 	return 1;
 }
 
@@ -55,7 +57,7 @@ void refrigerator(unsigned long flag)
 }
 
 /* 0 = success, else # of processes that we failed to stop */
-int freeze_processes(void)
+int freeze_processes(int all)
 {
        int todo;
        unsigned long start_time;
@@ -68,7 +70,7 @@ int freeze_processes(void)
 		read_lock(&tasklist_lock);
 		do_each_thread(g, p) {
 			unsigned long flags;
-			if (!freezeable(p))
+			if (!freezeable(p, all))
 				continue;
 			if ((p->flags & PF_FROZEN) ||
 			    (p->state == TASK_TRACED) ||
@@ -97,14 +99,14 @@ int freeze_processes(void)
 	return 0;
 }
 
-void thaw_processes(void)
+void thaw_processes(int all)
 {
 	struct task_struct *g, *p;
 
 	printk( "Restarting tasks..." );
 	read_lock(&tasklist_lock);
 	do_each_thread(g, p) {
-		if (!freezeable(p))
+		if (!freezeable(p, all))
 			continue;
 		if (p->flags & PF_FROZEN) {
 			p->flags &= ~PF_FROZEN;
Signature · 5 lines
Nigel Cunningham
Software Engineer, Canberra, Australia
http://www.cyclades.com

Ph: +61 (2) 6292 8028      Mob: +61 (417) 100 574
#5 lore raw
In reply to Pavel Machek
Quoted 10 lines · Pavel Machek

Hi!

Quoted 4 lines

adding a option to freeze/thaw_processes, first freeze all user processess, from now only kernel processess running, Now we can shrink more memory than current version, after that freeze all processes. that's mean if your swap space enough, swsusp will not fail.

Thanks for the port... ...what is the test case this fixes?

Patch is pretty pretty simple, that's good...

# free
....
Mem:        256368     198148
...
Swap:       524280     140108
# ./eatmem 256

now do swsusp, the current swsusp will fail, with the patch it works.

Signature · 5 lines
Hu Gang       .-.
              /v\
             // \\ 
Linux User  /(   )\  [204016]
GPG Key ID   ^^-^^   http://soulinfo.com/~hugang/hugang.asc

#include <stdio.h>

static int
do_malloc(int size)

{
	char *p;
	int i;

	for (i = 0; i < size; i++) {
		p = malloc(1024 * 1024);
		if (p == NULL) return -1;
		memset(p, 1, 1024 * 1024);
		printf("%2d\r", i);
		fflush(stdout);
	}
	return (0);
}

int
main(int argc, char *argv[])

{
	int size = 200;

	if (argc == 2) {
		size = atoi(argv[1]);
	}

	do_malloc(size);

	pause();
}
#6 lore raw

Hi!

Quoted 15 lines
Quoted 8 lines
Quoted 4 lines

adding a option to freeze/thaw_processes, first freeze all user processess, from now only kernel processess running, Now we can shrink more memory than current version, after that freeze all processes. that's mean if your swap space enough, swsusp will not fail.

Thanks for the port... ...what is the test case this fixes?

Patch is pretty pretty simple, that's good...

# free
....
Mem:        256368     198148
...
Swap:       524280     140108
Quoted 3 lines
# ./eatmem 256

now do swsusp, the current swsusp will fail, with the patch it works.

It worked here:

pavel@amd:~/misc$ gcc eatmem.c -o eatmem
eatmem.c: In function `do_malloc':
eatmem.c:10: warning: assignment makes pointer from integer without a
cast
pavel@amd:~/misc$ cat /proc/swaps
Filename                                Type            Size    Used
Priority
/dev/hda1                               partition       1953464 0
-2
pavel@amd:~/misc$ free
             total       used       free     shared    buffers
cached
Mem:       1031568     989672      41896          0      34340
788156
-/+ buffers/cache:     167176     864392
Swap:      1953464          0    1953464
pavel@amd:~/misc$ ./eatmem 1024
1023

(When it was printing around 900, I switched to another console and tried swsusp (worked ok), then tried again when it printed 1023).

I'm using patched kernel, however, and this patch might be relevant. Can you try to apply it and see if problem goes away? [This patch is ugly hack, but if it helps, we'll simply ask akpm to fix free_some_memory :-)].

Pavel

kernel/power/disk.c +16 -14
@@ -86,23 +86,25 @@
 
 static void free_some_memory(void)
 {
-	unsigned int i = 0;
-	unsigned int tmp;
-	unsigned long pages = 0;
-	char *p = "-\\|/";
-
-	printk("Freeing memory...  ");
-	while ((tmp = shrink_all_memory(10000))) {
-		pages += tmp;
-		printk("\b%c", p[i]);
-		i++;
-		if (i > 3)
-			i = 0;
+	int i;
+	for (i=0; i<5; i++) {
+		int i = 0, tmp;
+		long pages = 0;
+		char *p = "-\\|/";
+
+		printk("Freeing memory...  ");
+		while ((tmp = shrink_all_memory(10000))) {
+			pages += tmp;
+			printk("\b%c", p[i]);
+			i++;
+			if (i > 3)
+				i = 0;
+		}
+		printk("\bdone (%li pages freed)\n", pages);
+		msleep_interruptible(200);
 	}
-	printk("\bdone (%li pages freed)\n", pages);
 }
 
-
 static inline void platform_finish(void)
 {
 	if (pm_disk_mode == PM_DISK_PLATFORM) {
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Hi!

Quoted 11 lines
Quoted 7 lines

(When it was printing around 900, I switched to another console and tried swsusp (worked ok), then tried again when it printed 1023).

I'm using patched kernel, however, and this patch might be relevant. Can you try to apply it and see if problem goes away? [This patch is ugly hack, but if it helps, we'll simply ask akpm to fix free_some_memory :-)].

Yes, It works. :)
36880 * 4096 ~151MB

Quoted 6 lines

Stopping tasks: ==========================================| Freeing memory... done (36880 pages freed)
Freeing memory... done (5720 pages freed)
Freeing memory... done (2816 pages freed)
Freeing memory... done (1999 pages freed)
Freeing memory... done (1954 pages freed)

Okay, so we have to fix free_some_memory, instead of hacking refrigerator. Sorry.
Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#9 lore raw
In reply to [email protected]

Hi Steve.

I'll use this to get Suspend2 PPC going again, if you don't mind.

Regards,

Nigel

Quoted 317 lines · On Mon, 2005-01-03 at 23:26, [email protected] wrote:

----- Forwarded message from [email protected] -----

Date: Mon, 3 Jan 2005 20:25:57 +0800
To: [email protected]
Subject: [PATH]software suspend for ppc.

Hi Benjamin Herrenschmidt:

Here is a patch to make ppc32 support suspend, Test passed in my PowerBook, against with 2.6.10-mm1. Have a look. :)

I'm also someone can do more test with it.

thanks.

/arch/ppc/Kconfig renamed from arch/ppc/Kconfig +2 -0
@@ -1062,6 +1062,8 @@ config PROC_HARDWARE
 
 source "drivers/zorro/Kconfig"
 
+source "kernel/power/Kconfig"
+
 endmenu
 
 menu "Bus options"
/arch/ppc/kernel/Makefile renamed from arch/ppc/kernel/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-y				:= entry.o traps.o irq.o idle.o
 					semaphore.o syscalls.o setup.o \
 					cputable.o ppc_htab.o perfmon.o
 obj-$(CONFIG_6xx)		+= l2cr.o cpu_setup_6xx.o
+obj-$(CONFIG_SOFTWARE_SUSPEND) += swsusp.o
 obj-$(CONFIG_POWER4)		+= cpu_setup_power4.o
 obj-$(CONFIG_MODULES)		+= module.o ppc_ksyms.o
 obj-$(CONFIG_NOT_COHERENT_CACHE)	+= dma-mapping.o
/arch/ppc/kernel/signal.c renamed from arch/ppc/kernel/signal.c +10 -0
@@ -28,6 +28,7 @@
 #include <linux/elf.h>
 #include <linux/tty.h>
 #include <linux/binfmts.h>
+#include <linux/suspend.h>
 #include <asm/ucontext.h>
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
@@ -704,6 +705,14 @@ int do_signal(sigset_t *oldset, struct p
 	unsigned long frame, newsp;
 	int signr, ret;
 
+	if (current->flags & PF_FREEZE) {
+		refrigerator(PF_FREEZE);
+		signr = 0;
+		ret = regs->gpr[3];
+		if (!signal_pending(current))
+			goto no_signal;
+	}
+
 	if (!oldset)
 		oldset = &current->blocked;
 
@@ -726,6 +735,7 @@ int do_signal(sigset_t *oldset, struct p
 			regs->gpr[3] = EINTR;
 			/* note that the cr0.SO bit is already set */
 		} else {
+no_signal:
 			regs->nip -= 4;	/* Back up & retry system call */
 			regs->result = 0;
 			regs->trap = 0;
/arch/ppc/kernel/swsusp.c new file +88 -0
@@ -0,0 +1,88 @@
+/*
+ * Written by Hu Gang ([email protected])
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/spinlock.h>
+#include <linux/poll.h>
+#include <linux/delay.h>
+#include <linux/sysrq.h>
+#include <linux/proc_fs.h>
+#include <linux/irq.h>
+#include <linux/pm.h>
+#include <linux/adb.h>
+#include <linux/cuda.h>
+#include <linux/pmu.h>
+#include <linux/device.h>
+#include <linux/suspend.h>
+#include <asm/mmu_context.h>
+#include <asm/uaccess.h>
+#include <asm/suspend.h>
+
+#include "cpu_context.h"
+
+extern suspend_pagedir_t *pagedir_nosave __nosavedata;
+extern int nr_copy_pages __nosavedata;
+
+extern asmlinkage int swsusp_save(void);
+
+static void inline do_swsusp_copyback(void)
+{
+	register int i = 0; 
+	
+	for (i = 0; i < nr_copy_pages; i++) {
+		register int loop;
+		register unsigned long *orig, *copy;
+		
+		copy = (unsigned long *)pagedir_nosave[i].address;
+		orig = (unsigned long *)pagedir_nosave[i].orig_address;
+		
+		for (loop = 0; 
+		     loop < (PAGE_SIZE / sizeof(unsigned long));
+		     loop ++)
+			*(orig + loop) = *(copy + loop);
+	}
+}
+
+static struct saved_context swsusp_saved_context;
+
+void save_processor_state(void)
+{
+	__save_processor_state(&swsusp_saved_context);
+}
+
+void restore_processor_state(void)
+{
+	__restore_processor_state(&swsusp_saved_context);
+}
+
+void __flush_tlb_global(void)
+{
+	/* do nothing */
+}
+
+static struct saved_context saved_context;
+
+void swsusp_arch_suspend(void)
+{
+	save_context();
+	__save_processor_state(&saved_context);
+	swsusp_save();
+}
+
+void swsusp_arch_resume(void)
+{
+	save_context();
+	do_swsusp_copyback();
+	__restore_processor_state(&saved_context);
+	restore_context();
+}
/arch/ppc/kernel/cpu_context.h new file +89 -0
@@ -0,0 +1,89 @@
+/*
+ * Written by Hu Gang ([email protected])
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+void inline __save_processor_state(struct saved_context *s)
+{
+	/*asm volatile ("mflr 0; stw 0,%0" : "=m" (s->lr));*/
+	asm volatile ("mfcr 0; stw 0,%0" : "=m" (s->cr));
+	asm volatile ("stw 1,%0" : "=m" (s->sp));
+	asm volatile ("stw 2,%0" : "=m" (s->r2));
+	asm volatile ("stmw 12,%0" : "=m" (s->r12));
+
+	/* Save MSR & SDR1 */
+	asm volatile ("mfmsr 4; stw 4,%0" : "=m" (s->msr));
+	asm volatile ("mfsdr1 4; stw 4,%0": "=m" (s->sdr1));
+
+	/* Get a stable timebase and save it */
+	asm volatile ("1:\n"
+		      "mftbu 4;stw 4,%0\n"
+		      "mftb  5;stw 5,%1\n"
+		      "mftbu 3\n"
+		      "cmpw 3,4;\n"
+			  "bne 1b" : 
+			  "=m" (s->tb1),
+			  "=m" (s->tb2));
+		
+	/* Save SPRGs */
+	asm volatile ("mfsprg 4,0; stw 4,%0 " : "=m" (s->sprg[0]));
+	asm volatile ("mfsprg 4,1; stw 4,%0 " : "=m" (s->sprg[1]));
+	asm volatile ("mfsprg 4,2; stw 4,%0 " : "=m" (s->sprg[2]));
+	asm volatile ("mfsprg 4,3; stw 4,%0 " : "=m" (s->sprg[3]));
+}
+
+void inline __restore_processor_state(struct saved_context *s)
+{
+	/* Restore the BATs, and SDR1 */
+	asm volatile ("lwz 4,%0; mtsdr1 4" : "=m" (s->sdr1));
+	/* asm volatile ("lwz 3,%0" : "=m" (saved_context.msr)); */
+
+	asm volatile ("lwz 4,%0; mtsprg 0,4": "=m" (s->sprg[0]));
+	asm volatile ("lwz 4,%0; mtsprg 1,4": "=m" (s->sprg[1]));
+	asm volatile ("lwz 4,%0; mtsprg 2,4": "=m" (s->sprg[2]));
+	asm volatile ("lwz 4,%0; mtsprg 3,4": "=m" (s->sprg[3]));
+
+	/* Restore TB */
+	asm volatile ("li 3,0; mttbl 3; \n"
+		      "lwz 3,%0\n; lwz 4,%1\n"
+		      "mttbu 3; mttbl 4" :
+		      "=m" (s->tb1),
+		      "=m" (s->tb2));
+
+	/* Restore the callee-saved registers and return */
+	asm volatile ("lmw 12,%0" : "=m" (s->r12)); 
+	asm volatile ("lwz 2,%0" : "=m" (s->r2));
+	asm volatile ("lwz 1,%0" : "=m" (s->sp));
+	asm volatile ("lwz 0,%0; mtcr 0" : "=m" (s->cr)); 	
+	/*asm volatile ("lwz 0,%0; mtlr 0" : "=m" (s->lr));*/
+}
+
+static inline void save_context(void)
+{
+	pmu_suspend();
+}
+
+extern void enable_kernel_altivec(void);
+
+static inline void restore_context(void)
+{
+	printk("set context: <%p>\n", current);
+	set_context(current->active_mm->context,
+			current->active_mm->pgd);
+
+	printk("pmu_resume\n");
+	pmu_resume();
+
+#ifdef CONFIG_ALTIVEC
+	if (cur_cpu_spec[0]->cpu_features & CPU_FTR_ALTIVEC) {
+		printk("enable altivec\n");
+		enable_kernel_altivec();
+	}
+#endif
+	printk("enable fp\n");
+	enable_kernel_fp();
+}
/arch/ppc/kernel/vmlinux.lds.S renamed from arch/ppc/kernel/vmlinux.lds.S +6 -0
@@ -74,6 +74,12 @@ SECTIONS
     CONSTRUCTORS
   }
 
+  . = ALIGN(4096);
+  __nosave_begin = .;
+  .data_nosave : { *(.data.nosave) }
+  . = ALIGN(4096);
+  __nosave_end = .;
+
   . = ALIGN(32);
   .data.cacheline_aligned : { *(.data.cacheline_aligned) }
 
/include/asm-ppc/suspend.h new file +28 -0
@@ -0,0 +1,28 @@
+/*
+ * Written by Hu Gang ([email protected])
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _ASM_PPC_SUSPEND_H_
+#define _ASM_PPC_SUSPEND_H_
+
+static inline int
+arch_prepare_suspend(void)
+{
+
+	return 0;
+}
+
+/* image of the saved processor states */
+struct saved_context {
+	u32 lr, cr, sp, r2;
+	u64 r12;
+	u32 sprg[4];
+	u32 msr, sdr1, tb1, tb2;
+} __attribute__((packed));
+
+#endif
/include/linux/suspend.h renamed from include/linux/suspend.h +1 -1
@@ -1,7 +1,7 @@
 #ifndef _LINUX_SWSUSP_H
 #define _LINUX_SWSUSP_H
 
-#if defined(CONFIG_X86) || defined(CONFIG_FRV)
+#if defined(CONFIG_X86) || defined(CONFIG_FRV) || defined(CONFIG_PPC32)
 #include <asm/suspend.h>
 #endif
 #include <linux/swap.h>
Signature · 7 lines
Hu Gang       .-.
              /v\
             // \\ 
Linux User  /(   )\  [204016]
GPG Key ID   ^^-^^   http://soulinfo.com/~hugang/hugang.asc

----- End forwarded message -----
Signature · 5 lines
Nigel Cunningham
Software Engineer, Canberra, Australia
http://www.cyclades.com

Ph: +61 (2) 6292 8028      Mob: +61 (417) 100 574