Suspend 2 merge
Subsystems (53)
Hi everyone.
I know that I still have work to do on suspend2, but thought it was high time I got around to properly submitting the code for review, so here goes.
I have it split up into 51 patches, of which most are less than 20k, although there are three 50k patches. Changes to the rest of the kernel tree come first, then the core. The full tree can be found at
http://suspend2.bkbits.net:8080/merge-tree
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Suspend 2 merge: 7/51: Reboot handler hook.
Nice and simple.
We override swsusp's hook with the suspend2 one. It's not that I want to step on Pavel's toes. Rather, people who go to the trouble of applying suspend2, probably want to use it :>
kernel/sys.c +6 -2
@@ -502,10 +502,14 @@machine_restart (buffer);break ; -#ifdef CONFIG_SOFTWARE_SUSPEND +#ifdef CONFIG_SOFTWARE_SUSPEND2 case LINUX_REBOOT_CMD_SW_SUSPEND : { -int ret =software_suspend (); +int ret = -EINVAL ; +if (!(test_suspend_state (SUSPEND_DISABLED ))) { +suspend_try_suspend (); + ret =0 ; + }unlock_kernel ();return ret; }
Re: Suspend 2 merge: 7/51: Reboot handler hook.
kernel/sys.c line 513
Quoted 11 lines
kernel/sys.c +6
-2-#ifdef CONFIG_SOFTWARE_SUSPEND +#ifdef CONFIG_SOFTWARE_SUSPEND2 case LINUX_REBOOT_CMD_SW_SUSPEND : { -int ret =software_suspend (); +int ret = -EINVAL ; +if (!(test_suspend_state (SUSPEND_DISABLED ))) { +suspend_try_suspend (); + ret =0 ; + }unlock_kernel ();
total crap. Thbis patch breaks the existing swsusp and turns a clean interface into a horrible one. Just implement am
int software_suspend(void)
{
if (test_suspend_state(SUSPEND_DISABLED))
return -EINVAL;
suspend_try_suspend();
return 0;
}in your code.
Re: Suspend 2 merge: 7/51: Reboot handler hook.
Hi.
Quoted 6 lines · Christoph Hellwig
Quoted 6 lines
kernel/sys.c +2
-2-#ifdef CONFIG_SOFTWARE_SUSPEND +#ifdef CONFIG_SOFTWARE_SUSPEND2 case LINUX_REBOOT_CMD_SW_SUSPEND : { -int ret =software_suspend (); +int ret = -EINVAL ;
Quoted 8 lines
kernel/sys.c line 513
Quoted 5 lines
kernel/sys.c +4
-0+if (!(test_suspend_state (SUSPEND_DISABLED ))) { +suspend_try_suspend (); + ret =0 ; + }unlock_kernel ();total crap. Thbis patch breaks the existing swsusp and turns a clean interface into a horrible one. Just implement am
It doesn't break the existing suspend; rather it overrides the action. I will however tidy it up. Sorry about that; I reversed the test a while ago and didn't notice that it could be tidier. I note though that your solution fails to unlock_kernel().
Regards,
Nigel
Quoted 9 lines
int
software_suspend(void){ if (test_suspend_state(SUSPEND_DISABLED)) return -EINVAL; suspend_try_suspend(); return 0; }in your code.
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 7/51: Reboot handler hook.
Sorry.
Misunderstood you the first time. Got it right now.
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Suspend 2 merge: 10/51: Exports for suspend built as modules.
In reply to Nigel CunninghamNew exports for suspend. I've cut them down some as a result of the last review, but could perhaps do more? Would people prefer to see a single struct wrapping exported functions?
The sys_ functions are exported because a while ago, people suggested I use /dev/console to output text that doesn't need to be logged, and I also use /dev/splash for the bootsplash support. These functions were needed in order to get access to those files when we're resuming, and the ioctl for setting up writing text (canon). I'd prefer to use internal routines, but I suppose this way I get the text display on the serial console too :>
Avenrun I'd gladly drop, but apparently sendmail has some ugliness where it won't deliver your mail if the load average gets too high. Guess what suspending to disk does to your load average? (So we save the avenrun values at the start of the cycle and restore them at the end - anyone got a better idea? I'd love to do something different here).
drivers/acpi/hardware/hwsleep.c +4 -0
@@ -43,6 +43,7 @@*/ #include <acpi/acpi.h> +#include <linux/module.h> #define _COMPONENT ACPI_HARDWAREACPI_MODULE_NAME ("hwsleep" )
@@ -591,3 +592,6 @@return_ACPI_STATUS (status); } + +/* For suspend2 */ +EXPORT_SYMBOL (acpi_leave_sleep_state);
fs/bio.c +1 -0
@@ -1002,3 +1002,4 @@EXPORT_SYMBOL (bio_split_pool);EXPORT_SYMBOL (bio_copy_user);EXPORT_SYMBOL (bio_uncopy_user); +EXPORT_SYMBOL (bio_set_pages_dirty);
fs/ioctl.c +2 -3
@@ -138,8 +138,7 @@/* * Platforms implementing 32 bit compatibility ioctl handlers in -* modules need this exported +* modules need this exported. So does Suspend2 (when made as +* modules), so the export_symbol is now unconditional. */ -#ifdef CONFIG_COMPAT EXPORT_SYMBOL (sys_ioctl); -#endif
fs/namei.c +2 -0
@@ -1649,6 +1649,8 @@return error; } +EXPORT_SYMBOL (sys_mkdir); +/* * We try to drop the dentry early: we should have * a usage count of 2 if we're the only user of this
fs/namespace.c +4 -0
@@ -490,6 +490,8 @@return retval; } +EXPORT_SYMBOL (sys_umount); +#ifdef __ARCH_WANT_SYS_OLDUMOUNT/*
@@ -1187,6 +1189,8 @@return retval; } +EXPORT_SYMBOL (sys_mount); +/* * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values. * It can block. Requires the big lock held.
fs/proc/generic.c +2 -0
@@ -698,3 +698,5 @@ out:return ; } + +EXPORT_SYMBOL (proc_match);
fs/read_write.c +1 -0
@@ -314,6 +314,7 @@return ret; } +EXPORT_SYMBOL (sys_write); asmlinkage ssize_t sys_pread64(unsigned int fd, char __user *buf,size_t count,loff_t pos)
kernel/power/main.c +5 -1
@@ -15,7 +15,7 @@#include <linux/errno.h> #include <linux/init.h> #include <linux/pm.h> - +#include <linux/module.h> #include "power.h"
@@ -262,3 +262,7 @@ }core_initcall (pm_init); + +/* For Suspend2 ACPI support */ +EXPORT_SYMBOL (pm_ops); +EXPORT_SYMBOL (pm_disk_mode);
kernel/sched.c +1 -0
@@ -3798,6 +3798,7 @@read_unlock (&tasklist_lock); } +EXPORT_SYMBOL (show_state);void __devinit init_idle (task_t *idle,int cpu) {
kernel/sys.c +2 -0
@@ -523,6 +523,8 @@return 0 ; } +EXPORT_SYMBOL (sys_reboot); +static void deferred_cad (void *dummy) {notifier_call_chain (&reboot_notifier_list,SYS_RESTART ,NULL );
kernel/timer.c +1 -0
@@ -881,6 +881,7 @@* Requires xtime_lock to access. */ unsigned long avenrun[3 ]; +EXPORT_SYMBOL (avenrun);/* * calc_load - given tick count, update the avenrun load estimates.
mm/page_alloc.c +4 -0
@@ -2069,3 +2069,7 @@return table; } + +/* Exported for Software Suspend 2 */ +EXPORT_SYMBOL (nr_free_highpages); +EXPORT_SYMBOL (pgdat_list);
mm/swapfile.c +10 -0
@@ -1710,3 +1710,13 @@swap_device_unlock (swapdev);return ret; } + +/* Functions exported for Software Suspend's swapwriter */ +EXPORT_SYMBOL (swap_free); +EXPORT_SYMBOL (swap_info); +EXPORT_SYMBOL (sys_swapoff); +EXPORT_SYMBOL (sys_swapon); +EXPORT_SYMBOL (si_swapinfo); +EXPORT_SYMBOL (map_swap_page); +EXPORT_SYMBOL (get_swap_page); +EXPORT_SYMBOL (get_swap_info_struct);
mm/vmscan.c +3 -0
@@ -1221,6 +1221,9 @@ current->reclaim_state =NULL ; return ret; } + +/* For Suspend2 */ +EXPORT_SYMBOL (shrink_all_memory);#endif #ifdef CONFIG_HOTPLUG_CPU
Re: Suspend 2 merge: 10/51: Exports for suspend built as modules.
fs/ioctl.c line 145
Quoted 9 lines
/*
* Platforms implementing 32 bit compatibility ioctl handlers in
- * modules need this exported
+ * modules need this exported. So does Suspend2 (when made as
+ * modules), so theexport_symbolis now unconditional. */fs/ioctl.c +0
-2-#ifdef CONFIG_COMPAT EXPORT_SYMBOL (sys_ioctl); -#endif
This is definitly the wrong interface for whatever you want to do.
fs/namei.c line 1652
Quoted 8 lines
diff -ruN
400-exports-old/fs/namei.c400-exports-new/fs/namei.cfs/namei.c +1
-0@@ -1649,6 +1649,8 @@return error; } +EXPORT_SYMBOL (sys_mkdir);
Dito
fs/namespace.c line 493
Quoted 10 lines
fs/namei.c +0
-0* We try to drop the dentry early: we should have * a usage count of 2 if we're the only user of this diff -ruN
400-exports-old/fs/namespace.c400-exports-new/fs/namespace.cfs/namespace.c +1
-0@@ -490,6 +490,8 @@return retval; } +EXPORT_SYMBOL (sys_umount);
Dito
fs/namespace.c line 1192
Quoted 1 line
fs/namespace.c +1
-0+EXPORT_SYMBOL (sys_mount);
Dito.
fs/namespace.c line 495
Quoted 1 line
fs/namespace.c +1
-0+EXPORT_SYMBOL (proc_match);
Also nothing anything outside of procfs internals should do.
fs/namespace.c line 496
Quoted 1 line
fs/namespace.c +1
-0+EXPORT_SYMBOL (sys_write);
wrong aswell.
fs/namespace.c line 497
Quoted 1 line
fs/namespace.c +1
-0+EXPORT_SYMBOL (sys_reboot);
Dito
Quoted 2 lines
unsigned long avenrun[3];
+EXPORT_SYMBOL(avenrun);
Nothing you should poke into.
fs/namespace.c
Quoted 3 lines
fs/namespace.c +3
-0+/* Exported for Software Suspend 2 */ +EXPORT_SYMBOL (nr_free_highpages); +EXPORT_SYMBOL (pgdat_list);
Dito.
fs/namespace.c
Quoted 8 lines
fs/namespace.c +8
-0+EXPORT_SYMBOL (swap_free); +EXPORT_SYMBOL (swap_info); +EXPORT_SYMBOL (sys_swapoff); +EXPORT_SYMBOL (sys_swapon); +EXPORT_SYMBOL (si_swapinfo); +EXPORT_SYMBOL (map_swap_page); +EXPORT_SYMBOL (get_swap_page); +EXPORT_SYMBOL (get_swap_info_struct);
Dito. Lowlevel swapdevice access isn't something modules should poke into.
Nigel, why do I have this strange feeling that exactly the same patch was rejected already but you resubmitted it again?
If you want anything merged drop the modular swsusp bits, I doubt it'll ever be merged.
Re: Suspend 2 merge: 10/51: Exports for suspend built as modules.
Hi.
Quoted 11 lines · Christoph Hellwig
fs/ioctl.c line 145
Quoted 9 lines
/*
* Platforms implementing 32 bit compatibility ioctl handlers in
- * modules need this exported
+ * modules need this exported. So does Suspend2 (when made as
+ * modules), so theexport_symbolis now unconditional. */fs/ioctl.c +0
-2-#ifdef CONFIG_COMPAT EXPORT_SYMBOL (sys_ioctl); -#endif This is definitly the wrong interface for whatever you want to do.
Do you know what I want to do?
Frankly, I actually agree. I'd rather use vt_console_print and gotoxy directly to do the display of information that doesn't need to clutter the logs, but when I first submitted code for doing that, people suggested using /dev/console instead. That makes using these syscalls necessary.
Quoted 3 lines
Quoted 1 line
+EXPORT_SYMBOL(proc_match);
Also nothing anything outside of procfs internals should do.
This was because, following the "use files" methodology above, I have to be able to find the file I want to use (/proc/splash) even when /proc isn't mounted yet. I'll happily just call splash_write_proc.
Quoted 4 lines
Quoted 2 lines
unsigned long avenrun[3];
+EXPORT_SYMBOL(avenrun);Nothing you should poke into.
Mmm. Commented on this elsewhere. Perhaps rather than saving and restoring the values, I should inhibit them being updated? If the BIOS was doing the suspending/resuming, we wouldn't object to them not being updated. Does that sound like a better solution? (Remember the aim was avoid making sendmail etc refuse to work for a while because the load average is too high).
Quoted 5 lines
mm/page_alloc.c line 2075
Quoted 3 lines
mm/page_alloc.c +3
-0+/* Exported for Software Suspend 2 */ +EXPORT_SYMBOL (nr_free_highpages); +EXPORT_SYMBOL (pgdat_list);Dito.
Used for preparing the image.
Quoted 11 lines
mm/swapfile.c line 1722
Quoted 8 lines
mm/swapfile.c +8
-0+EXPORT_SYMBOL (swap_free); +EXPORT_SYMBOL (swap_info); +EXPORT_SYMBOL (sys_swapoff); +EXPORT_SYMBOL (sys_swapon); +EXPORT_SYMBOL (si_swapinfo); +EXPORT_SYMBOL (map_swap_page); +EXPORT_SYMBOL (get_swap_page); +EXPORT_SYMBOL (get_swap_info_struct);Dito. Lowlevel swapdevice access isn't something modules should poke into.
It is if they're writing to swap.
Quoted 2 lines
Nigel, why do I have this strange feeling that exactly the same patch was rejected already but you resubmitted it again?
Not exactly the same but yes, substantially. I listened then to the comments and applied changes. I'm listening now. Unfortunately, though, you just reject things outright without even discussing why they're there or whether there's a better way I might not have thought of. I freely admit that I'm not the world's greatest Linux guru; that's part of why I'm submitting these patches now for review. Could you please try to be more helpful? I'll promise to be receptive!
Quoted 2 lines
If you want anything merged drop the modular swsusp bits, I doubt it'll ever be merged.
Aside from other advantages (quicker development etc), the modular bits allow you to free about 150k (debugging compiled in) when you're not suspending. I thought that was well worth the little bit of extra code.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 10/51: Exports for suspend built as modules.
In reply to Nigel Cunninghamkernel/sched.c line 3801
Quoted 11 lines · Nigel Cunningham
New exports for suspend. I've cut them down some as a result of the last review, but could perhaps do more? Would people prefer to see a single struct wrapping exported functions?
kernel/sched.c +1
-0@@ -3798,6 +3798,7 @@read_unlock (&tasklist_lock); } +EXPORT_SYMBOL (show_state);
this one is ok i think, but make it EXPORT_SYMBOL_GPL() please.
Ingo
Re: Suspend 2 merge: 10/51: Exports for suspend built as modules.
Hi.
Quoted 10 lines · Ingo Molnar
Quoted 8 lines · Nigel Cunningham
New exports for suspend. I've cut them down some as a result of the last review, but could perhaps do more? Would people prefer to see a single struct wrapping exported functions?
kernel/sched.c +0
-0@@ -3798,6 +3798,7 @@
Quoted 5 lines
kernel/sched.c line 3801
Quoted 3 lines
kernel/sched.c +1
-0read_unlock (&tasklist_lock); } +EXPORT_SYMBOL (show_state);this one is ok i think, but make it
EXPORT_SYMBOL_GPL()please.
Okay. Will do.
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 10/51: Exports for suspend built as modules.
In reply to Nigel CunninghamHi!
Quoted 3 lines
The
sys_functions are exported because a while ago, people suggested I use/dev/consoleto output text that doesn't need to be logged, and I also use/dev/splashfor the bootsplash support. These functions were
Well, we don't do ascii-art on kernel boot and I do not see why we should do it on suspend. Distributions will love bootsplash integration, but it should stay as a separate patch.
See swsusp1... it has percentage printing, and I think it should be possible to make it look good enough.
Why do you need sys_mkdir?
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 10/51: Exports for suspend built as modules.
Hi.
Quoted 9 lines · Pavel Machek
Hi!
Quoted 3 lines
The
sys_functions are exported because a while ago, people suggested I use/dev/consoleto output text that doesn't need to be logged, and I also use/dev/splashfor the bootsplash support. These functions wereWell, we don't do ascii-art on kernel boot and I do not see why we should do it on suspend. Distributions will love bootsplash integration, but it should stay as a separate patch.
It's modular, so no problem there.
Quoted 2 lines
See swsusp1... it has percentage printing, and I think it should be possible to make it look good enough.
We can always make a tex_ mode_for_Pavel plugin :>
Quoted 1 line
Why do you need
sys_mkdir?
The text mode plugin is using it to make /dev (if it doesn't exist) so it can try to mount devfs (if necessary) and open /dev/console to do the output. I'd love to just use vt_console_print, but those who know better then me said to use /dev/console...
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 10/51: Exports for suspend built as modules.
Hi!
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
The
sys_functions are exported because a while ago, people suggested I use/dev/consoleto output text that doesn't need to be logged, and I also use/dev/splashfor the bootsplash support. These functions wereWell, we don't do ascii-art on kernel boot and I do not see why we should do it on suspend. Distributions will love bootsplash integration, but it should stay as a separate patch.
It's modular, so no problem there.
That *is* problem. mainline kernel is not expected to carry stuff like that. We do not have bash as a kernel module. Not even gzip. And we should not have ascii-art, too.
Quoted 4 lines
Quoted 2 lines
See swsusp1... it has percentage printing, and I think it should be possible to make it look good enough.
We can always make a
tex_mode_for_Pavelplugin :>
Yes, and then kill all the other plugins from mainline patches and submit that. That would work. Ouch and that means no ugly hooks all over the place in whatever goes into mainline.... and preferably no plugin interface, too.
Quoted 6 lines
Quoted 1 line
Why do you need
sys_mkdir?The text mode plugin is using it to make /dev (if it doesn't exist) so it can try to mount devfs (if necessary) and open
/dev/consoleto do the output. I'd love to just usevt_console_print, but those who know better then me said to use/dev/console...
Ugh, ouch. So if /dev/ is not there you just go and walk over user's filesystem? Please, let's forget the asciiart.
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!
Suspend 2 merge: 11/51: Export vt functions.
In reply to Nigel CunninghamOn wide > 128 char displays, the text display gets messed up if gotoxy's and gotoxay's variables are signed (I should confirm that this is still the case - it's been a while).
We need to modify kmsg_redirect to see our messages when debugging :>
drivers/char/vt.c +3 -2
@@ -913,7 +913,7 @@*/ static void gotoxy (int currcons,int new_x,int new_y) { -int min_y, max_y; +unsigned int min_y, max_y;if (new_x <0 ) x =0 ;
@@ -940,7 +940,7 @@ }/* for absolute user moves, when decom is set */ -static void gotoxay (int currcons,int new_x,int new_y) +static void gotoxay (int currcons,unsigned int new_x,unsigned int new_y) {gotoxy (currcons, new_x, decom ? (top+new_y) : new_y); }
@@ -3312,6 +3312,7 @@* Visible symbols for modules */ +EXPORT_SYMBOL (kmsg_redirect);EXPORT_SYMBOL (color_table);EXPORT_SYMBOL (default_red);EXPORT_SYMBOL (default_grn);
Suspend 2 merge:L 12/51: Disable OOM killer when suspending.
In reply to Nigel CunninghamWhen preparing the image, suspend eats all the memory in sight, both to reduce the image size and to improve the reliability of our stats (We've worked hard to make it work reliably under heavy load - 100+). Of course this can result in the OOM killer being triggered, so this simple test stops that happening.
mm/oom_kill.c +4 -0
@@ -20,6 +20,7 @@#include <linux/swap.h> #include <linux/timex.h> #include <linux/jiffies.h> +#include <linux/suspend.h> /* #define DEBUG */
@@ -237,6 +238,9 @@static unsigned long first, last, count, lastkill;unsigned long now, since; +if (test_suspend_state (SUSPEND_FREEZER_ON )) +return ; +spin_lock (&oom_lock); now = jiffies; since = now - last;
Re: Suspend 2 merge:L 12/51: Disable OOM killer when suspending.
Hi!
Quoted 5 lines
When preparing the image, suspend eats all the memory in sight, both to reduce the image size and to improve the reliability of our stats (We've worked hard to make it work reliably under heavy load - 100+). Of course this can result in the OOM killer being triggered, so this simple test stops that happening.
andrew's shrink_all_memory should enable you to free memory without hacking OOM killer, no?
If shrink_all_memory is broken... fix it.
Pavel
mm/oom_kill.c line 243
Quoted 3 lines
mm/oom_kill.c +3
-0+if (test_suspend_state (SUSPEND_FREEZER_ON )) +return ; +
Hmm, yes, something like this migh be usefull for BUG_ONs etc... For consistency, right name is probably in_suspend(void).
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge:L 12/51: Disable OOM killer when suspending.
Hi.
Quoted 10 lines · Pavel Machek
Hi!
Quoted 5 lines
When preparing the image, suspend eats all the memory in sight, both to reduce the image size and to improve the reliability of our stats (We've worked hard to make it work reliably under heavy load - 100+). Of course this can result in the OOM killer being triggered, so this simple test stops that happening.
andrew's
shrink_all_memoryshould enable you to free memory without hacking OOM killer, no?
I do use shrink_all_memory, but I also then allocate those pages that were freed. We added that when seeking to get Suspend to work well and reliably under heavy load. IIRC, the issue was that pages that were freed were immediately getting allocated by other programs. Having said this, it is a while since I looked at the code for preparing the image. I can take a look and confirm my thinking.
Quoted 1 line
If
shrink_all_memoryis broken... fix it.
Agree.
Quoted 6 lines
mm/oom_kill.c line 243
Quoted 3 lines
mm/oom_kill.c +3
-0+if (test_suspend_state (SUSPEND_FREEZER_ON )) +return ; +Hmm, yes, something like this migh be usefull for
BUG_ONsetc... For consistency, right name is probablyin_suspend(void).
There is a difference; there is sections of time where we're in_suspend (test_suspend_state(SUSPEND_RUNNING)) but the freezer isn't on (initial set up and cleanup). As far as the OOM killer goes, it probably doesn't matter which is used, but I thought it important to point out that freezer being on !== in_suspend(). (Freezer could also be on for S3?.. 'spose you don't care of OOM killer runs then, though). Would you like to see in_freezer()?
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge:L 12/51: Disable OOM killer when suspending.
Hi!
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
When preparing the image, suspend eats all the memory in sight, both to reduce the image size and to improve the reliability of our stats (We've worked hard to make it work reliably under heavy load - 100+). Of course this can result in the OOM killer being triggered, so this simple test stops that happening.
andrew's
shrink_all_memoryshould enable you to free memory without hacking OOM killer, no?
Quoted 6 lines
I do use
shrink_all_memory, but I also then allocate those pages that were freed. We added that when seeking to get Suspend to work well and reliably under heavy load. IIRC, the issue was that pages that were freed were immediately getting allocated by other programs. Having said this, it is a while since I looked at the code for preparing the image. I can take a look and confirm my thinking.
How is it possible that other programs steal memory when they are frozen? That just should not happen.
Quoted 10 lines
Quoted 2 lines
Hmm, yes, something like this migh be usefull for
BUG_ONsetc... For consistency, right name is probablyin_suspend(void).There is a difference; there is sections of time where we're
in_suspend(test_suspend_state(SUSPEND_RUNNING)) but the freezer isn't on (initial set up and cleanup). As far as the OOM killer goes, it probably doesn't matter which is used, but I thought it important to point out that freezer being on !==in_suspend(). (Freezer could also be on for S3?.. 'spose you don't care of OOM killer runs then, though). Would you like to seein_freezer()?
There was discussion on linux-pm that something like in_freezer() would be nice for sanity-checks, but don't introduce it just because of that.
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!
Suspend 2 merge: 13/51: Disable highmem tlb flush for copyback.
In reply to Nigel CunninghamWhen we're making/restoring our atomic copy of the image, secondary processors are frozen. Trying an SMP call at that time could thus lead to deadlock. Secondary processors have their tlbs unconditionally flushed when leaving the processor refrigerator, so this doesn't come back to bite us.
mm/highmem.c +5 -1
@@ -26,6 +26,7 @@#include <linux/init.h> #include <linux/hash.h> #include <linux/highmem.h> +#include <linux/suspend.h> #include <asm/tlbflush.h> static mempool_t *page_pool, *isa_page_pool;
@@ -94,7 +95,10 @@set_page_address (page,NULL ); } -flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); +if (test_suspend_state (SUSPEND_FREEZE_SMP )) +__flush_tlb (); +else +flush_tlb_kernel_range (PKMAP_ADDR (0 ),PKMAP_ADDR (LAST_PKMAP )); }static inline unsigned long map_new_virtual (struct page *page)
Re: Suspend 2 merge: 13/51: Disable highmem tlb flush for copyback.
Hi!
Quoted 3 lines
When we're making/restoring our atomic copy of the image, secondary processors are frozen. Trying an SMP call at that time could thus lead to deadlock. Secondary processors have
Yes, and thats reason not to do SMP calls, not to hack SMP calling!
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Suspend 2 merge: 9/51: init/* changes.
In reply to Nigel CunninghamThis patch includes all of the changes to init/*.
There are two main parts:
1) Make name_to_dev_t non init. Why should you need to reboot if all you want to do is change the device you're using to suspend? That's M$'s way :>. Suspend2 allows the user to change the resume2= parameter after booting via a proc entry. Making this code non-__init allows us to use the same code that will be used at boot time to parse that string.
2) Hooks for resuming. Suspend2 functionality can be compiled as modules or built in. Resuming can be activated via an initrd. These hooks allow for all of the combinations of the above. Allowing resuming from within an initrd is important because then you can set up LVM volumes (including encrypted devices), compile drivers for your resume device as modules and so on.
init/do_mounts.c +29 -5
@@ -52,7 +52,7 @@__setup ("ro" , readonly);__setup ("rw" , readwrite); -static dev_t __init try_name (char *name,int part) +static dev_t try_name (char *name,int part) {char path[64 ];char buf[32 ];
@@ -134,16 +134,21 @@* is mounted on rootfs /sys. */ -dev_t __init name_to_dev_t (char *name) +dev_t name_to_dev_t (char *name) {char s[32 ];char *p;dev_t res =0 ; -int part; +int part, mount_result;#ifdef CONFIG_SYSFS int mkdir_err =sys_mkdir ("/sys" ,0700 ); -if (sys_mount ("sysfs" ,"/sys" ,"sysfs" ,0 ,NULL ) <0 ) +/* +* When changing resume2 parameter for Software Suspend, sysfs may +* already be mounted. +*/ + mount_result =sys_mount ("sysfs" ,"/sys" ,"sysfs" ,0 ,NULL ); +if (mount_result <0 && mount_result != -EBUSY ) goto out;#endif
@@ -195,7 +200,8 @@ res =try_name (s, part); done:#ifdef CONFIG_SYSFS -sys_umount ("/sys" ,0 ); +if (mount_result >=0 ) +sys_umount ("/sys" ,0 ); out:if (!mkdir_err)sys_rmdir ("/sys" );
@@ -205,6 +211,8 @@ res =0 ; goto done; } +/* Exported for Software Suspend */ +EXPORT_SYMBOL (name_to_dev_t);static int __init root_dev_setup (char *line) {
@@ -398,9 +406,25 @@ is_floppy =MAJOR (ROOT_DEV ) ==FLOPPY_MAJOR ; +/* Suspend2: +* By this point, suspend_early_init has been called to initialise our +* proc interface. If modules are built in, they have registered (all +* of the above via late_initcalls). +* +* We have not yet looked to see if an image exists, however. If we +* have an initrd, it is expected that the user will have set it up +* to echo > /proc/software_suspend/activate and thus initiate any +* resume. If they don'tdo that, we do it immediately after the initrd +* is finished (major issues if they mount filesystems rw from the +* initrd! - they are warned. If there's no usable initrd, we do our +* check next +*/ if (initrd_load ()) goto out; +if (test_suspend_state (SUSPEND_RESUME_NOT_DONE )) +software_suspend_try_resume (); +if (is_floppy && rd_doload &&rd_load_disk (0 ))ROOT_DEV = Root_RAM0;
init/do_mounts_initrd.c +8 -1
@@ -7,6 +7,7 @@#include <linux/romfs_fs.h> #include <linux/initrd.h> #include <linux/sched.h> +#include <linux/suspend.h> #include "do_mounts.h"
@@ -58,10 +59,16 @@ pid =kernel_thread (do_linuxrc,"/linuxrc" ,SIGCHLD );if (pid >0 ) { -while (pid !=sys_wait4 (-1 , &i,0 ,NULL )) +while (pid !=sys_wait4 (-1 , &i,0 ,NULL )) {yield (); +if (current->flags &PF_FREEZE ) +refrigerator (PF_FREEZE ); + } } +if (test_suspend_state (SUSPEND_RESUME_NOT_DONE )) +software_suspend_try_resume (); +/* move initrd to rootfs' /old */ sys_fchdir (old_fd);sys_mount ("/" ,"." ,NULL ,MS_MOVE ,NULL );
init/main.c +3 -0
@@ -46,6 +46,7 @@#include <linux/rmap.h> #include <linux/mempolicy.h> #include <linux/key.h> +#include <linux/suspend.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -758,6 +759,8 @@else prepare_namespace (); +clear_suspend_state (SUSPEND_BOOT_TIME ); +/* * Ok, we have completed the initial bootup, and * we're essentially up and running. Get rid of the
kernel/power/swsusp.c +1 -1
@@ -1168,7 +1168,7 @@ } -extern dev_t __init name_to_dev_t (const char *line); +extern dev_t name_to_dev_t (char *line);static int __init read_pagedir (void ) {
Re: Suspend 2 merge: 9/51: init/* changes.
Hi!
Quoted 2 lines
1) Make
name_to_dev_tnon init. Why should you need to reboot if all you want to do is change the device you're using to suspend? That's M_'s way
Well, if you change it using /proc and forget to change kernel cmd line, you'll have a problem. Do you really change this so often?
And if you really want to make it changeable, pass major:minor from userland; once userland is running getting them is easy.
Quoted 6 lines
2) Hooks for resuming. Suspend2 functionality can be compiled as modules or built in. Resuming can be activated via an initrd. These hooks allow for all of the combinations of the above. Allowing resuming from within an initrd is important because then you can set up LVM volumes (including encrypted devices), compile drivers for your resume device as modules and so on.
Hmm , this will need a lot of testing and a lot of care... You for example mah not write to your fs's before activating it. And if you use this feature, kernel no longer has chance to kill suspend signature on normal boot, making "shoot(self, foot)" easier.
But for encrypted stuff it is probably only way to go, so... Just make sure people are not using it unless they *have* to.
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 9/51: init/* changes.
Hi.
Quoted 7 lines · Pavel Machek
Hi!
Quoted 2 lines
1) Make
name_to_dev_tnon init. Why should you need to reboot if all you want to do is change the device you're using to suspend? That's M_'s wayWell, if you change it using /proc and forget to change kernel cmd line, you'll have a problem. Do you really change this so often?
It's mostly used when setting up a new installation, and when attempting LVM support. It's particularly useful in the later case because you can swap off and so on, prepare your new LVM volume, prepare swap on it, do the echo > resume2 and then check dmesg, and be assured that you've got the right setup, all without needing to reboot. In the case of a new config, you still need to reboot once, of course, into the new kernel, but if you get the resume2= parameter wrong, you don't have to waste time rebooting just because of a typo. You can just fix your lilo.conf (or equiv) and use echo > resume2 to fix the mistake.
Quoted 2 lines
And if you really want to make it changeable, pass major:minor from userland; once userland is running getting them is easy.
Yes, but that's also far uglier, and who thinks in terms of major and minor numbers anyway? I think of my harddrive as /dev/sda, not 08:xx. The parsing accepts majors and minors, of course, but shouldn't we make these things easier to do, not harder? (Would we insist on using majors and minors for root=?).
Quoted 11 lines
Quoted 6 lines
2) Hooks for resuming. Suspend2 functionality can be compiled as modules or built in. Resuming can be activated via an initrd. These hooks allow for all of the combinations of the above. Allowing resuming from within an initrd is important because then you can set up LVM volumes (including encrypted devices), compile drivers for your resume device as modules and so on.
Hmm , this will need a lot of testing and a lot of care... You for example mah not write to your fs's before activating it. And if you use this feature, kernel no longer has chance to kill suspend signature on normal boot, making "
shoot(self, foot)" easier.
It has had it. We do rely on the user to make a sensible linuxrc/init, but there are examples and warnings given in the docs on Berlios, and plenty of checking done. We have to take the risk anyway: without it, we can't support Debian (ide support built as modules), LVM (needs to set up mappings in an initrd) or encrypted storage (ditto).
Quoted 2 lines
But for encrypted stuff it is probably only way to go, so... Just make sure people are not using it unless they *have* to.
See above.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 9/51: init/* changes.
Hi!
Quoted 8 lines
Quoted 2 lines
And if you really want to make it changeable, pass major:minor from userland; once userland is running getting them is easy.
Yes, but that's also far uglier, and who thinks in terms of major and minor numbers anyway? I think of my harddrive as
/dev/sda, not 08:xx. The parsing accepts majors and minors, of course, but shouldn't we make these things easier to do, not harder? (Would we insist on using majors and minors for root=?).
Kernel interface is not supposed to be "easy". root= has exception, that's init code, and you can't easily ls -al /dev at that point. If you want easy interface, create userland program that looks up minor/major in /dev/ and uses them.
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!
Re: Suspend 2 merge: 9/51: init/* changes.
Hi.
Quoted 11 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 2 lines
And if you really want to make it changeable, pass major:minor from userland; once userland is running getting them is easy.
Yes, but that's also far uglier, and who thinks in terms of major and minor numbers anyway? I think of my harddrive as
/dev/sda, not 08:xx. The parsing accepts majors and minors, of course, but shouldn't we make these things easier to do, not harder? (Would we insist on using majors and minors for root=?).
Quoted 4 lines
Kernel interface is not supposed to be "easy". root= has exception, that's init code, and you can't easily ls -al /dev at that point. If you want easy interface, create userland program that looks up minor/major in
/dev/and uses them.
That's a fair possibility, but is it really worth it when all we need to do is make two routines not be init? We would still have to duplicate some of this code elsewhere anyway, because we need to parse the major and minor numbers.
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 9/51: init/* changes.
Hi!
Quoted 14 lines
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
And if you really want to make it changeable, pass major:minor from userland; once userland is running getting them is easy.
Yes, but that's also far uglier, and who thinks in terms of major and minor numbers anyway? I think of my harddrive as
/dev/sda, not 08:xx. The parsing accepts majors and minors, of course, but shouldn't we make these things easier to do, not harder? (Would we insist on using majors and minors for root=?).Quoted 4 lines
Kernel interface is not supposed to be "easy". root= has exception, that's init code, and you can't easily ls -al /dev at that point. If you want easy interface, create userland program that looks up minor/major in
/dev/and uses them.
Quoted 4 lines
That's a fair possibility, but is it really worth it when all we need to do is make two routines not be init? We would still have to duplicate some of this code elsewhere anyway, because we need to parse the major and minor numbers.
Parsing major/minor should be as simple as sscanf("%d %d"). And you'll have one less modification to generic code. Yes I think it is worth it.
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!
Re: Suspend 2 merge: 9/51: init/* changes.
Hi.
Quoted 16 lines · Pavel Machek
Hi!
Quoted 14 lines
Quoted 13 lines
Quoted 8 lines
Quoted 2 lines
And if you really want to make it changeable, pass major:minor from userland; once userland is running getting them is easy.
Yes, but that's also far uglier, and who thinks in terms of major and minor numbers anyway? I think of my harddrive as
/dev/sda, not 08:xx. The parsing accepts majors and minors, of course, but shouldn't we make these things easier to do, not harder? (Would we insist on using majors and minors for root=?).Kernel interface is not supposed to be "easy". root= has exception, that's init code, and you can't easily ls -al /dev at that point. If you want easy interface, create userland program that looks up minor/major in
/dev/and uses them.
Quoted 8 lines
Quoted 4 lines
That's a fair possibility, but is it really worth it when all we need to do is make two routines not be init? We would still have to duplicate some of this code elsewhere anyway, because we need to parse the major and minor numbers.
Parsing major/minor should be as simple as
sscanf("%d %d"). And you'll have one less modification to generic code. Yes I think it is worth it.
In that case, we shouldn't access names at boot time either; the interface should be consistent, shouldn't it? I really would prefer to keep things as they are; is it worth all this fuss?
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 9/51: init/* changes.
Hi!
Quoted 7 lines
Quoted 3 lines
Parsing major/minor should be as simple as
sscanf("%d %d"). And you'll have one less modification to generic code. Yes I think it is worth it.In that case, we shouldn't access names at boot time either; the interface should be consistent, shouldn't it? I really would prefer to keep things as they are; is it worth all this fuss?
/proc file is really different from kernel commandline. Consistent interface is nice but run-time allocated kernel memory is nicer, and hooks to common code are not nice. Simply drop that /proc file and we are done with that fuss.
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!
Re: Suspend 2 merge: 9/51: init/* changes.
In reply to Pavel MachekQuoted 7 lines · Pavel Machek
Hi!
Quoted 2 lines
1) Make
name_to_dev_tnon init. Why should you need to reboot if all you want to do is change the device you're using to suspend? That's M_'s wayWell, if you change it using /proc and forget to change kernel cmd line, you'll have a problem. Do you really change this so often?
name_to_dev_t needs to be non-init in order to make it possible to trigger a resume when the block device driver isn't static. Pavel, would you be willing to consider a patch to make it possible to trigger swsusp resume from userspace? That gets things working with initrd kernels. I've been using something along these lines for a few weeks now, and it hasn't eaten my filesystem yet.
Quoted 4 lines
Hmm , this will need a lot of testing and a lot of care... You for example mah not write to your fs's before activating it. And if you use this feature, kernel no longer has chance to kill suspend signature on normal boot, making "
shoot(self, foot)" easier.
Yes, I was thinking of this mostly from a distribution perspective. There's always potential for data-loss if users resume after touching the root filesystem. On the other hand, it's currently possible for them to do that anyway (think booting a different kernel without swsusp support, then rebooting back into the swsusp one)
Signature · 1 line
Matthew Garrett | [email protected]
Re: Suspend 2 merge: 9/51: init/* changes.
Hi!
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
1) Make
name_to_dev_tnon init. Why should you need to reboot if all you want to do is change the device you're using to suspend? That's M_'s wayWell, if you change it using /proc and forget to change kernel cmd line, you'll have a problem. Do you really change this so often?
Quoted 6 lines
name_to_dev_tneeds to be non-init in order to make it possible to trigger a resume when the block device driver isn't static. Pavel, would you be willing to consider a patch to make it possible to trigger swsusp resume from userspace? That gets things working with initrd kernels. I've been using something along these lines for a few weeks now, and it hasn't eaten my filesystem yet.
Given it is not too intrusive... why not. Send it for comments. I probably will not use this myself, so you'll need to test/maintain it.
Quoted 5 lines
Yes, I was thinking of this mostly from a distribution perspective. There's always potential for data-loss if users resume after touching the root filesystem. On the other hand, it's currently possible for them to do that anyway (think booting a different kernel without swsusp support, then rebooting back into the swsusp one)
Yep...
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 9/51: init/* changes.
Quoted 11 lines · Pavel Machek
Quoted 7 lines
name_to_dev_tneeds to be non-init in order to make it possible to trigger a resume when the block device driver isn't static. Pavel, would you be willing to consider a patch to make it possible to trigger swsusp resume from userspace? That gets things working with initrd kernels. I've been using something along these lines for a few weeks now, and it hasn't eaten my filesystem yet.Given it is not too intrusive... why not. Send it for comments. I probably will not use this myself, so you'll need to test/maintain it.
This shouldn't be necessary. Since the resume is being initiated by userspace, it can perform the function of name_to_dev_t and just feed the numbers to the kernel. The code to do that is still in Debian's initrd-tools.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtRe: Suspend 2 merge: 9/51: init/* changes.
Quoted 9 lines · Herbert Xu
Quoted 3 lines · Pavel Machek
Given it is not too intrusive... why not. Send it for comments. I probably will not use this myself, so you'll need to test/maintain it.
This shouldn't be necessary. Since the resume is being initiated by userspace, it can perform the function of
name_to_dev_tand just feed the numbers to the kernel. The code to do that is still in Debian's initrd-tools.
Good point. Ok, what's the best way to present this to userspace? Add a /sys/power/resume and then echo a major:minor in there?
Signature · 1 line
Matthew Garrett | [email protected]
Re: Suspend 2 merge: 9/51: init/* changes.
Hi!
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines
Given it is not too intrusive... why not. Send it for comments. I probably will not use this myself, so you'll need to test/maintain it.
This shouldn't be necessary. Since the resume is being initiated by userspace, it can perform the function of
name_to_dev_tand just feed the numbers to the kernel. The code to do that is still in Debian's initrd-tools.Good point. Ok, what's the best way to present this to userspace? Add a
/sys/power/resumeand then echo a major:minor in there?
Yes, that sounds reasonable. Plus docuementation and big warning about usage of /sys/power/resume...
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!
Re: Suspend 2 merge: 9/51: init/* changes.
In reply to Matthew GarrettHi.
Quoted 6 lines · Matthew Garrett
Quoted 5 lines · Herbert Xu
Quoted 3 lines · Pavel Machek
Given it is not too intrusive... why not. Send it for comments. I probably will not use this myself, so you'll need to test/maintain it.
Quoted 7 lines
Quoted 4 lines
This shouldn't be necessary. Since the resume is being initiated by userspace, it can perform the function of
name_to_dev_tand just feed the numbers to the kernel. The code to do that is still in Debian's initrd-tools.Good point. Ok, what's the best way to present this to userspace? Add a
/sys/power/resumeand then echo a major:minor in there?
If you're ever going to add swapfile support, you're also going to want to be able to specify the blocksize and block at which the swapheader begins.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Suspend 2 merge: 8/51: /proc/acpi/sleep hook.
In reply to Nigel CunninghamSame thing as the previous patch, but for /proc/acpi/sleep.
drivers/acpi/sleep/proc.c +11 -0
@@ -68,6 +68,17 @@ goto Done; } state =simple_strtoul (str,NULL ,0 ); +#ifdef CONFIG_SOFTWARE_SUSPEND2 +/* +* I used to put this after the CONFIG_SOFTWARE_SUSPEND +* test, but people who compile in suspend2 usually want +* to use it instead of swsusp. --NC +*/ +if (state ==4 ) { +suspend_try_suspend (); + goto Done; + } +#endif #ifdef CONFIG_SOFTWARE_SUSPEND if (state ==4 ) {software_suspend ();
Re: Suspend 2 merge: 8/51: /proc/acpi/sleep hook.
Quoted 1 line · Nigel Cunningham
Same thing as the previous patch, but for
/proc/acpi/sleep.
And again totally bogus. Make sure swsusp and swsusp2 export the same interface. Preferably the old one, but if it absolutely doesn't fit your needs submit a patch to switch the old code to the new interface first.
Suspend 2 merge: 4/51: Get module list.
In reply to Nigel CunninghamThis provides access to the list of loaded modules for suspend's debugging output. When a cycle finishes, suspend outputs something the following:
Quoted 20 lines
Please include the following information in bug reports:
- SUSPEND core : 2.1.5.7
- Kernel Version : 2.6.9
- Compiler vers. : 3.3
- Modules loaded : tuner bttv videodevsnd_seq_osssnd_seq_midi_eventsnd_seqsnd_pcm_osssnd_mixer_osssnd_intel8x0snd_ac97_codecsnd_pcmsnd_timersnd_page_allocsnd_mpu401_uartsnd_rawmidisnd_seq_devicesnd soundcore visor usbserial usblp joydev evdev usbmouse usbhiduhci_hcdusbcoreppp_deflatezlib_deflatezlib_inflatebsd_compipt_LOGipt_stateipt_MASQUERADEiptable_natip_conntrackipt_multiportipt_REJECTiptable_filterip_tablesppp_asyncppp_genericslhccrc_ccittvideo_bufv4l2_commonbtcx_riscWin4Linmki_adapterradeon agpgartparport_pclp parport sgide_cdsr_modcdrom floppyaf_packete1000 loopdm_modtsdevsuspend_bootsplashsuspend_textsuspend_swapsuspend_block_iosuspend_lzfsuspend_core
- Attempt number : 9
- Parameters : 0 2304 32768 1 0 4096 5
- Limits : 261680 pages RAM. Initial boot: 252677.
- Overall expected compression percentage: 0.
- LZF Compressor enabled.
Quoted 8 lines
Compressed 922112000 bytes into 437892038 (52 percent compression).
- Swapwriter active.
Swap available for image: 294868 pages.
- Debugging compiled in.
- Preemptive kernel.
- SMP kernel.
- Highmem Support.
- I/O speed: Write 72 MB/s, Read 119 MB/s.
Including the modules loaded is very helpful for debugging problems.
kernel/module.c +14 -0
@@ -2105,6 +2105,18 @@ }EXPORT_SYMBOL (module_remove_driver); +int print_module_list_to_buffer (char * buffer,int size) +{ +struct module *mod; +int pos =0 ; + +list_for_each_entry (mod, &modules, list) +if (mod->name) + pos +=snprintf (buffer+pos, size-pos-1 , +"%s " , mod->name); +return pos; +} +#ifdef CONFIG_MODVERSIONS /* Generate the signature for struct module here, too, for modversions. */ void struct_module (struct module *mod) {return ; }
@@ -2115,3 +2127,5 @@struct list_head *kdb_modules = &modules;/* kdb needs the list of modules */ #endif /* CONFIG_KDB */ +/* For Suspend2 */ +EXPORT_SYMBOL (print_module_list_to_buffer);
Re: Suspend 2 merge: 4/51: Get module list.
Hi!
Quoted 33 lines
This provides access to the list of loaded modules for suspend's debugging output. When a cycle finishes, suspend outputs something the following:
Quoted 20 lines
Please include the following information in bug reports:
- SUSPEND core : 2.1.5.7
- Kernel Version : 2.6.9
- Compiler vers. : 3.3
- Modules loaded : tuner bttv videodevsnd_seq_osssnd_seq_midi_eventsnd_seqsnd_pcm_osssnd_mixer_osssnd_intel8x0snd_ac97_codecsnd_pcmsnd_timersnd_page_allocsnd_mpu401_uartsnd_rawmidisnd_seq_devicesnd soundcore visor usbserial usblp joydev evdev usbmouse usbhiduhci_hcdusbcoreppp_deflatezlib_deflatezlib_inflatebsd_compipt_LOGipt_stateipt_MASQUERADEiptable_natip_conntrackipt_multiportipt_REJECTiptable_filterip_tablesppp_asyncppp_genericslhccrc_ccittvideo_bufv4l2_commonbtcx_riscWin4Linmki_adapterradeon agpgartparport_pclp parport sgide_cdsr_modcdrom floppyaf_packete1000 loopdm_modtsdevsuspend_bootsplashsuspend_textsuspend_swapsuspend_block_iosuspend_lzfsuspend_core
- Attempt number : 9
- Parameters : 0 2304 32768 1 0 4096 5
- Limits : 261680 pages RAM. Initial boot: 252677.
- Overall expected compression percentage: 0.
- LZF Compressor enabled.Quoted 8 lines
Compressed 922112000 bytes into 437892038 (52 percent compression).
- Swapwriter active.
Swap available for image: 294868 pages.
- Debugging compiled in.
- Preemptive kernel.
- SMP kernel.
- Highmem Support.
- I/O speed: Write 72 MB/s, Read 119 MB/s.
Quoted 1 line
Including the modules loaded is very helpful for debugging problems.
It might be usefull as an add-on patch when people are actually debugging it, but I do not think it is needed for mainline. You can just do lsmod before suspend...
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 4/51: Get module list.
Hi.
Quoted 35 lines · Pavel Machek
Hi!
Quoted 33 lines
This provides access to the list of loaded modules for suspend's debugging output. When a cycle finishes, suspend outputs something the following:
Quoted 28 lines
Please include the following information in bug reports:
- SUSPEND core : 2.1.5.7
- Kernel Version : 2.6.9
- Compiler vers. : 3.3
- Modules loaded : tuner bttv videodevsnd_seq_osssnd_seq_midi_eventsnd_seqsnd_pcm_osssnd_mixer_osssnd_intel8x0snd_ac97_codecsnd_pcmsnd_timersnd_page_allocsnd_mpu401_uartsnd_rawmidisnd_seq_devicesnd soundcore visor usbserial usblp joydev evdev usbmouse usbhiduhci_hcdusbcoreppp_deflatezlib_deflatezlib_inflatebsd_compipt_LOGipt_stateipt_MASQUERADEiptable_natip_conntrackipt_multiportipt_REJECTiptable_filterip_tablesppp_asyncppp_genericslhccrc_ccittvideo_bufv4l2_commonbtcx_riscWin4Linmki_adapterradeon agpgartparport_pclp parport sgide_cdsr_modcdrom floppyaf_packete1000 loopdm_modtsdevsuspend_bootsplashsuspend_textsuspend_swapsuspend_block_iosuspend_lzfsuspend_core
- Attempt number : 9
- Parameters : 0 2304 32768 1 0 4096 5
- Limits : 261680 pages RAM. Initial boot: 252677.
- Overall expected compression percentage: 0.
- LZF Compressor enabled.
Compressed 922112000 bytes into 437892038 (52 percent compression).
- Swapwriter active.
Swap available for image: 294868 pages.
- Debugging compiled in.
- Preemptive kernel.
- SMP kernel.
- Highmem Support.
- I/O speed: Write 72 MB/s, Read 119 MB/s.
Quoted 4 lines
Quoted 1 line
Including the modules loaded is very helpful for debugging problems.
It might be usefull as an add-on patch when people are actually debugging it, but I do not think it is needed for mainline. You can just do lsmod before suspend...
Yes. It's still pretty helpful, but not as much as it has been in the past. We're almost at the point where we can automatically say "Have you got USB compiled in? Compile it as modules. Have you got USB modules loaded? Unload them and reload after suspending. Have you got DRI support loaded? Depending on chipset, do X, Y, or Z." That deals with the vast majority of freezes.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 4/51: Get module list.
Hi!
Quoted 9 lines
Quoted 2 lines
It might be usefull as an add-on patch when people are actually debugging it, but I do not think it is needed for mainline. You can just do lsmod before suspend...
Yes. It's still pretty helpful, but not as much as it has been in the past. We're almost at the point where we can automatically say "Have you got USB compiled in? Compile it as modules. Have you got USB modules loaded? Unload them and reload after suspending. Have you got DRI support loaded? Depending on chipset, do X, Y, or Z." That deals with the vast majority of freezes.
Yes, that's big problem. We need to get driver support right.... Hmm, perhaps we should at least make the "known-problematic" cases block suspend with helpfull message?
It works for me (tm) with usb with recent kernels.
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!
Suspend 2 merge: 3/51: e820 table support
In reply to Nigel CunninghamThe first of the 'real' candidates for merging.
This adds support for setting and clearing the Nosave status of pages based on the contents of the e820 table, and clearing Nosave for __init pages when they're freed.
arch/i386/mm/init.c +28 -8
@@ -27,6 +27,7 @@#include <linux/slab.h> #include <linux/proc_fs.h> #include <linux/efi.h> +#include <linux/suspend.h> #include <asm/processor.h> #include <asm/system.h>
@@ -266,12 +267,15 @@ {if (page_is_ram (pfn) && !(bad_ppro &&page_kills_ppro (pfn))) {ClearPageReserved (page); +ClearPageNosave (page);set_bit (PG_highmem, &page->flags);set_page_count (page,1 );__free_page (page); totalhigh_pages++; - }else + }else {SetPageReserved (page); +SetPageNosave (page); + } }#ifndef CONFIG_DISCONTIGMEM
@@ -349,7 +353,7 @@#endif } -#if defined(CONFIG_PM_DISK ) || defined(CONFIG_SOFTWARE_SUSPEND ) +#ifdef CONFIG_PM /* * Swap suspend & friends need this for resume because things like the intel-agp * driver might have split up a kernel 4MB mapping.
@@ -569,6 +573,7 @@int codesize, reservedpages, datasize, initsize;int tmp;int bad_ppro; +void * addr;#ifndef CONFIG_DISCONTIGMEM if (!mem_map)
@@ -599,12 +604,25 @@ totalram_pages +=__free_all_bootmem (); reservedpages =0 ; -for (tmp =0 ; tmp < max_low_pfn; tmp++) -/* -* Only count reserved RAM pages -*/ -if (page_is_ram (tmp) &&PageReserved (pfn_to_page (tmp))) - reservedpages++; + addr =__va (0 ); +for (tmp =0 ; tmp < max_low_pfn; tmp++, addr +=PAGE_SIZE ) { +if (page_is_ram (tmp)) { +/* +* Only count reserved RAM pages +*/ +if (PageReserved (mem_map+tmp)) + reservedpages++; +/* +* Mark nosave pages +*/ +if (addr >= (void *)&__nosave_begin && addr < (void *)&__nosave_end) +SetPageNosave (mem_map+tmp); + }else +/* +* Non-RAM pages are always nosave +*/ +SetPageNosave (mem_map+tmp); + }set_highmem_pages_init (bad_ppro);
@@ -703,6 +721,7 @@ addr = (unsigned long )(&__init_begin);for (; addr < (unsigned long )(&__init_end); addr +=PAGE_SIZE ) {ClearPageReserved (virt_to_page (addr)); +ClearPageNosave (virt_to_page (addr));set_page_count (virt_to_page (addr),1 );free_page (addr); totalram_pages++;
@@ -717,6 +736,7 @@printk (KERN_INFO "Freeing initrd memory: %ldk freed\n" , (end - start) >>10 );for (; start < end; start +=PAGE_SIZE ) {ClearPageReserved (virt_to_page (start)); +ClearPageNosave (virt_to_page (start));set_page_count (virt_to_page (start),1 );free_page (start); totalram_pages++;
mm/bootmem.c +4 -0
@@ -279,11 +279,13 @@ count +=BITS_PER_LONG ;__ClearPageReserved (page); +ClearPageNosave (page);set_page_count (page,1 );for (j =1 ; j <BITS_PER_LONG ; j++) {if (j +16 <BITS_PER_LONG )prefetchw (page + j +16 );__ClearPageReserved (page + j); +ClearPageNosave (page + j); }__free_pages (page,ffs (BITS_PER_LONG )-1 ); i +=BITS_PER_LONG ;
@@ -294,6 +296,7 @@if (v & m) { count++;__ClearPageReserved (page); +ClearPageNosave (page);set_page_count (page,1 );__free_page (page); }
@@ -314,6 +317,7 @@for (i =0 ; i < ((bdata->node_low_pfn-(bdata->node_boot_start >>PAGE_SHIFT ))/8 +PAGE_SIZE -1 )/PAGE_SIZE ; i++,page++) { count++;__ClearPageReserved (page); +ClearPageNosave (page);set_page_count (page,1 );__free_page (page); }
Re: Suspend 2 merge: 3/51: e820 table support
Hi!
Quoted 5 lines
The first of the 'real' candidates for merging.
This adds support for setting and clearing the Nosave status of pages based on the contents of the e820 table, and clearing Nosave for
__initpages when they're freed.
I'd say that page that is both nosave and __init would be a bug. But strategic BUG_ON() would be welcome...
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Suspend2 merge: 1/51: Device trees
In reply to Nigel CunninghamThis patch allows the device tree to be split up into multiple trees. I don't really expect it to be merged, but it is an important part of suspend at the moment, and I certainly want to see something like it that will allow us to suspend some parts of the device tree and not others. Suspend2 uses it to keep alive the hard drive (or equivalent) that we're writing the image to while suspending other devices, thus improving the consistency of the image written.
I remember from last time this was posted that someone commented on exporting the default device tree; I haven't changed that yet.
drivers/base/power/main.c +19 -5
@@ -4,6 +4,9 @@* Copyright (c) 2003 Patrick Mochel * Copyright (c) 2003 Open Source Development Lab * +* Partial tree additions +* Copyright (c) 2004 Nigel Cunningham +* * This file is released under the GPLv2 * *
@@ -23,10 +26,18 @@#include <linux/device.h> #include "power.h" -LIST_HEAD (dpm_active); -LIST_HEAD (dpm_off); -LIST_HEAD (dpm_off_irq); - +struct partial_device_tree default_device_tree = +{ + .dpm_active =LIST_HEAD_INIT (default_device_tree.dpm_active), + .dpm_off =LIST_HEAD_INIT (default_device_tree.dpm_off), + .dpm_off_irq =LIST_HEAD_INIT (default_device_tree.dpm_off_irq), +}; +EXPORT_SYMBOL (default_device_tree); + +/* +* One mutex for all trees because we can be moving items +* between trees. +*/ DECLARE_MUTEX (dpm_sem);DECLARE_MUTEX (dpm_list_sem);
@@ -77,7 +88,9 @@ dev->bus ? dev->bus->name : "No Bus", dev->kobj.name);atomic_set (&dev->power.pm_users,0 );down (&dpm_list_sem); -list_add_tail (&dev->power.entry, &dpm_active); +list_add_tail (&dev->power.entry, &default_device_tree.dpm_active); + dev->current_list =DEVICE_LIST_DPM_ACTIVE ; + dev->tree = &default_device_tree;device_pm_set_parent (dev, dev->parent);if ((error =dpm_sysfs_add (dev)))list_del (&dev->power.entry);
@@ -93,6 +106,7 @@dpm_sysfs_remove (dev);device_pm_release (dev->power.pm_parent);list_del_init (&dev->power.entry); + dev->current_list =DEVICE_LIST_NONE ;up (&dpm_list_sem); }
drivers/base/power/Makefile +1 -1
@@ -1,5 +1,5 @@ obj-y := shutdown.o -obj-$(CONFIG_PM) += main.o suspend.o resume.o runtime.o sysfs.o +obj-$(CONFIG_PM) += main.o suspend.o resume.o runtime.o sysfs.o tree.o ifeq ($(CONFIG_DEBUG_DRIVER),y) EXTRA_CFLAGS += -DDEBUG
drivers/base/power/power.h +17 -3
@@ -35,10 +35,22 @@/* * The PM lists. */ -extern struct list_head dpm_active; -extern struct list_head dpm_off; -extern struct list_head dpm_off_irq; +struct partial_device_tree +{ +struct list_head dpm_active; +struct list_head dpm_off; +struct list_head dpm_off_irq; +}; + +enum { +DEVICE_LIST_NONE , +DEVICE_LIST_DPM_ACTIVE , +DEVICE_LIST_DPM_OFF , +DEVICE_LIST_DPM_OFF_IRQ , +}; + +extern struct partial_device_tree default_device_tree;static inline struct dev_pm_info *to_pm_info (struct list_head * entry) {
@@ -64,7 +76,9 @@* resume.c */ +extern void dpm_resume_tree (struct partial_device_tree * tree);extern void dpm_resume (void ); +extern void dpm_power_up_tree (struct partial_device_tree * tree);extern void dpm_power_up (void );extern int resume_device (struct device *);
drivers/base/power/resume.c +29 -8
@@ -29,16 +29,17 @@ -void dpm_resume (void ) +void dpm_resume_tree (struct partial_device_tree * tree) {down (&dpm_list_sem); -while (!list_empty (&dpm_off)) { -struct list_head * entry = dpm_off.next; +while (!list_empty (&tree->dpm_off)) { +struct list_head * entry = tree->dpm_off.next;struct device * dev =to_device (entry);get_device (dev);list_del_init (entry); -list_add_tail (entry, &dpm_active); +list_add_tail (entry, &tree->dpm_active); + dev->current_list =DEVICE_LIST_DPM_ACTIVE ;up (&dpm_list_sem);if (!dev->power.prev_state)
@@ -50,6 +51,11 @@ } +void dpm_resume (void ) +{ +dpm_resume_tree (&default_device_tree); +} +/** * device_resume - Restore state of each device in system. *
@@ -66,6 +72,14 @@EXPORT_SYMBOL_GPL (device_resume); +void device_resume_tree (struct partial_device_tree * tree) +{ +down (&dpm_sem); +dpm_resume_tree (tree); +up (&dpm_sem); +} + +EXPORT_SYMBOL (device_resume_tree);/** * device_power_up_irq - Power on some devices.
@@ -78,20 +92,27 @@* Interrupts must be disabled when calling this. */ -void dpm_power_up (void ) +void dpm_power_up_tree (struct partial_device_tree * tree) { -while (!list_empty (&dpm_off_irq)) { -struct list_head * entry = dpm_off_irq.next; +while (!list_empty (&tree->dpm_off_irq)) { +struct list_head * entry = tree->dpm_off_irq.next;struct device * dev =to_device (entry);get_device (dev);list_del_init (entry); -list_add_tail (entry, &dpm_active); +list_add_tail (entry, &tree->dpm_active); + dev->current_list =DEVICE_LIST_DPM_ACTIVE ;resume_device (dev);put_device (dev); } } +EXPORT_SYMBOL (dpm_power_up_tree); + +void dpm_power_up (void ) +{ +dpm_power_up_tree (&default_device_tree); +}/** * device_pm_power_up - Turn on all devices that need special attention.
drivers/base/power/shutdown.c +1 -0
@@ -65,3 +65,4 @@sysdev_shutdown (); } +EXPORT_SYMBOL (device_shutdown);
drivers/base/power/suspend.c +29 -18
101 lines not on this page · raw message
drivers/base/power/tree.c +105 -0
105 lines not on this page · raw message
drivers/base/sys.c +2 -1
@@ -337,7 +337,7 @@ }return 0 ; } - +EXPORT_SYMBOL (sysdev_suspend);/** * sysdev_resume - Bring system devices back to life.
@@ -384,6 +384,7 @@ }return 0 ; } +EXPORT_SYMBOL (sysdev_resume);int __init system_bus_init (void )
include/linux/device.h +5 -0
@@ -285,6 +285,11 @@override */ void (*release)(struct device * dev); + +struct partial_device_tree * tree;/* Which tree of devices this +device is in */ +int current_list;/* Which list within the tree the +device is on (speeds moving) */ }; static inline struct device *
include/linux/pm.h +15 -2
@@ -235,12 +235,25 @@extern void device_pm_set_parent (struct device * dev,struct device * parent); +struct partial_device_tree ; +extern struct partial_device_tree default_device_tree; +extern int device_suspend (u32 state); +extern int device_suspend_tree (u32 state,struct partial_device_tree * tree);extern int device_power_down (u32 state); +extern int device_power_down_tree (u32 state,struct partial_device_tree * tree);extern void device_power_up (void ); +extern void device_power_up_tree (struct partial_device_tree * tree);extern void device_resume (void ); - - +extern void device_resume_tree (struct partial_device_tree * tree); +extern void device_merge_tree (struct partial_device_tree * source, +struct partial_device_tree * dest); +extern void device_switch_trees (struct device * dev,struct partial_device_tree * tree); +extern void dpm_power_up_tree (struct partial_device_tree * tree); +extern int sysdev_suspend (u32 state); +extern int sysdev_resume (void ); +extern struct partial_device_tree *device_create_tree (void ); +extern void device_destroy_tree (struct partial_device_tree * tree);#endif /* __KERNEL__ */ #endif /* _LINUX_PM_H */
Suspend2 merge: 2/51: Find class by name
In reply to Nigel CunninghamA second patch that shouldn't be needed but is at the moment. It is used to find any framebuffer drivers and add put them in the kept-alive device tree. Once Pavel's improvements to the PM_ states are merged, I hope this will be able to go away.
Not sure if would be helpful elsewhere?
drivers/base/class.c +21 -0
@@ -497,6 +497,25 @@kobject_put (&class_dev->kobj); } +struct class *class_find (char * name) +{ +struct class * this_class; + +if (!name) +return NULL ; + +down_read (&class_subsys.rwsem); +list_for_each_entry (this_class, &class_subsys.kset.list, subsys.kset.kobj.entry) { +if (!(strcmp (this_class->name, name))) { +class_get (this_class); +up_read (&class_subsys.rwsem); +return this_class; + } + } +up_read (&class_subsys.rwsem); + +return NULL ; +}int class_interface_register (struct class_interface *class_intf) {
@@ -579,3 +598,5 @@EXPORT_SYMBOL_GPL (class_interface_register);EXPORT_SYMBOL_GPL (class_interface_unregister); + +EXPORT_SYMBOL_GPL (class_find);
include/linux/device.h +1 -0
@@ -164,6 +164,7 @@extern struct class *class_get (struct class *);extern void class_put (struct class *); +extern struct class *class_find (char * name);struct class_attribute {
Suspend 2 merge: 17/51: Disable MCE checking during suspend.
In reply to Nigel CunninghamAvoid a potential SMP deadlock here.
arch/i386/kernel/cpu/mcheck/non-fatal.c +3 -1
@@ -17,6 +17,7 @@#include <linux/interrupt.h> #include <linux/smp.h> #include <linux/module.h> +#include <linux/suspend.h> #include <asm/processor.h> #include <asm/system.h>
@@ -57,7 +58,8 @@static void mce_work_fn (void *data) { -on_each_cpu (mce_checkregs,NULL ,1 ,1 ); +if (!test_suspend_state (SUSPEND_RUNNING )) +on_each_cpu (mce_checkregs,NULL ,1 ,1 );schedule_delayed_work (&mce_work,MCE_RATE ); }
Re: Suspend 2 merge: 17/51: Disable MCE checking during suspend.
Hi!
Quoted 1 line
Avoid a potential SMP deadlock here.
..and loose MCE report.
Pavel
Quoted 10 lines
arch/i386/kernel/cpu/mcheck/non-fatal.c +2
-1@@ -57,7 +58,8 @@static void mce_work_fn (void *data) { -on_each_cpu (mce_checkregs,NULL ,1 ,1 ); +if (!test_suspend_state (SUSPEND_RUNNING )) +on_each_cpu (mce_checkregs,NULL ,1 ,1 );schedule_delayed_work (&mce_work,MCE_RATE ); }
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 17/51: Disable MCE checking during suspend.
Hi.
Quoted 5 lines · Pavel Machek
Hi!
Quoted 1 line
Avoid a potential SMP deadlock here.
..and loose MCE report.
Deadlock or get an MCE report and do a printk when we're shutting down anyway?
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 17/51: Disable MCE checking during suspend.
Hi!
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Avoid a potential SMP deadlock here.
..and loose MCE report.
Deadlock or get an MCE report and do a printk when we're shutting down anyway?
If MCE happens, I'd like user to report it. Loosing it is wrong, deadlocking may be actually better because at least you get the report. I'd BUG().
MCEs are hardware problem, right? They should not be common.
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!
Re: Suspend 2 merge: 17/51: Disable MCE checking during suspend.
Hi.
Quoted 6 lines · Pavel Machek
Hi!
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Avoid a potential SMP deadlock here.
..and loose MCE report.
Quoted 8 lines
Quoted 2 lines
Deadlock or get an MCE report and do a printk when we're shutting down anyway?
If MCE happens, I'd like user to report it. Loosing it is wrong, deadlocking may be actually better because at least you get the report. I'd
BUG().MCEs are hardware problem, right? They should not be common.
It's not them occurring that's the problem, it's checking for them that involves an SMP call :<
Quoted 6 lines
static void
mce_work_fn(void *data){ if (!test_suspend_state(SUSPEND_RUNNING)) on_each_cpu(mce_checkregs, NULL, 1, 1); schedule_delayed_work(&mce_work, MCE_RATE); }
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 17/51: Disable MCE checking during suspend.
Hi!
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Avoid a potential SMP deadlock here.
..and loose MCE report.
Deadlock or get an MCE report and do a printk when we're shutting down anyway?
Quoted 8 lines
Quoted 5 lines
If MCE happens, I'd like user to report it. Loosing it is wrong, deadlocking may be actually better because at least you get the report. I'd
BUG().MCEs are hardware problem, right? They should not be common.
It's not them occurring that's the problem, it's checking for them that involves an SMP call :<
Oops, that bad... and checking is done periodically? That's bad. Okay, your solution is right here.
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!
Suspend 2 merge: 5/51: Workthread freezer support.
In reply to Nigel CunninghamThis thread adds freezer support for workthreads.
A new parameter in the create_ functions allows the thread to be marked as PF_NOFREEZE. This should only be used for threads that may need to run during writing the image.
In a later patch, you'll see a new SYNCTHREAD flag, used for processes that need to run while we're syncing data to disk, but not for writing the image. That isn't used here because all kernel threads are frozen after we've synced, so it's irrelevant to them.
drivers/acpi/osl.c +1 -1
@@ -90,7 +90,7 @@ return AE_NULL_ENTRY; }#endif - kacpid_wq =create_singlethread_workqueue ("kacpid" ); + kacpid_wq =create_singlethread_workqueue ("kacpid" ,0 );BUG_ON (!kacpid_wq);return AE_OK ;
drivers/block/ll_rw_blk.c +1 -1
@@ -3021,7 +3021,7 @@int __init blk_dev_init (void ) { - kblockd_workqueue =create_workqueue ("kblockd" ); + kblockd_workqueue =create_workqueue ("kblockd" ,PF_NOFREEZE );if (!kblockd_workqueue)panic ("Failed to create kblockd\n" );
drivers/char/hvc_console.c +1 -1
@@ -757,7 +757,7 @@/* Always start the kthread because there can be hotplug vty adapters * added later. */ - hvc_task =kthread_run (khvcd,NULL ,"khvcd" ); + hvc_task =kthread_run (khvcd,NULL ,PF_NOFREEZE ,"khvcd" );if (IS_ERR (hvc_task)) {panic ("Couldn't create kthread for console.\n" );put_tty_driver (hvc_driver);
drivers/char/hvcs.c +1 -1
@@ -1420,7 +1420,7 @@return -ENOMEM ; } - hvcs_task =kthread_run (khvcsd,NULL ,"khvcsd" ); + hvcs_task =kthread_run (khvcsd,NULL ,PF_NOFREEZE ,"khvcsd" );if (IS_ERR (hvcs_task)) {printk (KERN_ERR "HVCS: khvcsd creation failed. Driver not loaded.\n" );kfree (hvcs_pi_buff);
drivers/macintosh/therm_adt746x.c +1 -1
@@ -394,7 +394,7 @@write_both_fan_speed (th,-1 ); } - thread_therm =kthread_run (monitor_task, th,"kfand" ); + thread_therm =kthread_run (monitor_task, th,0 ,"kfand" );if (thread_therm ==ERR_PTR (-ENOMEM )) {printk (KERN_INFO "adt746x: Kthread creation failed\n" );
drivers/md/dm-crypt.c +1 -1
@@ -758,7 +758,7 @@if (!_crypt_io_pool)return -ENOMEM ; - _kcryptd_workqueue =create_workqueue ("kcryptd" ); + _kcryptd_workqueue =create_workqueue ("kcryptd" ,PF_NOFREEZE );if (!_kcryptd_workqueue) { r = -ENOMEM ;DMERR (PFX "couldn't create kcryptd" );
drivers/md/dm-raid1.c +1 -1
@@ -1233,7 +1233,7 @@if (r)return r; - _kmirrord_wq =create_workqueue ("kmirrord" ); + _kmirrord_wq =create_workqueue ("kmirrord" ,PF_SYNCTHREAD );if (!_kmirrord_wq) {DMERR ("couldn't start kmirrord" );dm_dirty_log_exit ();
drivers/md/kcopyd.c +1 -1
@@ -609,7 +609,7 @@return r; } - _kcopyd_wq =create_singlethread_workqueue ("kcopyd" ); + _kcopyd_wq =create_singlethread_workqueue ("kcopyd" ,PF_SYNCTHREAD );if (!_kcopyd_wq) {jobs_exit ();up (&kcopyd_init_lock);
drivers/message/i2o/driver.c +1 -1
@@ -80,7 +80,7 @@pr_debug ("Register driver %s\n" , drv->name);if (drv->event) { - drv->event_queue =create_workqueue (drv->name); + drv->event_queue =create_workqueue (drv->name,0 );if (!drv->event_queue) {printk (KERN_ERR "i2o: Could not initialize event queue " "for driver %s\n" , drv->name);
drivers/net/wan/sdlamain.c +1 -1
@@ -240,7 +240,7 @@printk (KERN_INFO "%s v%u.%u %s\n" , fullname,DRV_VERSION ,DRV_RELEASE , copyright); - wanpipe_wq =create_workqueue ("wanpipe_wq" ); + wanpipe_wq =create_workqueue ("wanpipe_wq" ,0 );if (!wanpipe_wq)return -ENOMEM ;
drivers/s390/cio/device.c +4 -3
@@ -151,15 +151,16 @@init_waitqueue_head (&ccw_device_init_wq);atomic_set (&ccw_device_init_count,0 ); - ccw_device_work =create_singlethread_workqueue ("cio" ); + ccw_device_work =create_singlethread_workqueue ("cio" ,0 );if (!ccw_device_work)return -ENOMEM ;/* FIXME: better errno ? */ - ccw_device_notify_work =create_singlethread_workqueue ("cio_notify" ); + ccw_device_notify_work =create_singlethread_workqueue ("cio_notify" , +0 );if (!ccw_device_notify_work) { ret = -ENOMEM ;/* FIXME: better errno ? */ goto out_err; } - slow_path_wq =create_singlethread_workqueue ("kslowcrw" ); + slow_path_wq =create_singlethread_workqueue ("kslowcrw" ,0 );if (!slow_path_wq) { ret = -ENOMEM ;/* FIXME: better errno ? */ goto out_err;
drivers/scsi/libata-core.c +1 -1
@@ -3591,7 +3591,7 @@static int __init ata_init (void ) { - ata_wq =create_workqueue ("ata" ); + ata_wq =create_workqueue ("ata" ,0 );if (!ata_wq)return -ENOMEM ;
fs/aio.c +1 -1
@@ -72,7 +72,7 @@ kioctx_cachep =kmem_cache_create ("kioctx" ,sizeof (struct kioctx ),0 ,SLAB_HWCACHE_ALIGN |SLAB_PANIC ,NULL ,NULL ); - aio_wq =create_workqueue ("aio" ); + aio_wq =create_workqueue ("aio" ,0 );pr_debug ("aio_setup: sizeof(struct page) = %d\n" , (int )sizeof (struct page ));
fs/reiserfs/journal.c +1 -1
@@ -2483,7 +2483,7 @@ reiserfs_mounted_fs_count++ ;if (reiserfs_mounted_fs_count <=1 ) - commit_wq =create_workqueue ("reiserfs" ); + commit_wq =create_workqueue ("reiserfs" ,PF_SYNCTHREAD );INIT_WORK (&journal->j_work, flush_async_commits, p_s_sb);return 0 ;
fs/xfs/linux-2.6/xfs_buf.c +2 -2
@@ -1784,11 +1784,11 @@ {int rval; - pagebuf_logio_workqueue =create_workqueue ("xfslogd" ); + pagebuf_logio_workqueue =create_workqueue ("xfslogd" ,PF_SYNCTHREAD );if (!pagebuf_logio_workqueue)return -ENOMEM ; - pagebuf_dataio_workqueue =create_workqueue ("xfsdatad" ); + pagebuf_dataio_workqueue =create_workqueue ("xfsdatad" ,PF_SYNCTHREAD );if (!pagebuf_dataio_workqueue) {destroy_workqueue (pagebuf_logio_workqueue);return -ENOMEM ;
include/linux/kthread.h +8 -2
@@ -25,20 +25,26 @@*/ struct task_struct *kthread_create (int (*threadfn)(void *data),void *data, +unsigned long freezer_flags,const char namefmt[], ...);/** * kthread_run: create and wake a thread. * @threadfn: the function to run until signal_pending(current). * @data: data ptr for @threadfn. +* @freezer_flags: process flags that should be used for freezing. +* PF_SYNCTHREAD if needed for syncing data to disk. +* PF_NOFREEZE if also needed for writing the image. +* 0 otherwise. * @namefmt: printf-style name for the thread. * * Description: Convenient wrapper for kthread_create() followed by * wake_up_process(). Returns the kthread, or ERR_PTR(-ENOMEM). */ -#define kthread_run (threadfn, data, namefmt, ...) \ +#define kthread_run (threadfn, data, freezer_flags, namefmt, ...) \ ({ \ struct task_struct *__k \ - = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \ + = kthread_create(threadfn, data, freezer_flags, \ + namefmt, ## __VA_ARGS__); \ if (!IS_ERR(__k)) \ wake_up_process(__k); \ __k; \
include/linux/workqueue.h +4 -3
@@ -51,9 +51,10 @@ }while (0 ) extern struct workqueue_struct *__create_workqueue(const char *name, -int singlethread); -#define create_workqueue (name) __create_workqueue((name), 0) -#define create_singlethread_workqueue (name) __create_workqueue((name), 1) +int singlethread, +unsigned long freezer_flag); +#define create_workqueue (name, flags) __create_workqueue((name), 0, flags) +#define create_singlethread_workqueue (name, flags) __create_workqueue((name), 1, flags)extern void destroy_workqueue (struct workqueue_struct *wq);
kernel/kmod.c +1 -1
@@ -274,6 +274,6 @@void __init usermodehelper_init (void ) { - khelper_wq =create_singlethread_workqueue ("khelper" ); + khelper_wq =create_singlethread_workqueue ("khelper" ,0 );BUG_ON (!khelper_wq); }
kernel/kthread.c +7 -0
@@ -19,6 +19,7 @@/* Information passed to kthread() from keventd. */ int (*threadfn)(void *data);void *data; +unsigned long freezer_flags;struct completion started;/* Result passed back to kthread_create() from keventd. */
@@ -80,6 +81,10 @@/* By default we can run anywhere, unlike keventd. */ set_cpus_allowed (current,CPU_MASK_ALL ); +/* Set our freezer flags */ + current->flags &= ~(PF_SYNCTHREAD |PF_NOFREEZE ); + current->flags |= create->freezer_flags; +/* OK, tell user we're spawned, wait for stop or wakeup */ __set_current_state (TASK_INTERRUPTIBLE );complete (&create->started);
@@ -115,6 +120,7 @@struct task_struct *kthread_create (int (*threadfn)(void *data),void *data, +unsigned long freezer_flags,const char namefmt[], ...) {
@@ -123,6 +129,7 @@ create.threadfn = threadfn; create.data = data; + create.freezer_flags = freezer_flags;init_completion (&create.started);init_completion (&create.done);
kernel/sched.c +2 -2
@@ -4146,10 +4146,10 @@switch (action) {case CPU_UP_PREPARE : - p =kthread_create (migration_thread, hcpu,"migration/%d" ,cpu); + p =kthread_create (migration_thread, hcpu,0 , +"migration/%d" ,cpu);if (IS_ERR (p))return NOTIFY_BAD ; - p->flags |=PF_NOFREEZE ;kthread_bind (p, cpu);/* Must be high prio: stop_machine expects to yield to it. */ rq =task_rq_lock (p, &flags);
kernel/softirq.c +3 -2
@@ -328,7 +328,6 @@static int ksoftirqd (void * __bind_cpu) {set_user_nice (current,19 ); - current->flags |=PF_NOFREEZE ;set_current_state (TASK_INTERRUPTIBLE );
@@ -338,6 +337,8 @@__set_current_state (TASK_RUNNING ); +try_to_freeze (PF_FREEZE ); +while (local_softirq_pending ()) {/* Preempt disable stops cpu going offline. If already offline, we'll be on wrong CPU:
@@ -430,7 +431,7 @@case CPU_UP_PREPARE :BUG_ON (per_cpu (tasklet_vec, hotcpu).list);BUG_ON (per_cpu (tasklet_hi_vec, hotcpu).list); - p =kthread_create (ksoftirqd, hcpu,"ksoftirqd/%d" , hotcpu); + p =kthread_create (ksoftirqd, hcpu,PF_NOFREEZE ,"ksoftirqd/%d" , hotcpu);if (IS_ERR (p)) {printk ("ksoftirqd for %i failed\n" , hotcpu);return NOTIFY_BAD ;
kernel/stop_machine.c +1 -1
@@ -174,7 +174,7 @@if (cpu ==NR_CPUS ) cpu =smp_processor_id (); - p =kthread_create (do_stop, &smdata,"kstopmachine" ); + p =kthread_create (do_stop, &smdata,0 ,"kstopmachine" );if (!IS_ERR (p)) {kthread_bind (p, cpu);wake_up_process (p);
kernel/workqueue.c +12 -9
@@ -186,8 +186,6 @@struct k_sigaction sa;sigset_t blocked; - current->flags |=PF_NOFREEZE ; -set_user_nice (current,-10 );/* Block and flush all signals */
@@ -208,6 +206,7 @@schedule (); else__set_current_state (TASK_RUNNING ); +try_to_freeze (PF_FREEZE );remove_wait_queue (&cwq->more_work, &wait);if (!list_empty (&cwq->worklist))
@@ -277,7 +276,8 @@ }static struct task_struct *create_workqueue_thread (struct workqueue_struct *wq, -int cpu) +int cpu, +unsigned long freezer_flags) {struct cpu_workqueue_struct *cwq = wq->cpu_wq + cpu;struct task_struct *p;
@@ -292,9 +292,11 @@init_waitqueue_head (&cwq->work_done);if (is_single_threaded (wq)) - p =kthread_create (worker_thread, cwq,"%s" , wq->name); + p =kthread_create (worker_thread, cwq, freezer_flags, +"%s" , wq->name);else - p =kthread_create (worker_thread, cwq,"%s/%d" , wq->name, cpu); + p =kthread_create (worker_thread, cwq, freezer_flags, +"%s/%d" , wq->name, cpu);if (IS_ERR (p))return NULL ; cwq->thread = p;
@@ -302,7 +304,8 @@ }struct workqueue_struct *__create_workqueue (const char *name, -int singlethread) +int singlethread, +unsigned long freezer_flags) {int cpu, destroy =0 ;struct workqueue_struct *wq;
@@ -320,7 +323,7 @@lock_cpu_hotplug ();if (singlethread) {INIT_LIST_HEAD (&wq->list); - p =create_workqueue_thread (wq,0 ); + p =create_workqueue_thread (wq,0 , freezer_flags);if (!p) destroy =1 ;else
@@ -330,7 +333,7 @@list_add (&wq->list, &workqueues);spin_unlock (&workqueue_lock);for_each_online_cpu (cpu) { - p =create_workqueue_thread (wq, cpu); + p =create_workqueue_thread (wq, cpu, freezer_flags);if (p) {kthread_bind (p, cpu);wake_up_process (p);
@@ -513,7 +516,7 @@void init_workqueues (void ) {hotcpu_notifier (workqueue_cpu_callback,0 ); - keventd_wq =create_workqueue ("events" ); + keventd_wq =create_workqueue ("events" ,PF_NOFREEZE );BUG_ON (!keventd_wq); }
mm/pdflush.c +1 -1
@@ -215,7 +215,7 @@static void start_one_pdflush_thread (void ) { -kthread_run (pdflush,NULL ,"pdflush" ); +kthread_run (pdflush,NULL ,0 ,"pdflush" ); }static int __init pdflush_init (void )
Re: Suspend 2 merge: 5/51: Workthread freezer support.
Hi!
Quoted 5 lines
This thread adds freezer support for workthreads.
A new parameter in the
create_functions allows the thread to be marked asPF_NOFREEZE. This should only be used for threads that may need to run during writing the image.
Ok.
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Suspend 2 merge: 16/51: Disable cache reaping during suspend.
In reply to Nigel CunninghamI have to admit to being a little unsure as to why this is needed, but suspend's reliability is helped a lot by disabling cache reaping while suspending. Perhaps one of the mm guys will be able to enlighten me here. Might be SMP related.
mm/slab.c +4 -1
@@ -92,6 +92,7 @@#include <linux/sysctl.h> #include <linux/module.h> #include <linux/rcupdate.h> +#include <linux/suspend.h> #include <asm/uaccess.h> #include <asm/cacheflush.h>
@@ -2730,7 +2731,9 @@ {struct list_head *walk; -if (down_trylock (&cache_chain_sem)) { +if ((unlikely (test_suspend_state (SUSPEND_RUNNING ))) || + (down_trylock (&cache_chain_sem))) + {/* Give up. Setup the next iteration. */ schedule_delayed_work (&__get_cpu_var (reap_work),REAPTIMEOUT_CPUC +smp_processor_id ());return ;
Re: Suspend 2 merge: 16/51: Disable cache reaping during suspend.
Hi!
Quoted 4 lines
I have to admit to being a little unsure as to why this is needed, but suspend's reliability is helped a lot by disabling cache reaping while suspending. Perhaps one of the mm guys will be able to enlighten me here. Might be SMP related.
It would be good to understand it. Rather than slowing common code... why not down(&cache_chain_sem) in suspend2?
Pavel
Quoted 17 lines
{
mm/slab.c +3
-2struct list_head *walk; -if (down_trylock (&cache_chain_sem)) { +if ((unlikely (test_suspend_state (SUSPEND_RUNNING ))) || + (down_trylock (&cache_chain_sem))) + {/* Give up. Setup the next iteration. */ schedule_delayed_work (&__get_cpu_var (reap_work),REAPTIMEOUT_CPUC +smp_processor_id ());return ; -To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 16/51: Disable cache reaping during suspend.
Hi.
Quoted 8 lines · Pavel Machek
Hi!
Quoted 4 lines
I have to admit to being a little unsure as to why this is needed, but suspend's reliability is helped a lot by disabling cache reaping while suspending. Perhaps one of the mm guys will be able to enlighten me here. Might be SMP related.
It would be good to understand it. Rather than slowing common code... why not
down(&cache_chain_sem)in suspend2?
Didn't consider it, to be honest.
That said, if/when we start to use cpu hotplug for SMP, we'll deadlock in cpuup_callback if we've got the sem.
Quoted 17 lines
Quoted 17 lines
{
mm/slab.c +3
-2struct list_head *walk; -if (down_trylock (&cache_chain_sem)) { +if ((unlikely (test_suspend_state (SUSPEND_RUNNING ))) || + (down_trylock (&cache_chain_sem))) + {/* Give up. Setup the next iteration. */ schedule_delayed_work (&__get_cpu_var (reap_work),REAPTIMEOUT_CPUC +smp_processor_id ());return ; -To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Suspend 2 merge: 20/51: Timer freezer (experimental).
In reply to Nigel CunninghamHere's experimental support for freezing timers. It doesn't really freeze them, but rather reschedules the call for a little later. One issue I need to think about is staggering the invocations at resume time, as some of the per CPU timer code seeks to do.
There is debugging code in here so that when it's used (it's off by default at the moment), and a timer that needs to be no_freeze holds up I/O, the user can find out what it is. Other code allows the timer freezer to be disabled on the fly (so you don't have to reboot because of this).
(This could replace the patches above for MCE checking and slab reaping).
diff -ruN 550-timer-freezer-old/drivers/block/ll_rw_blk.c 550-timer-freezer-new/drivers/block/ll_rw_blk.c
--- 550-timer-freezer-old/drivers/block/ll_rw_blk.c 2004-11-24
17:55:30.776567832 +1100
+++ 550-timer-freezer-new/drivers/block/ll_rw_blk.c 2004-11-24
17:23:36.145077968 +1100
@@ -254,6 +254,7 @@
q->unplug_timer.function = blk_unplug_timeout; q->unplug_timer.data = (unsigned long)q;
+ q->unplug_timer.no_freeze = 1;
/*
* by default assume old behaviour and bounce for any highmem page
diff -ruN 550-timer-freezer-old/drivers/input/serio/i8042.c 550-timer-freezer-new/drivers/input/serio/i8042.c
--- 550-timer-freezer-old/drivers/input/serio/i8042.c 2004-11-24
09:52:58.000000000 +1100
+++ 550-timer-freezer-new/drivers/input/serio/i8042.c 2004-11-24
17:23:36.154076600 +1100
@@ -1039,6 +1039,7 @@
dbg_init();
init_timer(&i8042_timer);
+ i8042_timer.no_freeze = 1;
i8042_timer.function = i8042_timer_func;
if (i8042_platform_init())
diff -ruN 550-timer-freezer-old/include/linux/timer.h 550-timer-freezer-new/include/linux/timer.h
--- 550-timer-freezer-old/include/linux/timer.h 2004-11-03
21:54:17.000000000 +1100
+++ 550-timer-freezer-new/include/linux/timer.h 2004-11-24
17:23:36.169074320 +1100
@@ -19,6 +19,8 @@
unsigned long data;
struct tvec_t_base_s *base;
+
+ int no_freeze;
};
#define TIMER_MAGIC 0x4b87ad6e
diff -ruN 550-timer-freezer-old/kernel/timer.c550-timer-freezer-new/kernel/timer.c
--- 550-timer-freezer-old/kernel/timer.c 2004-11-24 17:55:30.863554608
+1100
+++ 550-timer-freezer-new/kernel/timer.c 2004-11-24 17:55:22.021898744
+1100
@@ -31,6 +31,7 @@
#include <linux/time.h>
#include <linux/jiffies.h>
#include <linux/cpu.h>
+#include <linux/suspend.h>
#include <linux/syscalls.h>
#include <asm/uaccess.h>
@@ -429,6 +430,9 @@
*/
#define INDEX(N) (base->timer_jiffies >> (TVR_BITS + N * TVN_BITS)) &TVN_MASK
+#define FN_CACHE_SIZE 15
+static void * recent_fns[FN_CACHE_SIZE];
+
static inline void __run_timers(tvec_base_t *base) {
struct timer_list *timer;
@@ -463,7 +467,23 @@
smp_wmb();
timer->base = NULL; spin_unlock_irq(&base->lock);
- fn(data);
+ if (unlikely(test_suspend_state(SUSPEND_TIMER_FREEZER_ON) &&
(!timer->no_freeze))) {
+ int shown = 0, i, copy_start = 0;
+ for (i = 0; i < FN_CACHE_SIZE; i++)
+ if (fn == recent_fns[i]) {
+ shown = i + 1;
+ copy_start = i;
+ break;
+ }
+ for (i = copy_start; i < (FN_CACHE_SIZE - 1); i++)
+ recent_fns[i] = recent_fns[i+1];
+ recent_fns[FN_CACHE_SIZE - 1] = fn;
+ if (!shown) {
+ printk("Timed call of %p delayed while freezer on.\n", fn);
+ }
+ mod_timer(timer, jiffies + HZ);
+ } else
+ fn(data);
spin_lock_irq(&base->lock); goto repeat;
}
diff -ruN 550-timer-freezer-old/net/sched/sch_generic.c 550-timer-freezer-new/net/sched/sch_generic.c
--- 550-timer-freezer-old/net/sched/sch_generic.c 2004-11-24
09:53:13.000000000 +1100
+++ 550-timer-freezer-new/net/sched/sch_generic.c 2004-11-24
17:23:36.189071280 +1100
@@ -210,6 +210,7 @@
init_timer(&dev->watchdog_timer); dev->watchdog_timer.data = (unsigned long)dev; dev->watchdog_timer.function = dev_watchdog;
+ dev->watchdog_timer.no_freeze = 1;
}
void __netdev_watchdog_up(struct net_device *dev)
Suspend 2 merge: 34/51: Includes
In reply to Nigel CunninghamThese are the include changes files for suspend2.
I seek to keep this swsusp compatible, but it might be a little out of sync with Pavel's changes.
include/asm-i386/suspend.h +1 -0
@@ -3,6 +3,7 @@* Based on code * Copyright 2001 Patrick Mochel <[email protected]> */ +#include <linux/errno.h> #include <asm/desc.h> #include <asm/i387.h>
include/linux/suspend.h +246 -49
314 lines not on this page · raw message
kernel/power/block_io.h +52 -0
52 lines not on this page · raw message
kernel/power/pageflags.h +80 -0
80 lines not on this page · raw message
kernel/power/plugins.h +205 -0
205 lines not on this page · raw message
kernel/power/power.h +2 -0
@@ -1,6 +1,8 @@#include <linux/suspend.h> #include <linux/utsname.h> +#include "suspend.h" +/* With SUSPEND_CONSOLE defined, it suspend looks *really* cool, but we probably do not take enough locks for switching consoles, etc, so bad things might happen.
kernel/power/proc.h +64 -0
64 lines not on this page · raw message
kernel/power/range.h +105 -0
105 lines not on this page · raw message
kernel/power/smp.c +1 -0
@@ -15,6 +15,7 @@#include <linux/module.h> #include <asm/atomic.h> #include <asm/tlbflush.h> +#include "suspend.h" static atomic_t cpu_counter, freeze;
kernel/power/suspend.h +298 -0
298 lines not on this page · raw message
kernel/power/swsusp.c +3 -5
@@ -36,6 +36,8 @@* For TODOs,FIXMEs also look in Documentation/power/swsusp.txt */ +#define KERNEL_POWER_SWSUSP_C +#include <linux/module.h> #include <linux/mm.h> #include <linux/suspend.h>
@@ -51,9 +53,7 @@#include <linux/keyboard.h> #include <linux/spinlock.h> #include <linux/genhd.h> -#include <linux/kernel.h> #include <linux/major.h> -#include <linux/swap.h> #include <linux/pm.h> #include <linux/device.h> #include <linux/buffer_head.h>
@@ -70,9 +70,7 @@#include <asm/io.h> #include "power.h" - -/* References to section boundaries */ -extern char __nosave_begin, __nosave_end; +#include "suspend.h" extern int is_head_of_free_region (struct page *);
Re: Suspend 2 merge: 34/51: Includes
please submit header changes together with the matching code changes. And all this plugin thingies in here look like overengineering.
Re: Suspend 2 merge: 34/51: Includes
Hi.
Quoted 1 line · Christoph Hellwig
please submit header changes together with the matching code changes.
I can split them a little, but most of these suspend2 specific includes are used by multiple files. Ranges, for example, are used everywhere.
Quoted 1 line
And all this plugin thingies in here look like overengineering.
I can see that it might look that way, but it's actually fundamental to the support for building as modules (which is required for LVM & encryption), and has been really helpful in creating clear distinctions between the different parts of suspend. It also provides a clear method for someone to add support for their new wizz-bang storage method or compressor.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 34/51: Includes
Quoted 6 lines · Nigel Cunningham
I can see that it might look that way, but it's actually fundamental to the support for building as modules (which is required for LVM & encryption), and has been really helpful in creating clear distinctions between the different parts of suspend. It also provides a clear method for someone to add support for their new wizz-bang storage method or compressor.
I'm not entirely clear on this. Surely all that's needed for LVM and encryption support is for that to be set up in userspace and then allow userspace to trigger a second attempt at resume? I have a hacky patch for swsusp that allows that (at the moment it just adds a "resume" method to /sys/power/state), which gives you the functionality without the module pain.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Suspend 2 merge: 34/51: Includes
Hi.
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Nigel Cunningham
I can see that it might look that way, but it's actually fundamental to the support for building as modules (which is required for LVM & encryption), and has been really helpful in creating clear distinctions between the different parts of suspend. It also provides a clear method for someone to add support for their new wizz-bang storage method or compressor.
Quoted 6 lines
I'm not entirely clear on this. Surely all that's needed for LVM and encryption support is for that to be set up in userspace and then allow userspace to trigger a second attempt at resume? I have a hacky patch for swsusp that allows that (at the moment it just adds a "resume" method to
/sys/power/state), which gives you the functionality without the module pain.
Yes, sorry. I'm confusing initrd/ramfs support with modules. You can resume from an initrd/ramfs without building as modules.
Regardless, building support as modules does have the other advantages noted above, and I haven't found adding support for building as modules to be a pain at all.
Sorry again for confusing the issue.
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Suspend 2 merge: 24/51: Keyboard and serial console hooks.
In reply to Nigel CunninghamHere we add simple hooks so that the user can interact with suspend while it is running. (Hmm. The serial console condition could be simplified :>). The hooks allow you to do such things as:
- cancel suspending
- change the amount of detail of debugging info shown
- change what debugging info is shown
- pause the process
- single step
- toggle rebooting instead of powering down
drivers/char/keyboard.c +5 -0
@@ -33,6 +33,7 @@#include <linux/string.h> #include <linux/random.h> #include <linux/init.h> +#include <linux/suspend.h> #include <linux/slab.h> #include <linux/kbd_kern.h>
@@ -1091,6 +1092,10 @@return ; }#endif +if (down && (test_suspend_state (SUSPEND_RUNNING ))) { +suspend_handle_keypress (keycode,SUSPEND_KEY_KEYBOARD ); +return ; + }#if defined(CONFIG_SPARC32 ) || defined(CONFIG_SPARC64 )if (keycode ==KEY_A && sparc_l1_a_state) { sparc_l1_a_state =0 ;
drivers/serial/8250.c +10 -0
@@ -39,6 +39,7 @@#include <linux/serial_core.h> #include <linux/serial.h> #include <linux/serial_8250.h> +#include <linux/suspend.h> #include <asm/io.h> #include <asm/irq.h>
@@ -1068,6 +1069,15 @@ }if (uart_handle_sysrq_char (&up->port, ch, regs)) goto ignore_char; + +#if defined(CONFIG_SERIAL_CORE_CONSOLE ) && defined(CONFIG_SOFTWARE_SUSPEND2 ) +if (test_suspend_state (SUSPEND_SANITY_CHECK_PROMPT ) || +test_suspend_state (SUSPEND_RUNNING )) { +suspend_handle_keypress (ch,SUSPEND_KEY_SERIAL ); + goto ignore_char; + } +#endif +if ((lsr & up->port.ignore_status_mask) ==0 ) {tty_insert_flip_char (tty, ch, flag); }
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
Quoted 10 lines · Nigel Cunningham
Here we add simple hooks so that the user can interact with suspend while it is running. (Hmm. The serial console condition could be simplified :>). The hooks allow you to do such things as:
- cancel suspending
- change the amount of detail of debugging info shown
- change what debugging info is shown
- pause the process
- single step
- toggle rebooting instead of powering down
And why would we want this? If the users calls the suspend call he surely wants to suspend, right?
After all we don't have inkernel hooks to allow a user to read instead write after calling sys_write.
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
Hi, Christoph,
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Nigel Cunningham
Here we add simple hooks so that the user can interact with suspend while it is running. (Hmm. The serial console condition could be simplified :>). The hooks allow you to do such things as:
- cancel suspending
- change the amount of detail of debugging info shown
- change what debugging info is shown
- pause the process
- single step
- toggle rebooting instead of powering down
Quoted 2 lines
And why would we want this? If the users calls the suspend call he surely wants to suspend, right?
Probably, wrong. Suspend running server remotely, to resolve hotswap issues, f.e., and reboot to already prepared environment, without bothering techsupport in the middle of the night.
Quoted 3 lines
After all we don't have inkernel hooks to allow a user to read instead write after calling
sys_write.
Wrong analogy here, sorry.
Quoted 5 lines
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 1 line
Managing your Territory since the dawn of times ...
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
In reply to Christoph HellwigHi.
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Nigel Cunningham
Here we add simple hooks so that the user can interact with suspend while it is running. (Hmm. The serial console condition could be simplified :>). The hooks allow you to do such things as:
- cancel suspending
- change the amount of detail of debugging info shown
- change what debugging info is shown
- pause the process
- single step
- toggle rebooting instead of powering down
Quoted 2 lines
And why would we want this? If the users calls the suspend call he surely wants to suspend, right?
Have you ever pressed control-alt-delete/init 0 and then gone "Oh. I forgot, I wanted to..."? That's why you'd want to be able to cancel suspending.
The ability to toggle rebooting is helpful because you don't have to edit a config file/proc entry. You can use one key press to initiate the suspend, and press 'R' iif you want to reboot (eg for dual booting) instead of powering down.
The other options are really helpful when testing and debugging, and can be turned off at compile time.
By the way, thanks for all the feedback.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
In reply to Christoph HellwigQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Christoph" == Christoph Hellwig <[email protected]> writes:
Christoph> On Wed, Nov 24, 2004 at 11:59:02PM +1100, Nigel Cunningham
Quoted 10 lines · Christoph> wrote:
Quoted 10 lines
Here we add simple hooks so that the user can interact with suspend while it is running. (Hmm. The serial console condition could be simplified :>). The hooks allow you to do such things as:
- cancel suspending
- change the amount of detail of debugging info shown
- change what debugging info is shown
- pause the process
- single step
- toggle rebooting instead of powering down
Christoph> And why would we want this? If the users calls the suspend Christoph> call he surely wants to suspend, right?
Obviously you have never actually tried to use software suspend in real life.
I would kindly suggest that you try to use it on your laptop for at least several weeks in various circumstances. These features are a result of years of user experience.
--J.
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
Quoted 6 lines · Jan Rychter
Obviously you have never actually tried to use software suspend in real life.
I would kindly suggest that you try to use it on your laptop for at least several weeks in various circumstances. These features are a result of years of user experience.
I tend to buy laptops that just suspend when closing the lid, and no, I never had the strange desired to immediately reverse my choice. Neither do I want to stop the shutdown that I just initiated.
But for those people who do shutdown has a nice option to delay the actual shutdown/reboot - I'm pretty sure the same can be done for swsusp without sprinkling hooks all over the kernel.
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Christoph" == Christoph Hellwig <[email protected]> writes:
Quoted 6 lines · Jan Rychter
Quoted 6 lines
Obviously you have never actually tried to use software suspend in real life.
I would kindly suggest that you try to use it on your laptop for at least several weeks in various circumstances. These features are a result of years of user experience.
Christoph> I tend to buy laptops that just suspend when closing the Christoph> lid, and no, I never had the strange desired to immediately Christoph> reverse my choice. Neither do I want to stop the shutdown Christoph> that I just initiated.
Christoph> But for those people who do shutdown has a nice option to Christoph> delay the actual shutdown/reboot - I'm pretty sure the same Christoph> can be done for swsusp without sprinkling hooks all over the Christoph> kernel.
Please accept that there are people who requested these features and there are people who find them useful.
I really hope you understand that delaying a suspend is very different from allowing the user to interrupt it.
Also, many people suspend Linux only to reboot into Windows. In this case, the ability to tell the machine to reboot instead of powering down is very useful. Obviously, a perfect user would plan ahead and suspend "appropriately", depending on what he wants to do afterwards. Unfortunately, I have found that I'm not a perfect user and that I really tend to use and like these features.
As for me, I would much rather have a useful kernel that a beautiful kernel, because I rather tend to use it than watch it, but I can understand that other people may have different priorities. I would suggest we find a compromise.
--J.
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
Quoted 2 lines · Jan Rychter
Please accept that there are people who requested these features and there are people who find them useful.
There are millions of features usefull to some people. If these features can be implemented without affecting the existing codebase it's usually a no go. If OTOH the do nasty things with kernel internals, and the feature isn't exactly the most important in the world judgment is different.
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
In reply to Christoph HellwigQuoted 7 lines · Christoph Hellwig
Quoted 6 lines · Jan Rychter
Obviously you have never actually tried to use software suspend in real life.
I would kindly suggest that you try to use it on your laptop for at least several weeks in various circumstances. These features are a result of years of user experience.
Lets say <UNDERLINE><BOLD>THOUSANDS OF MAN YEARS</UNDERLINE></BOLD>
Quoted 2 lines
I tend to buy laptops that just suspend when closing the lid, and no, I
never
Quoted 2 lines
had the strange desired to immediately reverse my choice. Neither do I want to stop the shutdown that I just initiated.
Perhaps many less fortunate "users" ;) (_including_ myself), can change their minds anytime and open the lid again.
Thus, IMHO support for "changing ones mind" is imperative.
As to reboot, we hardly use it:
- Test partitions get reset with the yournal doing the dirty work.
- The main partition gets rebooted only:
- when some stupid app(s) leaked all memory away and we are out of swap
... sometimes weekly :-(
- for (monthly) fsck.
- when updating glibc twice a year or so
Dependable and flexible software suspend is a way of life yet to be experienced by many.
Offtopic, IMO a garbage collector is highly desirable...
Michael
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
In reply to Christoph HellwigQuoted 6 lines
Quoted 6 lines
Here we add simple hooks so that the user can interact with suspend while it is running. (Hmm. The serial console condition could be simplified :>). The hooks allow you to do such things as:
- cancel suspending
I can understand that you want this one. I do not think uglyness is worth it, through.
Quoted 1 line
Quoted 1 line
- change the amount of detail of debugging info shown
Use sysrq-X as you do during runtime.
Quoted 3 lines
Quoted 3 lines
- change what debugging info is shown
- pause the process
- single step
Usefull for developing swsusp but not for using it. Should live as a separate patch.
Quoted 1 line
Quoted 1 line
- toggle rebooting instead of powering down
This is prety much nonsensical. You can do echo reboot > disk. If you forget to do it, all you have to do is press power after it powers down. That's about as much work as pressing 'R' while you are suspending, right?
Please drop this one.
Quoted 5 lines
And why would we want this? If the users calls the suspend call he surely wants to suspend, right?
After all we don't have inkernel hooks to allow a user to read instead write after calling
sys_write.
:-))))))))).
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!
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
Hi.
Quoted 7 lines · Pavel Machek
Quoted 5 lines
Quoted 5 lines
Here we add simple hooks so that the user can interact with suspend while it is running. (Hmm. The serial console condition could be simplified :>). The hooks allow you to do such things as:
- change the amount of detail of debugging info shown
Use sysrq-X as you do during runtime.
No, I don't do this anymore. When I did, I had problems post-resume with the keyboard handler sometimes thinking SysRq was still pressed.
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
Hi!
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Here we add simple hooks so that the user can interact with suspend while it is running. (Hmm. The serial console condition could be simplified :>). The hooks allow you to do such things as:
- change the amount of detail of debugging info shown
Use sysrq-X as you do during runtime.
No, I don't do this anymore. When I did, I had problems post-resume with the keyboard handler sometimes thinking SysRq was still pressed.
Fix keyboard handler, then... It probably happens with other keys beside SysRq, right?
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!
Re: Suspend 2 merge: 24/51: Keyboard and serial console hooks.
Hi.
Quoted 8 lines · Pavel Machek
Hi!
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Here we add simple hooks so that the user can interact with suspend while it is running. (Hmm. The serial console condition could be simplified :>). The hooks allow you to do such things as:
- change the amount of detail of debugging info shown
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Use sysrq-X as you do during runtime.
No, I don't do this anymore. When I did, I had problems post-resume with the keyboard handler sometimes thinking SysRq was still pressed.
Fix keyboard handler, then... It probably happens with other keys beside SysRq, right?
I guess it would. Nevertheless, it's ugly to have to press SysRq + level; why make things more awkward than they need to be?
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Suspend 2 merge: 23/51: PPC support.
In reply to Nigel CunninghamQuoted 1 line
From Steve.
Not updated for a while, so I'm not sure if it still works. If not, it shouldn't take much to get it going again.
arch/ppc/Kconfig +2 -0
@@ -225,6 +225,8 @@ If in doubt, say Y here. +source kernel/power/Kconfig + source arch/ppc/platforms/4xx/Kconfig source arch/ppc/platforms/85xx/Kconfig
arch/ppc/kernel/signal.c +10 -0
@@ -604,6 +604,15 @@unsigned long frame, newsp;int signr, ret; +if (current->flags &PF_FREEZE ) { +refrigerator (PF_FREEZE ); + signr =0 ; + ret = regs->gpr[3 ]; +recalc_sigpending (); +if (!signal_pending (current)) + goto no_signal; + } +if (!oldset) oldset = ¤t->blocked;
@@ -626,6 +635,7 @@ 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/vmlinux.lds.S +6 -0
@@ -74,6 +74,12 @@ CONSTRUCTORS } + . = ALIGN(4096); + __nosave_begin = .; + .data_nosave : { *(.data.nosave) } + . = ALIGN(4096); + __nosave_end = .; + . = ALIGN(32); .data.cacheline_aligned : { *(.data.cacheline_aligned) }
arch/ppc/Makefile +1 -0
@@ -61,6 +61,7 @@ drivers-$(CONFIG_8xx) += arch/ppc/8xx_io/ drivers-$(CONFIG_4xx) += arch/ppc/4xx_io/ drivers-$(CONFIG_CPM2) += arch/ppc/8260_io/ +drivers-$(CONFIG_PM) += arch/ppc/power/ drivers-$(CONFIG_OPROFILE) += arch/ppc/oprofile/
arch/ppc/mm/init.c +13 -2
@@ -31,6 +31,7 @@#include <linux/bootmem.h> #include <linux/highmem.h> #include <linux/initrd.h> +#include <linux/suspend.h> #include <asm/pgalloc.h> #include <asm/prom.h>
@@ -149,6 +150,7 @@while (start < end) {ClearPageReserved (virt_to_page (start)); +ClearPageNosave (virt_to_page (start));set_page_count (virt_to_page (start),1 );free_page (start); cnt++;
@@ -188,6 +190,7 @@for (; start < end; start +=PAGE_SIZE ) {ClearPageReserved (virt_to_page (start)); +ClearPageNosave (virt_to_page (start));set_page_count (virt_to_page (start),1 );free_page (start); totalram_pages++;
@@ -424,8 +427,10 @@/* if we are booted from BootX with an initial ramdisk, make sure the ramdisk pages aren't reserved. */ if (initrd_start) { -for (addr = initrd_start; addr < initrd_end; addr +=PAGE_SIZE ) +for (addr = initrd_start; addr < initrd_end; addr +=PAGE_SIZE ) {ClearPageReserved (virt_to_page (addr)); +ClearPageNosave (virt_to_page (addr)); + } }#endif /* CONFIG_BLK_DEV_INITRD */
@@ -451,6 +456,12 @@ addr += PAGE_SIZE) {if (!PageReserved (virt_to_page (addr)))continue ; +/* +* Mark nosave pages +*/ +if (addr >= (void *)&__nosave_begin && addr < (void *)&__nosave_end) +SetPageNosave (virt_to_page (addr)); +if (addr < (ulong ) etext) codepages++; else if (addr >= (unsigned long)&__init_begin
@@ -468,6 +479,7 @@struct page *page = mem_map + pfn;ClearPageReserved (page); +ClearPageNosave (page);set_bit (PG_highmem, &page->flags);set_page_count (page,1 );__free_page (page);
@@ -501,7 +513,6 @@ pg->index = addr; } } - mem_init_done =1 ; }
arch/ppc/platforms/pmac_feature.c +4 -1
@@ -2146,7 +2146,10 @@ }, {"PowerBook6,1" ,"PowerBook G4 12\"" ,PMAC_TYPE_UNKNOWN_INTREPID , intrepid_features, -PMAC_MB_HAS_FW_POWER |PMAC_MB_MOBILE , + PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE +#ifdef CONFIG_SOFTWARE_REPLACE_SLEEP + |PMAC_MB_CAN_SLEEP , +#endif }, { "PowerBook6,2", "PowerBook G4", PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
arch/ppc/power/cpu.c +61 -0
61 lines not on this page · raw message
arch/ppc/power/cpu_reg.S +325 -0
325 lines not on this page · raw message
arch/ppc/power/Makefile +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_PM) += cpu.o +obj-$(CONFIG_SOFTWARE_SUSPEND2) += swsusp2-asm.o
arch/ppc/power/swsusp2-asm.S +53 -0
53 lines not on this page · raw message
arch/ppc/power/swsusp2.c +170 -0
170 lines not on this page · raw message
arch/ppc/power/swsusp2-copyback.S +73 -0
73 lines not on this page · raw message
drivers/macintosh/Kconfig +4 -0
@@ -187,4 +187,8 @@ tristate "Support for ANS LCD display" depends on ADB_CUDA && PPC_PMAC +config SOFTWARE_REPLACE_SLEEP + bool "Using Software suspend replace broken sleep function" + depends on SOFTWARE_SUSPEND2 + endmenu
drivers/macintosh/via-pmu.c +7 -0
@@ -2891,6 +2891,13 @@return -EACCES ;if (sleep_in_progress)return -EBUSY ; +#ifdef CONFIG_SOFTWARE_REPLACE_SLEEP + { +extern void software_suspend_pending (void ); +software_suspend_pending (); +return (0 ); + } +#endif sleep_in_progress =1 ;switch (pmu_kind) {case PMU_OHARE_BASED :
include/asm-ppc/suspend.h +14 -0
@@ -0,0 +1,14 @@ +#ifndef _PPC_SUSPEND_H +#define _PPC_SUSPEND_H + +static inline void flush_tlb_all (void ) +{ +/* Flush all TLBs */ + __asm__ __volatile__("lis 4, 0x1000" ); + __asm__ __volatile__("1: addic. 4,4,-0x1000" ); + __asm__ __volatile__("tlbie 4" ); + __asm__ __volatile__("blt 1b" ); + __asm__ __volatile__("sync" ); +} + +#endif
Re: Suspend 2 merge: 23/51: PPC support.
Hi!
Quoted 2 lines
Not updated for a while, so I'm not sure if it still works. If not, it shouldn't take much to get it going again.
It should have a lot in common with hugang's swsusp1/ppc support, right? Can you coordinate with him and get that in?
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 23/51: PPC support.
Hi.
Quoted 7 lines · Pavel Machek
Hi!
Quoted 2 lines
Not updated for a while, so I'm not sure if it still works. If not, it shouldn't take much to get it going again.
It should have a lot in common with hugang's swsusp1/ppc support, right? Can you coordinate with him and get that in?
He submitted it in the first place, so I'm already relying on him to send updates.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Suspend 2 merge: 25/51: Documentation
In reply to Nigel CunninghamHere is the kernel tree documentation. I have a word document that I'm also working on, which will provide detail not given here, including an explanation of the API for people who want to write new extensions.
Documentation/kernel-parameters.txt +8 -1
@@ -804,6 +804,8 @@ noresume [SWSUSP] Disables resume and restore original swap space. + noresume2 [SWSUSP2] Disables resuming and restores original swap signature. + no-scroll [VGA] Disables scrollback. This is required for the Braillex ib80-piezo Braille reader made by F.H. Papenmeier (Germany).
@@ -1011,7 +1013,12 @@ reserve= [KNL,BUGS] Force the kernel to ignore some iomem area - resume= [SWSUSP] Specify the partition device for software suspension + resume= [SWSUSP] Specify the partition device for software suspension. + + resume2= [SWSUSP2] Specify the storage device for software suspend. + Format: <writer>:<writer-parameters>. + See Documentation/power/swsusp2.txt for details of the formats + for available image writers. rhash_entries= [KNL,NET] Set number of hash buckets for route cache
Documentation/power/suspend2.txt +506 -0
506 lines not on this page · raw message
Suspend 2 merge: 26/51: Kconfig and makefile.
In reply to Nigel CunninghamHere are the changes to kernel/power/Makefile|Kconfig
kernel/power/Kconfig +137 -0
@@ -30,6 +30,8 @@ bool "Software Suspend (EXPERIMENTAL)" depends on EXPERIMENTAL && PM && SWAP ---help--- + Pavel's original version. + Enable the possibility of suspending the machine. It doesn't need APM. You may suspend your machine by 'swsusp' or 'shutdown -z <time>'
@@ -73,3 +75,138 @@ suspended image to. It will simply pick the first available swap device. +menu "Software Suspend 2" + +config SOFTWARE_SUSPEND2_CORE + tristate "Software Suspend 2" + depends on PM + select SOFTWARE_SUSPEND2 + ---help--- + Software Suspend 2 is the 'new and improved' suspend support. You + can now build it as modules, but be aware that this requires + initrd support (the modules you use in saving the image have to + be loaded in order for you to be able to resume!) + + See the Software Suspend home page (softwaresuspend.berlios.de) + for FAQs, HOWTOs and other documentation. + + config SOFTWARE_SUSPEND2 + bool + + if SOFTWARE_SUSPEND2 + config SOFTWARE_SUSPEND2_WRITER + bool + + comment 'Image Storage (you need at least one writer)' + depends on SOFTWARE_SUSPEND2_CORE + + config SOFTWARE_SUSPEND_SWAPWRITER + tristate ' Swap Writer' + depends on SWAP && SOFTWARE_SUSPEND2_CORE + select SOFTWARE_SUSPEND2_WRITER + ---help--- + This option enabled support for storing an image in your + swap space. Swap partitions are supported. Swap file + support is currently broken (16 April 2004). + + comment 'Page Transformers' + depends on SOFTWARE_SUSPEND2_WRITER + + if SOFTWARE_SUSPEND2_WRITER + config SOFTWARE_SUSPEND_LZF_COMPRESSION + tristate ' LZF image compression (Preferred)' + ---help--- + This option enables compression of pages stored during suspending + to disk, using LZF compression. LZF compression is fast and + still achieves a good compression ratio. + + You probably want to say 'Y'. + + config SOFTWARE_SUSPEND_GZIP_COMPRESSION + tristate ' GZIP image Compression (Slow)' + depends on SOFTWARE_SUSPEND2_CORE + select ZLIB_DEFLATE + select ZLIB_INFLATE + ---help--- + This option enables compression of pages stored during Software Suspend + process. Pages are compressed using the zlib library, with a default + setting (in code) of fastest compression (still VERY slow!). If your swap + device is painfully slow compared to your CPU, you might possibly want + this. Then again, you might just want to upgrade your storage (if you + can). + + Just in case you haven't gotten the hint yet, this option should be off + for most people. If will make your computer take a minute to suspend + when it could take seconds. + + config SOFTWARE_SUSPEND_DEVICE_MAPPER + tristate ' Device Mapper support' + depends on SOFTWARE_SUSPEND2_CORE && BLK_DEV_DM + ---help--- + This option creates a module which allows Suspend to tell the + device mapper code to allocate enough memory for its work while + suspending. It doesn't do anything else, but without it, dm-crypt + won't work properly. + + This option should be off for most people. + + comment 'User Interface Options' + + config SOFTWARE_SUSPEND_BOOTSPLASH + tristate ' Bootsplash support' + depends on SOFTWARE_SUSPEND2_CORE && BOOTSPLASH + ---help--- + This option enables support for Bootsplash (bootsplash.org). Suspend + can set the progress bar value and switch between silent and verbose + modes. (Silent mode is used when the debug level is 0 or 1). + + config SOFTWARE_SUSPEND_TEXT_MODE + tristate ' Text mode console support' + depends on SOFTWARE_SUSPEND2_CORE && VT + ---help--- + This option enables support for a text mode 'nice display'. If you don't + have/want bootsplash support, you probably want this. + + comment 'General Options' + + config SOFTWARE_SUSPEND_DEFAULT_RESUME2 + string ' Default resume device name' + ---help--- + You normally need to add a resume2= parameter to your lilo.conf or + equivalent. With this option properly set, the kernel has a value + to default. No damage will be done if the value is invalid. + + config SOFTWARE_SUSPEND_KEEP_IMAGE + bool ' Allow Keep Image Mode' + ---help--- + This option allows you to keep and image and reuse it. It is intended + __ONLY__ for use with systems where all filesystems are mounted read- + only (kiosks, for example). To use it, compile this option in and boot + normally. Set the KEEP_IMAGE flag in /proc/software_suspend and suspend. + When you resume, the image will not be removed. You will be unable to turn + off swap partitions (assuming you are using the swap writer), but future + suspends simply do a power-down. The image can be updated using the + kernel command line parameter suspend_act= to turn off the keep image + bit. Keep image mode is a little less user friendly on purpose - it + should not be used without thought! + + comment 'Debugging' + + config SOFTWARE_SUSPEND_DEBUG + bool ' Compile in debugging output' + ---help--- + This option enables the inclusion of debugging info in the software + suspend code. Turning it off will reduce the kernel size but make + debugging suspend & resume issues harder to do. + + For normal usage, this option can be turned off. + + endif + + endif + +endmenu + +comment 'Suspend2 depends on EXPERIMENTAL and PM support.' + depends on !EXPERIMENTAL || !PM +
kernel/power/Makefile +16 -0
@@ -6,6 +6,22 @@ swsusp-smp-$(CONFIG_SMP) += smp.o obj-y := main.o process.o console.o pm.o + +ifeq ($(CONFIG_SOFTWARE_SUSPEND2),y) +obj-y += suspend_builtin.o proc.o +endif + +suspend_core-objs := io.o memory_pool.o pagedir.o prepare_image.o \ + range.o suspend.o plugins.o suspend_ui.o utility.o + +obj-$(CONFIG_SOFTWARE_SUSPEND2_CORE) += suspend_core.o +obj-$(CONFIG_SOFTWARE_SUSPEND_BOOTSPLASH) += suspend_bootsplash.o +obj-$(CONFIG_SOFTWARE_SUSPEND_TEXT_MODE) += suspend_text.o +obj-$(CONFIG_SOFTWARE_SUSPEND_LZF_COMPRESSION) += suspend_lzf.o +obj-$(CONFIG_SOFTWARE_SUSPEND_GZIP_COMPRESSION) += suspend_gzip.o +obj-$(CONFIG_SOFTWARE_SUSPEND_DEVICE_MAPPER) += suspend_dm.o +obj-$(CONFIG_SOFTWARE_SUSPEND_SWAPWRITER) += suspend_block_io.o suspend_swap.o + obj-$(CONFIG_SOFTWARE_SUSPEND) += swsusp.o $(swsusp-smp-y) disk.o obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o
Re: Suspend 2 merge: 26/51: Kconfig and makefile.
Hi,
Quoted 12 lines · Nigel Cunningham
kernel/power/Kconfig +12
-0+menu "Software Suspend 2" + +config SOFTWARE_SUSPEND2_CORE + tristate "Software Suspend 2" + depends on PM + select SOFTWARE_SUSPEND2 + ---help--- + Software Suspend 2 is the 'new and improved' suspend support. You + can now build it as modules, but be aware that this requires + initrd support (the modules you use in saving the image have to + be loaded in order for you to be able to resume!) +
kernel/power/Kconfig line 99
Quoted 10 lines
kernel/power/Kconfig +10
-0+ See the Software Suspend home page (softwaresuspend.berlios.de) + for FAQs, HOWTOs and other documentation. + + config SOFTWARE_SUSPEND2 + bool + + if SOFTWARE_SUSPEND2 + config SOFTWARE_SUSPEND2_WRITER + bool +
Please don't use such indentations.
There is no need to use to select here either. If you really want to make it modular (and you can convince Christoph), you want to do something like this:
config SOFTWARE_SUSPEND2
tristate "Software Suspend 2"
depends on PM
config SOFTWARE_SUSPEND2_BUILTIN
def_bool SOFTWARE_SUSPEND2
and let everything else depend on SOFTWARE_SUSPEND2.
kernel/power/Kconfig line 106
Quoted 4 lines
kernel/power/Kconfig +4
-0+ config SOFTWARE_SUSPEND_SWAPWRITER + tristate ' Swap Writer' + depends on SWAP && SOFTWARE_SUSPEND2_CORE + select SOFTWARE_SUSPEND2_WRITER
This select is also bogus.
kernel/power/Makefile line 12
Quoted 4 lines
kernel/power/Makefile +4
-0+ +ifeq ($(CONFIG_SOFTWARE_SUSPEND2),y) +obj-y += suspend_builtin.o proc.o +endif
Use SOFTWARE_SUSPEND2_BUILTIN here without the ifeq.
bye, Roman
Re: Suspend 2 merge: 26/51: Kconfig and makefile.
Hi.
Quoted 20 lines · Roman Zippel
Hi,
Quoted 16 lines · Nigel Cunningham
kernel/power/Kconfig +16
-0+menu "Software Suspend 2" + +config SOFTWARE_SUSPEND2_CORE + tristate "Software Suspend 2" + depends on PM + select SOFTWARE_SUSPEND2 + ---help--- + Software Suspend 2 is the 'new and improved' suspend support. You + can now build it as modules, but be aware that this requires + initrd support (the modules you use in saving the image have to + be loaded in order for you to be able to resume!) + + See the Software Suspend home page (softwaresuspend.berlios.de) + for FAQs, HOWTOs and other documentation. + + config SOFTWARE_SUSPEND2
Quoted 8 lines
kernel/power/Kconfig line 99
Quoted 6 lines
kernel/power/Kconfig +6
-0+ bool + + if SOFTWARE_SUSPEND2 + config SOFTWARE_SUSPEND2_WRITER + bool +Please don't use such indentations.
I'm not sure exactly what 'such indentations' means. Could you please give me a pointer to how it should look (I was blindly following what I thought was the pattern to follow and will happily follow something else :>).
Quoted 3 lines
There is no need to use to select here either. If you really want to make it modular (and you can convince Christoph), you want to do something like this:
Okay. I've struggled a bit with the config language, and again looked to other places to see how to achieve things. I've obviously missed better code. Will give this a try.
Thanks very much!
Nigel
Quoted 24 lines
config
SOFTWARE_SUSPEND2
tristate "Software Suspend 2"
depends on PMconfig
SOFTWARE_SUSPEND2_BUILTIN
def_boolSOFTWARE_SUSPEND2and let everything else depend on
SOFTWARE_SUSPEND2.kernel/power/Kconfig line 106
Quoted 4 lines
kernel/power/Kconfig +4
-0+ config SOFTWARE_SUSPEND_SWAPWRITER + tristate ' Swap Writer' + depends on SWAP && SOFTWARE_SUSPEND2_CORE + select SOFTWARE_SUSPEND2_WRITERThis select is also bogus.
kernel/power/Makefile line 12
Quoted 4 lines
kernel/power/Makefile +4
-0+ +ifeq ($(CONFIG_SOFTWARE_SUSPEND2),y) +obj-y += suspend_builtin.o proc.o +endifUse
SOFTWARE_SUSPEND2_BUILTINhere without the ifeq.bye, Roman
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 26/51: Kconfig and makefile.
Hi,
Quoted 4 lines · Nigel Cunningham
I'm not sure exactly what 'such indentations' means. Could you please give me a pointer to how it should look (I was blindly following what I thought was the pattern to follow and will happily follow something else :>).
What did you look at it? Where else did you find such indentations?
bye, Roman
Re: Suspend 2 merge: 26/51: Kconfig and makefile.
Hi.
Quoted 10 lines · Roman Zippel
Hi,
Quoted 4 lines · Nigel Cunningham
I'm not sure exactly what 'such indentations' means. Could you please give me a pointer to how it should look (I was blindly following what I thought was the pattern to follow and will happily follow something else :>).
What did you look at it? Where else did you find such indentations?
I'm guessing now, but I don't think I've done anything inconsistent with the rest of the file. Assuming you mean the spaces before the help text, that is there in the help for CONFIG_PM, for example.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 26/51: Kconfig and makefile.
In reply to Roman ZippelHi.
Quoted 4 lines · Roman Zippel
Please don't use such indentations.
There is no need to use to select here either. If you really want to make it modular (and you can convince Christoph), you want to do something like this:
I think I've caught on to what you're meaning. Is this better?
menu "Software Suspend 2"
config SOFTWARE_SUSPEND2
tristate "Software Suspend 2"
depends on PM
---help---
Software Suspend 2 is the 'new and improved' suspend support. You can now build it as modules, but be aware that this requires initrd support (the modules you use in saving the image have to be loaded in order for you to be able to resume!)
See the Software Suspend home page (softwaresuspend.berlios.de) for FAQs, HOWTOs and other documentation.
config SOFTWARE_SUSPEND2_CORE
def_bool SOFTWARE_SUSPEND2
if SOFTWARE_SUSPEND2
comment 'Image Storage (you need at least one writer)' depends on SOFTWARE_SUSPEND2_CORE
config SOFTWARE_SUSPEND_SWAPWRITER
tristate ' Swap Writer'
depends on SWAP && SOFTWARE_SUSPEND2 ---help---
This option enabled support for storing an image in your swap space. Swap partitions are supported. Swap file support is currently broken (16 April 2004).
comment 'Page Transformers'
config SOFTWARE_SUSPEND_LZF_COMPRESSION
tristate ' LZF image compression (Preferred)'
---help---
This option enables compression of pages stored during suspending to disk, using LZF compression. LZF compression is fast and still achieves a good compression ratio.
You probably want to say 'Y'.
config SOFTWARE_SUSPEND_GZIP_COMPRESSION
tristate ' GZIP image Compression (Slow)'
select ZLIB_DEFLATE
select ZLIB_INFLATE
---help---
This option enables compression of pages stored during Software Suspend process. Pages are compressed using the zlib library, with a default setting (in code) of fastest compression (still VERY slow!). If your swap device is painfully slow compared to your CPU, you might possibly want this. Then again, you might just want to upgrade your storage (if you can).
Just in case you haven't gotten the hint yet, this option should be off for most people. If will make your computer take a minute to suspend when it could take seconds.
config SOFTWARE_SUSPEND_DEVICE_MAPPER
tristate ' Device Mapper support'
depends on BLK_DEV_DM
---help---
This option creates a module which allows Suspend to tell the device mapper code to allocate enough memory for its work while suspending. It doesn't do anything else, but without it, dm-crypt won't work properly.
This option should be off for most people.
comment 'User Interface Options'
config SOFTWARE_SUSPEND_BOOTSPLASH
tristate ' Bootsplash support'
depends on BOOTSPLASH
---help---
This option enables support for Bootsplash (bootsplash.org). Suspend can set the progress bar value and switch between silent and verbose modes. (Silent mode is used when the debug level is 0 or 1).
config SOFTWARE_SUSPEND_TEXT_MODE
tristate ' Text mode console support'
depends on VT
---help---
This option enables support for a text mode 'nice display'. If you don't have/want bootsplash support, you probably want this.
comment 'General Options'
config SOFTWARE_SUSPEND_DEFAULT_RESUME2
string ' Default resume device name'
---help---
You normally need to add a resume2= parameter to your lilo.conf or equivalent. With this option properly set, the kernel has a value to default. No damage will be done if the value is invalid.
config SOFTWARE_SUSPEND_KEEP_IMAGE
bool ' Allow Keep Image Mode'
---help---
This option allows you to keep and image and reuse it. It is intended __ONLY__ for use with systems where all filesystems are mounted read- only (kiosks, for example). To use it, compile this option in and boot normally. Set the KEEP_IMAGE flag in /proc/software_suspend and suspend. When you resume, the image will not be removed. You will be unable to turn off swap partitions (assuming you are using the swap writer), but future suspends simply do a power-down. The image can be updated using the kernel command line parameter suspend_act= to turn off the keep image bit. Keep image mode is a little less user friendly on purpose - it should not be used without thought!
comment 'Debugging'
config SOFTWARE_SUSPEND_DEBUG
bool ' Compile in debugging output'
---help---
This option enables the inclusion of debugging info in the software suspend code. Turning it off will reduce the kernel size but make debugging suspend & resume issues harder to do.
For normal usage, this option can be turned off.
config SOFTWARE_SUSPEND_CHECKSUMS
tristate ' Compile checksum module'
---help---
This option enables compilation of a checksumming module, which can be used to verify the correct operation of suspend.
For normal usage, this option can be turned off.
endif
endmenu
Suspend 2 merge: 19/51: Remove MTRR sysdev support.
In reply to Nigel CunninghamThis patch removes sysdev support for MTRRs (potential SMP hang and shouldn't be done with interrupts done anyway). Instead, we save and restore MTRRs when entering and exiting the processor freezers (ie when saving the registers & context for each CPU via an SMP call).
arch/i386/kernel/cpu/mtrr/main.c +11 -14
@@ -167,7 +167,6 @@atomic_dec (&data->count); local_irq_restore(flags); } -#endif /**
@@ -564,7 +563,7 @@static struct mtrr_value * mtrr_state; -static int mtrr_save (struct sys_device * sysdev,u32 state) +int mtrr_save (void ) {int i;int size = num_var_ranges *sizeof (struct mtrr_value );
@@ -584,28 +583,27 @@return 0 ; } -static int mtrr_restore (struct sys_device * sysdev) +/* Restore mtrrs on this CPU only. +* Done with interrupts disabled via __smp_lowlevel_suspend +*/ +int mtrr_restore_one_cpu (void ) {int i;for (i =0 ; i < num_var_ranges; i++) {if (mtrr_state[i].lsize) -set_mtrr (i, + mtrr_if->set (i, mtrr_state[i].lbase, mtrr_state[i].lsize, mtrr_state[i].ltype); } -kfree (mtrr_state);return 0 ; } - - -static struct sysdev_driver mtrr_sysdev_driver = { - .suspend = mtrr_save, - .resume = mtrr_restore, -}; - +void mtrr_restore_finish (void ) +{ +kfree (mtrr_state); +}/** * mtrr_init - initialize mtrrs on the boot CPU
@@ -692,8 +690,7 @@init_table ();init_other_cpus (); -return sysdev_driver_register (&cpu_sysdev_class, - &mtrr_sysdev_driver); +return 0 ; }return -ENXIO ; }
Re: Suspend 2 merge: 19/51: Remove MTRR sysdev support.
Quoted 4 lines · Nigel Cunningham
This patch removes sysdev support for MTRRs (potential SMP hang and shouldn't be done with interrupts done anyway). Instead, we save and restore MTRRs when entering and exiting the processor freezers (ie when saving the registers & context for each CPU via an SMP call).
I take it this has been tested with AGP and X11 running?
Thanks,
Zwane
Re: Suspend 2 merge: 19/51: Remove MTRR sysdev support.
Hi.
Quoted 8 lines · Zwane Mwaikambo
Quoted 4 lines · Nigel Cunningham
This patch removes sysdev support for MTRRs (potential SMP hang and shouldn't be done with interrupts done anyway). Instead, we save and restore MTRRs when entering and exiting the processor freezers (ie when saving the registers & context for each CPU via an SMP call).
I take it this has been tested with AGP and X11 running?
Absolutely. It is used all the time. (The machine I'm typing on now has HT support and I normally suspend from X - Radeon driver and just double checked that agpgart is loaded).
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 19/51: Remove MTRR sysdev support.
In reply to Nigel CunninghamHi!
Quoted 4 lines
This patch removes sysdev support for MTRRs (potential SMP hang and shouldn't be done with interrupts done anyway). Instead, we save and restore MTRRs when entering and exiting the processor freezers (ie when saving the registers & context for each CPU via an SMP call).
This will break acpi s3...
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 19/51: Remove MTRR sysdev support.
Quoted 8 lines · Pavel Machek
Hi!
Quoted 4 lines
This patch removes sysdev support for MTRRs (potential SMP hang and shouldn't be done with interrupts done anyway). Instead, we save and restore MTRRs when entering and exiting the processor freezers (ie when saving the registers & context for each CPU via an SMP call).
This will break acpi s3...
MTRR support is via sysdev is by design broken (SMP deadlock possible), so you need to add it to the right place in your S3 code. (ie, it's not that I'm breaking S3. It's already broken, but works while you only support suspending !SMP).
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Suspend 2 merge: 31/51: Export tlb flushing
In reply to Nigel CunninghamThis patch adds a do_flush_tlb_all function that does the SMP-appropriate thing for suspend after the image is restored.
arch/i386/kernel/smp.c +1 -1
@@ -476,7 +476,7 @@preempt_enable (); } -static void do_flush_tlb_all (void * info) +void do_flush_tlb_all (void * info) {unsigned long cpu =smp_processor_id ();
include/asm-i386/tlbflush.h +5 -0
@@ -82,6 +82,7 @@#define flush_tlb () __flush_tlb()#define flush_tlb_all () __flush_tlb_all()#define local_flush_tlb () __flush_tlb() +#define local_flush_tlb_all () __flush_tlb_all();static inline void flush_tlb_mm (struct mm_struct *mm) {
@@ -114,6 +115,10 @@extern void flush_tlb_current_task (void );extern void flush_tlb_mm (struct mm_struct *);extern void flush_tlb_page (struct vm_area_struct *,unsigned long ); +extern void do_flush_tlb_all (void * info); + +#define local_flush_tlb_all () \ + do_flush_tlb_all(NULL);#define flush_tlb () flush_tlb_current_task()
Re: Suspend 2 merge: 31/51: Export tlb flushing
--Nigel Cunningham <[email protected]> wrote (on Wednesday, November 24, 2004 23:59:50 +1100):
Quoted 2 lines
This patch adds a
do_flush_tlb_allfunction that does the SMP-appropriate thing for suspend after the image is restored.
Is software suspend only designed for i386, or is that the only arch that didn't have such a function already? Seems like too low a level to be exporting to me.
M.
Quoted 43 lines
diff -ruN
818-tlb-flushing-functions-old/arch/i386/kernel/smp.c818-tlb-flushing-functions-new/arch/i386/kernel/smp.carch/i386/kernel/smp.c +1
-1@@ -476,7 +476,7 @@preempt_enable (); } -static void do_flush_tlb_all (void * info) +void do_flush_tlb_all (void * info) {unsigned long cpu =smp_processor_id ();diff -ruN
818-tlb-flushing-functions-old/include/asm-i386/tlbflush.h818-tlb-flushing-functions-new/include/asm-i386/tlbflush.hinclude/asm-i386/tlbflush.h +5
-1@@ -82,6 +82,7 @@#define flush_tlb () __flush_tlb()#define flush_tlb_all () __flush_tlb_all()#define local_flush_tlb () __flush_tlb() +#define local_flush_tlb_all () __flush_tlb_all();static inline void flush_tlb_mm (struct mm_struct *mm) {@@ -114,6 +115,10 @@extern void flush_tlb_current_task (void );extern void flush_tlb_mm (struct mm_struct *);extern void flush_tlb_page (struct vm_area_struct *,unsigned long ); +extern void do_flush_tlb_all (void * info); + +#define local_flush_tlb_all () \ + do_flush_tlb_all(NULL);#define flush_tlb () flush_tlb_current_task() -To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: Suspend 2 merge: 31/51: Export tlb flushing
Hi.
Quoted 8 lines · Martin J. Bligh
--Nigel Cunningham <[email protected]> wrote (on Wednesday, November 24, 2004 23:59:50 +1100):
Quoted 2 lines
This patch adds a
do_flush_tlb_allfunction that does the SMP-appropriate thing for suspend after the image is restored.Is software suspend only designed for i386, or is that the only arch that didn't have such a function already? Seems like too low a level to be exporting to me.
There's lowlevel code for x86 and ppc at the moment, more arch specific code can be added. This function is used from the x86 restoration of the original kernel (arch/i386/power/suspend2.c).
Regards,
Nigel
Quoted 45 lines
M.
Quoted 43 lines
diff -ruN
818-tlb-flushing-functions-old/arch/i386/kernel/smp.c818-tlb-flushing-functions-new/arch/i386/kernel/smp.carch/i386/kernel/smp.c +1
-1@@ -476,7 +476,7 @@preempt_enable (); } -static void do_flush_tlb_all (void * info) +void do_flush_tlb_all (void * info) {unsigned long cpu =smp_processor_id ();diff -ruN
818-tlb-flushing-functions-old/include/asm-i386/tlbflush.h818-tlb-flushing-functions-new/include/asm-i386/tlbflush.hinclude/asm-i386/tlbflush.h +5
-1@@ -82,6 +82,7 @@#define flush_tlb () __flush_tlb()#define flush_tlb_all () __flush_tlb_all()#define local_flush_tlb () __flush_tlb() +#define local_flush_tlb_all () __flush_tlb_all();static inline void flush_tlb_mm (struct mm_struct *mm) {@@ -114,6 +115,10 @@extern void flush_tlb_current_task (void );extern void flush_tlb_mm (struct mm_struct *);extern void flush_tlb_page (struct vm_area_struct *,unsigned long ); +extern void do_flush_tlb_all (void * info); + +#define local_flush_tlb_all () \ + do_flush_tlb_all(NULL);#define flush_tlb () flush_tlb_current_task() -To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Suspend 2 merge: 30/51: Enable slab alloc fallback to suspend memory pool
In reply to Nigel CunninghamWhen we are preparing the image and have eaten all available memory, but before page allocations have been switched over to the memory pool, we sometimes need to allocate memory from slab for the image metadata (swap header information). This code allows the slab allocator to fall back to the memory pool in such circumstances. There is some extra debugging code there at the moment while I seek to diagnose intermittent slab corruption (not sure if it's suspend related).
mm/slab.c +16 -0
@@ -874,14 +874,30 @@ flags |= cachep->gfpflags;if (likely (nodeid ==-1 )) { addr = (void *)__get_free_pages (flags, cachep->gfporder); +if (unlikely ((!addr) && (current->pid == suspend_task) && +test_suspend_state (SUSPEND_SLAB_ALLOC_FALLBACK ))) { + addr = (void *)suspend2_get_grabbed_pages (0 ); +printk ("!! Slab addition satisfied via fallback code.\n" ); + }if (!addr)return NULL ; +if (unlikely (test_suspend_state (SUSPEND_RUNNING ))) +printk ("Order %d allocation %p added to slab %p.\n" , + cachep->gfporder, addr, cachep); page =virt_to_page (addr); }else { page =alloc_pages_node (nodeid, flags, cachep->gfporder); +if (unlikely ((!page) && (current->pid == suspend_task) && +test_suspend_state (SUSPEND_SLAB_ALLOC_FALLBACK ))) { + page =virt_to_page (suspend2_get_grabbed_pages (0 )); +printk ("!! Slab addition satisfied via fallback code.\n" ); + }if (!page)return NULL ; addr =page_address (page); +if (unlikely (test_suspend_state (SUSPEND_RUNNING ))) +printk ("Order %d allocation %p added to slab %p.\n" , + cachep->gfporder, addr, cachep); } i = (1 << cachep->gfporder);
Re: Suspend 2 merge: 30/51: Enable slab alloc fallback to suspend memory pool
Hi!
Quoted 7 lines
When we are preparing the image and have eaten all available memory, but before page allocations have been switched over to the memory pool, we sometimes need to allocate memory from slab for the image metadata (swap header information). This code allows the slab allocator to fall back to the memory pool in such circumstances. There is some extra debugging code there at the moment while I seek to diagnose intermittent slab corruption (not sure if it's suspend related).
More reasons to dislike two pagesets. Also you probably should not printk() with two !!s in it (but without severity). Is it bug or not?
Quoted 19 lines
diff -ruN
817-enable-slab-alloc-fallback-to-suspend-memory-pool-old/mm/slab.c817-enable-slab-alloc-fallback-to-suspend-memory-pool-new/mm/slab.cmm/slab.c +8
-0@@ -874,14 +874,30 @@ flags |= cachep->gfpflags;if (likely (nodeid ==-1 )) { addr = (void *)__get_free_pages (flags, cachep->gfporder); +if (unlikely ((!addr) && (current->pid == suspend_task) && +test_suspend_state (SUSPEND_SLAB_ALLOC_FALLBACK ))) { + addr = (void *)suspend2_get_grabbed_pages (0 ); +printk ("!! Slab addition satisfied via fallback code.\n" ); + }if (!addr)return NULL ; +if (unlikely (test_suspend_state (SUSPEND_RUNNING ))) +printk ("Order %d allocation %p added to slab %p.\n" , + cachep->gfporder, addr, cachep); page =virt_to_page (addr); }else {
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!
Suspend 2 merge: 18/51: Debug page_alloc support.
In reply to Nigel CunninghamThis patch provides support for making suspend work when DEBUG_PAGEALLOC is enabled.
arch/i386/mm/pageattr.c +44 -0
@@ -211,5 +213,49 @@EXPORT_SYMBOL (kernel_map_pages);#endif +#ifdef CONFIG_SOFTWARE_SUSPEND2 +#ifdef CONFIG_DEBUG_PAGEALLOC +static int page_is_kernel_mapped (struct page * page) +{ +pte_t *kpte; +unsigned long address; + +#ifdef CONFIG_HIGHMEM +if (page >= highmem_start_page) +return 0 ; +#endif + + address = (unsigned long )page_address (page); + + kpte =lookup_address (address); +if (!kpte) +return 0 ; + +if (pte_same (*kpte,mk_pte (page,PAGE_KERNEL ))) +return 1 ; + +return 0 ; +} + +int suspend_map_kernel_page (struct page * page,int enable) +{ +int is_already_mapped =page_is_kernel_mapped (page); + +if (enable == is_already_mapped) +return 1 ; + +kernel_map_pages (page,1 , enable); + +return 0 ; +} +#else +int suspend_map_kernel_page (struct page * page,int enable) +{ +return (enable ==1 ); +} +#endif +EXPORT_SYMBOL (suspend_map_kernel_page); +#endif +EXPORT_SYMBOL (change_page_attr);EXPORT_SYMBOL (global_flush_tlb);
Re: Suspend 2 merge: 18/51: Debug page_alloc support.
arch/i386/mm/pageattr.c line 226
Quoted 4 lines · Nigel Cunningham
arch/i386/mm/pageattr.c +4
-0+#ifdef CONFIG_HIGHMEM +if (page >= highmem_start_page) +return 0 ; +#endif
There's a patch pending in -mm to kill highmem_start_page. Please use PageHighMem().
-- Dave
Re: Suspend 2 merge: 18/51: Debug page_alloc support.
Hi.
Quoted 8 lines · Dave Hansen
arch/i386/mm/pageattr.c line 226
Quoted 4 lines · Nigel Cunningham
arch/i386/mm/pageattr.c +4
-0+#ifdef CONFIG_HIGHMEM +if (page >= highmem_start_page) +return 0 ; +#endif There's a patch pending in -mm to kill
highmem_start_page. Please usePageHighMem().
That's not out-of-line, is it? (We use it while resuming too, IIRC). I'll take a look.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 18/51: Debug page_alloc support.
Quoted 10 lines · Nigel Cunningham
Quoted 8 lines · Dave Hansen
arch/i386/mm/pageattr.c line 226
Quoted 4 lines · Nigel Cunningham
arch/i386/mm/pageattr.c +4
-0+#ifdef CONFIG_HIGHMEM +if (page >= highmem_start_page) +return 0 ; +#endif There's a patch pending in -mm to kill
highmem_start_page. Please usePageHighMem().
Quoted 2 lines
That's not out-of-line, is it? (We use it while resuming too, IIRC). I'll take a look.
Nope. That's a simple single-bit page->flags check.
-- Dave
Re: Suspend 2 merge: 18/51: Debug page_alloc support.
In reply to Nigel CunninghamHi!
Quoted 2 lines
This patch provides support for making suspend work when
DEBUG_PAGEALLOCis enabled.
Is swsusp1 broken in this config?
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 18/51: Debug page_alloc support.
Hi.
Quoted 6 lines · Pavel Machek
Hi!
Quoted 2 lines
This patch provides support for making suspend work when
DEBUG_PAGEALLOCis enabled.Is swsusp1 broken in this config?
I'd be surprised if it wasn't. You need to map pages in (and unmap them) to do the copy/restore.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Suspend 2 merge: 35/51: Code always built in to the kernel.
In reply to Nigel CunninghamThese are the files containing code that is always built in to the kernel when suspend support is compiled in.
- /proc/software_suspend simplified interface. This is to save me repeating the same code everywhere. Perhaps there are similar routines that others have written and I've missed. If so, feel free to point me to them (haven't looked much).
- basic support for complaining if the core isn't loaded
- support for loading the core and interfacing with it
- __init routines
- some routines to save exporting variables
kernel/power/proc.c +359 -0
@@ -0,0 +1,359 @@ +/* +* /kernel/power/proc.c +* +* Copyright (C) 2002-2003 Nigel Cunningham <[email protected]> +* +* This file is released under the GPLv2. +* +* This file contains support for proc entries for tuning Software Suspend. +* +* We have a generic handler that deals with the most common cases, and +* hooks for special handlers to use. +* +* Versions: +* 1: /proc/sys/kernel/suspend the only tuning interface +* 2: Initial version of this file +* 3: Removed kernel debugger parameter. +* Added checkpage parameter (for checking checksum of a page over time). +* 4: Added entry for maximum granularity in splash screen progress bar. +* (Progress bar is slow, but the right setting will vary with disk & +* processor speed and the user's tastes). +* 5: Added enable_escape to control ability to cancel aborting by pressing +* ESC key. +* 6: Removed checksumming and checkpage parameter. Made all debugging proc +* entries dependant upon debugging being compiled in. +* Meaning of some flags also changed in this version. +* 7: Added header_locations entry to simplify getting the resume= parameter for +* swapfiles easy and swapfile entry for automatically doing swapon/off from +* swapfiles as well as partitions. +* 8: Added option for marking process pages as pageset 2 (processes_pageset2). +* 9: Added option for keep image mode. +* Enumeration patch from Michael Frank applied. +* 10: Various corrections to when options are disabled/enabled; +* Added option for specifying expected compression. +* 11: Added option for freezer testing. Debug only. +* 12: Removed test entries no_async_[read|write], processes_pageset2 and +* NoPageset2. +* 13: Make default_console_level available when debugging disabled, but limited +* to 0 or 1. +* 14: Rewrite to allow for dynamic registration of proc entries and smooth the +* transition to kobjects in 2.6. +* 15: Add setting resume2 parameter without rebooting (still need to run lilo +* though!). Add support for generic string handling and switch resume2 to use +* it. +*/ + +#define SUSPEND_PROC_C + +static int suspend_proc_version =15 ; +static int suspend_proc_initialised =0 ; + +#include <linux/suspend.h> +#include <linux/module.h> +#include <linux/proc_fs.h> +#include <asm/uaccess.h> + +#include "suspend.h" +#include "proc.h" + +static struct list_head suspend_proc_entries; +static struct proc_dir_entry *suspend_dir; + +extern char resume2_file[256 ];/* For resume= kernel option */ + +/* +* proc_try_suspend +* +* This routine initiates a suspend cycle when /proc/software_suspend/do_suspend is +* written to. The value written is ignored. +*/ + +static int proc_try_suspend (struct file *file,const char *buffer, +unsigned long count,void *data) +{ +suspend_try_suspend (); +return count; +} + +/* +* proc_try_resume +* +* This routine initiates a suspend cycle when /proc/software_suspend/do_resume is +* written to. The value written is ignored. +*/ + +static int proc_try_resume (struct file *file,const char *buffer, +unsigned long count,void *data) +{ +software_suspend_try_resume (); +return count; +} + +/* +* generic_read_proc +* +* Generic handling for reading the contents of bits, integers, +* unsigned longs and strings. +*/ +static int generic_read_proc (char * page,char ** start,off_t off,int count, +int *eof,void *data) +{ +int len =0 ; +struct suspend_proc_data * proc_data = (struct suspend_proc_data *) data; + +switch (proc_data->type) { +case SUSPEND_PROC_DATA_CUSTOM : +printk ("Error! /proc/suspend/%s marked as having custom" +" routines, but the generic read routine has" +" been invoked.\n" , + proc_data->filename); +break ; +case SUSPEND_PROC_DATA_BIT : + len =sprintf (page,"%d\n" , + -test_bit (proc_data->data.bit.bit, + proc_data->data.bit.bit_vector)); +break ; +case SUSPEND_PROC_DATA_INTEGER : + { +int * variable = proc_data->data.integer.variable; + len =sprintf (page,"%d\n" , *variable); +break ; + } +case SUSPEND_PROC_DATA_UL : + { +long * variable = proc_data->data.ul.variable; + len =sprintf (page,"%lu\n" , *variable); +break ; + } +case SUSPEND_PROC_DATA_STRING : + { +char * variable = proc_data->data.string.variable; + len =sprintf (page,"%s\n" , variable); +break ; + } + } +/* Side effect routine? */ +if (proc_data->read_proc) + proc_data->read_proc (); + *eof =1 ; +return len; +} +/* +* generic_write_proc +* +* Generic routine for handling writing to files representing +* bits, integers and unsigned longs. +*/ + +static int generic_write_proc (struct file *file,const char * buffer, +unsigned long count,void * data) +{ +struct suspend_proc_data * proc_data = (struct suspend_proc_data *) data; +char * my_buf = (char *)get_zeroed_page (GFP_ATOMIC ); +int result = count; + +if (!my_buf) +return -ENOMEM ; + +if (count >PAGE_SIZE ) + count =PAGE_SIZE ; + +if (copy_from_user (my_buf, buffer, count)) +return -EFAULT ; + + my_buf[count] =0 ; + +switch (proc_data->type) { +case SUSPEND_PROC_DATA_CUSTOM : +printk ("Error! /proc/suspend/%s marked as having custom" +" routines, but the generic write routine has" +" been invoked.\n" , + proc_data->filename); +break ; +case SUSPEND_PROC_DATA_BIT : + { +int value =simple_strtoul (my_buf,NULL ,0 ); +if (value) +set_bit (proc_data->data.bit.bit, + (proc_data->data.bit.bit_vector)); +else +clear_bit (proc_data->data.bit.bit, + (proc_data->data.bit.bit_vector)); + } +break ; +case SUSPEND_PROC_DATA_INTEGER : + { +int * variable = proc_data->data.integer.variable; +int minimum = proc_data->data.integer.minimum; +int maximum = proc_data->data.integer.maximum; + *variable =simple_strtol (my_buf,NULL ,0 ); +if (((*variable) < minimum)) + *variable = minimum; + +if (((*variable) > maximum)) + *variable = maximum; +break ; + } +case SUSPEND_PROC_DATA_UL : + { +unsigned long * variable = proc_data->data.ul.variable; +unsigned long minimum = proc_data->data.ul.minimum; +unsigned long maximum = proc_data->data.ul.maximum; + *variable =simple_strtoul (my_buf,NULL ,0 ); + +if (minimum && ((*variable) < minimum)) + *variable = minimum; + +if (maximum && ((*variable) > maximum)) + *variable = maximum; +break ; + } +break ; +case SUSPEND_PROC_DATA_STRING : + { +int copy_len = + (count > + proc_data->data.string.max_length) ? + proc_data->data.string.max_length : + count; +char * variable = + proc_data->data.string.variable; +strncpy (variable, my_buf, copy_len); +if ((copy_len) && + (my_buf[copy_len -1 ] =='\n' )) + variable[count -1 ] =0 ; + variable[count] =0 ; + } +break ; + } +free_pages ((unsigned long ) my_buf,0 ); +/* Side effect routine? */ +if (proc_data->write_proc) { +int routine_result = proc_data->write_proc (); +if (routine_result <0 ) + result = routine_result; + } +return result; +} + +/* +* Non-plugin proc entries. +* +* This array contains entries that are automatically registered at +* boot. Plugins and the console code register their own entries separately. +*/ + +static struct suspend_proc_data proc_params[] = { + { .filename ="do_suspend" , + .permissions =PROC_WRITEONLY , + .type =SUSPEND_PROC_DATA_CUSTOM , + .data = { + .special = { + .write_proc = proc_try_suspend + } + } + }, + + { .filename ="do_resume" , + .permissions =PROC_WRITEONLY , + .type =SUSPEND_PROC_DATA_CUSTOM , + .data = { + .special = { + .write_proc = proc_try_resume + } + } + }, + + + { .filename ="interface_version" , + .permissions =PROC_READONLY , + .type =SUSPEND_PROC_DATA_INTEGER , + .data = { + .integer = { + .variable = &suspend_proc_version, + } + } + }, +}; + +/* +* suspend_initialise_proc +* +* Initialise the /proc/suspend tree. +* +*/ + +static void suspend_initialise_proc (void ) +{ +int i; +int numfiles =sizeof (proc_params) /sizeof (struct suspend_proc_data ); + +if (suspend_proc_initialised) +return ; + + suspend_dir =proc_mkdir ("software_suspend" ,NULL ); + +BUG_ON (!suspend_dir); + +INIT_LIST_HEAD (&suspend_proc_entries); + + suspend_proc_initialised =1 ; + +for (i=0 ; i< numfiles; i++) +suspend_register_procfile (&proc_params[i]); +} + +/* +* suspend_register_procfile +* +* Helper for registering a new /proc/suspend entry. +*/ + +struct proc_dir_entry *suspend_register_procfile ( +struct suspend_proc_data * suspend_proc_data) +{ +struct proc_dir_entry * new_entry; + +if (!suspend_proc_initialised) +suspend_initialise_proc (); + + new_entry =create_proc_entry ( + suspend_proc_data->filename, + suspend_proc_data->permissions, + suspend_dir); +if (new_entry) { +list_add_tail (&suspend_proc_data->proc_data_list, &suspend_proc_entries); +if (suspend_proc_data->type) { + new_entry->read_proc = generic_read_proc; + new_entry->write_proc = generic_write_proc; + }else { + new_entry->read_proc = suspend_proc_data->data.special.read_proc; + new_entry->write_proc = suspend_proc_data->data.special.write_proc; + } + new_entry->data = suspend_proc_data; + }else { +printk ("Error! create_proc_entry returned NULL.\n" ); +INIT_LIST_HEAD (&suspend_proc_data->proc_data_list); + } +return new_entry; +} + +/* +* suspend_unregister_procfile +* +* Helper for removing unwanted /proc/suspend entries. +* +*/ +void suspend_unregister_procfile (struct suspend_proc_data * suspend_proc_data) +{ +if (list_empty (&suspend_proc_data->proc_data_list)) +return ; + +remove_proc_entry ( + suspend_proc_data->filename, + suspend_dir); +list_del (&suspend_proc_data->proc_data_list); +} + +EXPORT_SYMBOL (suspend_register_procfile); +EXPORT_SYMBOL (suspend_unregister_procfile);
kernel/power/suspend_builtin.c +541 -0
541 lines not on this page · raw message
Re: Suspend 2 merge: 35/51: Code always built in to the kernel.
Hi!
Quoted 14 lines
kernel/power/proc.c +14
-0+/* +* generic_read_proc +* +* Generic handling for reading the contents of bits, integers, +* unsigned longs and strings. +*/ +static int generic_read_proc (char * page,char ** start,off_t off,int count, +int *eof,void *data) +{ +int len =0 ; +struct suspend_proc_data * proc_data = (struct suspend_proc_data *) data; + +switch (proc_data->type) { +case SUSPEND_PROC_DATA_CUSTOM :
kernel/power/proc.c line 115
Quoted 10 lines
kernel/power/proc.c +10
-0+printk ("Error! /proc/suspend/%s marked as having custom" +" routines, but the generic read routine has" +" been invoked.\n" , + proc_data->filename); +break ; +case SUSPEND_PROC_DATA_BIT : + len =sprintf (page,"%d\n" , + -test_bit (proc_data->data.bit.bit, + proc_data->data.bit.bit_vector)); +break ;
You have your own abstraction on the top of /proc? That's no-no.
kernel/power/proc.c line 245
Quoted 7 lines
kernel/power/proc.c +7
-0+/* +* Non-plugin proc entries. +* +* This array contains entries that are automatically registered at +* boot. Plugins and the console code register their own entries separately. +*/ +
...aha, you do that to enable plugin system. Take it as another reason why plugins have to go.
Quoted 27 lines
kernel/power/suspend_builtin.c +27
-0+/* +* Basic keypress handler for suspend. This is extensible +* via the user interface modules. +*/ + +/* For simplicity, we convert keyboard key codes to ascii, +* except in the case of function keys, which are mapped +* to 1-12. We can then use the same case statement for +* serial keyboards (and from a serial keyboard, you can +* press Control-A..L to toggle sections. +*/ +static unsigned int kbd_keytable[] = { +0 ,27 ,49 ,50 ,51 ,52 ,53 ,54 ,55 ,56 , +57 ,48 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,114 , +116 ,0 ,0 ,0 ,0 ,112 ,0 ,0 ,0 ,0 , +0 ,115 ,0 ,0 ,0 ,0 ,0 ,0 ,108 ,0 , +0 ,122 ,0 ,0 ,0 ,0 ,99 ,0 ,0 ,0 , +0 ,0 ,0 ,0 ,0 ,0 ,0 ,32 ,0 ,1 , +2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,0 , +0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , +0 ,0 ,0 ,0 ,0 ,0 ,0 ,11 ,12 ,0 , +}; + +/* +* keycode_to_action +* +* Convert a keycode (serial or keyboard) into our
kernel/power/suspend_builtin.c line 106
Quoted 10 lines
kernel/power/suspend_builtin.c +10
-0+* internal code (ascii, except for function keys). +*/ +static unsigned int keycode_to_action (unsigned int keycode,int source) +{ +if (source ==SUSPEND_KEY_SERIAL ) { +if (keycode >64 ) +return (keycode |32 ); +else +return keycode; + }
And your own keyboard driver :-(.
kernel/power/suspend_builtin.c line 244
Quoted 12 lines
kernel/power/suspend_builtin.c +12
-0+say ("BIG FAT WARNING!! %s\n\n" , suspend_print_buf); +if (can_erase_image) { +say ("If you want to use the current suspend image, reboot and try\n" ); +say ("again with the same kernel that you suspended from. If you want\n" ); +say ("to forget that image, continue and the image will be erased.\n" ); + }else { +say ("If you continue booting, note that any image WILL NOT BE REMOVED.\n" ); +say ("Suspend is unable to do so because the appropriate modules aren't\n" ); +say ("loaded. You should manually remove the image to avoid any\n" ); +say ("possibility of corrupting your filesystem(s) later.\n" ); + } +say ("Press SPACE to reboot or C to continue booting with this kernel\n" );
Plus kernel now actually expects user interaction to solve problems during boot. No, no.
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!
Re: Suspend 2 merge: 35/51: Code always built in to the kernel.
Hi.
Quoted 1 line · Pavel Machek
You have your own abstraction on the top of /proc? That's no-no.
You'd prefer the same code repeated 20 times?
Quoted 2 lines
...aha, you do that to enable plugin system. Take it as another reason why plugins have to go.
No, it's just useful. The /proc abstraction predated the plugins. What I really want to do is switch to kobjects for the plugins. But that can wait a little longer.
Quoted 1 line
And your own keyboard driver :-(.
It's not really a keyboard driver. We're just making serial console and local keypresses into the same key codes and letting them be handled by the relevant plugin.
Quoted 7 lines
Quoted 7 lines
kernel/power/suspend_builtin.c +7
-0+say ("BIG FAT WARNING!! %s\n\n" , suspend_print_buf); +if (can_erase_image) { +say ("If you want to use the current suspend image, reboot and try\n" ); +say ("again with the same kernel that you suspended from. If you want\n" ); +say ("to forget that image, continue and the image will be erased.\n" ); + }else { +say ("If you continue booting, note that any image WILL NOT BE REMOVED.\n" );
Quoted 8 lines
kernel/power/suspend_builtin.c line 244
Quoted 5 lines
kernel/power/suspend_builtin.c +5
-0+say ("Suspend is unable to do so because the appropriate modules aren't\n" ); +say ("loaded. You should manually remove the image to avoid any\n" ); +say ("possibility of corrupting your filesystem(s) later.\n" ); + } +say ("Press SPACE to reboot or C to continue booting with this kernel\n" );Plus kernel now actually expects user interaction to solve problems during boot. No, no.
You want your cake and to eat it too? :> We don't want to warn the user before they shoot themselves in the foot, but not loudly enough that they can't help notice and choose to do something before the damage is done?
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 35/51: Code always built in to the kernel.
Quoted 4 lines · Nigel Cunningham
You want your cake and to eat it too? :> We don't want to warn the user before they shoot themselves in the foot, but not loudly enough that they can't help notice and choose to do something before the damage is done?
We have userspace to do this, surely? Make the standard method of triggering resume involve an initrd, and have a small application that does sanity checks before the resume. In case of failure, have it prompt the user. As long as it doesn't do bad things to the filesystem, there's no danger. There's no reason to do this in the kernel.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Suspend 2 merge: 35/51: Code always built in to the kernel.
Hi Matthew.
Quoted 5 lines · Matthew Garrett
We have userspace to do this, surely? Make the standard method of triggering resume involve an initrd, and have a small application that does sanity checks before the resume. In case of failure, have it prompt the user. As long as it doesn't do bad things to the filesystem, there's no danger. There's no reason to do this in the kernel.
It was originally done in kernel space prior to us having initrd support, as a small extension on what was already there. I don't see a good reason to move it to working from an initrd because:
1) We're then assuming that everyone uses an initrd/initramfs, which is not true
2) We need to provide a way for this userspace program to obtain from the kernel the signature of the image and information about what we want the signature to look like. It will also then need to be able to tell the kernel to delete the image.
3) If you want the userspace program to actually read the signature itself, the kernel still needs to tell the userspace program where to find that signature (what device, block and blocksize). That device can't be mounted/swapon'd to do this; it needs to be a raw read.
4) This whole method means there's even more code to maintain!
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 35/51: Code always built in to the kernel.
In reply to Nigel CunninghamHi!
Quoted 3 lines
Quoted 1 line
You have your own abstraction on the top of /proc? That's no-no.
You'd prefer the same code repeated 20 times?
Rest of kernel is pretty happy with /proc as-is. Why can't suspend2 just play along?
How many options are really neccessary? activate is not. selecting of reboot can already be done in /sys. Some percentages? There really should not be 20 things to configure.
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
kernel/power/suspend_builtin.c +7
-0+say ("BIG FAT WARNING!! %s\n\n" , suspend_print_buf); +if (can_erase_image) { +say ("If you want to use the current suspend image, reboot and try\n" ); +say ("again with the same kernel that you suspended from. If you want\n" ); +say ("to forget that image, continue and the image will be erased.\n" ); + }else { +say ("If you continue booting, note that any image WILL NOT BE REMOVED.\n" );Quoted 8 lines
kernel/power/suspend_builtin.c line 244
Quoted 5 lines
kernel/power/suspend_builtin.c +5
-0+say ("Suspend is unable to do so because the appropriate modules aren't\n" ); +say ("loaded. You should manually remove the image to avoid any\n" ); +say ("possibility of corrupting your filesystem(s) later.\n" ); + } +say ("Press SPACE to reboot or C to continue booting with this kernel\n" );Plus kernel now actually expects user interaction to solve problems during boot. No, no.
Quoted 4 lines
You want your cake and to eat it too? :> We don't want to warn the user before they shoot themselves in the foot, but not loudly enough that they can't help notice and choose to do something before the damage is done?
Kernel boot is not expected to be interactive. I'd do
if (can_erase_image)
printk("Incorrect kernel version, image killed\n");
else
panic("Can't kill suspended image");
PavelSignature · 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!
Re: Suspend 2 merge: 35/51: Code always built in to the kernel.
Hi again.
Quoted 7 lines · Pavel Machek
Kernel boot is not expected to be interactive. I'd do
if (
can_erase_image)printk("Incorrect kernel version, image killed\n"); else panic("Can't kill suspended image");
Comes down, again, to user friendliness. Just because I can erase the image, doesn't mean I should. It may be that the user just pressed the down arrow one too few times in lilo, and they really do have the right kernel, but started the wrong one. Or it may be that they're still setting up their initrd, didn't get it quite right, know that no damage will be done and want to continue booting. We should let the user think about what they want to do and then do it.
I need to get on with the work I planned on doing today, so I'm going to hang up after sending this. That's not at all to say that I want you to stop sending email; just that I won't be replying for a while.
Once again, thanks very much for your effort. It is good to be made to defend design decisions and to see where you could do things better or took things for granted that 'aint necessarily so.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 35/51: Code always built in to the kernel.
Hi!
Quoted 8 lines
Quoted 7 lines
Kernel boot is not expected to be interactive. I'd do
if (
can_erase_image)printk("Incorrect kernel version, image killed\n"); else panic("Can't kill suspended image");
Quoted 7 lines
Comes down, again, to user friendliness. Just because I can erase the image, doesn't mean I should. It may be that the user just pressed the down arrow one too few times in lilo, and they really do have the right kernel, but started the wrong one. Or it may be that they're still setting up their initrd, didn't get it quite right, know that no damage will be done and want to continue booting. We should let the user think about what they want to do and then do it.
User friendlyness is nice, but I think "boot is not interactive" is stronger requirement than that.
Quoted 3 lines
I need to get on with the work I planned on doing today, so I'm going to hang up after sending this. That's not at all to say that I want you to stop sending email; just that I won't be replying for a while.
No problem, I need some sleep.
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!
Re: Suspend 2 merge: 35/51: Code always built in to the kernel.
In reply to Nigel CunninghamQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Nigel" == Nigel Cunningham <[email protected]>:
Nigel> Hi.
Nigel> On Fri, 2004-11-26 at 10:32, Pavel Machek wrote:
[...]
Quoted 2 lines
Quoted 2 lines
Plus kernel now actually expects user interaction to solve problems during boot. No, no.
Nigel> You want your cake and to eat it too? :> We don't want to warn Nigel> the user before they shoot themselves in the foot, but not Nigel> loudly enough that they can't help notice and choose to do Nigel> something before the damage is done?
You're forgetting that Pavel's idea of user interaction is via BUG_ON() and panic(). That's obviously "cleaner", "less ugly", and "smaller".
Sorry, can't help being sarcastic after watching the tone of some of these exchanges, particularly comments from pedestals that are being made so often. I find it rather sad.
--J.
Re: Suspend 2 merge: 35/51: Code always built in to the kernel.
Quoted 7 lines · Jan Rychter
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Nigel" == Nigel Cunningham <[email protected]>:
Nigel> Hi.
Nigel> On Fri, 2004-11-26 at 10:32, Pavel Machek wrote:
[...]Quoted 2 lines
Quoted 2 lines
Plus kernel now actually expects user interaction to solve problems during boot. No, no.
Quoted 7 lines
Nigel> You want your cake and to eat it too? :> We don't want to warn Nigel> the user before they shoot themselves in the foot, but not Nigel> loudly enough that they can't help notice and choose to do Nigel> something before the damage is done?
You're forgetting that Pavel's idea of user interaction is via
BUG_ON()andpanic(). That's obviously "cleaner", "less ugly", and "smaller".
If you have a "can't happen" condition, it is just plain wrong to return 0 and succeed. If you can't understand that, well, that's your problem, not mine.
Now, if you want kernel that asks user "really mount ext3 on /dev/hda3 filesystem to /, WARNING: you should run fsck first, press f to do that", that's your option, feel free to start your own kernel fork.
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!
Suspend 2 merge: 47/51: GZIP support.
In reply to Nigel CunninghamThe original compressor. Slow. I've tried to drop it, but for reasons I simply don't understand, some users still want it.
kernel/power/suspend_gzip.c +560 -0
@@ -0,0 +1,560 @@ +/* +* kernel/power/gzip_compression.c +* +* Copyright (C) 2003,2004 Nigel Cunningham <[email protected]> +* +* This file is released under the GPLv2. +* +* This file contains data compression routines for suspend. +* Compression is implemented using the zlib library. +* +*/ + +#include <linux/suspend.h> +#include <linux/module.h> +#include <linux/highmem.h> +#include <linux/zlib.h> + +#include "plugins.h" +#include "proc.h" +#include "suspend.h" + +/* Forward declaration for the ops structure we export */ +struct suspend_plugin_ops gzip_compression_ops; + +/* The next driver in the pipeline */ +static struct suspend_plugin_ops * next_driver; + +/* Zlib routines we use to compress/decompress the data */ +extern int zlib_compress (unsigned char *data_in,unsigned char *cpage_out, +u32 *sourcelen,u32 *dstlen); +extern void zlib_decompress (unsigned char *data_in,unsigned char *cpage_out, +u32 srclen,u32 destlen); + +/* Buffers */ +static void *compression_workspace =NULL ; +static char *local_buffer =NULL ; + +/* Configuration data we pass to zlib */ +static z_stream strm; + +/* Stats we save */ +static __nosavedata unsigned long bytes_in =0 , bytes_out =0 ; + +/* Expected compression is used to reduce the amount of storage allocated */ +static int expected_gzip_compression =0 ; + +/* ---- Zlib memory management ---- */ + +/* allocate_zlib_compression_space +* +* Description: Allocate space for zlib to use in compressing our data. +* Each call must have a matching call to free_zlib_memory. +* Returns: Int: Zero if successful, -ENONEM otherwise. +*/ +static inline int allocate_zlib_compression_space (void ) +{ +BUG_ON (compression_workspace); + + compression_workspace =vmalloc_32 (zlib_deflate_workspacesize ()); +if (!compression_workspace) { +printk (KERN_WARNING +"Failed to allocate %d bytes for deflate workspace\n" , +zlib_deflate_workspacesize ()); +return -ENOMEM ; + } + +return 0 ; +} + +/* allocate_zlib_decompression_space +* +* Description: Allocate space for zlib to use in decompressing our data. +* Each call must have a matching call to free_zlib_memory. +* Returns: Int: Zero if successful, -ENONEM otherwise. +*/ +static inline int allocate_zlib_decompression_space (void ) +{ +BUG_ON (compression_workspace); + + compression_workspace =vmalloc_32 (zlib_inflate_workspacesize ()); +if (!compression_workspace) { +printk (KERN_WARNING +"Failed to allocate %d bytes for inflate workspace\n" , +zlib_inflate_workspacesize ()); +return -ENOMEM ; + } + +return 0 ; +} + +/* free_zlib_memory +* +* Description: Frees memory allocated by either allocation routine (above). +*/ +static inline void free_zlib_memory (void ) +{ +if (!compression_workspace) +return ; + +vfree (compression_workspace); + compression_workspace =NULL ; +} + +/* ---- Local buffer management ---- */ + +/* allocate_local_buffer +* +* Description: Allocates a page of memory for buffering output. +* Returns: Int: Zero if successful, -ENONEM otherwise. +*/ +static int allocate_local_buffer (void ) +{ +if (local_buffer) +return 0 ; + + local_buffer = (char *)get_zeroed_page (GFP_ATOMIC ); + +if (!local_buffer) { +printk (KERN_ERR +"Failed to allocate a page for compression " +"driver's buffer.\n" ); +return -ENOMEM ; + } + +return 0 ; +} + +/* free_local_buffer +* +* Description: Frees memory allocated for buffering output. +*/ +static inline void free_local_buffer (void ) +{ +if (local_buffer) +free_pages ((unsigned long ) local_buffer,0 ); + local_buffer =NULL ; +} + +/* ---- Functions exported via operations struct ---- */ + +/* gzip_write_init +* +* Description: Allocate buffers and prepares zlib for deflating a new stream +* of data. +* Arguments: Stream_number: Ignored. +* Returns: Int. Zero if successful, otherwise an appropriate error number. +*/ + +static int gzip_write_init (int stream_number) +{ +int result; + + next_driver =get_next_filter (&gzip_compression_ops); + +if (!next_driver) { +printk ("GZip Compression Driver: Argh! No one wants my output!" ); +return -ECHILD ; + } + +if ((result =allocate_zlib_compression_space ())) +return result; + +if ((result =allocate_local_buffer ())) +return result; + + strm.total_in =0 ; + strm.total_out =0 ; + strm.workspace = compression_workspace; + strm.next_out = (char *) local_buffer; + strm.avail_out =PAGE_SIZE ; + result =zlib_deflateInit (&strm,Z_BEST_SPEED ); + +if (Z_OK != result) { + printk(KERN_ERR name_suspend "Failed to initialise zlib.\n"); +return -EPERM ; + } + +/* +* Reset the statistics iif we are about to write the first part of +* the image +*/ +if (stream_number ==2 ) + bytes_in = bytes_out =0 ; + +return 0 ; +} + +/* gzip_write_chunk() +* +* Description: Compress a page of data, buffering output and passing on +* filled pages to the next plugin in the pipeline. +* Arguments: Buffer_start: Pointer to a buffer of size PAGE_SIZE, +* containing data to be compressed. +* Returns: 0 on success. Otherwise the error is that returned by later +* plugins, -ECHILD if we have a broken pipeline or -EPERM if +* zlib errs. +*/ + +static int gzip_write_chunk (struct page * buffer_page) +{ +int ret; +char * buffer_start =kmap (buffer_page); + +/* Work to do */ + strm.next_in = buffer_start; + strm.avail_in =PAGE_SIZE ; +while (strm.avail_in) { + ret =zlib_deflate (&strm,Z_PARTIAL_FLUSH ); +if (ret !=Z_OK ) { +printk ("Zlib failed to compress our data. " +"Result code was %d.\n" , ret); +kunmap (buffer_page); +return -EPERM ; + } + +if (!strm.avail_out) { + +if ((ret = next_driver->ops.filter.write_chunk ( +virt_to_page (local_buffer)))) { +kunmap (buffer_page); +return ret; + } + strm.next_out = local_buffer; + strm.avail_out =PAGE_SIZE ; + } + } +kunmap (buffer_page); + +return 0 ; +} + +/* gzip_write_cleanup() +* +* Description: Flush remaining data, update statistics and free allocated +* space. +* Returns: Zero. Never fails. Okay. Zlib might fail... but it shouldn't. +*/ + +static int gzip_write_cleanup (void ) +{ +int ret =0 , finished =0 ; + +while (!finished) { +if (strm.avail_out) { + ret =zlib_deflate (&strm,Z_FINISH ); + +if (ret ==Z_STREAM_END ) { + ret =zlib_deflateEnd (&strm); + finished =1 ; + } + +if ((ret !=Z_OK ) && (ret !=Z_STREAM_END )) { +zlib_deflateEnd (&strm); +printk ("Failed to finish compressing data. " +"Result %d received.\n" , ret); +return -EPERM ; + } + } + +if ((!strm.avail_out) || (finished)) { +if ((ret = next_driver->ops.filter.write_chunk ( +virt_to_page (local_buffer)))) +return ret; + strm.next_out = local_buffer; + strm.avail_out =PAGE_SIZE ; + } + } + + bytes_in+= strm.total_in; + bytes_out+= strm.total_out; + +free_zlib_memory (); +free_local_buffer (); + +return 0 ; +} + +/* gzip_read_init +* +* Description: Prepare to read a new stream of data. +* Arguments: Stream_number: Not used. +* Returns: Int. Zero if successful, otherwise an appropriate error number. +*/ + +static int gzip_read_init (int stream_number) +{ +int result; + + next_driver =get_next_filter (&gzip_compression_ops); + +if (!next_driver) { +printk ("GZip Compression Driver: Argh! " +"No one wants to feed me data!" ); +return -ECHILD ; + } + +if ((result =allocate_zlib_decompression_space ())) +return result; + +if ((result =allocate_local_buffer ())) +return result; + + strm.total_in =0 ; + strm.total_out =0 ; + strm.workspace = compression_workspace; + strm.avail_in =0 ; +if ((result =zlib_inflateInit (&strm)) !=Z_OK ) { + printk(KERN_ERR name_suspend "Failed to initialise zlib.\n"); +return -EPERM ; + } + +return 0 ; +} + +/* gzip_read_chunk() +* +* Description: Retrieve data from later plugins and decompress it until the +* input buffer is filled. +* Arguments: Buffer_start: Pointer to a buffer of size PAGE_SIZE. +* Sync: Whether the previous plugin (or core) wants its +* data synchronously. +* Returns: Zero if successful. Error condition from me or from downstream +* on failure. +*/ + +static int gzip_read_chunk (struct page * buffer_page,int sync) +{ +int ret; +char * buffer_start =kmap (buffer_page); + +/* +* All our reads must be synchronous - we can't decompress +* data that hasn't been read yet. +*/ + +/* Work to do */ + strm.next_out = buffer_start; + strm.avail_out =PAGE_SIZE ; +while (strm.avail_out) { +if (!strm.avail_in) { +if ((ret = next_driver->ops.filter.read_chunk ( +virt_to_page (local_buffer), +SUSPEND_SYNC )) <0 ) { +kunmap (buffer_page); +return ret; + } + strm.next_in = local_buffer; + strm.avail_in =PAGE_SIZE ; + } + + ret =zlib_inflate (&strm,Z_PARTIAL_FLUSH ); + +if ((ret ==Z_BUF_ERROR ) && (!strm.avail_in)) { +continue ; + } + +if ((ret !=Z_OK ) && (ret !=Z_STREAM_END )) { +printk ("Zlib failed to decompress our data. " +"Result code was %d.\n" , ret); +kunmap (buffer_page); +return -EPERM ; + } + } +kunmap (buffer_page); + +return 0 ; +} + +/* read_cleanup() +* +* Description: Clean up after reading part or all of a stream of data. +* Returns: int: Always zero. Never fails. +*/ + +static int gzip_read_cleanup (void ) +{ +zlib_inflateEnd (&strm); + +free_zlib_memory (); +free_local_buffer (); +return 0 ; +} + +/* gzip_print_debug_stats +* +* Description: Print information to be recorded for debugging purposes into a +* buffer. +* Arguments: buffer: Pointer to a buffer into which the debug info will be +* printed. +* size: Size of the buffer. +* Returns: Number of characters written to the buffer. +*/ + +static int gzip_print_debug_stats (char * buffer,int size) +{ +int pages_in = bytes_in >>PAGE_SHIFT ; +int pages_out = bytes_out >>PAGE_SHIFT ; +int len; + +//Output the compression ratio achieved. + len =suspend_snprintf (buffer, size,"- GZIP compressor enabled.\n" ); +if (pages_in) + len+=suspend_snprintf (buffer+len, size - len, +" Compressed %ld bytes into %ld.\n " +"Image compressed by %d percent.\n" , + bytes_in, bytes_out, (pages_in - pages_out) *100 / pages_in); +return len; +} + +/* compression_memory_needed +* +* Description: Tell the caller how much memory we need to operate during +* suspend/resume. +* Returns: Unsigned long. Maximum number of bytes of memory required for +* operation. +*/ + +static unsigned long gzip_memory_needed (void ) +{ +return PAGE_SIZE +max (zlib_deflate_workspacesize (), +zlib_inflate_workspacesize ()); +} + +static unsigned long gzip_storage_needed (void ) +{ +return 2 *sizeof (unsigned long ); +} + +/* gzip_save_config_info +* +* Description: Save information needed when reloading the image at resume time. +* Arguments: Buffer: Pointer to a buffer of size PAGE_SIZE. +* Returns: Number of bytes used for saving our data. +*/ + +static int gzip_save_config_info (char * buffer) +{ + *((unsigned long *) buffer) = bytes_in; + *((unsigned long *) (buffer +sizeof (unsigned long ))) = bytes_out; + *((int *) (buffer +2 *sizeof (unsigned long ))) = expected_gzip_compression; +return 2 *sizeof (unsigned long ) +sizeof (int ); +} + +/* gzip_load_config_info +* +* Description: Reload information needed for decompressing the image at +* resume time. +* Arguments: Buffer: Pointer to the start of the data. +* Size: Number of bytes that were saved. +*/ + +static void gzip_load_config_info (char * buffer,int size) +{ +if (size ==2 *sizeof (unsigned long ) +sizeof (int )) { + bytes_in = *((unsigned long *) buffer); + bytes_out = *((unsigned long *) (buffer +sizeof (unsigned long ))); + expected_gzip_compression = *((int *) (buffer +2 *sizeof (unsigned long ))); + }else +printk ("Suspend GZIP config info size mismatch: settings ignored.\n" ); +return ; +} + +/* gzip_get_expected_compression +* +* Description: Returns the expected ratio between data passed into this plugin +* and the amount of data output when writing. +* Returns: The value set by the user via our proc entry. +*/ + +static int gzip_get_expected_compression (void ) +{ +return 100 - expected_gzip_compression; +} + +/* +* data for our proc entries. +*/ + +struct suspend_proc_data expected_compression_proc_data = { + .filename ="expected_gzip_compression" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_INTEGER , + .data = { + .integer = { + .variable = &expected_gzip_compression, + .minimum =0 , + .maximum =99 , + } + } +}; + +struct suspend_proc_data disable_compression_proc_data = { + .filename ="disable_gzip_compression" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_INTEGER , + .data = { + .integer = { + .variable = &gzip_compression_ops.disabled, + .minimum =0 , + .maximum =1 , + } + } +}; + +/* +* Ops structure. +*/ + +struct suspend_plugin_ops gzip_compression_ops = { + .type =FILTER_PLUGIN , + .name ="Zlib Page Compressor" , + .memory_needed = gzip_memory_needed, + .print_debug_info = gzip_print_debug_stats, + .save_config_info = gzip_save_config_info, + .load_config_info = gzip_load_config_info, + .storage_needed = gzip_storage_needed, + .ops = { + .filter = { + .write_init = gzip_write_init, + .write_chunk = gzip_write_chunk, + .write_cleanup = gzip_write_cleanup, + .read_init = gzip_read_init, + .read_chunk = gzip_read_chunk, + .read_cleanup = gzip_read_cleanup, + .expected_compression = gzip_get_expected_compression, + } + } +}; + +/* ---- Registration ---- */ + +static __init int gzip_load (void ) +{ +int result; + +if (!(result =suspend_register_plugin (&gzip_compression_ops))) { +printk ("Software Suspend Gzip Compression Driver registered.\n" ); +suspend_register_procfile (&expected_compression_proc_data); +suspend_register_procfile (&disable_compression_proc_data); + } +return result; +} + +#ifdef MODULE +static __exit void gzip_unload(void) +{ +printk ("Software Suspend Gzip Compression Driver unloading.\n" ); +suspend_unregister_procfile (&expected_compression_proc_data); +suspend_unregister_procfile (&disable_compression_proc_data); +suspend_unregister_plugin (&gzip_compression_ops); +} + +module_init (gzip_load); +module_exit (gzip_unload); +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Nigel Cunningham" ); +MODULE_DESCRIPTION ("Gzip Compression support for Suspend2" ); +#else +late_initcall (gzip_load); +#endif
Re: Suspend 2 merge: 47/51: GZIP support.
Hi!
Quoted 2 lines
The original compressor. Slow. I've tried to drop it, but for reasons I simply don't understand, some users still want it.
Okay, IGNORE THOSE @#*$&!)!& USERS!
You need to say no. 500 lines of code, when superior code is available is bad idea. You know gzip is wrong thing. If some user wants it, it is he maintaining the patch. Simple.
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!
Suspend 2 merge: 45/51: Bootsplash support.
In reply to Nigel CunninghamSupport for bootsplash.
I might switch to fbsplash soon. It is better supported.
kernel/power/suspend_bootsplash.c +302 -0
@@ -0,0 +1,302 @@ +/* +* kernel/power/suspend2_bootsplash.c +* +* Copyright (C) 2004 Nigel Cunningham <[email protected]> +* +* This file is released under the GPLv2. +* +* This file implements bootsplash support for suspend2. +*/ +#define SUSPEND_CONSOLE_C + +#define __KERNEL_SYSCALLS__ + +#include <linux/suspend.h> +#include <linux/console.h> +#include <linux/proc_fs.h> +#include <linux/hardirq.h> +#include <asm/hardirq.h> + +#include "plugins.h" +#include "proc.h" +#include "suspend.h" + +static int barwidth =100 , barposn =-1 , newbarposn =0 ; +static int lastloglevel =-1 ; + +/* Your bootsplash progress bar may have a width of (eg) 1024 pixels. That +* doesn't necessarily mean you want the bar updated 1024 times when writing +* the image */ +static int bar_granularity_limit =0 ; + +/* ------------------ Splash screen defines -------------------------- */ + +extern struct display fb_display[MAX_NR_CONSOLES ]; + +/* splash_is_on +* +* Description: Determine whether a VT has a splash screen on. +* Arguments: int consolenr. The VT number of a console to check. +* Returns: Boolean indicating whether the splash screen for +* that console is on right now. +*/ +static int splash_is_on (int consolenr) +{ +struct splash_data *info =get_splash_data (consolenr); + +if (info) +return ((info->splash_state &1 ) ==1 ); +return 0 ; +} + +/* splash_write_proc. +* +* Write to Bootsplash's proc entry. We need this to work when /proc +* hasn't been mounted yet and / can't be mounted. In addition, we +* want it to work despite the fact that bootsplash (under 2.4 at least) +* removes its proc entry when it shouldn't. We therefore use +* our proc.c find_proc_dir_entry routine to get the location of the +* write routine once (boot time & at start of each resume), and keep it. +*/ + +extern struct proc_dir_entry *find_proc_dir_entry (const char *name, +struct proc_dir_entry *parent); + +static void splash_write_proc (const char *buffer,unsigned long count) +{ +static write_proc_t * write_routine; +struct proc_dir_entry * proc_entry; + +if (in_interrupt ()) +return ; + +if (unlikely (!write_routine)) { + proc_entry =find_proc_dir_entry ("splash" , &proc_root); +if (proc_entry) + write_routine = proc_entry->write_proc; + } + +if (write_routine) +write_routine (NULL , buffer, count,NULL ); +} + +/* fb_splash-set_progress +* +* Description: Set the progress bar position for a splash screen. +* Arguments: int consolenr. The VT number of a console to use. +* unsigned long value, unsigned long maximum: +* The proportion (value/maximum) of the bar to fill. +*/ + +static int fb_splash_set_progress (int consolenr,unsigned long value, +unsigned long maximum) +{ +char procstring[15 ]; +int length, bitshift =generic_fls (maximum) -16 ; +static unsigned long lastvalue =0 ; +unsigned long thisvalue; + +BUG_ON (consolenr >=MAX_NR_CONSOLES ); + +if (in_interrupt ()) +return 0 ; + +if (value > maximum) + value = maximum; + +/* Avoid math problems - we can't do 64 bit math here +* (and don't need it - anyone got screen resolution +* of 65536 pixels or more?) */ +if (bitshift >0 ) { + maximum = maximum >> bitshift; + value = value >> bitshift; + } + + thisvalue = value *65534 / maximum; + + length =sprintf (procstring,"show %lu" , thisvalue); + +splash_write_proc (procstring, length); + + lastvalue = thisvalue; + +return 0 ; +} + +/* bootsplash_loglevel_change +* +* Description: Update the display when the user changes the log level. +*/ + +static void bootsplash_loglevel_change (void ) +{ +/* Calculate progress bar width. Note that whether the +* splash screen is on might have changed (this might be +* the first call in a new cycle), so we can't take it +* for granted that the width should be the same as +* last time we came in here */ +if (!splash_is_on (fg_console)) +return ; + +/* proc interface ensures bar_granularity_limit >= 0 */ +if (bar_granularity_limit) + barwidth = bar_granularity_limit; +else + barwidth =100 ; + +/* Only reset the display if we're switching between nice display +* and displaying debugging output */ +if (console_loglevel >1 ) { +if (lastloglevel <2 ) +splash_write_proc ("verbose\n" ,9 ); + }else if (lastloglevel >1 ) +splash_write_proc ("silent\n" ,8 ); + + lastloglevel = console_loglevel; +} + +static void bootsplash_prepare (void ) +{ +if (!splash_is_on (fg_console)) +return ; + +if (console_loglevel <2 ) +splash_write_proc ("silent\n" ,8 ); +else +splash_write_proc ("verbose\n" ,9 ); +} + +/* bootsplash_update_progress +* +* Description: Update the progress bar and (if on) in-bar message. +* Arguments: UL value, maximum: Current progress percentage (value/max). +* const char *fmt, ...: Message to be displayed in the middle +* of the progress bar. +* Note that a NULL message does not mean that any previous +* message is erased! For that, you need message with +* clearbar on. +* Returns: Unsigned long: The next value where status needs to be updated. +* This is to reduce unnecessary calls to update_progress. +* +* Note that for Bootsplash, we ignore the in-bar message +*/ +static unsigned long bootsplash_update_progress ( +unsigned long value,unsigned long maximum, +const char *fmt,va_list args) +{ +unsigned long next_update =0 ; +int bitshift =generic_fls (maximum) -16 ; + +if ((!maximum) || (!barwidth)) +return maximum; + +if (value <0 ) + value =0 ; + +if (value > maximum) + value = maximum; + +/* Try to avoid math problems - we can't do 64 bit math here +* (and shouldn't need it - anyone got screen resolution +* of 65536 pixels or more?) */ +if (bitshift >0 ) { +unsigned long temp_maximum = maximum >> bitshift; +unsigned long temp_value = value >> bitshift; + newbarposn = (int ) (temp_value * barwidth / temp_maximum); + }else + newbarposn = (int ) (value * barwidth / maximum); + +if (newbarposn < barposn) + barposn =0 ; + + next_update = ((newbarposn +1 ) * maximum / barwidth) +1 ; + +if ((splash_is_on (fg_console)) && + (newbarposn != barposn)) { +fb_splash_set_progress (fg_console, value, maximum); + barposn = newbarposn; + } +return next_update; +} + +/* +* User interface specific /proc/suspend entries. +*/ +static struct suspend_plugin_ops bootsplash_ops; + +static struct suspend_proc_data proc_params[] = { + { .filename ="bootsplash_granularity_limit" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_INTEGER , + .data = { + .integer = { + .variable = &bar_granularity_limit, + .minimum =1 , + .maximum =2000 , + } + } + }, + + { .filename ="disable_bootsplash_support" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_INTEGER , + .data = { + .integer = { + .variable = &bootsplash_ops.disabled, + .minimum =0 , + .maximum =1 , + } + } + } +}; + +static struct suspend_plugin_ops bootsplash_ops = { + .type =UI_PLUGIN , + .name ="Bootsplash Support" , + .ops = { + .ui = { + .prepare = bootsplash_prepare, + .log_level_change = bootsplash_loglevel_change, + .update_progress = bootsplash_update_progress, + .post_kernel_restore_redraw = + bootsplash_prepare, + } + } +}; + +/* ---- Registration ---- */ + +static __init int bootsplash_load (void ) +{ +int i, numfiles =sizeof (proc_params) /sizeof (struct suspend_proc_data ); +int result; + +if (!(result =suspend_register_plugin (&bootsplash_ops))) { +printk ("Software Suspend Bootsplash Support loaded.\n" ); +for (i=0 ; i< numfiles; i++) +suspend_register_procfile (&proc_params[i]); + } +return result; +} + +#ifdef MODULE +static __exit void bootsplash_unload(void) +{ +int i, numfiles =sizeof (proc_params) /sizeof (struct suspend_proc_data ); + +printk ("Software Suspend Bootsplash support unloading.\n" ); + +for (i=0 ; i< numfiles; i++) +suspend_unregister_procfile (&proc_params[i]); + +suspend_unregister_plugin (&bootsplash_ops); +} + +module_init (bootsplash_load); +module_exit (bootsplash_unload); +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Nigel Cunningham" ); +MODULE_DESCRIPTION ("Suspend2 Bootsplash support" ); +#else +late_initcall (bootsplash_load); +#endif
Suspend 2 merge: 42/51: Suspend.c
In reply to Nigel CunninghamHere's the heart of the core :> (No, that's not a typo).
- Device suspend/resume calls
- Power down
- Highest level routine
- all_settings proc entry handling
kernel/power/suspend.c +2019 -0
@@ -0,0 +1,2019 @@ +/* +* kernel/power/suspend2.c +* +* Copyright (C) 1998-2001 Gabor Kuti <[email protected]> +* Copyright (C) 1998,2001,2002 Pavel Machek <[email protected]> +* Copyright (C) 2002-2003 Florent Chabaud <[email protected]> +* Copyright (C) 2002-2004 Nigel Cunningham <[email protected]> +* +* This file is released under the GPLv2. +* +* This file is to realize architecture-independent +* machine suspend feature using pretty near only high-level routines +* +* We'd like to thank the following people for their work: +* +* Pavel Machek <[email protected]>: +* Modifications, defectiveness pointing, being with Gabor at the very beginning, +* suspend to swap space, stop all tasks. Port to 2.4.18-ac and 2.5.17. +* +* Steve Doddi <[email protected]>: +* Support the possibility of hardware state restoring. +* +* Raph <[email protected]>: +* Support for preserving states of network devices and virtual console +* (including X and svgatextmode) +* +* Kurt Garloff <[email protected]>: +* Straightened the critical function in order to prevent compilers from +* playing tricks with local variables. +* +* Andreas Mohr <[email protected]> +* +* Alex Badea <[email protected]>: +* Fixed runaway init +* +* Jeff Snyder <[email protected]> +* ACPI patch +* +* Nathan Friess <[email protected]> +* Some patches. +* +* Michael Frank <[email protected]> +* Extensive testing and help with improving stability. +* +* Variable definitions which are needed if PM is enabled but +* SOFTWARE_SUSPEND is disabled are found near the top of process.c. +*/ + +#define SUSPEND_MAIN_C +//#define DEBUG_DEVICE_TREE + +#include <linux/suspend.h> +#include <linux/reboot.h> +#include <linux/module.h> +#include <linux/console.h> +#include <linux/version.h> +#include <linux/device.h> +#include <linux/highmem.h> +#include <asm/uaccess.h> + +#include "suspend.h" +#include "block_io.h" +#include "plugins.h" +#include "proc.h" +#include "pageflags.h" + +#ifdef CONFIG_X86 +#include <asm/i387.h> /* for kernel_fpu_end */ +#endif + +static unsigned long suspend_powerdown_method =5 ;/* S5 = off */ +static int suspend_acpi_state_used =0 ; + +static u32 pm_disk_mode_save; +struct partial_device_tree * suspend_device_tree; +EXPORT_SYMBOL (suspend_device_tree); + +#ifdef CONFIG_SMP +static void ensure_on_processor_zero (void ) +{ +set_cpus_allowed (current,cpumask_of_cpu (0 )); +BUG_ON (smp_processor_id () !=0 ); +} +#else +#define ensure_on_processor_zero () do { } while(0) +#endif + +#ifdef CONFIG_ACPI +extern u32 acpi_leave_sleep_state (u8 sleep_state); +#endif + +#ifdef DEBUG_DEVICE_TREE +#include "../../drivers/base/power/power.h" +#include <linux/device.h> + +void display_device_tree (struct partial_device_tree * tree,char * header) +{ +struct device * dev; + +if (header) +printk (header); +printk (" === Tree %p ===\n\n" , tree); + +printk (" -- Active\n" ); +list_for_each_entry (dev, &tree->dpm_active, power.entry) { +printk (" %p->%p" , dev, dev->parent); +printk (" %s\n" , dev->kobj.k_name ? dev->kobj.k_name :"<null>" ); + } +printk ("\n -- DPM Off\n" ); +list_for_each_entry (dev, &tree->dpm_off, power.entry) { +printk (" %p->%p" , dev, dev->parent); +printk (" %s\n" , dev->kobj.k_name ? dev->kobj.k_name :"<null>" ); + } + +printk ("\n -- DPM Off IRQ\n" ); +list_for_each_entry (dev, &tree->dpm_off_irq, power.entry) { +printk (" %p->%p" , dev, dev->parent); +printk (" %s\n" , dev->kobj.k_name ? dev->kobj.k_name :"<null>" ); + } +printk ("\n--- Done ---\n" ); +} +#else +#define display_device_tree (tree, header) do { } while(0) +#endif + +/* suspend_drivers_resume +* @stage - One of... +*/ + +enum { +SUSPEND_DRIVERS_USED_DEVICES_IRQS_DISABLED , +SUSPEND_DRIVERS_USED_DEVICES_IRQS_ENABLED , +SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_DISABLED , +SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_ENABLED , +SUSPEND_DRIVERS_PRE_POWERDOWN , +}; + +void suspend_drivers_resume (int stage) +{ +switch (stage) { +case SUSPEND_DRIVERS_USED_DEVICES_IRQS_DISABLED : +BUG_ON (!irqs_disabled ()); +if (!TEST_ACTION_STATE (SUSPEND_DISABLE_SYSDEV_SUPPORT )) +sysdev_resume (); +dpm_power_up_tree (suspend_device_tree); +break ; + +case SUSPEND_DRIVERS_USED_DEVICES_IRQS_ENABLED : +BUG_ON (irqs_disabled ()); +display_device_tree (suspend_device_tree, +"suspend_drivers_resume stage 1." ); +device_resume_tree (suspend_device_tree); +display_device_tree (suspend_device_tree, +"Post resume tree call." ); +break ; + +case SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_DISABLED : +BUG_ON (!irqs_disabled ()); +display_device_tree (&default_device_tree, +"suspend_drivers_resume stage 2.\n" ); +dpm_power_up_tree (&default_device_tree); +break ; + +case SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_ENABLED : +BUG_ON (irqs_disabled ()); +device_resume_tree (&default_device_tree); +display_device_tree (&default_device_tree, +"Post power up.\n" ); +#ifdef CONFIG_ACPI +if (suspend_acpi_state_used) +acpi_leave_sleep_state (suspend_acpi_state_used); +#endif +display_device_tree (&default_device_tree, +"suspend_drivers_resume stage 3.\n" ); +device_resume_tree (&default_device_tree); +display_device_tree (&default_device_tree, +"Post resume default device tree.\n" ); +#ifdef CONFIG_ACPI +if (suspend_acpi_state_used && + pm_ops && pm_ops->finish) + pm_ops->finish (suspend_acpi_state_used); +#endif +break ; + } +} + +/* suspend_drivers_suspend +* @stage - one of: +* 1: Power down drivers not used in writing the image +* 2: Quiesce drivers used in writing the image +* (prior to making atomic copy) +* 3: Power down drivers used in writing the image and +* enter the suspend mode if configured to do so. +* +*/ +static int suspend_drivers_suspend (int stage) +{ +int result =0 ; + +switch (stage) { +case SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_DISABLED : +BUG_ON (!irqs_disabled ()); +if (!result) + result =device_power_down_tree ( +PM_SUSPEND_DISK , &default_device_tree); +display_device_tree (&default_device_tree, +"Post suspend power down device tree.\n" ); +break ; + +case SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_ENABLED : +BUG_ON (irqs_disabled ()); +display_device_tree (&default_device_tree, +"suspend_drivers_suspend stage 1.\n" ); + result =device_suspend_tree ( +PM_SUSPEND_DISK , &default_device_tree); +break ; + +case SUSPEND_DRIVERS_USED_DEVICES_IRQS_DISABLED : +BUG_ON (!irqs_disabled ()); + result =device_power_down_tree (PM_SUSPEND_DISK , suspend_device_tree); +if (!TEST_ACTION_STATE (SUSPEND_DISABLE_SYSDEV_SUPPORT )) +sysdev_suspend (PM_SUSPEND_DISK ); +break ; + +case SUSPEND_DRIVERS_USED_DEVICES_IRQS_ENABLED : +BUG_ON (irqs_disabled ()); +display_device_tree (suspend_device_tree, +"suspend_drivers_suspend stage 2.\n" ); + result =device_suspend_tree ( +PM_SUSPEND_DISK , suspend_device_tree); +display_device_tree (suspend_device_tree, +"Post suspend device tree.\n" ); +break ; + +case SUSPEND_DRIVERS_PRE_POWERDOWN :/* Power down system */ +BUG_ON (irqs_disabled ()); +display_device_tree (suspend_device_tree, +"suspend_drivers_suspend stage 3.\n" ); + + result =device_suspend_tree ( +PM_SUSPEND_DISK , suspend_device_tree); +break ; + } +return result; +} + +#ifdef CONFIG_SOFTWARE_SUSPEND_DEBUG +void show_pcp_lists (void ) +{ +int cpu, temperature; +struct zone *zone; + +for_each_zone (zone) { +printk ("%s per-cpu:" , zone->name); + +if (!zone->present_pages) { +printk (" empty\n" ); +continue ; + }else +printk ("\n" ); + +for (cpu =0 ; cpu <NR_CPUS ; ++cpu) { +struct per_cpu_pageset *pageset; + +if (!cpu_possible (cpu)) +continue ; + + pageset = zone->pageset + cpu; + +for (temperature =0 ; temperature <2 ; temperature++) +printk ("cpu %d %s: low %d, high %d, batch %d, count %d.\n" , + cpu, + temperature ?"cold" :"hot" , + pageset->pcp[temperature].low, + pageset->pcp[temperature].high, + pageset->pcp[temperature].batch, + pageset->pcp[temperature].count); + } + } +} +#else +#define show_pcp_lists () do { } while(0) +#endif + +/* -------------------------------------------------------------------------- */ + +static int suspend_version_specific_initialise (void ) +{ +struct class * class; +struct class_device * class_dev; + +suspend_save_avenrun (); + +PRINTFREEMEM ("after draining local pages" ); +suspend_store_free_mem (SUSPEND_FREE_DRAIN_PCP ,0 ); + +if (TEST_DEBUG_STATE (SUSPEND_FREEZER )) +show_pcp_lists (); + +if (pm_ops) { + pm_disk_mode_save = pm_ops->pm_disk_mode; + pm_ops->pm_disk_mode =PM_DISK_PLATFORM ; + } + +BUG_ON (suspend_device_tree); + suspend_device_tree =device_create_tree (); +if (IS_ERR (suspend_device_tree)) { + suspend_device_tree =NULL ; +return -ENOMEM ; + } + +/* Now check for graphics class devices, so we can keep the display on while suspending */ + class =class_find ("graphics" ); +if (class) { +list_for_each_entry (class_dev, &class->children, node) +device_switch_trees (class_dev->dev, suspend_device_tree); +class_put (class); + } +return 0 ; +} + +static void suspend_version_specific_cleanup (void ) +{ +suspend_restore_avenrun (); + +if (pm_ops) pm_ops->pm_disk_mode = pm_disk_mode_save; + +if (suspend_device_tree) { +device_merge_tree (suspend_device_tree, &default_device_tree); +device_destroy_tree (suspend_device_tree); +display_device_tree (&default_device_tree, +" ==== POST DEVICE MERGE TREE ====\n" ); + suspend_device_tree =NULL ; + } +} +/* Variables to be preserved over suspend */ +int pageset1_sizelow =0 , pageset2_sizelow =0 ; + +unsigned long orig_mem_free =0 ; + +extern void do_suspend2_lowlevel (int resume); +extern unsigned long header_storage_for_plugins (void ); +extern int suspend_initialise_plugin_lists (void ); +extern void suspend_relinquish_console (void ); +extern volatile int suspend_io_time[2 ][2 ]; +void empty_suspend_memory_pool (void ); +int read_primary_suspend_image (void ); +extern void display_nosave_pages (void ); +extern int num_writers; + +extern void suspend_console_proc_init (void ); +extern void suspend_console_proc_exit (void ); +extern int suspend2_prepare_console (void ); +extern void suspend2_cleanup_console (void ); + +unsigned long * in_use_map =NULL ; +unsigned long * pageset2_map =NULL ; +unsigned long * checksum_map =NULL ; +#ifdef CONFIG_DEBUG_PAGEALLOC +unsigned long * unmap_map =NULL ; +#endif + +char * debug_info_buffer; + +int image_size_limit =0 ; +int max_async_ios =128 ; + +/* Pagedir.c */ +extern void copy_pageset1 (void ); +extern int allocate_local_pageflags (unsigned long ** pagemap,int setnosave); +extern void free_pagedir (struct pagedir * p); +extern int free_local_pageflags (unsigned long ** pagemap); + +/* Prepare_image.c */ + +extern int prepare_image (void ); + +unsigned long forced_ps1_size =0 , forced_ps2_size =0 ; + +/* proc.c */ +extern int suspend_cleanup_proc (void ); + +extern int suspend2_register_core (struct suspend2_core_ops * ops_pointer); +extern void suspend2_unregister_core (void ); + +#ifdef CONFIG_SOFTWARE_SUSPEND_DEBUG + +int suspend_free_mem_values[MAX_FREEMEM_SLOTS ][2 ]; +/* These should match the enumerated type in suspend.h */ +static char * suspend_free_mem_descns[MAX_FREEMEM_SLOTS ] = { +"Start/End " ,/* 0 */ +"Console Allocn " , +"Drain pcp " , +"InUse map " , +"PS2 map " , +"Checksum map " ,/* 5 */ +"Reload pages " , +"Init plugins " , +"Memory pool " , +"Freezer " , +"Eat Memory " ,/* 10 */ +"Syncing " , +"Grabbed Memory " , +"Range Pages " , +"Extra PD1 pages" , +"Writer storage " ,/* 15 */ +"Header storage " , +"Checksum pages " , +"KStat data " , +"Debug Info " , +"Remove Image " ,/* 20 */ +"I/O " , +"I/O info " , +"Start one " , +}; + +/* store_free_mem +*/ + + +void suspend_store_free_mem (int slot,int side) +{ +static int last_free_mem; +int this_free_mem =real_nr_free_pages () + suspend_amount_grabbed + +suspend_memory_pool_level (0 ); +int i; + +BUG_ON (slot >=MAX_FREEMEM_SLOTS ); + +suspend_message (SUSPEND_MEMORY ,SUSPEND_HIGH ,0 , +"Last free mem was %d. Is now %d. " , + last_free_mem, this_free_mem); + +if (slot ==0 ) { +if (!side) +for (i =1 ; i <MAX_FREEMEM_SLOTS ; i++) { + suspend_free_mem_values[i][0 ] =0 ; + suspend_free_mem_values[i][1 ] =0 ; + } + suspend_free_mem_values[slot][side] = this_free_mem; + }else + suspend_free_mem_values[slot][side] += this_free_mem - last_free_mem; + last_free_mem = this_free_mem; +suspend_message (SUSPEND_MEMORY ,SUSPEND_HIGH ,0 , +"%s value %d now %d.\n" , + suspend_free_mem_descns[slot], + side, + suspend_free_mem_values[slot][side]); +} + +/* +* display_free_mem +*/ +static void display_free_mem (void ) +{ +int i; + + +if (!TEST_DEBUG_STATE (SUSPEND_MEMORY )) +return ; + +suspend_message (SUSPEND_MEMORY ,SUSPEND_HIGH ,0 , +"Start: %7d End: %7d.\n" , + suspend_free_mem_values[0 ][0 ], + suspend_free_mem_values[0 ][1 ]); + +for (i =1 ; i <MAX_FREEMEM_SLOTS ; i++) +if (suspend_free_mem_values[i][0 ] + suspend_free_mem_values[i][1 ]) +suspend_message (SUSPEND_MEMORY ,SUSPEND_HIGH ,0 , +"%s %7d %7d.\n" , + suspend_free_mem_descns[i], + suspend_free_mem_values[i][0 ], + suspend_free_mem_values[i][1 ]); +} +#endif + +/* +* save_image +* Result code (int): Zero on success, non zero on failure. +* Functionality : High level routine which performs the steps necessary +* to prepare and save the image after preparatory steps +* have been taken. +* Key Assumptions : Processes frozen, sufficient memory available, drivers +* suspended. +* Called from : do_suspend2_suspend_2 +*/ +extern struct pageset_sizes_result recalculate_stats (void ); +extern int write_pageset (struct pagedir * pagedir,int whichtowrite); +extern int write_image_header (void ); +extern int read_secondary_pagedir (int overwrittenpagesonly); + +static int save_image (void ) +{ +int temp_result; + +if (RAM_TO_SUSPEND > max_mapnr) { +prepare_status (1 ,1 , +"Couldn't get enough free pages, on %ld pages short" , +RAM_TO_SUSPEND - max_mapnr); + goto abort_saving; + } + +suspend_message (SUSPEND_ANY_SECTION ,SUSPEND_LOW ,1 , +" - Final values: %d and %d.\n" , + pageset1_size, + pageset2_size); + +/* Suspend devices we're not going to use in writing the image */ +if (active_writer && active_writer->dpm_set_devices) + active_writer->dpm_set_devices (); +suspend_drivers_suspend (SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_ENABLED ); +local_irq_disable (); +suspend_drivers_suspend (SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_DISABLED ); +local_irq_enable (); + +check_shift_keys (1 ,"About to write pagedir2." ); + + temp_result =write_pageset (&pagedir2,2 ); + +check_shift_keys (1 ,"About to copy pageset 1." ); + +if (temp_result ==-1 ||TEST_RESULT_STATE (SUSPEND_ABORTED )) + goto abort_saving; + +prepare_status (1 ,0 ,"Doing atomic copy..." ); + +do_suspend2_lowlevel (0 ); + +return 0 ; +abort_saving: +suspend_drivers_resume (SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_ENABLED ); +local_irq_disable (); +suspend_drivers_resume (SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_DISABLED ); +local_irq_enable (); + +return -1 ; +} + +int save_image_part1 (void ) +{ +int temp_result; + +suspend_map_atomic_copy_pages (); + +suspend_checksum_calculate_checksums (); + +BUG_ON (!irqs_disabled ()); + +if (!TEST_ACTION_STATE (SUSPEND_TEST_FILTER_SPEED )) +copy_pageset1 (); + +/* +* ---- FROM HERE ON, NEED TO REREAD PAGESET2 IF ABORTING!!! ----- +* +*/ + +suspend_unmap_atomic_copy_pages (); + +/* +* Other processors have waited for me to make the atomic copy of the +* kernel +*/ + +smp_continue (); + +#ifdef CONFIG_X86 +kernel_fpu_end (); +#endif + +#ifdef CONFIG_PREEMPT +preempt_enable_no_resched (); +#endif + +suspend_drivers_resume (SUSPEND_DRIVERS_USED_DEVICES_IRQS_DISABLED ); + +local_irq_enable (); +suspend_drivers_resume (SUSPEND_DRIVERS_USED_DEVICES_IRQS_ENABLED ); + +update_status (pageset2_size, pageset1_size + pageset2_size,NULL ); + +if (TEST_RESULT_STATE (SUSPEND_ABORTED )) + goto abort_reloading_pagedir_two; + +check_shift_keys (1 ,"About to write pageset1." ); + +/* +* End of critical section. +*/ + +suspend_message (SUSPEND_ANY_SECTION ,SUSPEND_LOW ,1 , +"-- Writing pageset1\n" ); + + temp_result =write_pageset (&pagedir1,1 ); + +if (TEST_ACTION_STATE (SUSPEND_TEST_FILTER_SPEED )) { +/* We didn't overwrite any memory, so no reread needs to be done. */ +return -1 ; + } + +if (temp_result ==-1 ||TEST_RESULT_STATE (SUSPEND_ABORTED )) + goto abort_reloading_pagedir_two; + +check_shift_keys (1 ,"About to write header." ); + +if (TEST_RESULT_STATE (SUSPEND_ABORTED )) + goto abort_reloading_pagedir_two; + + temp_result =write_image_header (); + +if (temp_result || (TEST_RESULT_STATE (SUSPEND_ABORTED ))) + goto abort_reloading_pagedir_two; + +check_shift_keys (1 ,"About to power down or reboot." ); + +return 0 ; + +abort_reloading_pagedir_two: + temp_result =read_secondary_pagedir (1 ); + +/* If that failed, we're sunk. Panic! */ +if (temp_result) +panic ("Attempt to reload pagedir 2 while aborting " +"a suspend failed." ); + +return -1 ; + +} + +static void suspend_power_off (void ) +{ +sys_reboot (LINUX_REBOOT_MAGIC1 ,LINUX_REBOOT_MAGIC2 , +LINUX_REBOOT_CMD_POWER_OFF ,NULL ); + +prepare_status (1 ,0 ,"Probably not capable for powerdown." ); +while (1 ) +cpu_relax (); +/* NOTREACHED */ +} + +static void suspend_enter_acpi_state (u32 state) +{ + suspend_acpi_state_used = state; + +if (pm_ops && pm_ops->prepare) { +if (!pm_ops->prepare (state)) { +if (pm_ops && pm_ops->enter) + pm_ops->enter (state); +else +printk ("Failed to enter state.\n" ); + }else +printk ("Prepare ops failed.\n" ); + }else +printk ("No prepare ops.\n" ); +} + +/* +* suspend_power_down +* Functionality : Powers down or reboots the computer once the image +* has been written to disk. +* Key Assumptions : Able to reboot/power down via code called or that +* the warning emitted if the calls fail will be visible +* to the user (ie printk resumes devices). +* Called From : do_suspend2_suspend_2 +*/ + +extern asmlinkage long sys_reboot (int magic1,int magic2,unsigned int cmd, +void * arg); +extern void apm_power_off (void ); + +void suspend_power_down (void ) +{ +if (TEST_ACTION_STATE (SUSPEND_REBOOT )) { +prepare_status (1 ,0 ,"Ready to reboot." ); +sys_reboot (LINUX_REBOOT_MAGIC1 ,LINUX_REBOOT_MAGIC2 , +LINUX_REBOOT_CMD_RESTART ,NULL ); + } + +suspend_drivers_suspend (SUSPEND_DRIVERS_PRE_POWERDOWN ); + +if (suspend_powerdown_method ==3 ) { +prepare_status (1 ,0 ,"Seeking to suspend-to-ram." ); +suspend_enter_acpi_state (PM_SUSPEND_MEM ); +prepare_status (1 ,0 ,"Entering S3 failed. Using normal powerdown." ); + }else if (suspend_powerdown_method ==4 ) { +prepare_status (1 ,0 ,"Seeking to enter ACPI suspend-to-disk state." ); +suspend_enter_acpi_state (PM_SUSPEND_DISK ); +prepare_status (1 ,0 ,"Entering S4 failed. Using normal powerdown." ); + }else +prepare_status (1 ,0 ,"Powering down." ); + +/* +* FIXME: At resume, we'll still think we used S4 if we tried it. +* Does it matter? +*/ + suspend_acpi_state_used =0 ; +suspend_power_off (); +} + +/* +* do_suspend2_resume_1 +* Functionality : Preparatory steps for copying the original kernel back. +* Called From : do_suspend2_lowlevel +*/ + +static void do_suspend2_resume_1 (void ) +{ +suspend_message (SUSPEND_ANY_SECTION ,SUSPEND_LOW ,1 , + name_suspend"About to copy pageset1 back...\n" ); + +if (active_writer && active_writer->dpm_set_devices) + active_writer->dpm_set_devices (); + +suspend_drivers_suspend (SUSPEND_DRIVERS_USED_DEVICES_IRQS_ENABLED ); +suspend_drivers_suspend (SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_ENABLED ); +local_irq_disable ();/* irqs might have been re-enabled on us */ +suspend_drivers_suspend (SUSPEND_DRIVERS_USED_DEVICES_IRQS_DISABLED ); +local_irq_disable (); +suspend_drivers_suspend (SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_DISABLED ); +local_irq_enable (); + +suspend_map_atomic_copy_pages (); + +/* Get other cpus ready to restore their original contexts */ +smp_suspend (); + +local_irq_disable (); + +#ifdef CONFIG_PREEMPT +preempt_disable (); +#endif + +barrier (); +mb (); + +MDELAY (2000 ); +} + +/* +* do_suspend2_resume_2 +* Functionality : Steps taken after copying back the original kernel at +* resume. +* Key Assumptions : Will be able to read back secondary pagedir (if +* applicable). +* Called From : do_suspend2_lowlevel +*/ + +static void do_suspend2_resume_2 (void ) +{ +set_suspend_state (SUSPEND_NOW_RESUMING ); +set_suspend_state (SUSPEND_PAGESET2_NOT_LOADED ); + +suspend_unmap_atomic_copy_pages (); + +#ifdef CONFIG_PREEMPT +preempt_enable (); +#endif + +local_irq_disable (); +suspend_drivers_resume (SUSPEND_DRIVERS_USED_DEVICES_IRQS_DISABLED ); +local_irq_enable (); + +suspend_drivers_resume (SUSPEND_DRIVERS_USED_DEVICES_IRQS_ENABLED ); + +suspend_post_restore_redraw (); + +check_shift_keys (1 ,"About to reload secondary pagedir." ); + +read_secondary_pagedir (0 ); +clear_suspend_state (SUSPEND_PAGESET2_NOT_LOADED ); + +suspend_checksum_print_differences (); + +prepare_status (0 ,0 ,"Cleaning up..." ); + +clear_suspend_state (SUSPEND_USE_MEMORY_POOL ); + +local_irq_disable (); +suspend_drivers_resume (SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_DISABLED ); +local_irq_enable (); +suspend_drivers_resume (SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_ENABLED ); +} + +/* +* do_suspend2_suspend_1 +* Functionality : Steps taken prior to saving CPU state and the image +* itself. +* Called From : do_suspend2_lowlevel +*/ + +static void do_suspend2_suspend_1 (void ) +{ +/* Save other cpu contexts */ +smp_suspend (); + +suspend_drivers_suspend (SUSPEND_DRIVERS_USED_DEVICES_IRQS_ENABLED ); + +mb (); +barrier (); + +#ifdef CONFIG_PREEMPT +preempt_disable (); +#endif +local_irq_disable (); +suspend_drivers_suspend (SUSPEND_DRIVERS_USED_DEVICES_IRQS_DISABLED ); +} + +/* +* do_suspend2_suspend_2 +* Functionality : Steps taken after saving CPU state to save the +* image and powerdown/reboot or recover on failure. +* Key Assumptions : save_image returns zero on success; otherwise we need to +* clean up and exit. The state on exiting this routine +* should be essentially the same as if we have suspended, +* resumed and reached the end of do_suspend2_resume_2. +* Called From : do_suspend2_lowlevel +*/ +static void do_suspend2_suspend_2 (void ) +{ +if (!save_image_part1 ()) +suspend_power_down (); + +if (!TEST_RESULT_STATE (SUSPEND_ABORT_REQUESTED ) && + !TEST_ACTION_STATE (SUSPEND_TEST_FILTER_SPEED ) && + suspend_powerdown_method !=3 ) + printk(KERN_EMERG name_suspend +"Suspend failed, trying to recover...\n" ); +MDELAY (1000 ); + +local_irq_disable (); +suspend_drivers_resume (SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_DISABLED ); +local_irq_enable (); +suspend_drivers_resume (SUSPEND_DRIVERS_UNUSED_DEVICES_IRQS_ENABLED ); + +barrier (); +mb (); +} + +static inline void lru_check_page (struct page * page) +{ +if (!PageLRU (page)) +printk ("Page %p/%p in inactivelist but not marked LRU.\n" , + page,page_address (page)); +} + +/* get_debug_info +* Functionality: Store debug info in a buffer. +* Called from: suspend_try_suspend. +*/ + +#define SNPRINTF(a...) len += suspend_snprintf(debug_info_buffer + len, \ + PAGE_SIZE - len - 1, ## a) + +static int get_suspend_debug_info (void ) +{ +int len =0 ; +if (!debug_info_buffer) { + debug_info_buffer = (char *)get_zeroed_page (GFP_ATOMIC ); +if (!debug_info_buffer) { +printk ("Error! Unable to allocate buffer for" +"software suspend debug info.\n" ); +return 0 ; + } + } + +SNPRINTF ("Please include the following information in bug reports:\n" ); +SNPRINTF ("- SUSPEND core : %s\n" ,SUSPEND_CORE_VERSION ); +SNPRINTF ("- Kernel Version : %s\n" ,UTS_RELEASE ); +SNPRINTF ("- Compiler vers. : %d.%d\n" , __GNUC__, __GNUC_MINOR__); +#ifdef CONFIG_MODULES +SNPRINTF ("- Modules loaded : " ); + { +#if LINUX_VERSION_CODE <KERNEL_VERSION (2 ,5 ,0 ) +struct module *this_mod; +extern struct module *module_list; + this_mod = module_list; +while (this_mod) { +if (this_mod->name) +SNPRINTF ("%s " , this_mod->name); + this_mod = this_mod->next; + } +#else +extern int print_module_list_to_buffer (char * buffer,int size); + len+=print_module_list_to_buffer (debug_info_buffer + len, +PAGE_SIZE - len -1 ); +#endif + } +SNPRINTF ("\n" ); +#else +SNPRINTF ("- No module support.\n" ); +#endif +SNPRINTF ("- Attempt number : %d\n" , nr_suspends); +if (num_range_pages) +SNPRINTF ("- Pageset sizes : %d (%d low) and %d (%d low).\n" , + pagedir1.lastpageset_size, + pageset1_sizelow, + pagedir2.lastpageset_size, + pageset2_sizelow); +#ifdef CONFIG_SOFTWARE_SUSPEND_DEBUG +SNPRINTF ("- Parameters : %ld %ld %ld %d %d %d %ld\n" , + suspend_result, + suspend_action, + suspend_debug_state, + suspend_default_console_level, + image_size_limit, + max_async_ios, + suspend_powerdown_method); +#else +SNPRINTF ("- Parameters : %ld %ld %d %d %ld\n" , + suspend_result, + suspend_action, + image_size_limit, + max_async_ios, + suspend_powerdown_method); +#endif +if (num_range_pages) +SNPRINTF ("- Calculations : Image size: %lu. " +"Ram to suspend: %ld.\n" , +STORAGE_NEEDED (1 ),RAM_TO_SUSPEND ); +SNPRINTF ("- Limits : %lu pages RAM. Initial boot: %lu.\n" , + max_mapnr, orig_mem_free); +SNPRINTF ("- Overall expected compression percentage: %d.\n" , +100 -expected_compression_ratio ()); + len+=print_plugin_debug_info (debug_info_buffer + len, +PAGE_SIZE - len -1 ); +#ifdef CONFIG_SOFTWARE_SUSPEND_DEBUG +SNPRINTF ("- Debugging compiled in.\n" ); +#endif +#ifdef CONFIG_PREEMPT +SNPRINTF ("- Preemptive kernel.\n" ); +#endif +#ifdef CONFIG_SMP +SNPRINTF ("- SMP kernel.\n" ); +#endif +#ifdef CONFIG_HIGHMEM +SNPRINTF ("- Highmem Support.\n" ); +#endif +if (num_range_pages) +SNPRINTF ("- Max ranges used: %d ranges in %d pages.\n" , + max_ranges_used, num_range_pages); +if (suspend_io_time[0 ][1 ]) { +SNPRINTF ("- I/O speed: Write %d MB/s" , + (MB ((unsigned long ) suspend_io_time[0 ][0 ]) *HZ / + suspend_io_time[0 ][1 ])); +if (suspend_io_time[1 ][1 ]) +SNPRINTF (", Read %d MB/s" , + (MB ((unsigned long ) suspend_io_time[1 ][0 ]) *HZ / + suspend_io_time[1 ][1 ])); +SNPRINTF (".\n" ); + } +else if (num_range_pages) +SNPRINTF ("- Suspend cancelled. No I/O speed stats.\n" ); + +return len; +} + +extern int PageInPagedir (struct pagedir * p,struct page * page); +static unsigned long display_metadata_page; + +static char * state_string[3 ] = {"Source" ,"Destination" ,"Dest/Allocd" }; + +void __display_metadata_state (int pagedir,int state) +{ +int i; + +if (!state) +return ; + +printk ("[ Pagedir %d:" , pagedir); +for (i=0 ; i <3 ; i++) +if (state & (1 << i)) +printk ("%s " , state_string[i]); +printk ("]" ); +} + +void display_metadata_state (struct page * page) +{ +__display_metadata_state (1 ,PageInPagedir (&pagedir1, page)); +__display_metadata_state (2 ,PageInPagedir (&pagedir2, page)); +if (PageNosave (page)) +printk ("[ NoSave ]" ); +if (PageReserved (page)) +printk ("[ Reserved ]" ); +if (PageHighMem (page)) +printk ("[ Highmem ]" ); +} + +void proc_display_metadata_state (void ) +{ +printk ("Page number %lu. Struct page at %p, virt address %p:" , + display_metadata_page, + mem_map + display_metadata_page, +page_address (mem_map + display_metadata_page)); +display_metadata_state (mem_map + display_metadata_page); +printk ("\n" ); +} + +/* +* debuginfo_read_proc +* Functionality : Displays information that may be helpful in debugging +* software suspend. +*/ +int debuginfo_read_proc (char * page,char ** start,off_t off,int count, +int *eof,void *data) +{ +int info_len, copy_len; + +initialise_suspend_plugins (); + info_len =get_suspend_debug_info (); +cleanup_suspend_plugins (); + + copy_len =min (info_len - (int ) off, count); +if (copy_len <0 ) + copy_len =0 ; + +if (copy_len) { +memcpy (page, debug_info_buffer + off, copy_len); + *start = page; + } + +if (copy_len + off == info_len) + *eof =1 ; + +free_pages ((unsigned long ) debug_info_buffer,0 ); + debug_info_buffer =NULL ; +return copy_len; +} + +static int get_suspend_debug_info (void ); + +static int allocate_bitmaps (void ) +{ +suspend_message (SUSPEND_MEMORY ,SUSPEND_VERBOSE ,1 , +"Allocating in_use_map\n" ); +if (allocate_local_pageflags (&in_use_map,1 )) +return 1 ; + +suspend_store_free_mem (SUSPEND_FREE_IN_USE_MAP ,0 ); +PRINTFREEMEM ("after allocating in_use_map" ); + +if (allocate_local_pageflags (&pageset2_map,1 )) +return 1 ; + +suspend_store_free_mem (SUSPEND_FREE_PS2_MAP ,0 ); +PRINTFREEMEM ("after allocating pageset2 map" ); + +#ifdef CONFIG_DEBUG_PAGEALLOC +if (allocate_local_pageflags (&unmap_map,1 )) +return 1 ; + +suspend_store_free_mem (SUSPEND_FREE_UNMAP_MAP ,0 ); +PRINTFREEMEM ("after allocating unmap map" ); +#endif + +suspend_store_free_mem (4 ,0 ); + +return 0 ; +} + +static void free_metadata (void ) +{ +put_rangepages_list (); + +free_ranges (); +suspend_store_free_mem (SUSPEND_FREE_RANGE_PAGES ,1 ); +PRINTFREEMEM ("after freeing ranges" ); + +free_local_pageflags (&pageset2_map); +PRINTFREEMEM ("after freeing pageset2 map" ); +suspend_store_free_mem (SUSPEND_FREE_PS2_MAP ,1 ); + +free_local_pageflags (&in_use_map); +PRINTFREEMEM ("after freeing inuse map" ); +suspend_store_free_mem (SUSPEND_FREE_IN_USE_MAP ,1 ); +} + +/* +* software_suspend_pending +* Functionality : First level of code for software suspend invocations. +* Stores and restores load averages (to avoid a spike), +* allocates bitmaps, freezes processes and eats memory +* as required before suspending drivers and invoking +* the 'low level' code to save the state to disk. +* By the time we return from do_suspend2_lowlevel, we +* have either failed to save the image or successfully +* suspended and reloaded the image. The difference can +* be discerned by checking SUSPEND_ABORTED. +* Called From : +*/ + +extern void free_pageset_size_bloat (void ); + +void do_activate (void ) +{ +int i; + +/* Suspend always runs on processor 0 */ +ensure_on_processor_zero (); + +display_nosave_pages (); + +#ifdef CONFIG_SOFTWARE_SUSPEND_KEEP_IMAGE +if (TEST_RESULT_STATE (SUSPEND_KEPT_IMAGE )) { +if (TEST_ACTION_STATE (SUSPEND_KEEP_IMAGE )) { +printk ("Image already stored:" +" powering down immediately." ); +suspend_power_down (); +return ;/* It might now, but just in case we're using S3*/ + }else { +printk ("Invalidating previous image.\n" ); + active_writer->ops.writer.invalidate_image (); + } + } +#endif + +printk (name_suspend"Initiating a software suspend cycle.\n" ); +set_suspend_state (SUSPEND_RUNNING ); + + max_ranges_used =0 ; + nr_suspends++; +clear_suspend_state (SUSPEND_NOW_RESUMING ); + + suspend_io_time[0 ][0 ] = suspend_io_time[0 ][1 ] = suspend_io_time[1 ][0 ] = + suspend_io_time[1 ][1 ] =0 ; + +PRINTFREEMEM ("at start of do_activate" ); +suspend_store_free_mem (SUSPEND_FREE_BASE ,0 ); + +suspend2_prepare_console (); + +free_metadata ();/* We might have kept it */ + +if (suspend_version_specific_initialise ()) + goto out; + +if (allocate_bitmaps ()) + goto out; + +PRINTFREEMEM ("after allocating bitmaps" ); + +display_nosave_pages (); + +set_chain_names (&pagedir1); +set_chain_names (&pagedir2); + +if (initialise_suspend_plugins ()) + goto out; + +PRINTFREEMEM ("after initialising plugins" ); +suspend_store_free_mem (SUSPEND_FREE_INIT_PLUGINS ,0 ); + +/* Free up memory if necessary */ +suspend_message (SUSPEND_ANY_SECTION ,SUSPEND_VERBOSE ,1 , +"Preparing image.\n" ); +if (prepare_image () ||TEST_RESULT_STATE (SUSPEND_ABORTED )) + goto out; + +PRINTFREEMEM ("after preparing image" ); + +if (TEST_ACTION_STATE (SUSPEND_FREEZER_TEST )) + goto out; + +display_nosave_pages (); + +if (!TEST_RESULT_STATE (SUSPEND_ABORTED )) { +prepare_status (1 ,0 ,"Starting to save the image.." ); +save_image (); + } + +out: +free_pageset_size_bloat (); + +PRINTFREEMEM ("at 'out'" ); + + i =get_suspend_debug_info (); + +suspend_store_free_mem (SUSPEND_FREE_DEBUG_INFO ,0 ); + +clear_suspend_state (SUSPEND_USE_MEMORY_POOL ); + +free_pagedir (&pagedir2); +PRINTFREEMEM ("after freeing pagedir 1" ); +free_pagedir (&pagedir1); +PRINTFREEMEM ("after freeing pagedir 2" ); + +#ifdef CONFIG_SOFTWARE_SUSPEND_KEEP_IMAGE +if (TEST_ACTION_STATE (SUSPEND_KEEP_IMAGE ) && + !TEST_ACTION_STATE (SUSPEND_ABORTED )) { +suspend_message (SUSPEND_ANY_SECTION ,SUSPEND_LOW ,1 , + name_suspend"Not invalidating the image due " +"to Keep Image being enabled.\n" ); +SET_RESULT_STATE (SUSPEND_KEPT_IMAGE ); + } else +#endif + active_writer->ops.writer.invalidate_image (); + +empty_suspend_memory_pool (); +PRINTFREEMEM ("after freeing memory pool" ); +suspend_store_free_mem (SUSPEND_FREE_MEM_POOL ,1 ); + +if (!TEST_ACTION_STATE (SUSPEND_KEEP_METADATA )) +free_metadata (); + +#ifdef CONFIG_DEBUG_PAGE_ALLOC +free_local_pageflags (&unmap_map); +PRINTFREEMEM ("after freeing unmap map" ); +suspend_store_free_mem (SUSPEND_UNMAP_MAP ,1 ); +#endif + +if (debug_info_buffer) { +/* Printk can only handle 1023 bytes, including +* its level mangling. */ +for (i =0 ; i <3 ; i++) +printk ("%s" , debug_info_buffer + (1023 * i)); +free_pages ((unsigned long ) debug_info_buffer,0 ); + debug_info_buffer =NULL ; + } + +PRINTFREEMEM ("after freeing debug info buffer" ); +suspend_store_free_mem (SUSPEND_FREE_DEBUG_INFO ,1 ); + +cleanup_suspend_plugins (); + +PRINTFREEMEM ("after cleaning up suspend plugins" ); +suspend_store_free_mem (SUSPEND_FREE_INIT_PLUGINS ,1 ); + +suspend_version_specific_cleanup (); + +display_nosave_pages (); + +thaw_processes (FREEZER_ALL_THREADS ); + +PRINTFREEMEM ("after thawing processes" ); +suspend_store_free_mem (SUSPEND_FREE_FREEZER ,1 ); + +suspend_store_free_mem (SUSPEND_FREE_BASE ,1 ); +#ifdef CONFIG_SOFTWARE_SUSPEND_DEBUG +display_free_mem (); +#endif + +clear_suspend_state (SUSPEND_RUNNING ); +PRINTFREEMEM ("at end of do_activate" ); +#ifdef CONFIG_PREEMPT +#endif +suspend2_cleanup_console (); + +} + +int attempt_to_parse_resume_device (void ) +{ +struct list_head *writer; +struct suspend_plugin_ops * this_writer; +int result =0 ; +mm_segment_t oldfs; + + oldfs =get_fs ();set_fs (KERNEL_DS ); + + active_writer =NULL ; +clear_suspend_state (SUSPEND_RESUME_DEVICE_OK ); +set_suspend_state (SUSPEND_DISABLED ); + +if (!num_writers) { +printk (name_suspend"No writers have been registered.\n" ); + goto out; + } + +if (!resume2_file[0 ]) { + result = -EINVAL ; + goto out; + } + +list_for_each (writer, &suspend_writers) { + this_writer = list_entry(writer, struct suspend_plugin_ops, + ops.writer.writer_list); + +/* +* Not sure why you'd want to disable a writer, but +* we should honour the flag if we're providing it +*/ +if (this_writer->disabled) { +printk (name_suspend +"Writer '%s' is disabled. Ignoring it.\n" , + this_writer->name); +continue ; + } + + result = this_writer->ops.writer.parse_image_location ( + resume2_file, (num_writers ==1 )); + +switch (result) { +case -EINVAL : +/* +* For this writer, but not a valid +* configuration +*/ + +printk (name_suspend +"Not able to successfully parse this " +"resume device. Suspending disabled.\n" ); + goto out; + +case 0 : +/* +* For this writer and valid. +*/ + + active_writer = this_writer; + +/* We may not have any filters compiled in */ + +set_suspend_state (SUSPEND_RESUME_DEVICE_OK ); +clear_suspend_state (SUSPEND_DISABLED ); +printk (name_suspend"Suspending enabled.\n" ); + goto out; + +case 1 : +/* +* Not for this writer. Try the next one. +*/ + +break ; + } + } +printk (name_suspend"No matching writer found. Suspending disabled.\n" ); + result = -EINVAL ; +out: +clear_suspend_state (SUSPEND_RUNNING ); +set_fs (oldfs); +return result; +} + +/* +* +*/ + +static void __suspend2_verify_checksums (void ) +{ +if (checksum_plugin) + checksum_plugin->ops.checksum.check_checksums (); +} + +#define ALL_SETTINGS_VERSION 2 + +/* +* suspend_write_compat_proc. +* +* This entry allows all of the settings to be set at once. +* It was originally for compatibility with pre- /proc/suspend +* versions, but has been retained because it makes saving and +* restoring the configuration simpler. +*/ +static int suspend_write_compat_proc (struct file *file,const char * buffer, +unsigned long count,void * data) +{ +char * buf1 = (char *)get_zeroed_page (GFP_ATOMIC ), *curbuf, *lastbuf; +char * buf2 = (char *)get_zeroed_page (GFP_ATOMIC ); +int i, file_offset =0 , used_size =0 , reparse_resume_device =0 ; +unsigned long nextval; +struct suspend_plugin_ops * plugin; +struct plugin_header * plugin_header =NULL ; + +if ((!buf1) || (!buf2)) +return -ENOMEM ; + +while (file_offset < count) { +int length = count - file_offset; +if (length > (PAGE_SIZE - used_size)) + length =PAGE_SIZE - used_size; + +if (copy_from_user (buf1 + used_size, buffer + file_offset, length)) +return -EFAULT ; + + curbuf = buf1; + +if (!file_offset) { +/* Integers first */ +for (i =0 ; i <8 ; i++) { +if (!*curbuf) +break ; + lastbuf = curbuf; + nextval =simple_strtoul (curbuf, &curbuf,0 ); +if (curbuf == lastbuf) +break ; +switch (i) { +case 0 : +if (nextval !=ALL_SETTINGS_VERSION ) { +printk ("Error loading saved settings. This data is for version %ld, but kernel module uses format %d.\n" , + nextval,ALL_SETTINGS_VERSION ); + goto out; + } +case 1 : + suspend_result = nextval; +break ; +case 2 : + suspend_action = nextval; +break ; +case 3 : +#ifdef CONFIG_SOFTWARE_SUSPEND_DEBUG + suspend_debug_state = nextval; +#endif +break ; +case 4 : + suspend_default_console_level = nextval; +#ifndef CONFIG_SOFTWARE_SUSPEND_DEBUG +if (suspend_default_console_level >1 ) + suspend_default_console_level =1 ; +#endif +break ; +case 5 : + image_size_limit = nextval; +break ; +case 6 : + max_async_ios = nextval; +if (max_async_ios >MAX_READAHEAD ) + max_async_ios =MAX_READAHEAD ; +if (max_async_ios <1 ) + max_async_ios =1 ; +break ; +case 7 : +#ifdef CONFIG_ACPI + suspend_powerdown_method = nextval; +if (suspend_powerdown_method <3 ) + suspend_powerdown_method =3 ; + if (suspend_powerdown_method > 5) +#endif + suspend_powerdown_method =5 ; +break ; + } + + curbuf++; +while (*curbuf ==' ' ) + curbuf++; + } + +if (count <= (curbuf - buf1)) + goto out; +else { +list_for_each_entry (plugin, &suspend_plugins, plugin_list) + plugin->disabled =1 ; + } + } + +if (((unsigned long ) curbuf & ~PAGE_MASK ) +sizeof (plugin_header) >PAGE_SIZE ) + goto shift_buffer; + +/* Plugins */ + plugin_header = (struct plugin_header *) curbuf; + +if (((unsigned long ) curbuf & ~PAGE_MASK ) +sizeof (plugin_header) + plugin_header->data_length >PAGE_SIZE ) + goto shift_buffer; + +if (plugin_header->magic !=0xADEDC0DE ) { +printk ("Bad plugin data magic.\n" ); +break ; + } + + plugin =find_plugin_given_name (plugin_header->name); + +if (plugin) {/* May validly have config saved for a plugin not now loaded */ +if ((plugin->type ==WRITER_PLUGIN ) && + ((!active_writer && plugin->disabled && !plugin_header->disabled) || + (active_writer == plugin && plugin_header->disabled))) + reparse_resume_device =1 ; + plugin->disabled = plugin_header->disabled; +if (plugin_header->data_length) + plugin->load_config_info (curbuf +sizeof (struct plugin_header ), + plugin_header->data_length); + }else +printk ("Data for plugin %s not used because not currently loaded.\n" , plugin_header->name); + + curbuf +=sizeof (struct plugin_header ) + plugin_header->data_length; + +shift_buffer: +if (!(curbuf - buf1)) +break ; + + file_offset += curbuf - buf1; + + used_size =PAGE_SIZE + buf1 - curbuf; +memcpy (buf2, curbuf, used_size); +memcpy (buf1, buf2, used_size); + } +out: +free_pages ((unsigned long ) buf1,0 ); +free_pages ((unsigned long ) buf2,0 ); + +if (reparse_resume_device) { +printk ("Active writer disabled or no active writer and one or more just enabled. Reparsing resume device.\n" ); +attempt_to_parse_resume_device (); + } + +return count; +} + +/* +* suspend_read_compat_proc. +* +* Like it's _write_ sibling, this entry allows all of the settings +* to be read at once. +* It too was originally for compatibility with pre- /proc/suspend +* versions, but has been retained because it makes saving and +* restoring the configuration simpler. +*/ +static int suspend_read_compat_proc (char * page,char ** start,off_t off,int count, +int *eof,void *data) +{ +struct suspend_plugin_ops * this_plugin; +char * buffer = (char *)get_zeroed_page (GFP_ATOMIC ); +int index =1 , file_pos =0 , page_offset =0 , len; +int copy_len =0 ; +struct plugin_header plugin_header; + +if (!buffer) { +printk ("Failed to allocate a buffer for getting " +"plugin configuration info.\n" ); +return -ENOMEM ; + } + + plugin_header.magic =0xADEDC0DE ; + + len =sprintf (buffer,"%d %ld %ld %ld %d %d %d %ld\n" , +ALL_SETTINGS_VERSION , + suspend_result, + suspend_action, + suspend_debug_state, + suspend_default_console_level, + image_size_limit, + max_async_ios, + suspend_powerdown_method); + +if (len >= off) { + copy_len = (len < off + count) ? len - off : count - off; +memcpy (page, buffer + off, copy_len); + page_offset+= copy_len; + } + + file_pos += len; + +/* +* We have to know which data goes with which plugin, so we at +* least write a length of zero for a plugin. Note that we are +* also assuming every plugin's config data takes <= PAGE_SIZE. +*/ + +/* For each plugin (in registration order) */ +list_for_each_entry (this_plugin, &suspend_plugins, plugin_list) { + +/* Get the data from the plugin */ +if (this_plugin->save_config_info) { + plugin_header.data_length = this_plugin->save_config_info (buffer); + }else + plugin_header.data_length =0 ; + +if (file_pos > (off + count)) { + file_pos +=sizeof (struct plugin_header ) + plugin_header.data_length; +continue ; + } + + len =0 ; +if ((file_pos +sizeof (struct plugin_header ) >= off) && + (file_pos < (off + count))) { + +/* Save the details of the plugin */ +memcpy (plugin_header.name, this_plugin->name, +SUSPEND_MAX_PLUGIN_NAME_LENGTH ); + plugin_header.disabled = this_plugin->disabled; + plugin_header.type = this_plugin->type; + plugin_header.index = index++; + + copy_len =sizeof (struct plugin_header ); + +if (copy_len + page_offset > count) + copy_len = count - page_offset; + +memcpy (page + page_offset, + ((char *) &plugin_header) + off + page_offset - file_pos, + copy_len); + + page_offset += copy_len; + } + + file_pos +=sizeof (struct plugin_header ); + +if (plugin_header.data_length && (file_pos >= off) && (file_pos < (off + count))) { + copy_len = plugin_header.data_length; + +if (copy_len + page_offset > count + off) + copy_len = count - page_offset; + +memcpy (page + page_offset, + buffer, + copy_len); + + page_offset += copy_len; + + } + + file_pos += plugin_header.data_length; + + } +free_pages ((unsigned long ) buffer,0 ); +if (page_offset < count) + *eof =1 ; +return page_offset; +} + +extern int initialise_suspend_plugins (void ); +extern void cleanup_suspend_plugins (void ); +static char suspend_core_version[] =SUSPEND_CORE_VERSION ; + +static int resume2_write_proc (void ) +{ +mm_segment_t oldfs; + + oldfs =get_fs ();set_fs (KERNEL_DS ); +initialise_suspend_plugins (); +attempt_to_parse_resume_device (); +cleanup_suspend_plugins (); +set_fs (oldfs); +return 0 ; +} + +/* +* Core proc entries that aren't built in. +* +* This array contains entries that are automatically registered at +* boot. Plugins and the console code register their own entries separately. +*/ + +static struct suspend_proc_data proc_params[] = { + { .filename ="all_settings" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_CUSTOM , + .data = { + .special = { + .read_proc = suspend_read_compat_proc, + .write_proc = suspend_write_compat_proc, + } + } + }, + + { .filename ="debug_info" , + .permissions =PROC_READONLY , + .type =SUSPEND_PROC_DATA_CUSTOM , + .data = { + .special = { + .read_proc = debuginfo_read_proc, + } + } + }, + + { .filename ="disable_sysdev_suspend" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_BIT , + .data = { + .bit = { + .bit_vector = &suspend_action, + .bit =SUSPEND_DISABLE_SYSDEV_SUPPORT , + } + } + }, + + { .filename ="freeze_timers" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_BIT , + .data = { + .bit = { + .bit_vector = &suspend_action, + .bit =SUSPEND_FREEZE_TIMERS , + } + } + }, + + { .filename ="image_size_limit" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_INTEGER , + .data = { + .integer = { + .variable = &image_size_limit, + .minimum =-2 , + .maximum =32767 , + } + } + }, + + { .filename ="last_result" , + .permissions =PROC_READONLY , + .type =SUSPEND_PROC_DATA_UL , + .data = { + .ul = { + .variable = &suspend_result, + } + } + }, + + { .filename ="reboot" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_BIT , + .data = { + .bit = { + .bit_vector = &suspend_action, + .bit =SUSPEND_REBOOT , + } + } + }, + + { .filename ="resume2" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_STRING , + .data = { + .string = { + .variable = resume2_file, + .max_length =255 , + } + }, + .write_proc = resume2_write_proc, + }, + + + { .filename ="version" , + .permissions =PROC_READONLY , + .type =SUSPEND_PROC_DATA_STRING , + .data = { + .string = { + .variable = suspend_core_version, + } + } + }, + +#ifdef CONFIG_SOFTWARE_SUSPEND_DEBUG + { .filename ="freezer_test" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_BIT , + .data = { + .bit = { + .bit_vector = &suspend_action, + .bit =SUSPEND_FREEZER_TEST , + } + } + }, + + { .filename ="keep_metadata" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_BIT , + .data = { + .bit = { + .bit_vector = &suspend_action, + .bit =SUSPEND_KEEP_METADATA , + } + } + }, + + { .filename ="test_filter_speed" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_BIT , + .data = { + .bit = { + .bit_vector = &suspend_action, + .bit =SUSPEND_TEST_FILTER_SPEED , + } + } + }, + + { .filename ="slow" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_BIT , + .data = { + .bit = { + .bit_vector = &suspend_action, + .bit =SUSPEND_SLOW , + } + } + }, + + { .filename ="display_metadata_page" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_UL , + .data = { + .ul = { + .variable = &display_metadata_page, + } + } + }, +#endif + + { .filename ="forced_pageset1_size" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_UL , + .data = { + .ul = { + .variable = &forced_ps1_size, + } + } + }, + + { .filename ="forced_pageset2_size" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_UL , + .data = { + .ul = { + .variable = &forced_ps2_size, + } + } + }, + +#if defined(CONFIG_ACPI) + { .filename ="powerdown_method" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_UL , + .data = { + .ul = { + .variable = &suspend_powerdown_method, + .minimum =3 , + .maximum =5 , + } + } + }, +#endif + +#ifdef CONFIG_SOFTWARE_SUSPEND_KEEP_IMAGE + { .filename ="keep_image" , + .permissions =PROC_RW , + .type =SUSPEND_PROC_DATA_BIT , + .data = { + .bit = { + .bit_vector = &suspend_action, + .bit =SUSPEND_KEEP_IMAGE , + } + } + }, +#endif +}; + +extern int debuginfo_read_proc (char * page,char ** start,off_t off,int count, +int *eof,void *data); + +/* +* Called from init kernel_thread. +* We check if we have an image and if so we try to resume. +* We also start ksuspendd if configuration looks right. +*/ + +extern int freeze_processes (int no_progress); + +static int do_resume (void ) +{ +int ret =0 ; +int read_image_result =0 ; + +/* Suspend always runs on processor 0 */ +ensure_on_processor_zero (); + +if (sizeof (swp_entry_t) !=sizeof (long )) { + printk(KERN_WARNING name_suspend +"The size of swp_entry_t != size of long. " + "Please report this!\n"); +return ret; + } + +set_suspend_state (SUSPEND_RUNNING ); + +if (!resume2_file[0 ]) + printk(KERN_WARNING name_suspend +"You need to use a resume2= command line parameter to " +"tell Software Suspend 2 where to look for an image.\n" ); + +if (!(test_suspend_state (SUSPEND_RESUME_DEVICE_OK ))) +attempt_to_parse_resume_device (); + +if (!(test_suspend_state (SUSPEND_RESUME_DEVICE_OK ))) { +/* +* Without a usable storage device we can do nothing - +* even if noresume is given +*/ + +if (!num_writers) + printk(KERN_ALERT name_suspend +"No writers have been registered.\n" ); +else + printk(KERN_ALERT name_suspend +"Missing or invalid storage location " +"(resume2= parameter). Please correct and " +"rerun lilo (or equivalent) before " +"suspending.\n" ); +clear_suspend_state (SUSPEND_RUNNING ); +return ret; + } + +/* We enable the possibility of machine suspend */ + orig_mem_free =real_nr_free_pages (); + + suspend_task = current->pid; + + read_image_result =read_primary_suspend_image ();/* non fatal error ignored */ + +if (test_suspend_state (SUSPEND_NORESUME_SPECIFIED )) + printk(KERN_WARNING name_suspend "Resuming disabled as requested.\n"); + +if (read_image_result) { + suspend_task =0 ; +clear_suspend_state (SUSPEND_RUNNING ); +return ret; + } + +/* +* Ensure our suspend device tree is configured (2.6) as +* at suspend time +*/ + +suspend_version_specific_initialise (); + +freeze_processes (1 ); + +prepare_status (0 ,0 , +"Copying original kernel back (no status - sensitive!)..." ); + +do_suspend2_lowlevel (1 ); +BUG (); + +return ret; +} + +extern int suspend_plugin_keypress (unsigned int keycode); +extern void request_abort_suspend (void ); +extern void schedule_suspend_message (int message_number); + +int suspend_keypress (unsigned int keycode) +{ +/* These keys work even if no output is enabled. +* (To get this far, we must be suspending or resuming). +*/ +switch (keycode) { +case 27 : +/* Abort suspend */ +if (TEST_ACTION_STATE (SUSPEND_CAN_CANCEL )) +request_abort_suspend (); +break ; +case 114 : +/* Otherwise, if R pressed, toggle rebooting */ + suspend_action ^= (1 <<SUSPEND_REBOOT ); +schedule_suspend_message (2 ); +break ; +default : +return suspend_plugin_keypress (keycode); + } +return 1 ; +} + +extern void suspend_early_boot_message_plugins (void ); +extern void cleanup_finished_suspend_io (void ); + +struct suspend2_core_ops core_ops = { + .do_suspend = do_activate, + .do_resume = do_resume, + .resume1 = do_suspend2_resume_1, + .resume2 = do_suspend2_resume_2, + .suspend1 = do_suspend2_suspend_1, + .suspend2 = do_suspend2_suspend_2, + .free_pool_pages = free_suspend_pool_pages, + .get_pool_pages = get_suspend_pool_pages, + .get_grabbed_pages = get_grabbed_pages, + .cleanup_finished_io = cleanup_finished_suspend_io, + .suspend_message = __suspend_message, + .update_status = update_status, + .prepare_status = prepare_status, + .schedule_message = schedule_suspend_message, + .early_boot_plugins = suspend_early_boot_message_plugins, + .keypress = suspend_keypress, + .verify_checksums = __suspend2_verify_checksums, +}; + +static struct proc_dir_entry *compat_parent; +extern void suspend_memory_pool_init (void ); + +static __init int core_load (void ) +{ +int i, numfiles =sizeof (proc_params) /sizeof (struct suspend_proc_data ); + +if (suspend2_register_core (&core_ops)) +return -EBUSY ; + +printk ("Software Suspend Core.\n" ); +for (i=0 ; i< numfiles; i++) +suspend_register_procfile (&proc_params[i]); + +suspend_console_proc_init (); + +suspend_memory_pool_init (); + +#if LINUX_VERSION_CODE <KERNEL_VERSION (2 ,5 ,0 ) +return 0 ; +#else +return (!!compat_parent); +#endif +} + +#ifdef MODULE +static __exit void core_unload(void) +{ +int i, numfiles =sizeof (proc_params) /sizeof (struct suspend_proc_data ); + +printk ("Software Suspend Core unloading.\n" ); +suspend_console_proc_exit (); + +for (i=0 ; i< numfiles; i++) +suspend_unregister_procfile (&proc_params[i]); + +suspend2_unregister_core (); +} + +module_init (core_load); +module_exit (core_unload); +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Nigel Cunningham" ); +MODULE_DESCRIPTION ("Suspend2 core" ); +#else +late_initcall (core_load); +#endif +EXPORT_SYMBOL (checksum_map); +EXPORT_SYMBOL (attempt_to_parse_resume_device);
Re: Suspend 2 merge: 42/51: Suspend.c
Quoted 6 lines · Nigel Cunningham
Here's the heart of the core :> (No, that's not a typo).
- Device suspend/resume calls
- Power down
- Highest level routine
-all_settingsproc entry handling
This isn't the only patch (the utility.c file is another one) which introduces functions/helpers which are subsystem specific (like ACPI) but somehow land up in the same file with a suspend_ prefix. I understand that it'll be more work but can you get them integrated with the subsystem in question?
Thanks,
Zwane
Re: Suspend 2 merge: 42/51: Suspend.c
Hi.
Quoted 9 lines · Zwane Mwaikambo
Quoted 6 lines · Nigel Cunningham
Here's the heart of the core :> (No, that's not a typo).
- Device suspend/resume calls
- Power down
- Highest level routine
-all_settingsproc entry handling
Quoted 5 lines
This isn't the only patch (the
utility.cfile is another one) which introduces functions/helpers which are subsystem specific (like ACPI) but somehow land up in the same file with asuspend_prefix. I understand that it'll be more work but can you get them integrated with the subsystem in question?
Okee doke. I've thought about separating some of those debugging specific functions out into their own file too.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 42/51: Suspend.c
In reply to Nigel CunninghamHi!
Quoted 6 lines
Here's the heart of the core :> (No, that's not a typo).
- Device suspend/resume calls
- Power down
- Highest level routine
-all_settingsproc entry handling
Can we get rid of all the debugging? It makes it hard to see real code between all the debugging stuff.
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!
Suspend 2 merge: 37/51: Memory pool support.
In reply to Nigel CunninghamThis is the memory pool support. It handles all pages freed and allocated between the preparation of the image and the completion of resuming, except prior to restoring the original kernel at resume time. It is designed for speed and to match the fact that suspend2 just about exclusively uses order 0 allocations. ("Just about" is why a couple of order one and two allocations are also available).
kernel/power/memory_pool.c +378 -0
@@ -0,0 +1,378 @@ +/* +* kernel/power/memory_pool.c +* +* Copyright (C) 2003,2004 Nigel Cunningham <[email protected]> +* +* This file is released under the GPLv2. +* +* It contains routines for managing the memory pool during software suspend +* operation. +* +* The memory pool is a pool of pages from which page allocations +* are satisfied while we are suspending, and into which freed pages are +* released. In this way, we can keep the image size static and consistent +* while still using normal I/O routines to save the image and while saving +* the image in two parts. +* +* During suspend, almost all of the page allocations are order zero. Provision +* is made for one order one and one order two allocation. This provision is +* utilised by the swapwriter for allocating memory which is used for structures +* containing header page. (It could be made to use order zero allocations; this +* just hasn't been done yet). +*/ + +#define SUSPEND_MEMORY_POOL_C + +#include <linux/suspend.h> +#include <linux/module.h> +#include <linux/highmem.h> + +#include "suspend.h" +#include "plugins.h" +#include "pageflags.h" + +/* We keep high memory pages that are freed, but don't use them */ +struct memory_pool { +struct list_head contents[MAX_ORDER ]; +int level[MAX_ORDER ]; +}; + +static struct memory_pool normal_pool, highmem_pool; + +static int suspend_pool_level_limit[MAX_ORDER ]; +static spinlock_t suspend_memory_pool_lock =SPIN_LOCK_UNLOCKED ; + +static int min_pool_level =0 ; + +#ifdef CONFIG_SOFTWARE_SUSPEND_DEBUG +/* display_memory_pool_pages() +* +* Description: Display the current contents of the memory pool. +*/ +static void __display_memory_pool_pages (struct memory_pool * pool) +{ +int order; + +for (order =0 ; order <MAX_ORDER ; order++) { +struct page * page; +int index =0 ; +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_VERBOSE ,1 , +"- Order %d:\n" , order); +list_for_each_entry (page, &pool->contents[order], lru) { +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_VERBOSE ,1 , +"[%p] " , page); + index++; +if (!(index%8 )) +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_VERBOSE ,1 , +"\n" ); + } + +if (pool->level[order]) +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_VERBOSE ,1 , +"(%d entries)\n" , pool->level[order]); +else +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_VERBOSE ,1 , +"(empty)\n" ); + } +} + +void display_memory_pool_pages (void ) +{ +if (!TEST_DEBUG_STATE (SUSPEND_MEM_POOL )) +return ; + +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_VERBOSE ,1 ,"Memory pool:\n" ); +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_VERBOSE ,1 ,"Normal pages:\n" ); +__display_memory_pool_pages (&normal_pool); +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_VERBOSE ,1 ,"High pages:\n" ); +__display_memory_pool_pages (&highmem_pool); +} +#else +#define display_memory_pool_pages () do { } while(0) +#endif + +__init void initialise_pool (struct memory_pool * pool) +{ +int i; + +for (i =0 ; i <MAX_ORDER ; i++) { + pool->level[i] =0 ; +INIT_LIST_HEAD (&pool->contents[i]); + } + + suspend_pool_level_limit[1 ] =1 ; + suspend_pool_level_limit[2 ] =1 ; +} + +__init void suspend_memory_pool_init (void ) +{ +/* Initialise lists */ +initialise_pool (&normal_pool); +initialise_pool (&highmem_pool); +} + +/* get_from_pool() +* +* Description: Remove head of a pool list +*/ + +static struct page *get_from_pool (struct memory_pool * pool,int order) +{ +struct page * page; +int j; + +if (!pool->level[order]) +return 0 ; + + page = list_entry(pool->contents[order].next, struct page, lru); +list_del_init (&page->lru); + pool->level[order]--; + +for (j =0 ; j < (1 << order); j++) +ClearPageChecksumIgnore (page + j); + +if (page_count (page) !=1 ) +printk ("Error getting page %p from memory pool. " +"Page count is %d (should be 1).\n" , + page, +page_count (page)); + +BUG_ON (PageLRU (page) ||PageActive (page)); + +display_memory_pool_pages (); +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_MEDIUM ,0 , +"\r%4d %4d %4d." , + normal_pool.level[0 ], + normal_pool.level[1 ], + normal_pool.level[2 ]); + +return page; +} + +/* add_to_pool() +* +* Description: Insert new head in a pool list +*/ + +static void add_to_pool (struct memory_pool * pool,int order,struct page * this) +{ +int j; + + pool->level[order]++; +list_add (&this->lru, &pool->contents[order]); +for (j =0 ; j < (1 << order); j++) +SetPageChecksumIgnore (this + j); + +display_memory_pool_pages (); +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_MEDIUM ,0 , +"\r%4d %4d %4d." , + normal_pool.level[0 ], + normal_pool.level[1 ], + normal_pool.level[2 ]); +} + +/* suspend_memory_pool_level() +* +* Description: Returns the number of pages currently in the pool. +* Returns: Int. Number of pages in the pool. +*/ +int suspend_memory_pool_level (int only_lowmem) +{ +int order, sum =0 ; + +for (order =0 ; order <MAX_ORDER ; order++) + sum += normal_pool.level[order] * (1 << order); + +if (!only_lowmem) +for (order =0 ; order <MAX_ORDER ; order++) + sum += highmem_pool.level[order] * (1 << order); +return sum; +} + +/* fill_suspend_memory_pool() +* +* Description: Fill the memory pool from the main free memory pool in the +* first instance, or grabbed pages if that fails. +* We allocate @sizesought order 0 pages, plus 1 each +* of the higher order allocations. +* Arguments: int. Number of order zero pages requested. +* Returns: int. Number of order zero pages obtained. +*/ +int fill_suspend_memory_pool (int sizesought) +{ +int i =0 , order, orig_state = +test_suspend_state (SUSPEND_USE_MEMORY_POOL ); +unsigned long *this =NULL ; +unsigned long flags; + +spin_lock_irqsave (&suspend_memory_pool_lock, flags); + +/* Pools must not be active for this to work */ +clear_suspend_state (SUSPEND_USE_MEMORY_POOL ); + + suspend_pool_level_limit[0 ] = sizesought; + +for (order =MAX_ORDER ; order >=0 ; order--) { +int wanted = suspend_pool_level_limit[order] - + normal_pool.level[order]; +for (i = normal_pool.level[order]; + i < suspend_pool_level_limit[order]; i++) { + this = (unsigned long *)get_grabbed_pages (order); +if (!this) { +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_ERROR ,1 , +"%d order %d pages wanted for suspend " +"memory pool, got %d.\n" , + wanted, order, i -1 ); +break ; + } +add_to_pool (&normal_pool, order,virt_to_page (this)); + } + } + +if (orig_state) +set_suspend_state (SUSPEND_USE_MEMORY_POOL ); + + min_pool_level = normal_pool.level[0 ]; + +spin_unlock_irqrestore (&suspend_memory_pool_lock, flags); + +return 0 ; +} + +/* empty_suspend_memory_pool() +* +* Description: Drain our memory pool. +*/ +void __empty_suspend_memory_pool (struct memory_pool * pool) +{ +int order; +struct page * this; + +for (order =0 ; order <MAX_ORDER ; order++) +while ((this =get_from_pool (pool, order))) +__free_pages (this, order); + +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_LOW ,1 , +"Min pool level was %d/%d.\n" , min_pool_level, suspend_pool_level_limit[0 ]); +} + +void empty_suspend_memory_pool (void ) +{ +unsigned long flags; + +spin_lock_irqsave (&suspend_memory_pool_lock, flags); + +display_memory_pool_pages (); + +/* Pool must not be active for this to work */ +clear_suspend_state (SUSPEND_USE_MEMORY_POOL ); + +__empty_suspend_memory_pool (&normal_pool); +__empty_suspend_memory_pool (&highmem_pool); + +spin_unlock_irqrestore (&suspend_memory_pool_lock, flags); +} + +/* get_suspend_pool_pages() +* +* Description: Our equivalent to __alloc_pages (minus zone mask). +* May be called from interrupt context. +* Arguments: unsigned int: Mask. We really only care about __GFP_WAIT. +* We're giving normal zone pages regardless. +* order: The number of pages (1 << order) wanted. +* Returns: struct page *: Pointer (possibly NULL) to pages allocated. +*/ +struct page *get_suspend_pool_pages (unsigned int gfp_mask,unsigned int order) +{ +unsigned long flags; +struct page * page; + +if (order >0 ) { +spin_lock_irqsave (&suspend_memory_pool_lock, flags); +if (!normal_pool.level[order]) { +printk ("No order %d allocation available.\n" , + order); +display_memory_pool_pages (); +spin_unlock_irqrestore ( + &suspend_memory_pool_lock, + flags); +return NULL ; + } + goto check_and_return; + } + +try_again: +if ((!normal_pool.level[order]) && (!(gfp_mask & __GFP_WAIT))) { +spin_lock_irqsave (&suspend_memory_pool_lock, flags); +display_memory_pool_pages (); +spin_unlock_irqrestore (&suspend_memory_pool_lock, flags); +return NULL ; + } + +while (!normal_pool.level[order]) { +if (active_writer->ops.writer.wait_on_io) + active_writer->ops.writer.wait_on_io (0 ); +schedule (); + } + +spin_lock_irqsave (&suspend_memory_pool_lock, flags); +if (!normal_pool.level[order]) { +spin_unlock_irqrestore (&suspend_memory_pool_lock, flags); + goto try_again; + } +check_and_return: + page =get_from_pool (&normal_pool, order); + +if (normal_pool.level[0 ] < min_pool_level) + min_pool_level = normal_pool.level[0 ]; +if (!normal_pool.level[0 ]) +printk ("Normal pool empty.\n" ); + +spin_unlock_irqrestore (&suspend_memory_pool_lock, flags); + +return page; +} + +/* free_suspend_pool_pages() +* +* Description: Our equivalent to __free_pages. Put freed pages into the pool. +* HighMem pages do still get freed to the normal pool because they +* aren't going to affect the consistency of our image - worse case, +* we write a few free pages. +* Arguments: Struct page *: First page to be freed. +* Unsigned int: Size of allocation being freed. +*/ +void free_suspend_pool_pages (struct page *page,unsigned int order) +{ +unsigned long flags; +int i; +struct memory_pool * pool = &normal_pool; + +suspend_message (SUSPEND_MEM_POOL ,SUSPEND_VERBOSE ,1 , +"Freeing page %p (%p), order %d.\n" , +page_address (page), page, order); + +if (PageHighMem (page)) + pool = &highmem_pool; + +#ifdef CONFIG_MMU +set_page_count (page,1 ); +#else +for (i =0 ; i < (1 << order); i++) +set_page_count (page + i,1 ); +#endif +if (pool == &normal_pool) { +char * address =page_address (page); +for (i =0 ; i < (1 << order); i++) { +clear_page (address); + address +=PAGE_SIZE ; + } + } + +spin_lock_irqsave (&suspend_memory_pool_lock, flags); +add_to_pool (pool, order, page); +spin_unlock_irqrestore (&suspend_memory_pool_lock, flags); +return ; +} + +EXPORT_SYMBOL (suspend_memory_pool_level);
Re: Suspend 2 merge: 37/51: Memory pool support.
Hi!
Quoted 6 lines
This is the memory pool support. It handles all pages freed and allocated between the preparation of the image and the completion of resuming, except prior to restoring the original kernel at resume time. It is designed for speed and to match the fact that suspend2 just about exclusively uses order 0 allocations. ("Just about" is why a couple of order one and two allocations are also available).
You really should use generic routines. Having your own malloc of course allows you to be slightly faster; but it also means that code is much bigger and much uglier.
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!
Suspend 2 merge: 33/51: More documentation.
In reply to Nigel CunninghamMore documentation for suspend. The internals.txt file is still to be completed (and a bit out of date, too!).
Documentation/power/internals.txt +364 -0
@@ -0,0 +1,364 @@ + Software Suspend 2.0 Internal Documentation. + Version 1 + +1. Introduction. + + Software Suspend 2.0 is an addition to the Linux Kernel, designed to + allow the user to quickly shutdown and quickly boot a computer, without + needing to close documents or programs. It is equivalent to the + hibernate facility in some laptops. This implementation, however, + requires no special BIOS or hardware support. + + The code in these files is based upon the original implementation + prepared by Gabor Kuti and additional work by Pavel Machek and a + host of others. This code has been substantially reworked by Nigel + Cunningham, again with the help and testing of many others, not the + least of whom is Michael Frank, At its heart, however, the operation is + essentially the same as Gabor's version. + +2. Overview of operation. + + The basic sequence of operations is as follows: + + a. Quiesce all other activity. + b. Ensure enough memory and storage space are available, and attempt + to free memory/storage if necessary. + c. Allocate the required memory and storage space. + d. Write the image. + e. Power down. + + There are a number of complicating factors which mean that things are + not as simple as the above would imply, however... + + o The activity of each process must be stopped at a point where it will + not be holding locks necessary for saving the image, or unexpectedly + restart operations due to something like a timeout and thereby make + our image inconsistent. + + o It is desirous that we sync outstanding I/O to disk before calculating + image statistics. This reduces corruption if one should suspend but + then not resume, and also makes later parts of the operation safer (see + below). + + o We need to get as close as we can to an atomic copy of the data. + Inconsistencies in the image will result inconsistent memory contents at + resume time, and thus in instability of the system and/or file system + corruption. This would appear to imply a maximum image size of one half of + the amount of RAM, but we have a solution... (again, below). + + o In 2.6, we must play nicely with the other suspend-to-disk + implementations. + +3. Detailed description of internals. + + a. Quiescing activity. + + Safely quiescing the system is achieved in a number of steps. First, we + wait for existing activity to complete, while holding new activity until + post-resume. Second, we sync unwritten buffers. Third, we send a + 'pseudo-signal' to all processes that have not yet entered the + 'refrigerator' but should be frozen, causing them to be refrigerated. + + Waiting for existing activity to complete is achieved by using hooks at + the beginning and end of critical paths in the kernel code. When a process + enters a section where it cannot be safely refrigerated, the process flag + PF_FRIDGE_WAIT is set from the SWSUSP_ACTIVITY_STARTING macro. In the same + routine, at completion of the critical region, a SWSUSP_ACTIVITY_END macro + resets the flag. The _STARTING and _ENDING macros also atomically adjust + the global counter swsusp_num_active. While the counter is non-zero, + Software Suspend's freezer will wait. + + These macros serve two other additional purposes. Local variables are used + to ensure that processes can safely pass through multiple _STARTING and + _ENDING macros, and checks are made to ensure that the freezer is not + waiting for activity to finish. If a process wants to start on a critical + path when Suspend is waiting for activity to finish, it will be held at the + start of the critical path and refrigerated earlier than would normally be + the case. It will be allowed to continue operation after the Suspend cycle + is finished or aborted. + + A process in a critical path may also have a section where it releases + locks and can be safely stopped until post-resume. For these cases, the + SWSUSP_ACTIVITY_PAUSING and _RESTARTING macros may be used. They function + in a similar manner to the _STARTING and _ENDING macros. + + Finally, we remember that some threads may be necessary for syncing data to + storage. These threads have PF_SYNCTHREAD set, and may use the special macro + SWSUSP_ACTIVITY_SYNCTHREAD_PAUSING to indicate that Suspend can safely + continue, while not themselves entering the refrigerator. + + Once activity is stopped, Suspend will initiate a fsync of all devices. + This aims to increase the integrity of the disk state, just in case + something should go wrong. + + During the initial stage, Suspend indicates its desire that processes be + stopped by setting the FREEZE_NEW_ACTIVITY bit of swsusp_state. Once the + sync is complete, SYNCTHREAD processes no longer need to run. The + FREEZE_UNREFRIGERATED bit is now set, causing them to be refrigerated as + well, should they attempt to start new activity. (There should be nothing + for them to do, but just-in-case). + + Suspend can now put remaining processes in the refrigerator without fear + of deadlocking or leaving dirty data unsynced. The refrigerator is a + procedure where processes wait until the cycle is complete. While in there, + we can be sure that they will not perform activity that will make our + image inconsistent. Processes enter the refrigerator either by being + caught at one of the previously mentioned hooks, or by receiving a 'pseudo- + signal' from Suspend at this stage. I call it a pseudo signal because + signal_wake_up is called for the process when it actually hasn't been + signalled. A special hook in the signal handler then calls the refrigerator. + The refrigerator, in turn, recalculates the signal pending status to + ensure no ill effects result. + + Not all processes are refrigerated. The Suspend thread itself, of course, + is one such thread. Others are flagged by setting PF_NOFREEZE, usually + because they are needed during suspend. + + In 2.4, the dosexec thread (Win4Lin) is treated specially. It does not + handle us even pretending to send it a signal. This is worked-around by + us adjusting the can_schedule() macro in schedule.c to stop the task from + being scheduled during suspend. Ugly, but it works. The 2.6 version of + Win4Lin has been made compatible. + + b. Ensure enough memory & storage are available. + c. Allocate the required memory and storage space. + + These steps are merged together in the prepare_image function, found in + prepare_image.c. The functions are merged because of the cyclical nature + of the problem of calculating how much memory and storage is needed. Since + the data structures containing the information about the image must + themselves take memory and use storage, the amount of memory and storage + required changes as we prepare the image. Since the changes are not large, + only one or two iterations will be required to achieve a solution. + + d. Write the image. + + We previously mentioned the need to create an atomic copy of the data, and + the half-of-memory limitation that is implied in this. This limitation is + circumvented by dividing the memory to be saved into two parts, called + pagesets. + + Pageset2 contains the page cache - the pages on the active and inactive + lists. These pages are saved first and reloaded last. While saving these + pages, the swapwriter plugin carefully ensures that the work of writing + the pages doesn't make the image inconsistent. Pages added to the LRU + lists are immediately shot down, and careful accounting for available + memory aids debugging. No atomic copy of these pages needs to be made. + + Writing the image requires memory, of course, and at this point we have + also not yet suspended the drivers. To avoid the possibility of remaining + activity corrupting the image, we allocate a special memory pool. Calls + to __alloc_pages and __free_pages_ok are then diverted to use our memory + pool. Pages in the memory pool are saved as part of pageset1 regardless of + whether or not they are used. + + Once pageset2 has been saved, we suspend the drivers and save the CPU + context before making an atomic copy of pageset1, resuming the drivers + and saving the atomic copy. After saving the two pagesets, we just need to + save our metadata before powering down. + + Having saved pageset2 pages, we can safely overwrite their contents with + the atomic copy of pageset1. This is how we manage to overcome the half of + memory limitation. Pageset2 is normally far larger than pageset1, and + pageset1 is normally much smaller than half of the memory, with the result + that pageset2 pages can be safely overwritten with the atomic copy of + pageset1. This is where we need to be careful about syncing, however. + Pageset2 will probably contain filesystem meta data. If this is overwritten + with pageset1 and then a sync occurs, the filesystem will be corrupted - + at least until resume time and another sync of the restored data. Since + there is a possibility that the user might not resume or (may it never be!) + that suspend might oops, we do our utmost to avoid syncing filesystems after + copying pageset1. + + e. Power down. + + Powering down uses standard kernel routines. Prior to this, however, we + suspend drivers again, ensuring that write caches are flushed. + +4. The method of writing the image. + + Software Suspend 2.0rc3 and later contain an internal API which is + designed to simplify the implementation of new methods of transforming + the image to be written and writing the image itself. Prior to rc3, + compression support was inlined in the image writing code, and the data + structures and code for managing swap were intertwined with the rest of + the code. A number of people had expressed interest in implementing + image encryption, and alternative methods of storing the image. This + internal API makes that possible by implementing 'plugins'. + + A plugin is a single file which encapsulates the functionality needed + to transform a pageset of data (encryption or compression, for example), + or to write the pageset to a device. The former type of plugin is called + a 'page-transformer', the later a 'writer'. + + Plugins are linked together in pipeline fashion. There may be zero or more + page transformers in a pipeline, and there is always exactly one writer. + The pipeline follows this pattern: + + --------------------------------- + | Software Suspend Core | + --------------------------------- + | + | + --------------------------------- + | Page transformer 1 | + --------------------------------- + | + | + --------------------------------- + | Page transformer 2 | + --------------------------------- + | + | + --------------------------------- + | Writer | + --------------------------------- + + During the writing of an image, the core code feeds pages one at a time + to the first plugin. This plugin performs whatever transformations it + implements on the incoming data, completely consuming the incoming data and + feeding output in a similar manner to the next plugin. A plugin may buffer + its output. + + During reading, the pipeline works in the reverse direction. The core code + calls the first plugin with the address of a buffer which should be filled. + (Note that the buffer size is always PAGE_SIZE at this time). This plugin + will in turn request data from the next plugin and so on down until the + writer is made to read from the stored image. + + Part of definition of the structure of a plugin thus looks like this: + + /* Writing the image proper */ + int (*write_init) (int stream_number); + int (*write_chunk) (char * buffer_start); + int (*write_cleanup) (void); + + /* Reading the image proper */ + int (*read_init) (int stream_number); + int (*read_chunk) (char * buffer_start, int sync); + int (*read_cleanup) (void); + + It should be noted that the _cleanup routines may be called before the + full stream of data has been read or written. While writing the image, + the user may (depending upon settings) choose to abort suspending, and + if we are in the midst of writing the last portion of the image, a portion + of the second pageset may be reread. + + In addition to the above routines for writing the data, all plugins have a + number of other routines: + + TYPE indicates whether the plugin is a page transformer or a writer. + #define TRANSFORMER_PLUGIN 1 + #define WRITER_PLUGIN 2 + + NAME is the name of the plugin, used in generic messages. + + PLUGIN_LIST is used to link the plugin into the list of all plugins. + + MEMORY_NEEDED returns the number of pages of memory required by the plugin + to do its work. + + STORAGE_NEEDED returns the number of pages in the suspend header required + to store the plugin's configuration data. + + PRINT_DEBUG_INFO fills a buffer with information to be displayed about the + operation or settings of the plugin. + + SAVE_CONFIG_INFO returns a buffer of PAGE_SIZE or smaller (the size is the + return code), containing the plugin's configuration info. This information + will be written in the image header and restored at resume time. Since this + buffer is allocated after the atomic copy of the kernel is made, you don't + need to worry about the buffer being freed. + + LOAD_CONFIG_INFO gives the plugin a pointer to the the configuration info + which was saved during suspending. Once again, the plugin doesn't need to + worry about freeing the buffer. The kernel will be overwritten with the + original kernel, so no memory leak will occur. + + OPS contains the operations specific to transformers and writers. These are + described below. + + The complete definition of struct swsusp_plugin_ops is: + + struct swsusp_plugin_ops { + /* Functions common to transformers and writers */ + int type; + char * name; + struct list_head plugin_list; + unsigned long (*memory_needed) (void); + unsigned long (*storage_needed) (void); + int (*print_debug_info) (char * buffer, int size); + int (*save_config_info) (char * buffer); + void (*load_config_info) (char * buffer, int len); + + /* Writing the image proper */ + int (*write_init) (int stream_number); + int (*write_chunk) (char * buffer_start); + int (*write_cleanup) (void); + + /* Reading the image proper */ + int (*read_init) (int stream_number); + int (*read_chunk) (char * buffer_start, int sync); + int (*read_cleanup) (void); + + union { + struct swsusp_transformer_ops transformer; + struct swsusp_writer_ops writer; + } ops; + }; + + + The operations specific to transformers are few in number: + + struct swsusp_transformer_ops { + int (*expected_compression) (void); + struct list_head transformer_list; + }; + + Expected compression returns the expected ratio between the amount of + data sent to this plugin and the amount of data it passes to the next + plugin. The value is used by the core code to calculate the amount of + space required to write the image. If the ratio is not achieved, the + writer will complain when it runs out of space with data still to + write, and the core code will abort the suspend. + + transformer_list links together page transformers, in the order in + which they register, which is in turn determined by order in the + Makefile. + + There are many more operations specific to a writer: + + struct swsusp_writer_ops { + + long (*storage_available) (void); + + unsigned long (*storage_allocated) (void); + + int (*release_storage) (void); + + long (*allocate_header_space) (unsigned long space_requested); + int (*allocate_storage) (unsigned long space_requested); + + int (*write_header_init) (void); + int (*write_header_chunk) (char * buffer_start, int buffer_size); + int (*write_header_cleanup) (void); + + int (*read_header_init) (void); + int (*read_header_chunk) (char * buffer_start, int buffer_size); + int (*read_header_cleanup) (void); + + int (*prepare_save) (void); + int (*post_load) (void); + + int (*parse_image_location) (char * buffer); + + int (*image_exists) (void); + + int (*invalidate_image) (void); + + int (*wait_on_io) (int flush_all); + + struct list_head writer_list; + }; + + STORAGE_AVAILABLE is
Documentation/power/todo.txt +19 -0
@@ -0,0 +1,19 @@ +Suspend2 todo list + +20041021 + 2.1 known issues: + ---------------- +- NFS support missing +- Encryption support missing +- DRI support for 2.4 & 2.6 +- USB support under 2.4 and 2.6 +- Incomplete support in other drivers +- No support for discontig memory +- Currently requires PSE extension (/proc/cpuinfo) +- Highmem >4GB not supported + +20040107 +- Further cleaning up. + +20031216 +- Include progress-bar-granularity in all_settings.
Suspend 2 merge: 22/51: Suspend2 lowlevel code.
In reply to Nigel CunninghamLowlevel code for i386. This is the code responsible for saving and restoring CPU state, and for restoring the original kernel (except LRU pages, which are loaded afterwards).
arch/i386/power/Makefile +3 -1
@@ -1,2 +1,4 @@ -obj-$(CONFIG_PM) += cpu.o +CFLAGS_suspend2.o = -O0 + +obj-$(CONFIG_PM) += cpu.o suspend2.o obj-$(CONFIG_SOFTWARE_SUSPEND) += swsusp.o
arch/i386/power/suspend2.c +639 -0
639 lines not on this page · raw message
Re: Suspend 2 merge: 22/51: Suspend2 lowlevel code.
Quoted 14 lines · Nigel Cunningham
+ * SMP support:
+ * All SMP processors enter this routine during suspend. The one through
+ * which the suspend is initiated (which, for simplicity, is always CPU 0)
+ * sends the others here using an IPI duringdo_suspend2_suspend_1. They
+ * remain here until after the atomic copy of the kernel is made, to ensure
+ * that they don't mess with memory in the meantime (even just idling will
+ * do that). Once the atomic copy is made, they are free to carry on idling.
+ * Note that we must let them go, because if we're using compression, the
+ * vfree calls in the compressors will result in IPIs being called and hanging
+ * because the CPUs are still here.
+ *
+ * At resume time, we do a similar thing. CPU 0 sends the others in here using
+ * an IPI. It then copies the original kernel back, restores its own processor
+ * context and flushes local tlbs before freeing the others to do the same.
Quoted 8 lines
+ * They can then go back to idling while CPU 0 reloads pageset 2, cleans up
+ * and unfreezes the processes.
+ *
+ * (Remember that freezing and thawing processes also uses IPIs, as may
+ * decompressing the data. Again, therefore, we cannot leave the other processors
+ * in here).
+ *
+ * At the moment, we do nothing about APICs, even though the code is there.
Ok,
Do you see anything missing (from an implementation point of view)
for the following?
Suspend:
1) suspend all cpus, save cpu0
2) proceed with state saving on cpu0 only
3) begin suspend
Resume:
1) begin resume
2) offline all currently online cpus
3) proceed with state restoring
4) online all previously online cpus
A lot of the subsystems which have work split across cpus will now have work migrated across to cpu0, in that regard, which have you made swsusp savvy? It looks like the timer changes might need looking at any others?
Thanks,
Zwane
Re: Suspend 2 merge: 22/51: Suspend2 lowlevel code.
Hi.
Quoted 9 lines · Zwane Mwaikambo
Ok,
Do you see anything missing (from an implementation point of view)
for the following?Suspend:
1) suspend all cpus, save cpu0
2) proceed with state saving on cpu0 only
3) begin suspend
Quoted 5 lines
Resume:
1) begin resume
2) offline all currently online cpus
3) proceed with state restoring
4) online all previously online cpus
That's roughly what we're doing now, apart from the offlining/onlining. I had considered trying to take better advantage of SMP support (perhaps run a decompression thread on one CPU and the writer on the other, eg), so we might want to apply this just to the region immediately around the atomic copy/restore. That makes me wonder, though, what the advantage is to switching to using the hotplug functionality - is it x86 only, or more cross platform? (If more cross platform, that might possibly be an advantage over the current code).
Quoted 3 lines
A lot of the subsystems which have work split across cpus will now have work migrated across to cpu0, in that regard, which have you made swsusp savvy? It looks like the timer changes might need looking at any others?
All of the other threads, including the migration threads, are frozen, so I don't believe that anything gets migrated to CPU0. I'll double check when I next suspend.
As to the timers, I fully agree. Thawing them needs a mechanism for keeping the per-cpu timers staggered.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 22/51: Suspend2 lowlevel code.
Quoted 8 lines · Nigel Cunningham
That's roughly what we're doing now, apart from the offlining/onlining. I had considered trying to take better advantage of SMP support (perhaps run a decompression thread on one CPU and the writer on the other, eg), so we might want to apply this just to the region immediately around the atomic copy/restore. That makes me wonder, though, what the advantage is to switching to using the hotplug functionality - is it x86 only, or more cross platform? (If more cross platform, that might possibly be an advantage over the current code).
It's cross platform and removes the requirement for patches like;
Subject: Suspend 2 merge: 13/51: Disable highmem tlb flush for copyback.
Re: Suspend 2 merge: 22/51: Suspend2 lowlevel code.
Hi.
Quoted 11 lines · Zwane Mwaikambo
Quoted 8 lines · Nigel Cunningham
That's roughly what we're doing now, apart from the offlining/onlining. I had considered trying to take better advantage of SMP support (perhaps run a decompression thread on one CPU and the writer on the other, eg), so we might want to apply this just to the region immediately around the atomic copy/restore. That makes me wonder, though, what the advantage is to switching to using the hotplug functionality - is it x86 only, or more cross platform? (If more cross platform, that might possibly be an advantage over the current code).
Quoted 3 lines
It's cross platform and removes the requirement for patches like;
Subject: Suspend 2 merge: 13/51: Disable highmem tlb flush for copyback.
Good point. I didn't see that.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 22/51: Suspend2 lowlevel code.
In reply to Nigel CunninghamHi!
Quoted 1 line
+#include "
../../../kernel/power/suspend.h"
Ouch.
Quoted 1 line
+#define
loaddebug(thread,register)> + __asm__("movl %0,%%db" #register > + : /* no output */ > + :"r" ((thread)->debugreg[register]))
This should be already defined somewhere...
Quoted 5 lines
+ * Note that the context and timing of this function is pretty critical.
+ * With a minimal amount of things going on in the caller and in here, gcc
+ * does a good job of being just a dumb compiler. Watch the assembly output
+ * if anything changes, though, and make sure everything is going in the right
+ * place.
You should include assembly source (unless you can test all the compilers...). Feel free to include C version, too, but #ifdef it out.
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 22/51: Suspend2 lowlevel code.
Hi.
Quoted 9 lines · Pavel Machek
Hi!
Quoted 1 line
+#include "
../../../kernel/power/suspend.h"Ouch.
Quoted 1 line
+#define
loaddebug(thread,register)> + __asm__("movl %0,%%db" #register > + : /* no output */ > + :"r" ((thread)->debugreg[register]))This should be already defined somewhere...
Will look for it.
Quoted 8 lines
Quoted 5 lines
+ * Note that the context and timing of this function is pretty critical.
+ * With a minimal amount of things going on in the caller and in here, gcc
+ * does a good job of being just a dumb compiler. Watch the assembly output
+ * if anything changes, though, and make sure everything is going in the right
+ * place.You should include assembly source (unless you can test all the compilers...). Feel free to include C version, too, but #ifdef it out.
I'm thinking I should actually be removing the comment. The C is simple, clear, fast and easy to maintain and we haven't actually had any problems at all with compilers. All my tweaking in here has turned out to be irrelevant to the real cause of problems (I recently found a bug where work queues were wrongly inheriting freezer flags; since fixing that, all the symptoms in this area have gone away).
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 22/51: Suspend2 lowlevel code.
Hi!
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
+ * Note that the context and timing of this function is pretty critical.
+ * With a minimal amount of things going on in the caller and in here, gcc
+ * does a good job of being just a dumb compiler. Watch the assembly output
+ * if anything changes, though, and make sure everything is going in the right
+ * place.You should include assembly source (unless you can test all the compilers...). Feel free to include C version, too, but #ifdef it out.
Quoted 6 lines
I'm thinking I should actually be removing the comment. The C is simple, clear, fast and easy to maintain and we haven't actually had any problems at all with compilers. All my tweaking in here has turned out to be irrelevant to the real cause of problems (I recently found a bug where work queues were wrongly inheriting freezer flags; since fixing that, all the symptoms in this area have gone away).
See the flames I got when I did just that. No, it needs to be in assembly, because (by standard) C compiler is allowed to misoptimize it.
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!
Suspend 2 merge: 14/51: Disable page alloc failure message when suspending
In reply to Nigel CunninghamWhile eating memory, we will potentially trigger this a lot. We therefore disable the message when suspending.
mm/page_alloc.c +4 -1
@@ -725,7 +725,10 @@ } nopage: -if (!(gfp_mask & __GFP_NOWARN) &&printk_ratelimit ()) { +if ((!(gfp_mask & __GFP_NOWARN)) && + (!test_suspend_state (SUSPEND_RUNNING )) && +printk_ratelimit ()) { +printk (KERN_WARNING "%s: page allocation failure." " order:%d, mode:0x%x\n" , p->comm, order, gfp_mask);
Re: Suspend 2 merge: 14/51: Disable page alloc failure message when suspending
Quoted 2 lines · Nigel Cunningham
While eating memory, we will potentially trigger this a lot. We therefore disable the message when suspending.
So call the allocator with __GFP_NOWARN
Re: Suspend 2 merge: 14/51: Disable page alloc failure message when suspending
Hi.
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Nigel Cunningham
While eating memory, we will potentially trigger this a lot. We therefore disable the message when suspending.
So call the allocator with
__GFP_NOWARN
Everywhere?
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 14/51: Disable page alloc failure message when suspending
In reply to Nigel CunninghamQuoted 8 lines · Nigel Cunningham
While eating memory, we will potentially trigger this a lot. We therefore disable the message when suspending.
diff -ruN
503-disable-page-alloc-warnings-while-suspending-old/mm/page_alloc.c503-disable-page-alloc-warnings-while-suspending-new/mm/page_alloc.cmm/page_alloc.c +0
-0@@ -725,7 +725,10 @@ }
mm/page_alloc.c line 734
Quoted 10 lines
mm/page_alloc.c +4
-1nopage: -if (!(gfp_mask & __GFP_NOWARN) &&printk_ratelimit ()) { +if ((!(gfp_mask & __GFP_NOWARN)) && + (!test_suspend_state (SUSPEND_RUNNING )) && +printk_ratelimit ()) { +printk (KERN_WARNING "%s: page allocation failure." " order:%d, mode:0x%x\n" , p->comm, order, gfp_mask);
Following Documentation/SubmittingPatches, please submit patches made with "diff -urp":
-p --show-c-function
Show which C function each change is in.
Otherwise, it's a lot harder to figure out what you're modifying.
-- Dave
Re: Suspend 2 merge: 14/51: Disable page alloc failure message when suspending
Hi.
Quoted 23 lines · Dave Hansen
Quoted 8 lines · Nigel Cunningham
While eating memory, we will potentially trigger this a lot. We therefore disable the message when suspending.
diff -ruN
503-disable-page-alloc-warnings-while-suspending-old/mm/page_alloc.c503-disable-page-alloc-warnings-while-suspending-new/mm/page_alloc.cmm/page_alloc.c +0
-0@@ -725,7 +725,10 @@ }mm/page_alloc.c line 734
Quoted 10 lines
mm/page_alloc.c +4
-1nopage: -if (!(gfp_mask & __GFP_NOWARN) &&printk_ratelimit ()) { +if ((!(gfp_mask & __GFP_NOWARN)) && + (!test_suspend_state (SUSPEND_RUNNING )) && +printk_ratelimit ()) { +printk (KERN_WARNING "%s: page allocation failure." " order:%d, mode:0x%x\n" , p->comm, order, gfp_mask);Following
Documentation/SubmittingPatches, please submit patches made with "diff -urp":
Quoted 4 lines
-p --show-c-function
Show which C function each change is in.Otherwise, it's a lot harder to figure out what you're modifying.
Okay; thanks. I wont go redoing all of the patches now, but are there specific ones you'd like to see?
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 14/51: Disable page alloc failure message when suspending
Quoted 11 lines · Nigel Cunningham
Quoted 7 lines · Dave Hansen
Following
Documentation/SubmittingPatches, please submit patches made with "diff -urp":-p --show-c-function
Show which C function each change is in.Otherwise, it's a lot harder to figure out what you're modifying.
Okay; thanks. I wont go redoing all of the patches now, but are there specific ones you'd like to see?
I'd just add it to whatever scripts you use to publish patches and do it that way from now on for all of them.
-- Dave
Re: Suspend 2 merge: 14/51: Disable page alloc failure message when suspending
In reply to Nigel CunninghamHi!
Quoted 2 lines
While eating memory, we will potentially trigger this a lot. We therefore disable the message when suspending.
You should only trigger this while eating memory, so *one* GFP_NOWARN should be enough. And shrink_all_memory should fix it anyway.
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 14/51: Disable page alloc failure message when suspending
Hi.
Quoted 7 lines · Pavel Machek
Hi!
Quoted 2 lines
While eating memory, we will potentially trigger this a lot. We therefore disable the message when suspending.
You should only trigger this while eating memory, so *one*
GFP_NOWARNshould be enough. Andshrink_all_memoryshould fix it anyway.
Agreed. I wasn't seriously suggesting changing everywhere to be GFP_NOWARN. Perhaps I should be more explicit in what I'm saying here. The problem isn't just suspend trying to allocate memory. It's _ANYTHING_ that might be running trying to allocate memory while we're eating memory. (Remember that we don't just call shrink_all_memory, but also allocate that memory so other processes don't grab it and stop us making forward progress). As a result, they're going to scream when they can't allocate a page.
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 14/51: Disable page alloc failure message when suspending
Hi!
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
While eating memory, we will potentially trigger this a lot. We therefore disable the message when suspending.
You should only trigger this while eating memory, so *one*
GFP_NOWARNshould be enough. Andshrink_all_memoryshould fix it anyway.
Quoted 8 lines
Agreed. I wasn't seriously suggesting changing everywhere to be
GFP_NOWARN. Perhaps I should be more explicit in what I'm saying here. The problem isn't just suspend trying to allocate memory. It's _ANYTHING_ that might be running trying to allocate memory while we're eating memory. (Remember that we don't just callshrink_all_memory, but also allocate that memory so other processes don't grab it and stop us making forward progress). As a result, they're going to scream when they can't allocate a page.
Hmm, that does not look too healthy. That means that userland programs will see all kinds of weird error conditions that normally "almost-can't-happen" during normal usage.
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!
Re: Suspend 2 merge: 14/51: Disable page alloc failure message when suspending
Hi.
Quoted 17 lines · Pavel Machek
Hi!
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
While eating memory, we will potentially trigger this a lot. We therefore disable the message when suspending.
You should only trigger this while eating memory, so *one*
GFP_NOWARNshould be enough. Andshrink_all_memoryshould fix it anyway.Quoted 8 lines
Agreed. I wasn't seriously suggesting changing everywhere to be
GFP_NOWARN. Perhaps I should be more explicit in what I'm saying here. The problem isn't just suspend trying to allocate memory. It's _ANYTHING_ that might be running trying to allocate memory while we're eating memory. (Remember that we don't just callshrink_all_memory, but also allocate that memory so other processes don't grab it and stop us making forward progress). As a result, they're going to scream when they can't allocate a page.
Quoted 3 lines
Hmm, that does not look too healthy. That means that userland programs will see all kinds of weird error conditions that normally "almost-can't-happen" during normal usage.
Failure to allocate memory should be something any caller to get_*_page deals with, so if they don't, are we to be blamed?
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 14/51: Disable page alloc failure message when suspending
Hi!
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Agreed. I wasn't seriously suggesting changing everywhere to be
GFP_NOWARN. Perhaps I should be more explicit in what I'm saying here. The problem isn't just suspend trying to allocate memory. It's _ANYTHING_ that might be running trying to allocate memory while we're eating memory. (Remember that we don't just callshrink_all_memory, but also allocate that memory so other processes don't grab it and stop us making forward progress). As a result, they're going to scream when they can't allocate a page.
Quoted 6 lines
Quoted 3 lines
Hmm, that does not look too healthy. That means that userland programs will see all kinds of weird error conditions that normally "almost-can't-happen" during normal usage.
Failure to allocate memory should be something any caller to get_*_page deals with, so if they don't, are we to be blamed?
Well, you'll have things like select() returning -ENOMEM. Applications will not be too happpy. We can probably live with that, but it is not nice.
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!
Suspend 2 merge: 15/51: Disable pdflush during suspend.
In reply to Nigel CunninghamHere we disable pdflush once we've finished syncing data to disk. We might be writing to a swap file, and don't want to corrupt the user's disk by writing invalid data to their superblock.
mm/page-writeback.c +9 -0
@@ -29,6 +29,7 @@#include <linux/sysctl.h> #include <linux/cpu.h> #include <linux/syscalls.h> +#include <linux/suspend.h> /* * The maximum number of pages to writeout in a single bdflush/kupdate
@@ -369,6 +370,12 @@ .for_kupdate = 1, }; +if (test_suspend_state (SUSPEND_DISABLE_SYNCING )) { + start_jif = jiffies; + next_jif = start_jif + (dirty_writeback_centisecs *HZ ) /100 ; + goto out; + } +sync_supers ();get_writeback_state (&wbs);
@@ -389,6 +396,8 @@ } nr_to_write -=MAX_WRITEBACK_PAGES - wbc.nr_to_write; } + +out:if (time_before (next_jif, jiffies +HZ )) next_jif = jiffies +HZ ;if (dirty_writeback_centisecs)
Suspend 2 merge: 21/51: Refrigerator upgrade.
In reply to Nigel CunninghamHere's the suspend2 version of the process refrigerator. We do things in three steps:
1. Freeze userspace threads (p->mm != NULL) that don't have PF_SYNCTHREAD. This should stop new I/O being submitted.
2. Let data get synced to disk and run our own sys_sync just in case no one else was. PF_SYNCTHREAD is given to processes when they begin a sys_sync (or sibling) and removed when they exit the call, so no sync operations were hung under step 1. After this we set the DISABLE_SYNCING flag to stop further syncs.
3. Since kernel threads that don't have PF_NOFREEZE.
Included in this patch is a new try_to_freeze() macro Andrew M suggested a while back. The refrigerator declarations are put in sched.h to save extra includes of suspend.h.
Changes to keep swsusp working are included.
Note that you can also thaw just the kernel threads; this allows syncing while eating memory.
arch/arm/kernel/signal.c +1 -4
@@ -12,7 +12,6 @@#include <linux/signal.h> #include <linux/ptrace.h> #include <linux/personality.h> -#include <linux/suspend.h> #include <asm/cacheflush.h> #include <asm/ucontext.h>
@@ -689,10 +688,8 @@if (!user_mode (regs))return 0 ; -if (current->flags &PF_FREEZE ) { -refrigerator (0 ); +if (try_to_freeze (0 )) goto no_signal; - }if (current->ptrace &PT_SINGLESTEP )ptrace_cancel_bpt (current);
arch/i386/kernel/io_apic.c +1 -0
@@ -575,6 +575,7 @@for ( ; ; ) {set_current_state (TASK_INTERRUPTIBLE ); time_remaining =schedule_timeout (time_remaining); +try_to_freeze (PF_FREEZE );if (time_after (jiffies, prev_balance_time+balanced_irq_interval)) {do_irq_balance ();
arch/i386/kernel/signal.c +1 -4
@@ -18,7 +18,6 @@#include <linux/unistd.h> #include <linux/stddef.h> #include <linux/personality.h> -#include <linux/suspend.h> #include <linux/ptrace.h> #include <linux/elf.h> #include <asm/processor.h>
@@ -596,10 +595,8 @@return 1 ;#endif -if (current->flags &PF_FREEZE ) { -refrigerator (0 ); +if (try_to_freeze (PF_FREEZE ) && !signal_pending (current)) goto no_signal; - }if (!oldset) oldset = ¤t->blocked;
arch/mips/kernel/irixsig.c +1 -4
@@ -13,7 +13,6 @@#include <linux/smp_lock.h> #include <linux/time.h> #include <linux/ptrace.h> -#include <linux/suspend.h> #include <asm/ptrace.h> #include <asm/uaccess.h>
@@ -182,10 +181,8 @@if (!user_mode (regs))return 1 ; -if (current->flags &PF_FREEZE ) { -refrigerator (0 ); +if (try_to_freeze (0 )) goto no_signal; - }if (!oldset) oldset = ¤t->blocked;
arch/mips/kernel/signal32.c +1 -4
@@ -18,7 +18,6 @@#include <linux/wait.h> #include <linux/ptrace.h> #include <linux/compat.h> -#include <linux/suspend.h> #include <linux/bitops.h> #include <asm/asm.h>
@@ -700,10 +699,8 @@if (!user_mode (regs))return 1 ; -if (current->flags &PF_FREEZE ) { -refrigerator (0 ); +if (try_to_freeze (0 )) goto no_signal; - }if (!oldset) oldset = ¤t->blocked;
arch/mips/kernel/signal.c +1 -4
@@ -18,7 +18,6 @@#include <linux/errno.h> #include <linux/wait.h> #include <linux/ptrace.h> -#include <linux/suspend.h> #include <linux/unistd.h> #include <linux/bitops.h>
@@ -551,10 +550,8 @@if (!user_mode (regs))return 1 ; -if (current->flags &PF_FREEZE ) { -refrigerator (0 ); +if (try_to_freeze (0 )) goto no_signal; - }if (!oldset) oldset = ¤t->blocked;
arch/sh/kernel/signal.c +1 -4
@@ -24,7 +24,6 @@#include <linux/tty.h> #include <linux/personality.h> #include <linux/binfmts.h> -#include <linux/suspend.h> #include <asm/ucontext.h> #include <asm/uaccess.h>
@@ -579,10 +578,8 @@if (!user_mode (regs))return 1 ; -if (current->flags &PF_FREEZE ) { -refrigerator (0 ); +if (try_to_freeze (0 )) goto no_signal; - }if (!oldset) oldset = ¤t->blocked;
arch/sh64/kernel/signal.c +1 -3
@@ -701,10 +701,8 @@if (!user_mode (regs))return 1 ; -if (current->flags &PF_FREEZE ) { -refrigerator (0 ); +if (try_to_freeze (0 )) goto no_signal; - }if (!oldset) oldset = ¤t->blocked;
arch/x86_64/kernel/signal.c +1 -4
@@ -24,7 +24,6 @@#include <linux/stddef.h> #include <linux/personality.h> #include <linux/compiler.h> -#include <linux/suspend.h> #include <asm/ucontext.h> #include <asm/uaccess.h> #include <asm/i387.h>
@@ -417,10 +416,8 @@return 1 ; } -if (current->flags &PF_FREEZE ) { -refrigerator (0 ); +if (try_to_freeze (0 )) goto no_signal; - }if (!oldset) oldset = ¤t->blocked;
drivers/ieee1394/ieee1394_core.c +8 -7
@@ -32,7 +32,6 @@#include <linux/bitops.h> #include <linux/kdev_t.h> #include <linux/skbuff.h> -#include <linux/suspend.h> #include <asm/byteorder.h> #include <asm/semaphore.h>
@@ -1030,15 +1029,17 @@daemonize ("khpsbpkt" ); -while (!down_interruptible (&khpsbpkt_sig)) { -if (khpsbpkt_kill) +while (1 ) { +if (down_interruptible (&khpsbpkt_sig)) { +if (try_to_freeze (0 )) +continue ; +printk ("khpsbpkt: received unexpected signal?!\n" );break ; - -if (current->flags &PF_FREEZE ) { -refrigerator (0 ); -continue ; } +if (khpsbpkt_kill) +break ; +while ((skb =skb_dequeue (&hpsbpkt_queue)) !=NULL ) { packet = (struct hpsb_packet *)skb->data;
drivers/ieee1394/nodemgr.c +3 -4
@@ -19,7 +19,6 @@#include <linux/delay.h> #include <linux/pci.h> #include <linux/moduleparam.h> -#include <linux/suspend.h> #include <asm/atomic.h> #include "ieee1394_types.h"
@@ -1480,10 +1479,8 @@if (down_interruptible (&hi->reset_sem) ||down_interruptible (&nodemgr_serialize)) { -if (current->flags &PF_FREEZE ) { -refrigerator (0 ); +if (try_to_freeze (PF_FREEZE ))continue ; - }printk ("NodeMgr: received unexpected signal?!\n" );break ; }
@@ -1498,6 +1495,8 @@for (i =0 ; i <4 ; i++) {set_current_state (TASK_INTERRUPTIBLE );if (msleep_interruptible (63 )) { +if (try_to_freeze (PF_FREEZE )) +continue ;up (&nodemgr_serialize); goto caught_signal; }
drivers/input/serio/serio.c +1 -3
@@ -34,7 +34,6 @@#include <linux/completion.h> #include <linux/sched.h> #include <linux/smp_lock.h> -#include <linux/suspend.h> #include <linux/slab.h> MODULE_AUTHOR ("Vojtech Pavlik <[email protected]>" );
@@ -225,8 +224,7 @@do {serio_handle_events ();wait_event_interruptible (serio_wait, !list_empty (&serio_event_list)); -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE ); +try_to_freeze (PF_FREEZE ); }while (!signal_pending (current));printk (KERN_DEBUG "serio: kseriod exiting\n" );
drivers/md/md.c +1 -3
@@ -36,7 +36,6 @@#include <linux/sysctl.h> #include <linux/devfs_fs_kernel.h> #include <linux/buffer_head.h> /* for invalidate_bdev */ -#include <linux/suspend.h> #include <linux/init.h>
@@ -2761,6 +2760,7 @@*/ daemonize (thread->name,mdname (thread->mddev)); + current->flags |=PF_NOFREEZE ; current->exit_signal =SIGCHLD ;allow_signal (SIGKILL );
@@ -2785,8 +2785,6 @@wait_event_interruptible (thread->wqueue,test_bit (THREAD_WAKEUP , &thread->flags)); -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE );clear_bit (THREAD_WAKEUP , &thread->flags);
drivers/media/video/msp3400.c +5 -2
@@ -741,6 +741,7 @@ {DECLARE_WAITQUEUE (wait, current); +again:add_wait_queue (&msp->wq, &wait);if (!kthread_should_stop ()) {if (timeout <0 ) {
@@ -756,9 +757,11 @@#endif } } -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE );remove_wait_queue (&msp->wq, &wait); + +if (try_to_freeze (PF_FREEZE )) + goto again; +return msp->restart; }
drivers/media/video/tvaudio.c +1 -0
@@ -285,6 +285,7 @@schedule (); }remove_wait_queue (&chip->wq, &wait); +try_to_freeze (PF_FREEZE );if (chip->done ||signal_pending (current))break ;dprintk ("%s: thread wakeup\n" ,i2c_clientname (&chip->c));
drivers/mtd/mtd_blkdevs.c +2 -0
@@ -113,6 +113,8 @@schedule ();remove_wait_queue (&tr->blkcore_priv->thread_wq, &wait); +try_to_freeze (PF_FREEZE ); +spin_lock_irq (rq->queue_lock);continue ;
drivers/net/8139too.c +1 -3
@@ -108,7 +108,6 @@#include <linux/mii.h> #include <linux/completion.h> #include <linux/crc32.h> -#include <linux/suspend.h> #include <asm/io.h> #include <asm/uaccess.h> #include <asm/irq.h>
@@ -1624,8 +1623,7 @@do { timeout =interruptible_sleep_on_timeout (&tp->thr_wait, timeout);/* make swsusp happy with our thread */ -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE ); +try_to_freeze (PF_FREEZE ); }while (!signal_pending (current) && (timeout >0 ));if (signal_pending (current)) {
drivers/net/irda/sir_kthread.c +1 -5
@@ -19,7 +19,6 @@#include <linux/smp_lock.h> #include <linux/completion.h> #include <linux/delay.h> -#include <linux/suspend.h> #include <net/irda/irda.h>
@@ -113,6 +112,7 @@DECLARE_WAITQUEUE (wait, current);daemonize ("kIrDAd" ); + current->flags |=PF_NOFREEZE ; irda_rq_queue.thread = current;
@@ -135,10 +135,6 @@__set_task_state (current,TASK_RUNNING );remove_wait_queue (&irda_rq_queue.kick, &wait); -/* make swsusp happy with our thread */ -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE ); -run_irda_queue (); }
drivers/net/irda/stir4200.c +0 -1
@@ -46,7 +46,6 @@#include <linux/time.h> #include <linux/skbuff.h> #include <linux/netdevice.h> -#include <linux/suspend.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/usb.h>
drivers/net/wireless/airo.c +1 -3
@@ -33,7 +33,6 @@#include <linux/string.h> #include <linux/timer.h> #include <linux/interrupt.h> -#include <linux/suspend.h> #include <linux/in.h> #include <linux/bitops.h> #include <asm/io.h>
@@ -2918,8 +2917,7 @@flush_signals (current);/* make swsusp happy with our thread */ -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE ); +try_to_freeze (PF_FREEZE );if (test_bit (JOB_DIE , &ai->flags))break ;
drivers/pcmcia/cs.c +1 -3
@@ -48,7 +48,6 @@#include <linux/pm.h> #include <linux/pci.h> #include <linux/device.h> -#include <linux/suspend.h> #include <asm/system.h> #include <asm/irq.h>
@@ -718,8 +717,7 @@ }schedule (); -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE ); +try_to_freeze (PF_FREEZE );if (!skt->thread)break ;
drivers/pcmcia/socket_sysfs.c +0 -1
@@ -25,7 +25,6 @@#include <linux/pm.h> #include <linux/pci.h> #include <linux/device.h> -#include <linux/suspend.h> #include <asm/system.h> #include <asm/irq.h>
drivers/pnp/pnpbios/core.c +4 -0
@@ -179,6 +179,10 @@* Poll every 2 seconds */ msleep_interruptible (2000 ); + +if (current->flags &PF_FREEZE ) +refrigerator (PF_FREEZE ); +if (signal_pending (current))break ;
drivers/scsi/libata-core.c +0 -1
@@ -35,7 +35,6 @@#include <linux/timer.h> #include <linux/interrupt.h> #include <linux/completion.h> -#include <linux/suspend.h> #include <linux/workqueue.h> #include <scsi/scsi.h> #include "scsi.h"
drivers/usb/core/hub.c +1 -3
@@ -26,7 +26,6 @@#include <linux/ioctl.h> #include <linux/usb.h> #include <linux/usbdevice_fs.h> -#include <linux/suspend.h> #include <asm/semaphore.h> #include <asm/uaccess.h>
@@ -2713,8 +2712,7 @@do {hub_events ();wait_event_interruptible (khubd_wait, !list_empty (&hub_event_list)); -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE ); +try_to_freeze (PF_FREEZE ); }while (!signal_pending (current));pr_debug ("%s: khubd exiting\n" , usbcore_name);
drivers/w1/w1.c +2 -5
@@ -32,7 +32,6 @@#include <linux/device.h> #include <linux/slab.h> #include <linux/sched.h> -#include <linux/suspend.h> #include "w1.h" #include "w1_io.h"
@@ -628,8 +627,7 @@ timeout = w1_timeout*HZ ;do { timeout =interruptible_sleep_on_timeout (&w1_control_wait, timeout); -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE ); +try_to_freeze (PF_FREEZE ); }while (!signal_pending (current) && (timeout >0 ));if (signal_pending (current))
@@ -701,8 +699,7 @@ timeout = w1_timeout*HZ ;do { timeout =interruptible_sleep_on_timeout (&dev->kwait, timeout); -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE ); +try_to_freeze (PF_FREEZE ); }while (!signal_pending (current) && (timeout >0 ));if (signal_pending (current))
fs/afs/kafsasyncd.c +2 -0
@@ -116,6 +116,8 @@remove_wait_queue (&kafsasyncd_sleepq, &myself);set_current_state (TASK_RUNNING ); +try_to_freeze (PF_FREEZE ); +/* discard pending signals */ afs_discard_my_signals ();
fs/afs/kafstimod.c +2 -0
@@ -91,6 +91,8 @@complete_and_exit (&kafstimod_dead,0 ); } +try_to_freeze (PF_FREEZE ); +/* discard pending signals */ afs_discard_my_signals ();
fs/buffer.c +54 -2
145 lines not on this page · raw message
fs/jbd/journal.c +1 -0
@@ -130,6 +130,7 @@ current_journal = journal;daemonize ("kjournald" ); + current->flags |=PF_SYNCTHREAD ;/* Set up an interval timer which can be used to trigger a commit wakeup after the commit interval expires */
fs/jffs/intrep.c +4 -0
@@ -3338,6 +3338,7 @@ D1(int i = 1);daemonize ("jffs_gcd" ); + current->flags |=PF_SYNCTHREAD ; c->gc_task = current;
@@ -3373,6 +3374,9 @@siginfo_t info;unsigned long signr =0 ; +if (try_to_freeze (PF_FREEZE )) +continue ; +spin_lock_irq (¤t->sighand->siglock); signr =dequeue_signal (current, ¤t->blocked, &info);spin_unlock_irq (¤t->sighand->siglock);
fs/jffs2/background.c +1 -6
@@ -15,7 +15,6 @@#include <linux/jffs2.h> #include <linux/mtd/mtd.h> #include <linux/completion.h> -#include <linux/suspend.h> #include "nodelist.h"
@@ -93,12 +92,8 @@schedule (); } -if (current->flags &PF_FREEZE ) { -refrigerator (0 ); -/* refrigerator() should recalc sigpending for us -but doesn't. No matter - allow_signal() will. */ +if (try_to_freeze (0 ))continue ; - }cond_resched ();
fs/jfs/jfs_logmgr.c +1 -0
@@ -2316,6 +2316,7 @@struct lbuf *bp;daemonize ("jfsIO" ); + current->flags |=PF_SYNCTHREAD ;complete (&jfsIOwait);
fs/jfs/jfs_txnmgr.c +1 -1
@@ -47,7 +47,6 @@#include <linux/vmalloc.h> #include <linux/smp_lock.h> #include <linux/completion.h> -#include <linux/suspend.h> #include <linux/module.h> #include <linux/moduleparam.h> #include "jfs_incore.h"
@@ -2727,6 +2726,7 @@struct jfs_sb_info *sbi;daemonize ("jfsCommit" ); + current->flags |=PF_SYNCTHREAD ;complete (&jfsIOwait);
fs/lockd/clntlock.c +2 -0
@@ -200,6 +200,7 @@struct inode *inode;daemonize ("%s-reclaim" , host->h_name); + current->flags |=PF_SYNCTHREAD ;allow_signal (SIGKILL );/* This one ensures that our parent doesn't terminate while the
@@ -222,6 +223,7 @@ fl->fl_u.nfs_fl.flags &= ~NFS_LCK_RECLAIM ;nlmclnt_reclaim (host, fl); +try_to_freeze (PF_FREEZE );if (signalled ())break ; goto restart;
fs/lockd/clntproc.c +1 -0
@@ -310,6 +310,7 @@prepare_to_wait (queue, &wait,TASK_INTERRUPTIBLE );if (!signalled ()) {schedule_timeout (NLMCLNT_GRACE_WAIT ); +try_to_freeze (PF_FREEZE );if (!signalled ()) status =0 ; }
fs/lockd/svc.c +3 -0
@@ -112,6 +112,7 @@up (&lockd_start);daemonize ("lockd" ); + current->flags |=PF_SYNCTHREAD ;/* Process request with signals blocked, but allow SIGKILL. */ allow_signal (SIGKILL );
@@ -135,6 +136,8 @@while ((nlmsvc_users || !signalled ()) && nlmsvc_pid == current->pid) {long timeout =MAX_SCHEDULE_TIMEOUT ; +try_to_freeze (PF_SYNCTHREAD ); +if (signalled ()) {flush_signals (current);if (nlmsvc_ops) {
fs/nfsd/nfssvc.c +1 -0
@@ -180,6 +180,7 @@/* Lock module and set up kernel thread */ lock_kernel ();daemonize ("nfsd" ); + current->flags |=PF_SYNCTHREAD ;/* After daemonize() this kernel thread shares current->fs * with the init process. We need to create files with a
fs/reiserfs/journal.c +0 -1
@@ -50,7 +50,6 @@#include <linux/stat.h> #include <linux/string.h> #include <linux/smp_lock.h> -#include <linux/suspend.h> #include <linux/buffer_head.h> #include <linux/workqueue.h> #include <linux/writeback.h>
fs/xfs/linux-2.6/xfs_buf.c +2 -5
@@ -51,7 +51,6 @@#include <linux/sysctl.h> #include <linux/proc_fs.h> #include <linux/workqueue.h> -#include <linux/suspend.h> #include <linux/percpu.h> #include "xfs_linux.h"
@@ -1657,7 +1656,7 @@/* Set up the thread */ daemonize ("xfsbufd" ); - current->flags |=PF_MEMALLOC ; + current->flags |=PF_MEMALLOC |PF_SYNCTHREAD ; pagebuf_daemon_task = current; pagebuf_daemon_active =1 ;
@@ -1665,9 +1664,7 @@INIT_LIST_HEAD (&tmp); do { - /* swsusp */ - if (current->flags & PF_FREEZE) - refrigerator(PF_FREEZE); + try_to_freeze(PF_FREEZE); set_current_state(TASK_INTERRUPTIBLE); schedule_timeout((xfs_buf_timer_centisecs * HZ) / 100);
fs/xfs/linux-2.6/xfs_super.c +2 -3
@@ -71,7 +71,6 @@#include <linux/namei.h> #include <linux/init.h> #include <linux/mount.h> -#include <linux/suspend.h> #include <linux/writeback.h> STATIC struct quotactl_ops linvfs_qops;
@@ -472,6 +471,7 @@struct vfs_sync_work *work, *n;daemonize ("xfssyncd" ); + current->flags |=PF_SYNCTHREAD ; vfsp->vfs_sync_work.w_vfs = vfsp; vfsp->vfs_sync_work.w_syncer = vfs_sync_worker;
@@ -485,8 +485,7 @@set_current_state (TASK_INTERRUPTIBLE ); timeleft =schedule_timeout (timeleft);/* swsusp */ -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE ); +try_to_freeze (PF_FREEZE );if (vfsp->vfs_flag &VFS_UMOUNT )break ;
include/linux/sched.h +35 -1
@@ -19,6 +19,7 @@#include <asm/page.h> #include <asm/ptrace.h> #include <asm/mmu.h> +#include <asm/current.h> #include <linux/smp.h> #include <linux/sem.h>
@@ -701,7 +702,7 @@#define PF_MEMDIE 0x00001000/* Killed for out-of-memory */ #define PF_FLUSHER 0x00002000/* responsible for disk writeback */ -#define PF_FREEZE 0x00004000/* this task should be frozen for suspend */ +#define PF_FREEZE 0x00004000/* this task is being frozen for suspend now */ #define PF_NOFREEZE 0x00008000/* this thread should not be frozen */ #define PF_FROZEN 0x00010000/* frozen for system suspend */ #define PF_FSTRANS 0x00020000/* inside a filesystem transaction */
@@ -710,6 +711,8 @@#define PF_LESS_THROTTLE 0x00100000/* Throttle me less: I clean memory */ #define PF_SYNCWRITE 0x00200000/* I am doing a sync write */ #define PF_BORROWED_MM 0x00400000/* I am a kthread doing use_mm */ +#define PF_SYNCTHREAD 0x00800000/* this thread can start activity during the +early part of freezing processes */ #ifdef CONFIG_SMP extern int set_cpus_allowed (task_t *p,cpumask_t new_mask);
@@ -720,6 +723,29 @@ }#endif +/* try_to_freeze +* +* Checks whether we need to enter the refrigerator +* and returns 1 if we did so. +*/ +#ifdef CONFIG_PM +extern void refrigerator (unsigned long ); + +static inline int try_to_freeze (unsigned long refrigerator_flags) +{ +if (unlikely (current->flags &PF_FREEZE )) { +refrigerator (refrigerator_flags); +return 1 ; + }else +return 0 ; +} +#else +static inline int try_to_freeze (unsigned long refrigerator_flags) +{ +return 0 ; +} +#endif +extern unsigned long long sched_clock (void );/* sched_exec is called by processes performing an exec */
@@ -1119,6 +1145,14 @@#endif +#ifdef CONFIG_PM +extern void refrigerator (unsigned long ); +extern unsigned int suspend_task; +#else +#define refrigerator (a) do { } while(0) +#define suspend_task (0) +#endif +#endif /* __KERNEL__ */ #endif
kernel/exit.c +3 -0
@@ -15,6 +15,7 @@#include <linux/module.h> #include <linux/completion.h> #include <linux/personality.h> +#include <linux/suspend.h> #include <linux/tty.h> #include <linux/namespace.h> #include <linux/key.h>
@@ -802,6 +803,8 @@panic ("Attempted to kill init!" );if (tsk->io_context)exit_io_context (); +if (unlikely (test_suspend_state (SUSPEND_FREEZER_ON ))) +refrigerator (0 ); tsk->flags |=PF_EXITING ;del_timer_sync (&tsk->real_timer);
kernel/fork.c +5 -0
@@ -39,6 +39,7 @@#include <linux/audit.h> #include <linux/profile.h> #include <linux/rmap.h> +#include <linux/suspend.h> #include <asm/pgtable.h> #include <asm/pgalloc.h>
@@ -1125,6 +1126,10 @@int trace =0 ;long pid =alloc_pidmap (); + +if (unlikely (test_suspend_state (SUSPEND_FREEZER_ON ))) +refrigerator (0 ); +if (pid <0 )return -EAGAIN ;if (unlikely (current->ptrace)) {
kernel/power/disk.c +3 -3
@@ -116,7 +116,7 @@device_resume ();platform_finish ();enable_nonboot_cpus (); -thaw_processes (); +thaw_processes (FREEZER_ALL_THREADS );pm_restore_console (); }
@@ -128,7 +128,7 @@pm_prepare_console ();sys_sync (); -if (freeze_processes ()) { +if (freeze_processes (1 )) { error = -EBUSY ; goto Thaw; }
@@ -152,7 +152,7 @@platform_finish (); Thaw:enable_nonboot_cpus (); -thaw_processes (); +thaw_processes (FREEZER_ALL_THREADS );pm_restore_console ();return error; }
kernel/power/main.c +3 -3
@@ -55,7 +55,7 @@pm_prepare_console (); -if (freeze_processes ()) { +if (freeze_processes (1 )) { error = -EAGAIN ; goto Thaw; }
@@ -72,7 +72,7 @@if (pm_ops->finish) pm_ops->finish (state); Thaw: -thaw_processes (); +thaw_processes (FREEZER_ALL_THREADS );pm_restore_console ();return error; }
@@ -107,7 +107,7 @@device_resume ();if (pm_ops && pm_ops->finish) pm_ops->finish (state); -thaw_processes (); +thaw_processes (FREEZER_ALL_THREADS );pm_restore_console (); }
kernel/power/power.h +2 -2
@@ -45,8 +45,8 @@extern struct subsystem power_subsys; -extern int freeze_processes (void ); -extern void thaw_processes (void ); +extern int freeze_processes (int no_progress); +extern void thaw_processes (int which_threads);extern int pm_prepare_console (void );extern void pm_restore_console (void );
kernel/power/process.c +473 -73
594 lines not on this page · raw message
kernel/signal.c +3 -2
@@ -2178,10 +2178,11 @@sigandsets (¤t->blocked, ¤t->blocked, &these);recalc_sigpending ();spin_unlock_irq (¤t->sighand->siglock); - current->state =TASK_INTERRUPTIBLE ; timeout =schedule_timeout (timeout); - +if (current->flags &PF_FREEZE ) { +refrigerator (PF_FREEZE ); + }spin_lock_irq (¤t->sighand->siglock); sig =dequeue_signal (current, &these, &info); current->blocked = current->real_blocked;
mm/pdflush.c +2 -4
@@ -17,7 +17,6 @@#include <linux/gfp.h> #include <linux/init.h> #include <linux/module.h> -#include <linux/suspend.h> #include <linux/fs.h> // Needed by writeback.h #include <linux/writeback.h> // Prototypes pdflush_operation() #include <linux/kthread.h>
@@ -90,7 +89,7 @@static int __pdflush (struct pdflush_work *my_work) { - current->flags |=PF_FLUSHER ; + current->flags |= (PF_FLUSHER |PF_SYNCTHREAD ); my_work->fn =NULL ; my_work->who = current;INIT_LIST_HEAD (&my_work->list);
@@ -106,8 +105,7 @@spin_unlock_irq (&pdflush_lock);schedule (); -if (current->flags &PF_FREEZE ) { -refrigerator (PF_FREEZE ); +if (try_to_freeze (PF_FREEZE )) {spin_lock_irq (&pdflush_lock);continue ; }
mm/vmscan.c +1 -3
@@ -21,7 +21,6 @@#include <linux/highmem.h> #include <linux/file.h> #include <linux/writeback.h> -#include <linux/suspend.h> #include <linux/blkdev.h> #include <linux/buffer_head.h> /* for try_to_release_page(), buffer_heads_over_limit */
@@ -1170,8 +1169,7 @@ tsk->flags |=PF_MEMALLOC |PF_KSWAPD ;for ( ; ; ) { -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE ); +try_to_freeze (PF_FREEZE );prepare_to_wait (&pgdat->kswapd_wait, &wait,TASK_INTERRUPTIBLE );schedule ();finish_wait (&pgdat->kswapd_wait, &wait);
net/bluetooth/rfcomm/core.c +2 -0
@@ -1726,6 +1726,8 @@schedule (); } +try_to_freeze (PF_FREEZE ); +/* Process stuff */ clear_bit (RFCOMM_SCHED_WAKEUP , &rfcomm_event);rfcomm_process_sessions ();
net/rxrpc/krxiod.c +2 -0
@@ -138,6 +138,8 @@_debug ("### End Work" ); +try_to_freeze (PF_FREEZE ); +/* discard pending signals */ rxrpc_discard_my_signals ();
net/rxrpc/krxsecd.c +2 -0
@@ -107,6 +107,8 @@_debug ("### End Inbound Calls" ); +try_to_freeze (PF_FREEZE ); +/* discard pending signals */ rxrpc_discard_my_signals ();
net/rxrpc/krxtimod.c +2 -0
@@ -90,6 +90,8 @@complete_and_exit (&krxtimod_dead,0 ); } +try_to_freeze (PF_FREEZE ); +/* discard pending signals */ rxrpc_discard_my_signals ();
net/sunrpc/sched.c +0 -1
@@ -18,7 +18,6 @@#include <linux/smp.h> #include <linux/smp_lock.h> #include <linux/spinlock.h> -#include <linux/suspend.h> #include <linux/sunrpc/clnt.h> #include <linux/sunrpc/xprt.h>
net/sunrpc/svcsock.c +2 -3
@@ -31,7 +31,6 @@#include <linux/slab.h> #include <linux/netdevice.h> #include <linux/skbuff.h> -#include <linux/suspend.h> #include <net/sock.h> #include <net/checksum.h> #include <net/ip.h>
@@ -1187,6 +1186,7 @@ arg->len = (pages-1 )*PAGE_SIZE ; arg->tail[0 ].iov_len =0 ; +try_to_freeze (PF_FREEZE );if (signalled ())return -EINTR ;
@@ -1227,8 +1227,7 @@schedule_timeout (timeout); -if (current->flags &PF_FREEZE ) -refrigerator (PF_FREEZE ); +try_to_freeze (PF_FREEZE );spin_lock_bh (&serv->sv_lock);remove_wait_queue (&rqstp->rq_wait, &wait);
Re: Suspend 2 merge: 21/51: Refrigerator upgrade.
Hi!
Quoted 3 lines
Included in this patch is a new
try_to_freeze()macro Andrew M suggested a while back. The refrigerator declarations are put insched.hto save extra includes ofsuspend.h.
try_to_freeze looks nice. Could we get it in after 2.6.10 opens?
drivers/pnp/pnpbios/core.c line 188
Quoted 12 lines
+++
582-refrigerator-new/drivers/pnp/pnpbios/core.c2004-11-24 17:58:33.769748640 +1100drivers/pnp/pnpbios/core.c +4
-0@@ -179,6 +179,10 @@* Poll every 2 seconds */ msleep_interruptible (2000 ); + +if (current->flags &PF_FREEZE ) +refrigerator (PF_FREEZE ); +if (signal_pending (current))break ;
Use new interface here?
fs/buffer.c line 182
Quoted 11 lines
*/
intfsync_super(struct super_block *sb)
{fs/buffer.c +8
-0+int ret; + +/* A safety net. During suspend, we might overwrite +* memory containing filesystem info. We don't then +* want to sync it to disk. */ +if (unlikely (test_suspend_state (SUSPEND_DISABLE_SYNCING ))) +return 0 ; +
If it is safety net, do BUG_ON().
Pavel
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Re: Suspend 2 merge: 21/51: Refrigerator upgrade.
Hi.
Quoted 7 lines · Pavel Machek
Hi!
Quoted 3 lines
Included in this patch is a new
try_to_freeze()macro Andrew M suggested a while back. The refrigerator declarations are put insched.hto save extra includes ofsuspend.h.
try_to_freezelooks nice. Could we get it in after 2.6.10 opens?
I'm hoping to get the whole thing in mm once all these replies are dealt with. Does that sound unrealistic?
try_to_freeze() should certainly be possible, because it was Andrew's idea to start with.
Quoted 6 lines
Quoted 6 lines
+++
582-refrigerator-new/drivers/pnp/pnpbios/core.c2004-11-24 17:58:33.769748640 +1100drivers/pnp/pnpbios/core.c +1
-0@@ -179,6 +179,10 @@* Poll every 2 seconds */ msleep_interruptible (2000 ); +
Quoted 8 lines
drivers/pnp/pnpbios/core.c line 188
Quoted 6 lines
drivers/pnp/pnpbios/core.c +3
-0+if (current->flags &PF_FREEZE ) +refrigerator (PF_FREEZE ); +if (signal_pending (current))break ;Use new interface here?
Could do. Will change.
Quoted 5 lines
Quoted 5 lines
*/
intfsync_super(struct super_block *sb)
{(quoted diff) +2
-0+ int ret; +
Quoted 8 lines
fs/buffer.c line 182
Quoted 6 lines
fs/buffer.c +6
-0+/* A safety net. During suspend, we might overwrite +* memory containing filesystem info. We don't then +* want to sync it to disk. */ +if (unlikely (test_suspend_state (SUSPEND_DISABLE_SYNCING ))) +return 0 ; +If it is safety net, do
BUG_ON().
Could get triggered by user pressing SysRq. (Or via a panic?). I don't think the SysRq should result in a panic; nor should a panic result in a recursive call to panic (although I'm wondering here, wasn't the call to syncing in panic taken out?).
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 21/51: Refrigerator upgrade.
Hi!
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Included in this patch is a new
try_to_freeze()macro Andrew M suggested a while back. The refrigerator declarations are put insched.hto save extra includes ofsuspend.h.
try_to_freezelooks nice. Could we get it in after 2.6.10 opens?I'm hoping to get the whole thing in mm once all these replies are dealt with. Does that sound unrealistic?
Yes, a little ;-).
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
*/
intfsync_super(struct super_block *sb)
{(quoted diff) +2
-0+ int ret; +Quoted 8 lines
fs/buffer.c line 182
Quoted 6 lines
fs/buffer.c +6
-0+/* A safety net. During suspend, we might overwrite +* memory containing filesystem info. We don't then +* want to sync it to disk. */ +if (unlikely (test_suspend_state (SUSPEND_DISABLE_SYNCING ))) +return 0 ; +If it is safety net, do
BUG_ON().
Quoted 4 lines
Could get triggered by user pressing SysRq. (Or via a panic?). I don't think the SysRq should result in a panic; nor should a panic result in a recursive call to panic (although I'm wondering here, wasn't the call to syncing in panic taken out?).
Silently doing nothing when user asked for sync is not nice, either. BUG() is better solution than that.
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!
Re: Suspend 2 merge: 21/51: Refrigerator upgrade.
Hi.
Quoted 6 lines · Pavel Machek
Hi!
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Included in this patch is a new
try_to_freeze()macro Andrew M suggested a while back. The refrigerator declarations are put insched.hto save extra includes ofsuspend.h.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
try_to_freezelooks nice. Could we get it in after 2.6.10 opens?I'm hoping to get the whole thing in mm once all these replies are dealt with. Does that sound unrealistic?
Yes, a little ;-).
I'm not talking about talking about problems and then doing nothing :> I'm writing a list of changes as I look at each of these responses. Assuming they're all addressed (or not changed for good reasons), and the code is actually useful, why shouldn't it go into mm?
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
fs/buffer.c line 182
Quoted 11 lines
*/
intfsync_super(struct super_block *sb)
{fs/buffer.c +8
-0+int ret; + +/* A safety net. During suspend, we might overwrite +* memory containing filesystem info. We don't then +* want to sync it to disk. */ +if (unlikely (test_suspend_state (SUSPEND_DISABLE_SYNCING ))) +return 0 ; +If it is safety net, do
BUG_ON().
Quoted 7 lines
Quoted 4 lines
Could get triggered by user pressing SysRq. (Or via a panic?). I don't think the SysRq should result in a panic; nor should a panic result in a recursive call to panic (although I'm wondering here, wasn't the call to syncing in panic taken out?).
Silently doing nothing when user asked for sync is not nice, either.
BUG()is better solution than that.
I don't think we should BUG because the user presses Sys-Rq S while suspending. I'll make it BUG_ON() and make the Sys_Rq printk & ignore when suspending. Sound reasonable?
Regards,
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 21/51: Refrigerator upgrade.
Hi!
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Included in this patch is a new
try_to_freeze()macro Andrew M suggested a while back. The refrigerator declarations are put insched.hto save extra includes ofsuspend.h.
try_to_freezelooks nice. Could we get it in after 2.6.10 opens?I'm hoping to get the whole thing in mm once all these replies are dealt with. Does that sound unrealistic?
Quoted 6 lines
Quoted 1 line
Yes, a little ;-).
I'm not talking about talking about problems and then doing nothing :> I'm writing a list of changes as I look at each of these responses. Assuming they're all addressed (or not changed for good reasons), and the code is actually useful, why shouldn't it go into mm?
It has chance to go into mm, but I do not think all 51 patches will go at once. And I expect few more rounds of patches / comments. (And then some patch / "it is too big" flamewar, too :-).
Quoted 6 lines
Quoted 2 lines
Silently doing nothing when user asked for sync is not nice, either.
BUG()is better solution than that.I don't think we should BUG because the user presses Sys-Rq S while suspending. I'll make it
BUG_ON()and make theSys_Rqprintk & ignore when suspending. Sound reasonable?
Yes, that's better. ... only that it means just another hook somewhere :-(.
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!
Re: Suspend 2 merge: 21/51: Refrigerator upgrade.
Hi.
Quoted 13 lines · Pavel Machek
Hi!
Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Included in this patch is a new
try_to_freeze()macro Andrew M suggested a while back. The refrigerator declarations are put insched.hto save extra includes ofsuspend.h.
try_to_freezelooks nice. Could we get it in after 2.6.10 opens?I'm hoping to get the whole thing in mm once all these replies are dealt with. Does that sound unrealistic?
Yes, a little ;-).
Quoted 8 lines
Quoted 4 lines
I'm not talking about talking about problems and then doing nothing :> I'm writing a list of changes as I look at each of these responses. Assuming they're all addressed (or not changed for good reasons), and the code is actually useful, why shouldn't it go into mm?
It has chance to go into mm, but I do not think all 51 patches will go at once. And I expect few more rounds of patches / comments. (And then some patch / "it is too big" flamewar, too :-).
Didn't see any flamewar over the size of Reiser4. :>
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Silently doing nothing when user asked for sync is not nice, either.
BUG()is better solution than that.I don't think we should BUG because the user presses Sys-Rq S while suspending. I'll make it
BUG_ON()and make theSys_Rqprintk & ignore when suspending. Sound reasonable?Yes, that's better. ... only that it means just another hook somewhere :-(.
:<. But we're only talking two or three lines. Let's keep it in perspective.
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 21/51: Refrigerator upgrade.
Hi!
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Silently doing nothing when user asked for sync is not nice, either.
BUG()is better solution than that.I don't think we should BUG because the user presses Sys-Rq S while suspending. I'll make it
BUG_ON()and make theSys_Rqprintk & ignore when suspending. Sound reasonable?
Quoted 5 lines
Quoted 2 lines
Yes, that's better. ... only that it means just another hook somewhere :-(.
:<. But we're only talking two or three lines. Let's keep it in perspective.
I think even three lines are bad. It means that swsusp is no longer self-contained subsystem, but that it has its hooks all over the place. And those hooks need to be maintained, too.
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!
Re: Suspend 2 merge: 21/51: Refrigerator upgrade.
Hi.
Quoted 12 lines · Pavel Machek
Hi!
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Silently doing nothing when user asked for sync is not nice, either.
BUG()is better solution than that.I don't think we should BUG because the user presses Sys-Rq S while suspending. I'll make it
BUG_ON()and make theSys_Rqprintk & ignore when suspending. Sound reasonable?Yes, that's better. ... only that it means just another hook somewhere :-(.
Quoted 6 lines
Quoted 2 lines
:<. But we're only talking two or three lines. Let's keep it in perspective.
I think even three lines are bad. It means that swsusp is no longer self-contained subsystem, but that it has its hooks all over the place. And those hooks need to be maintained, too.
Yes, but suspending can't practically be a self contained system. We can try to convince ourselves that we're making it self contained by hiding behind the driver model, but in reality, the driver model is just a nice name for our sticky little fingers in all the other drivers, ensuring they do the right thing when we want to go to sleep. Hooks in other code is just the equivalent, but without the nice name. Perhaps I should invent one. How about the "quiescing subsystem"? :>
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Re: Suspend 2 merge: 21/51: Refrigerator upgrade.
Hi!
Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Silently doing nothing when user asked for sync is not nice, either.
BUG()is better solution than that.I don't think we should BUG because the user presses Sys-Rq S while suspending. I'll make it
BUG_ON()and make theSys_Rqprintk & ignore when suspending. Sound reasonable?Yes, that's better. ... only that it means just another hook somewhere :-(.
Quoted 6 lines
Quoted 2 lines
:<. But we're only talking two or three lines. Let's keep it in perspective.
I think even three lines are bad. It means that swsusp is no longer self-contained subsystem, but that it has its hooks all over the place. And those hooks need to be maintained, too.
Quoted 7 lines
Yes, but suspending can't practically be a self contained system. We can try to convince ourselves that we're making it self contained by hiding behind the driver model, but in reality, the driver model is just a nice name for our sticky little fingers in all the other drivers, ensuring they do the right thing when we want to go to sleep. Hooks in other code is just the equivalent, but without the nice name. Perhaps I should invent one. How about the "quiescing subsystem"? :>
I know it can't be self-contained, but it should be as self-contained as possible.
And driver-model means that interaction between swsusp and rest of the code is pretty well defined and driver authors do not need to understand the swsusp to properly support it.
Plus driver-model is usefull for suspend-to-ram, too.
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!
Re: Suspend 2 merge: 21/51: Refrigerator upgrade.
In reply to Nigel CunninghamHi!
Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Silently doing nothing when user asked for sync is not nice, either.
BUG()is better solution than that.I don't think we should BUG because the user presses Sys-Rq S while suspending. I'll make it
BUG_ON()and make theSys_Rqprintk & ignore when suspending. Sound reasonable?Yes, that's better. ... only that it means just another hook somewhere :-(.
Quoted 6 lines
Quoted 2 lines
:<. But we're only talking two or three lines. Let's keep it in perspective.
I think even three lines are bad. It means that swsusp is no longer self-contained subsystem, but that it has its hooks all over the place. And those hooks need to be maintained, too.
Quoted 7 lines
Yes, but suspending can't practically be a self contained system. We can try to convince ourselves that we're making it self contained by hiding behind the driver model, but in reality, the driver model is just a nice name for our sticky little fingers in all the other drivers, ensuring they do the right thing when we want to go to sleep. Hooks in other code is just the equivalent, but without the nice name. Perhaps I should invent one. How about the "quiescing subsystem"? :>
Actually, "quiescing subsystem" with defined (and documented!) interface might be an improvement ;-).
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!
Re: Suspend 2 merge: 21/51: Refrigerator upgrade.
In reply to Nigel CunninghamQuoted 2 lines
I'm hoping to get the whole thing in mm once all these replies are dealt with. Does that sound unrealistic?
Yes. Absolutely.
Suspend 2 merge: 41/51: Ranges (extents).
In reply to Nigel CunninghamThis is the heart of our metadata storage.
The comments at the top of range.c say it all. Ranges are used to store the which pages are in which pageset. The swapwriter uses them to store which swap addresses are allocated and what block numbers on the swap devices those addresses map to (we can't swapon at resume time to find out).
kernel/power/range.c +784 -0
@@ -0,0 +1,784 @@ +/* Suspend2 routines for manipulating ranges. +* +* (C) 2003-2004 Nigel Cunningham <[email protected]> +* +* Distributed under GPLv2. +* +* These encapsulate the manipulation of ranges. I learnt after writing this +* code that ranges are more commonly called extents. They work like this: +* +* A lot of the data that suspend saves involves continguous ranges of memory +* or storage. Let's say that we're storing data on disk in blocks 1-32768 and +* 49152-49848 of a swap partition. Rather than recording 1, 2, 3... in arrays +* pointing to the locations, we simply use: +* +* struct range { +* unsigned long min; +* unsigned long max; +* struct range * next; +* } +* +* We can then store 1-32768 and 49152-49848 in 2 struct ranges, using 24 bytes +* instead of something like 133,860. This is of course inefficient where a range +* covers only one or two values, but the benefits gained by the much larger +* ranges more than outweight these instances. +* +* Whole pages are allocated to store ranges, with unused structs being chained +* together and linked into an unused_ranges list: +* +* struct range * unused_ranges; (just below). +* +* We can fit 341 ranges in a 4096 byte page (rangepage), with 4 bytes left over. +* These four bytes, referred to as the RangePageLink, are used to link the pages +* together. The RangePageLink is a pointer to the next page, or'd with the index +* number of the page. +* +* RangePages are stored in the header of the suspend image. For portability +* between suspend time and resume time, we 'relativise' the contents of each page +* before writing them to disk. That is, each .next and each RangePageLink is +* changed to point not to an absolute location, but to the relative location in +* the list of pages. This makes all the information valid and usable (after it +* has been absolutised again, of course) regardless of where it is reloaded to +* at resume time. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/suspend.h> +#include <linux/mm.h> + +#include "pageflags.h" +#include "suspend.h" + +struct range * unused_ranges =NULL ; +int nr_unused_ranges =0 ; +int max_ranges_used =0 ; +int num_range_pages =0 ; +static unsigned long ranges_allocated =0 ; +struct range * first_range_page =NULL , * last_range_page =NULL ; + +/* Add_range_pages +* +* Allocates and initialises new pages for storing ranges. +* Returns 1 on failure to get a page. +* Otherwise adds the new pages to the unused_ranges pool and returns 0. +* During resuming, it ensures the page added doesn't collide with memory that +* will be overwritten when copying the original kernel back. +*/ + +static int add_range_pages (int number_requested) +{ +int i, j; +struct range * ranges; +void **eaten_memory =NULL , **this; + +for (j =0 ; j < number_requested; j++) { +if (test_suspend_state (SUSPEND_NOW_RESUMING )) { +struct page * pageaddr; +/* Make sure page doesn't collide when we're resuming */ +while ((this = (void **)get_zeroed_page (GFP_ATOMIC ))) { + pageaddr =virt_to_page (this); +if (!PageInUse (pageaddr)) +break ; + *this = eaten_memory; + eaten_memory = this; + } +// Free unwanted memory +while (eaten_memory) { + this = eaten_memory; + eaten_memory = *eaten_memory; +free_page ((unsigned long ) this); + } + }else + this = (void *)get_grabbed_pages (0 ); + +if (!this) +return 1 ; + + num_range_pages++; +if (!first_range_page) + first_range_page = (struct range *) this; +if (last_range_page) + *RANGEPAGELINK (last_range_page) |= (unsigned long ) this; + *RANGEPAGELINK (this) = num_range_pages; + last_range_page = (struct range *) this; + ranges = (struct range *) this; +for (i =0 ; i <RANGES_PER_PAGE ; i++) + (ranges+i)->next = (ranges+i+1 ); + (ranges + i -1 )->next = unused_ranges; + unused_ranges = ranges; + nr_unused_ranges += i; + } +return 0 ; +} + + +/* +* Free ranges. +* +* Frees pages allocated by add_range_pages() +* +* Checks that all ranges allocated have been freed and emits a warning if this +* is not true. +*/ + +int free_ranges (void ) +{ +int i; +struct range * this_range_page = first_range_page, + * next_range_page =NULL ; + +if (ranges_allocated) +printk (" *** Warning: %ld ranges still allocated when " +"free_ranges() called.\n" , ranges_allocated); + +for (i =0 ; i < num_range_pages; i++) { + next_range_page = (struct range *) + (((unsigned long ) + (*RANGEPAGELINK (this_range_page))) &PAGE_MASK ); +free_pages ((unsigned long ) this_range_page,0 ); + this_range_page = next_range_page; + } + + nr_unused_ranges = num_range_pages = ranges_allocated =0 ; + unused_ranges = last_range_page = first_range_page =NULL ; + +return 0 ; +} + +/* get_range +* +* Returns a free range, having removed it from the unused list and having +* incremented the usage count. May imply allocating a new page and may +* therefore fail, returning NULL instead. +* +* No locking. This is because we are only called from suspend, which is single +* threaded. +*/ + +static struct range *get_range (void ) +{ +struct range * result; + +if ((!unused_ranges) && (add_range_pages (1 ))) +return NULL ; + + result = unused_ranges; + unused_ranges = unused_ranges->next; + nr_unused_ranges--; + ranges_allocated++; +if (ranges_allocated > max_ranges_used) + max_ranges_used++; + result->minimum = result->maximum =0 ; + result->next =NULL ; +return result; +} + +/* +* put_range. +* +* Returns a range to the pool of unused pages and decrements the usage count. +* +* Assumes unlinking is done by the caller. +*/ +void put_range (struct range * range) +{ +if (!range) { +printk ("Error! put_range called with NULL range.\n" ); +return ; + } + range->minimum = range->maximum =0 ; + range->next = unused_ranges; + unused_ranges = range; + ranges_allocated--; + nr_unused_ranges++; +} + +/* +* put_range_chain. +* +* Returns a whole chain of ranges to the unused pool. +*/ +void put_range_chain (struct rangechain * chain) +{ +int count =0 ; +struct range * this; + +if (chain->first) { + this = chain->first; +while (this) { + this->minimum = this->maximum =0 ; + this=this->next; + } + chain->last->next = unused_ranges; + unused_ranges = chain->first; + count = chain->allocs - chain->frees; + ranges_allocated -= count; + nr_unused_ranges += count; + + chain->first =NULL ; + chain->last =NULL ; + chain->size =0 ; + chain->allocs =0 ; + chain->frees =0 ; + chain->timesusedoptimisation =0 ; + chain->lastaccessed =NULL ;/* Invalidate optimisation info */ + chain->prevtolastaccessed =NULL ; + chain->prevtoprev =NULL ; + } +} + +/* print_chain. +* +* Displays the contents of a chain. +* +* printmethod: +* 0: integer +* 1: hex +* 2: page number +*/ +void print_chain (int debuglevel,struct rangechain * chain,int printmethod) +{ +struct range * this = chain->first; +int count =0 , size =0 ; + +if ((console_loglevel < debuglevel) || (!this) || + (!TEST_DEBUG_STATE (SUSPEND_RANGES ))) +return ; + +if (!chain->name) +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"Chain %p\n" , chain); +else +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"%s\n" , chain->name); + +while (this) { +/* +* 'This' is printed separately so it is displayed if an oops +* results. +*/ +switch (printmethod) { +case 0 : +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"(%p) " , + this); +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"%lx-%lx; " , + this->minimum, this->maximum); +break ; +case 1 : +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"(%p)" , + this); +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"%lu-%lu; " , + this->minimum, this->maximum); +break ; +case 2 : +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"(%p)" , + this); +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"%p-%p; " , +page_address (mem_map+this->minimum), +page_address (mem_map+this->maximum) + +PAGE_SIZE -1 ); +break ; + } + size+= this->maximum - this->minimum +1 ; + this = this->next; + count++; +if (!(count%4 )) +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"\n" ); + } + +if ((count%4 )) +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"\n" ); + +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"%d entries/%ld allocated. " +"Allocated %d and freed %d. Size %d." , + count, + ranges_allocated, + chain->allocs, + chain->frees, + size); +if (count != (chain->allocs - chain->frees)) { + chain->debug =1 ; +check_shift_keys (1 ,"Discrepancy in chain." ); + } +suspend_message (SUSPEND_RANGES , debuglevel,1 ,"\n" ); +} + +/* +* add_to_range_chain. +* +* Takes a value to be stored and a pointer to a chain and adds the value to +* the range chain, merging with an existing range or adding a new entry as +* necessary. Ranges are stored in increasing order. +* +* Values should be consecutive, and so may need to be transformed first. (eg +* for pages, would want to call with page-mem_map). +* +* Important optimisation: +* We store in the chain info the location of the last range accessed or added +* (and its previous). If the next value is outside this range by one, we start +* from the previous entry instead of the start of the chain. In cases of heavy +* fragmentation, this saves a lot of time searching. +* +* Returns: +* 0 if successful +* 1 if the value is already included. +* 2 if unable to allocate memory. +* 3 if fall out bottom (shouldn't happen). +*/ + +int add_to_range_chain (struct rangechain * chain,unsigned long value) +{ +struct range * this, * prev =NULL , * prevtoprev =NULL ; +int usedoptimisation =0 ; + +if (!chain->first) {/* Empty */ + chain->last = chain->first =get_range (); +if (!chain->first) { +printk ("Error unable to allocate the first range for " +"the chain.\n" ); +return 2 ; + } + chain->allocs++; + chain->first->maximum = value; + chain->first->minimum = value; + chain->size++; +return 0 ; + } + + this = chain->first; + +if (chain->lastaccessed && chain->prevtolastaccessed && + chain->prevtoprev) { +if ((value +1 ) == chain->lastaccessed->minimum) { + prev = chain->prevtoprev; + this = chain->prevtolastaccessed; + usedoptimisation =1 ; + }else if (((value -1 ) == chain->lastaccessed->maximum)) { + prev = chain->prevtolastaccessed; + this = chain->lastaccessed; + usedoptimisation =1 ; + } + } + +while (this) { +/* Need new entry prior to this? */ +if ((value +1 ) < this->minimum) { +struct range * new =get_range (); +if (!new) +return 2 ; + chain->allocs++; + new->minimum = value; + new->maximum = value; + new->next = this; +/* Prior to start of chain? */ +if (!prev) + chain->first = new; +else + prev->next = new; +if (!usedoptimisation) { + chain->prevtoprev = prevtoprev; + chain->prevtolastaccessed = prev; + chain->lastaccessed = new; + } + chain->size++; +return 0 ; + } + +if ((this->minimum <= value) && (this->maximum >= value)) { +if (chain->name) +printk ("%s:" , chain->name); +else +printk ("%p:" , chain); +printk ("Trying to add a value (%ld/0x%lx) already " +"included in chain.\n" , + value, value); +print_chain (SUSPEND_ERROR , chain,0 ); +check_shift_keys (1 ,NULL ); +return 1 ; + } +if ((value +1 ) == this->minimum) { + this->minimum = value; +if (!usedoptimisation) { + chain->prevtoprev = prevtoprev; + chain->prevtolastaccessed = prev; + chain->lastaccessed = this; + } + chain->size++; +return 0 ; + } +if ((value -1 ) == this->maximum) { +if ((this->next) && + (this->next->minimum == value +1 )) { +struct range * oldnext = this->next; + this->maximum = this->next->maximum; + this->next = this->next->next; +if ((chain->last) == oldnext) + chain->last = this; +put_range (oldnext); +/* Invalidate optimisation info */ + chain->lastaccessed =NULL ; + chain->frees++; +if (!usedoptimisation) { + chain->prevtoprev = prevtoprev; + chain->prevtolastaccessed = prev; + chain->lastaccessed = this; + } + chain->size++; +return 0 ; + } + this->maximum = value; +if (!usedoptimisation) { + chain->prevtoprev = prevtoprev; + chain->prevtolastaccessed = prev; + chain->lastaccessed = this; + } + chain->size++; +return 0 ; + } +if (!this->next) { +struct range * new =get_range (); +if (!new) { +printk ("Error unable to append a new range to " +"the chain.\n" ); +return 2 ; + } + chain->allocs++; + new->minimum = value; + new->maximum = value; + new->next =NULL ; + this->next = new; + chain->last = new; +if (!usedoptimisation) { + chain->prevtoprev = prev; + chain->prevtolastaccessed = this; + chain->lastaccessed = new; + } + chain->size++; +return 0 ; + } + prevtoprev = prev; + prev = this; + this = this->next; + } +printk ("\nFell out the bottom of add_to_range_chain. This shouldn't " +"happen!\n" ); +SET_RESULT_STATE (SUSPEND_ABORTED ); +return 3 ; +} + +/* append_range +* Used where we know a range is to be added to the end of the list +* and does not need merging with the current last range. +* (count_data_pages only at the moment) +*/ + +int append_range_to_range_chain (struct rangechain * chain, +unsigned long minimum,unsigned long maximum) +{ +struct range * newrange =NULL ; + + newrange =get_range (); +if (!newrange) { +printk ("Error unable to append a new range to the chain.\n" ); +return 2 ; + } + + chain->allocs++; + chain->size+= (maximum - minimum +1 ); + newrange->minimum = minimum; + newrange->maximum = maximum; + newrange->next =NULL ; + +if (chain->last) { + chain->last->next = newrange; + chain->last = newrange; + }else + chain->last = chain->first = newrange; + +/* No need to reset optimisation info since added to end */ +return 0 ; +} + +int append_to_range_chain (int chain,unsigned long min,unsigned long max) +{ +int result =0 ; + +switch (chain) { +case 0 : +return 0 ; +case 1 : + result =append_range_to_range_chain ( + &pagedir1.origranges, min, max); +break ; +case 2 : + result =append_range_to_range_chain ( + &pagedir2.origranges, min, max); +if (!result) + result =append_range_to_range_chain ( + &pagedir1.destranges, min, max); + } +return result; +} + +/* -------------- Routines for relativising and absoluting ranges ------------- +* +* Prepare rangesets for save by translating addresses to relative indices. +*/ +void relativise_ranges (void ) +{ +struct range * this_range_page = first_range_page; +int i; + +while (this_range_page) { +struct range * this_range = this_range_page; +for (i =0 ; i <RANGES_PER_PAGE ; i++) { +if (this_range->next) { +struct range * orig = this_range->next; + this_range->next = +RANGE_RELATIVE (this_range->next); +suspend_message (SUSPEND_RANGES ,SUSPEND_VERBOSE ,1 , +"Relativised range %d on this page is %p. Absolutised range is %p.\n" , + i, this_range->next, orig); + } + this_range++; + } + this_range_page = (struct range *) + ((*RANGEPAGELINK (this_range_page)) &PAGE_MASK ); + } +} + +/* Convert ->next pointers for ranges back to absolute values. +* The issue is finding out what page the absolute value is now at. +* If we use an array of values, we gain speed, but then we need to +* be able to allocate contiguous pages. Fortunately, this is done +* prior to loading pagesets, so we can just allocate the pages +* needed, set up our array and use it and then discard the data +* before we exit. +*/ + +void absolutise_ranges () +{ +struct range * this_range_page = first_range_page; +int i; + +while (this_range_page) { +struct range * this_range = this_range_page; +for (i =0 ; i <RANGES_PER_PAGE ; i++) { +if (this_range->next) { +struct range * orig = this_range->next; + this_range->next = +RANGE_ABSOLUTE (this_range->next); +suspend_message (SUSPEND_RANGES ,SUSPEND_VERBOSE ,1 , +"Relativised range %d on this page is %p. Absolutised range is %p.\n" , + i, orig, this_range->next); + } + this_range++; + } + this_range_page = (struct range *) + ((*RANGEPAGELINK (this_range_page)) &PAGE_MASK ); + } +} + +void absolutise_chain (struct rangechain * chain) +{ +if (chain->first) + chain->first =RANGE_ABSOLUTE (chain->first); +if (chain->last) + chain->last =RANGE_ABSOLUTE (chain->last); +if (chain->lastaccessed) + chain->lastaccessed =RANGE_ABSOLUTE (chain->lastaccessed); +if (chain->prevtolastaccessed) + chain->prevtolastaccessed = +RANGE_ABSOLUTE (chain->prevtolastaccessed); +if (chain->prevtoprev) + chain->prevtoprev = +RANGE_ABSOLUTE (chain->prevtoprev); +} + +void relativise_chain (struct rangechain * chain) +{ +if (chain->first) + chain->first =RANGE_RELATIVE (chain->first); +if (chain->last) + chain->last =RANGE_RELATIVE (chain->last); +if (chain->lastaccessed) + chain->lastaccessed =RANGE_RELATIVE (chain->lastaccessed); +if (chain->prevtolastaccessed) + chain->prevtolastaccessed = +RANGE_RELATIVE (chain->prevtolastaccessed); +if (chain->prevtoprev) + chain->prevtoprev =RANGE_RELATIVE (chain->prevtoprev); +} + +/* +* Each page in the rangepages lists starts with a pointer to the next page +* containing the list. This lets us only use order zero allocations. +*/ +#define POINTERS_PER_PAGE ((PAGE_SIZE / sizeof(void *)) - 1) +static unsigned long * range_pagelist =NULL ; + +unsigned long *get_rangepages_list_entry (int index) +{ +int pagenum, offset, i; +unsigned long * current_list_page = range_pagelist; + +BUG_ON (index > num_range_pages); + + pagenum = index /POINTERS_PER_PAGE ; + offset = index - (pagenum *POINTERS_PER_PAGE ); + +for (i =0 ; i < pagenum; i++) + current_list_page = *((unsigned long **) current_list_page); + +return (unsigned long *) current_list_page[offset]; +} + +int get_rangepages_list (void ) +{ +struct range * this_range_page = first_range_page; +int i, j, pages_needed, num_in_this_page; +unsigned long * current_list_page = range_pagelist; +unsigned long * prev_list_page =NULL ; + + pages_needed = + ((num_range_pages +POINTERS_PER_PAGE -1 ) /POINTERS_PER_PAGE ); + +for (i =0 ; i < pages_needed; i++) { +int page_start = i *POINTERS_PER_PAGE ; + +if (!current_list_page) { + current_list_page = + (unsigned long *)get_grabbed_pages (0 ); +if (!current_list_page) + current_list_page = (unsigned long *)get_zeroed_page (GFP_ATOMIC ); +if (!current_list_page) { +abort_suspend ("Unable to allocate memory for a range pages list." ); +printk ("Number of range pages is %d.\n" , num_range_pages); +return -ENOMEM ; + } + + current_list_page[0 ] =0 ; +if (!prev_list_page) + range_pagelist = current_list_page; +else { + *prev_list_page = (unsigned long ) current_list_page; + prev_list_page = current_list_page; + } + } + + num_in_this_page = num_range_pages - page_start; +if (num_in_this_page >POINTERS_PER_PAGE ) + num_in_this_page =POINTERS_PER_PAGE ; + +for (j =1 ; j <= num_in_this_page; j++) { + current_list_page[j] = (unsigned long ) this_range_page; + + this_range_page = (struct range *) (((unsigned long ) + (*RANGEPAGELINK (this_range_page))) &PAGE_MASK ); + } + +for (j = (num_in_this_page +1 ); j <=POINTERS_PER_PAGE ; j++) + current_list_page[j] =0 ; + +if ((num_range_pages - page_start) >POINTERS_PER_PAGE ) + current_list_page = (unsigned long *) current_list_page[0 ]; + } + +return 0 ; +} + +void put_rangepages_list (void ) +{ +unsigned long * last; + +while (range_pagelist) { + last = range_pagelist; + range_pagelist = *((unsigned long **) range_pagelist); +free_pages ((unsigned long ) last,0 ); + } +} + +int PageRangePage (char * seeking) +{ +int i; + +for (i =1 ; i <= num_range_pages; i++) +if (get_rangepages_list_entry (i) == + (unsigned long *) seeking) +return 1 ; + +return 0 ; +} +/* relocate_rangepages +* +* Called at the start of resuming. As well as absolutising pages, we need +* to ensure they won't be overwritten by the kernel we're restoring. +*/ +int relocate_rangepages () +{ +void **eaten_memory =NULL ; +void **c = eaten_memory, *m =NULL , *f; +int oom =0 , i, numeaten =0 ; +unsigned long * prev_page =NULL ; + +for (i =1 ; i <= num_range_pages; i++) { +int this_collides =0 ; +unsigned long * this_page =get_rangepages_list_entry (i); + + this_collides =PageInUse (virt_to_page (this_page)); + +if (!this_collides) { + prev_page = this_page; +continue ; + } + +while ((m = (void *)get_zeroed_page (GFP_ATOMIC ))) { +memset (m,0 ,PAGE_SIZE ); +if (!PageInUse (virt_to_page (m))) { +copy_page (m, (void *) this_page); +free_page ((unsigned long ) this_page); +if (i ==1 ) + first_range_page = m; +else + *RANGEPAGELINK (prev_page) = + (i | (unsigned long ) m); + prev_page = m; +break ; + } + numeaten++; + eaten_memory = m; + *eaten_memory = c; + c = eaten_memory; + } + +if (!m) { +printk ("\nRan out of memory trying to relocate " +"rangepages (tried %d pages).\n" , numeaten); + oom =1 ; +break ; + } + } + + c = eaten_memory; +while (c) { + f = c; + c = *c; +if (f) +free_pages ((unsigned long ) f,0 ); + } + eaten_memory =NULL ; + +if (oom) +return -ENOMEM ; +else +return 0 ; +} + +EXPORT_SYMBOL (put_rangepages_list); +EXPORT_SYMBOL (get_rangepages_list); +EXPORT_SYMBOL (get_rangepages_list_entry); +EXPORT_SYMBOL (absolutise_chain); +EXPORT_SYMBOL (relativise_chain); +EXPORT_SYMBOL (put_range); +EXPORT_SYMBOL (put_range_chain); +EXPORT_SYMBOL (add_to_range_chain); +EXPORT_SYMBOL (PageRangePage);
Quoted 9 lines · Nigel Cunningham
Hi everyone.
I know that I still have work to do on suspend2, but thought it was high time I got around to properly submitting the code for review, so here goes.
I have it split up into 51 patches, of which most are less than 20k, although there are three 50k patches. Changes to the rest of the kernel tree come first, then the core. The full tree can be found at
Your way of merging looks rather wrong. Please submit changes against the current swsusp code that introduce one feature after another to bring it at the level you want. You'll surely have to rewrok it a lot until all reviewers are happy.
And most importantly for each patch explain exactly what feature it implements and why, etc.. "swsusp2" tells exactly nothing about the changed you do.
Hi.
Quoted 4 lines · Christoph Hellwig
Your way of merging looks rather wrong. Please submit changes against the current swsusp code that introduce one feature after another to bring it at the level you want. You'll surely have to rewrok it a lot until all reviewers are happy.
I realise that it needs further cleanup; that's why I'm submitting it now for comment and not asking 'please apply'. As to patching against swsusp, I'm purposely not doing that. The reason is that suspend2 isn't a bunch of incremental changes to swsusp. It has been redesigned from the ground up and I'd have to pull swsusp to pieces and put it back together to do the same things.
I'm thus seeking to simply merge the existing code, let Pavel and others get to the point where they're ready to say "Okay, we're satisfied that suspend2 does everything swsusp does and more and better." Then we can remove swsusp. This is the plan that was discussed with Pavel and Andrew ages ago. I've just been slow to get there because I'm doing this part-time voluntary.
Quoted 3 lines
And most importantly for each patch explain exactly what feature it implements and why, etc.. "swsusp2" tells exactly nothing about the changed you do.
Okay. The changes include:
- Almost no BUG() statements. Wherever possible, if something goes wrong, we back out and give the user a perfectly usable system back
- Speed: All I/O is asynchronous where possible and readahead used where not. Routines everywhere optimised to get things done as fast as poss. (Think low battery).
- Flexible: You can tune performance to your system in a number of ways. You can use/not use bootsplash, text output, compression drivers as you choose. You can change your swap configuration without having to reboot just to change the resume2= parameter. You can cancel a suspend if you want, or disable the possibility of doing so.
- Reliability. I haven't run the tests for a while, but Michael Frank produced a suite that was used to stress test the software (under 2.4) while running 100s (1000s at least once) of cycles. There have been some significant changes since then, but the software is essentially the same.
- Test bed: Around 10,000 downloads of the 1.0 patch, 2730 to date of the 2.1.5 version I released 2 weeks ago.
- Swap file support
- Support for LVM/dm-crypt and siblings
- Support for having device drivers as modules (resume from an initrd/initramfs)
- Almost all memory allocations are order 0, making suspend more reliable under load.
- Designed to save as much of memory as possible rather than as little (making the system more responsive post-resume).
- Support for SMP
- Support for preempt
- Support for 4GB highmem (hope to do 64GB soonish)
- Support for suspending/resuming over a network possible but not yet implemented (hope to do so soon)
I realise it's only some, but I think it gives you the jist :>
Nigel
Signature · 7 lines
Nigel Cunningham Pastoral Worker Christian Reformed Church of Tuggeranong PO Box 1004, Tuggeranong, ACT 2901 You see, at just the right time, when we were still powerless, Christ died for the ungodly. -- Romans 5:6
Hi!
Quoted 12 lines
Quoted 4 lines
Your way of merging looks rather wrong. Please submit changes against the current swsusp code that introduce one feature after another to bring it at the level you want. You'll surely have to rewrok it a lot until all reviewers are happy.
I realise that it needs further cleanup; that's why I'm submitting it now for comment and not asking 'please apply'. As to patching against swsusp, I'm purposely not doing that. The reason is that suspend2 isn't a bunch of incremental changes to swsusp. It has been redesigned from the ground up and I'd have to pull swsusp to pieces and put it back together to do the same things.
Quoted 6 lines
I'm thus seeking to simply merge the existing code, let Pavel and others get to the point where they're ready to say "Okay, we're satisfied that suspend2 does everything swsusp does and more and better." Then we can remove swsusp. This is the plan that was discussed with Pavel and Andrew ages ago. I've just been slow to get there because I'm doing this part-time voluntary.
hugang seems to show that it indeed is possible to incrementally turn swsusp into suspend2. I do not think Andrew really wanted it that way, and I thought of that as of neccessary evil.
[Okay, at this point I'll understand when you'll put my picture as a texture to some doom3 monster and shoot me thousand times... Lot of work went into suspend2, but in the meantime lot of work went into swsusp1, too...]
Quoted 8 lines
Quoted 3 lines
And most importantly for each patch explain exactly what feature it implements and why, etc.. "swsusp2" tells exactly nothing about the changed you do.
Okay. The changes include:
- Almost no
BUG()statements. Wherever possible, if something goes wrong, we back out and give the user a perfectly usable system back
Patrick did a lot of work in this area, and there are 10 BUGs() in swsusp just now. [And I do not think "no BUGs()" is a feature -- look at my comments, at one point you just ignored "can not happen condition". That's bad, it can hide real bugs.] I have no reports of swsusp1 going BUG() for users, and that's what counts.
Quoted 3 lines
- Speed: All I/O is asynchronous where possible and readahead used where not. Routines everywhere optimised to get things done as fast as poss. (Think low battery).
I fixed O(n^2) behaviour in swsusp1 (not yet in). I do not think that asynchronous I/O is does that much difference.
Quoted 5 lines
- Reliability. I haven't run the tests for a while, but Michael Frank produced a suite that was used to stress test the software (under 2.4) while running 100s (1000s at least once) of cycles. There have been some significant changes since then, but the software is essentially the same.
Well, swsusp1 is getting a lot of testing too. Is the test-suite somewhere easily available?
Quoted 2 lines
- Test bed: Around 10,000 downloads of the 1.0 patch, 2730 to date of the 2.1.5 version I released 2 weeks ago.
Hmm, look at number of downloads of 2.6.9 kernel, I think I win here ;-)))). SuSE9.2 is actually shipping swsusp1 and advertising it as a feature. And it seems to work for people...
Quoted 4 lines
- Swap file support
- Support for LVM/dm-crypt and siblings
- Support for having device drivers as modules (resume from an initrd/initramfs)
Okay, you win these.
Quoted 2 lines
- Almost all memory allocations are order 0, making suspend more reliable under load.
I'll have to fix this. Fortunately hugang already has a patch.
Quoted 2 lines
- Designed to save as much of memory as possible rather than as little (making the system more responsive post-resume).
hugang already has a patch, but I'm not 100% sure if I want it in. Yes, people seem to like this feature, but it complicates *design*, quite a lot.
Quoted 3 lines
- Support for SMP
- Support for preempt
- Support for 4GB highmem (hope to do 64GB soonish)
This works in swsusp1, too. Parts of SMP support need to be rewritten to assembly, but same is probably true for suspend2.
I'm not sure if there are still problems with swsusp1 refrigerator, if so add
- Suspend2 actually works under load
to the list.
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!