Miscellaneous patches
Subsystems (12)
cover Miscellaneous patches
These patches add a few files providing general files (version.h etc), and patch files outside kernel/power to add boot time hooks for resuming, reserve netlink socket numbers and such like.
PATCH 1/13 Suspend2 version header.
Header declaring the suspend2 version.
kernel/power/version.h | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
kernel/power/version.h new file +10 -0
@@ -0,0 +1,10 @@ +/* +* kernel/power/version.h +* +* Copyright 2004-2006 Nigel Cunningham <[email protected]> +* +* Distributed under GPLv2. +*/ + +#define SUSPEND_CORE_VERSION "2.2.6.1" +#define name_suspend "Suspend2 " SUSPEND_CORE_VERSION ": "
--
Nigel Cunningham nigel at suspend2 dot net
PATCH 2/13 Boot time hooks.
In reply to Nigel CunninghamHooks for checking whether to resume when booting.
init/do_mounts.c | 28 +++++++++++++++++++++++++--- init/do_mounts_initrd.c | 10 +++++++++- init/main.c | 4 +++- 3 files changed, 37 insertions(+), 5 deletions(-)
init/do_mounts.c +25 -3
@@ -138,11 +138,16 @@ 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
@@ -194,7 +199,8 @@ dev_t name_to_dev_t(char *name) 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" );
@@ -420,9 +426,25 @@ void __init prepare_namespace(void) 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/suspend2/do_resume and thus initiate any +* resume. If they don't do 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 )) +suspend2_try_resume (); +if (is_floppy && rd_doload &&rd_load_disk (0 ))ROOT_DEV = Root_RAM0;
init/do_mounts_initrd.c +9 -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"
@@ -59,10 +60,17 @@ static void __init handle_initrd(void) current->flags |=PF_NOFREEZE ; pid =kernel_thread (do_linuxrc,"/linuxrc" ,SIGCHLD );if (pid >0 ) { -while (pid !=sys_wait4 (-1 ,NULL ,0 ,NULL )) +while (pid !=sys_wait4 (-1 ,NULL ,0 ,NULL )) {yield (); +try_to_freeze (); + } } +if (test_suspend_state (SUSPEND_RESUME_NOT_DONE )) +printk (KERN_ERR "Suspend2: Initrd lacks echo > /proc/suspend2/do_resume.\n" ); +clear_suspend_state (SUSPEND_BOOT_TIME ); + current->flags &= ~PF_NOFREEZE ; +/* move initrd to rootfs' /old */ sys_fchdir (old_fd);sys_mount ("/" ,"." ,NULL ,MS_MOVE ,NULL );
init/main.c +3 -1
@@ -681,7 +681,9 @@ static int init(void * unused)/* * check if there is an early userspace init. If yes, let it do all -* the work +* the work. For suspend2, we assume that it will do the right thing +* with regard to trying to resume at the right place. When that +* happens, the BOOT_TIME flag will be cleared. */ if (!ramdisk_execute_command)
--
Nigel Cunningham nigel at suspend2 dot net
PATCH 3/13 Add netlink socket numbers.
In reply to Nigel CunninghamReserve netlink socket numbers for use by Suspend2 userspace helpers.
include/linux/netlink.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
include/linux/netlink.h +2 -0
@@ -21,6 +21,8 @@#define NETLINK_DNRTMSG 14/* DECnet routing messages */ #define NETLINK_KOBJECT_UEVENT 15/* Kernel messages to userspace */ #define NETLINK_GENERIC 16 +#define NETLINK_SUSPEND2_USERUI 17/* For suspend2's userui */ +#define NETLINK_SUSPEND2_USM 18/* For suspend2's userui */ #define MAX_LINKS 32
--
Nigel Cunningham nigel at suspend2 dot net
PATCH 4/13 Follow page routine.
In reply to Nigel CunninghamThis variant of the follow page routine is used by Suspend2 to find existing pages that belong to a process without changing anything in the process.
mm/memory.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
mm/memory.c +9 -0
@@ -958,6 +958,15 @@ no_page_table:return page; } +/* +* We want the address of the page for Suspend2 to mark as being in pageset1. +*/ + +struct page *suspend2_follow_page (struct mm_struct *mm,unsigned long address) +{ +return follow_page (mm->mmap, address,0 ); +} +int get_user_pages (struct task_struct *tsk,struct mm_struct *mm,unsigned long start,int len,int write,int force,struct page **pages,struct vm_area_struct **vmas)
--
Nigel Cunningham nigel at suspend2 dot net
PATCH 5/13 LRU paranoia patch.
In reply to Nigel CunninghamModify the Set/Clear LRU flag macros to also BUG_ON() when freezing is complete, iff CONFIG_PM_DEBUG is enabled. The LRU is supposed to be static before the atomic copy is made. This just helps verify that this is happening.
include/linux/page-flags.h | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
include/linux/page-flags.h +8 -0
@@ -7,6 +7,7 @@#include <linux/percpu.h> #include <linux/cache.h> +#include <linux/freezer.h> /* For Suspend2 LRU paranoid Set|ClearPageLRU definitions */ #include <asm/pgtable.h> /*
@@ -255,9 +256,16 @@ extern void __mod_page_state_offset(unsi#define TestClearPageDirty (page) test_and_clear_bit(PG_dirty, &(page)->flags)#define PageLRU (page) test_bit(PG_lru, &(page)->flags) + +#ifdef CONFIG_PM_DEBUG #define SetPageLRU (page) set_bit(PG_lru, &(page)->flags)#define ClearPageLRU (page) clear_bit(PG_lru, &(page)->flags)#define __ClearPageLRU (page) __clear_bit(PG_lru, &(page)->flags) +#else +#define SetPageLRU (page) do { BUG_ON(test_freezer_state(FREEZING_COMPLETE)); set_bit(PG_lru, &(page)->flags); } while(0) +#define ClearPageLRU (page) do { BUG_ON(test_freezer_state(FREEZING_COMPLETE)); clear_bit(PG_lru, &(page)->flags); } while(0) +#define __ClearPageLRU (page) do { BUG_ON(test_freezer_state(FREEZING_COMPLETE)); __clear_bit(PG_lru, &(page)->flags); } while(0) +#endif #define PageActive (page) test_bit(PG_active, &(page)->flags)#define SetPageActive (page) set_bit(PG_active, &(page)->flags)
--
Nigel Cunningham nigel at suspend2 dot net
PATCH 6/13 Remove __nosave declarations in power.h
In reply to Nigel CunninghamRemove __nosave_begin and __nosave_end declarations in kernel/power/power.h as they conflict with the one in include/linux/suspend2.h.
kernel/power/power.h | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
kernel/power/power.h +0 -3
@@ -35,9 +35,6 @@ static struct subsys_attribute _name##_aextern struct subsystem power_subsys; -/* References to section boundaries */ -extern const void __nosave_begin, __nosave_end; -extern struct pbe *pagedir_nosave;/* Preferred image size in bytes (default 500 MB) */
--
Nigel Cunningham nigel at suspend2 dot net
PATCH 7/13 Page_alloc paranoia.
In reply to Nigel CunninghamAdd paranoia to the page_alloc code to ensure we don't start page reclaim during suspending.
mm/page_alloc.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-)
mm/page_alloc.c +13 -5
@@ -25,6 +25,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/suspend.h> +#include <linux/freezer.h> #include <linux/pagevec.h> #include <linux/blkdev.h> #include <linux/slab.h>
@@ -37,6 +38,7 @@#include <linux/nodemask.h> #include <linux/vmalloc.h> #include <linux/mempolicy.h> +#include "../kernel/power/pageflags.h" #include <asm/tlbflush.h> #include <asm/div64.h>
@@ -905,7 +907,8 @@ get_page_from_freelist(gfp_t gfp_mask, uelse mark = (*z)->pages_high;if (!zone_watermark_ok (*z, order, mark, - classzone_idx, alloc_flags)) + classzone_idx, alloc_flags) && +likely (!test_freezer_state (FREEZER_ON )))if (!zone_reclaim_mode || !zone_reclaim (*z, gfp_mask, order))continue ;
@@ -950,10 +953,12 @@ restart:if (page) goto got_pg; -do { -if (cpuset_zone_allowed (*z, gfp_mask|__GFP_HARDWALL)) -wakeup_kswapd (*z, order); - }while (*(++z)); +if (likely (!test_freezer_state (FREEZER_ON ))) { +do { +if (cpuset_zone_allowed (*z, gfp_mask|__GFP_HARDWALL)) +wakeup_kswapd (*z, order); + }while (*(++z)); + }/* * OK, we're below the kswapd watermark and have kicked background
@@ -997,6 +1002,7 @@ nofail_alloc:if (page) goto got_pg;if (gfp_mask & __GFP_NOFAIL) { +BUG_ON (unlikely (test_freezer_state (FREEZING_COMPLETE )));blk_congestion_wait (WRITE ,HZ /50 ); goto nofail_alloc; }
@@ -1009,6 +1015,8 @@ nofail_alloc: goto nopage; rebalance: +BUG_ON (unlikely (test_freezer_state (FREEZER_ON ))); +cond_resched ();/* We now go into synchronous reclaim */
--
Nigel Cunningham nigel at suspend2 dot net
Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
Quoted 3 lines · Nigel Cunningham
Add paranoia to the
page_alloccode to ensure we don't start page reclaim during suspending.
Nack. Set PF_MEMALLOC if you must.
Quoted 72 lines
Signed-off-by Nigel Cunningham <[email protected]>mm/page_alloc.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-)mm/page_alloc.c +13
-6@@ -25,6 +25,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/suspend.h> +#include <linux/freezer.h> #include <linux/pagevec.h> #include <linux/blkdev.h> #include <linux/slab.h> @@ -37,6 +38,7 @@#include <linux/nodemask.h> #include <linux/vmalloc.h> #include <linux/mempolicy.h> +#include "../kernel/power/pageflags.h" #include <asm/tlbflush.h> #include <asm/div64.h> @@ -905,7 +907,8 @@ get_page_from_freelist(gfp_t gfp_mask, uelse mark = (*z)->pages_high;if (!zone_watermark_ok (*z, order, mark, - classzone_idx, alloc_flags)) + classzone_idx, alloc_flags) && +likely (!test_freezer_state (FREEZER_ON )))if (!zone_reclaim_mode || !zone_reclaim (*z, gfp_mask, order))continue ;@@ -950,10 +953,12 @@ restart:if (page) goto got_pg; -do { -if (cpuset_zone_allowed (*z, gfp_mask|__GFP_HARDWALL)) -wakeup_kswapd (*z, order); - }while (*(++z)); +if (likely (!test_freezer_state (FREEZER_ON ))) { +do { +if (cpuset_zone_allowed (*z, gfp_mask|__GFP_HARDWALL)) +wakeup_kswapd (*z, order); + }while (*(++z)); + }/* * OK, we're below the kswapd watermark and have kicked background @@ -997,6 +1002,7 @@ nofail_alloc:if (page) goto got_pg;if (gfp_mask & __GFP_NOFAIL) { +BUG_ON (unlikely (test_freezer_state (FREEZING_COMPLETE )));blk_congestion_wait (WRITE ,HZ /50 ); goto nofail_alloc; }@@ -1009,6 +1015,8 @@ nofail_alloc: goto nopage; rebalance: +BUG_ON (unlikely (test_freezer_state (FREEZER_ON ))); +cond_resched ();/* We now go into synchronous reclaim */ --Nigel Cunningham nigel at suspend2 dot net
Signature · 2 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
Hi.
Quoted 5 lines · Nick Piggin
Quoted 2 lines · Nigel Cunningham
Add paranoia to the
page_alloccode to ensure we don't start page reclaim during suspending.Nack. Set
PF_MEMALLOCif you must.
That would work for the thread doing the suspending. What about other kernel threads that might run and allocate memory during the cycle because of $RANDOM_EVENT? We don't want them triggering memory freeing either.
Regards,
Nigel
Signature · 2 lines
See http://www.suspend2.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
Quoted 6 lines · Nigel Cunningham
Hi.
Quoted 2 lines · Nick Piggin
Nigel Cunningham wrote:
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Add paranoia to the
page_alloccode to ensure we don't start page reclaim during suspending.Nack. Set
PF_MEMALLOCif you must.That would work for the thread doing the suspending. What about other kernel threads that might run and allocate memory during the cycle because of $RANDOM_EVENT? We don't want them triggering memory freeing either.
Haven't you suspended the other threads at this point?
What are the consequences of allocating memory?
Signature · 2 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
Hi Nick.
Quoted 8 lines · Nick Piggin
Quoted 7 lines · Nigel Cunningham
Hi.
Quoted 4 lines · Nick Piggin
Quoted 2 lines · Nigel Cunningham
Add paranoia to the
page_alloccode to ensure we don't start page reclaim during suspending.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Nack. Set
PF_MEMALLOCif you must.That would work for the thread doing the suspending. What about other kernel threads that might run and allocate memory during the cycle because of $RANDOM_EVENT? We don't want them triggering memory freeing either.
Haven't you suspended the other threads at this point?
Userspace is frozen, but kernel threads are still running. I'm therefore thinking of allocation of memory by drivers while we're writing the first part of the image (prior to the atomic copy).
Quoted 1 line
What are the consequences of allocating memory?
My concern isn't with them allocating any memory, but with the memory allocation routines trying to enter the vmscan.c routines to free memory. This would almost certainly free some of the LRU pages we're saving separately prior to the atomic copy, resulting in an inconsistent image and crashes and/or on disk corruption post resume. I've recently seen Rafael's code to take pages off the LRU, and realise that may be a better solution, but am not sure what adverse side effects it has.
Regards,
Nigel
Signature · 2 lines
See http://www.suspend2.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
In reply to Nick PigginHi Nick.
Quoted 10 lines · Nick Piggin
Quoted 9 lines · Nigel Cunningham
Hi.
Quoted 5 lines · Nick Piggin
Quoted 2 lines · Nigel Cunningham
Add paranoia to the
page_alloccode to ensure we don't start page reclaim during suspending.Nack. Set
PF_MEMALLOCif you must.
Quoted 8 lines
Quoted 4 lines
That would work for the thread doing the suspending. What about other kernel threads that might run and allocate memory during the cycle because of $RANDOM_EVENT? We don't want them triggering memory freeing either.
Haven't you suspended the other threads at this point?
What are the consequences of allocating memory?
Did you see my reply to these questions?
Regards,
Nigel
Signature · 2 lines
See http://www.suspend2.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
Quoted 6 lines · Nigel Cunningham
Quoted 3 lines
Haven't you suspended the other threads at this point?
What are the consequences of allocating memory?
Did you see my reply to these questions?
Hi Nigel,
Yes I did, sorry I thought I replied but it seems not.
I do think taking the pages off the LRU, or otherwise pinning them on it does sound like a better approach.
Signature · 2 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
In reply to Nigel CunninghamNigel wrote:
- do {
- if (cpuset_zone_allowed(*z, gfp_mask|__GFP_HARDWALL))
- wakeup_kswapd(*z, order);
- } while (*(++z));
+ if (likely(!test_freezer_state(FREEZER_ON))) {
+ do {
+ if (cpuset_zone_allowed(*z, gfp_mask|__GFP_HARDWALL))
+ wakeup_kswapd(*z, order);
+ } while (*(++z));
+ }
The cpuset_zone_allowed() check above was removed recently, thanks to a Chris Wright patch. So the above patch won't apply to Linus's or Andrew's current tree.
Signature · 3 lines
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.925.600.0401Re: [Suspend2][ 07/13] [Suspend2] Page_alloc paranoia.
Hi.
Quoted 13 lines · Paul Jackson
Nigel wrote:
mm/page_alloc.c +6
-4-do { -if (cpuset_zone_allowed (*z, gfp_mask|__GFP_HARDWALL)) -wakeup_kswapd (*z, order); - }while (*(++z)); +if (likely (!test_freezer_state (FREEZER_ON ))) { +do { +if (cpuset_zone_allowed (*z, gfp_mask|__GFP_HARDWALL)) +wakeup_kswapd (*z, order); + }while (*(++z)); + }
Quoted 3 lines
The
cpuset_zone_allowed()check above was removed recently, thanks to a Chris Wright patch. So the above patch won't apply to Linus's or Andrew's current tree.
This is for 2.6.17. I'm just about to update my git tree. Sorry - forever playing catchup :)
Regards,
Nigel
Signature · 2 lines
See http://www.suspend2.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
PATCH 8/13 Powerpc support (needed?)
In reply to Nigel CunninghamSupport for the powerpc. Originally merged as part of the suspend2 arch-specific code. I'm not sure if this is needed now that we use swsusp code.
drivers/macintosh/Kconfig | 4 + drivers/macintosh/via-pmu.c | 7 +++ include/asm-ppc/cpu_context.h | 110 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 0 deletions(-)
drivers/macintosh/Kconfig +4 -0
@@ -200,4 +200,8 @@ config ANSLCD 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 SUSPEND2 + endmenu
drivers/macintosh/via-pmu.c +7 -0
@@ -2654,6 +2654,13 @@ pmu_ioctl(struct inode * inode, struct freturn -EACCES ;if (sleep_in_progress)return -EBUSY ; +#ifdef CONFIG_SOFTWARE_REPLACE_SLEEP + { +extern void suspend2_try_suspend (void ); +suspend2_try_suspend (); +return (0 ); + } +#endif sleep_in_progress =1 ;switch (pmu_kind) {case PMU_OHARE_BASED :
include/asm-ppc/cpu_context.h new file +110 -0
110 lines not on this page · raw message
--
Nigel Cunningham nigel at suspend2 dot net
PATCH 9/13 Reset kswapd_max_order after resume.
In reply to Nigel CunninghamReset the kswapd_max_order value to zero after resume so that we don't get a swap storm.
mm/vmscan.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
mm/vmscan.c +2 -1
@@ -1244,7 +1244,8 @@ static int kswapd(void *p)for ( ; ; ) {unsigned long new_order; -try_to_freeze (); +if (try_to_freeze ()) + pgdat->kswapd_max_order =0 ;prepare_to_wait (&pgdat->kswapd_wait, &wait,TASK_INTERRUPTIBLE ); new_order = pgdat->kswapd_max_order;
--
Nigel Cunningham nigel at suspend2 dot net
PATCH 10/13 Replace swsusp reboot hook.
In reply to Nigel CunninghamReplace the swsusp reboot hook with one for suspend2.
kernel/sys.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/sys.c +3 -3
@@ -737,12 +737,12 @@ asmlinkage long sys_reboot(int magic1, iunlock_kernel ();return -EINVAL ; -#ifdef CONFIG_SOFTWARE_SUSPEND +#ifdef CONFIG_SUSPEND2 case LINUX_REBOOT_CMD_SW_SUSPEND : { -int ret =software_suspend (); +suspend2_try_suspend ();unlock_kernel (); -return ret; +return 0 ; }#endif
--
Nigel Cunningham nigel at suspend2 dot net
PATCH 11/13 snprintf_used function
In reply to Nigel CunninghamThe normal snprintf function tells you how many characters would have been appended to a buffer if it was large enough. For Suspend2, we want to know how many characters were actually added. This variant of the routine does that.
include/linux/kernel.h | 2 ++ lib/vsprintf.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 0 deletions(-)
include/linux/kernel.h +2 -0
@@ -108,6 +108,8 @@ extern int vsprintf(char *buf, const cha __attribute__ ((format (printf, 2, 0)));extern int snprintf (char * buf,size_t size,const char * fmt, ...) __attribute__ ((format (printf,3 ,4 ))); +extern int snprintf_used (char *buffer,int buffer_size, +const char *fmt, ...);extern int vsnprintf (char *buf,size_t size,const char *fmt,va_list args) __attribute__ ((format (printf,3 ,0 )));extern int scnprintf (char * buf,size_t size,const char * fmt, ...)
lib/vsprintf.c +23 -0
@@ -236,6 +236,29 @@ static char * number(char * buf, char *return buf; } +/* +* vsnprintf_used +* +* Functionality : Print a string with parameters to a buffer of a +* limited size. Unlike vsnprintf, we return the number +* of bytes actually put in the buffer, not the number +* that would have been put in if it was big enough. +*/ +int snprintf_used (char *buffer,int buffer_size,const char *fmt, ...) +{ +int result; +va_list args; + +if (!buffer_size) +return 0 ; + +va_start (args, fmt); + result =vsnprintf (buffer, buffer_size, fmt, args); +va_end (args); + +return result > buffer_size ? buffer_size : result; +} +/** * vsnprintf - Format a string and place it in a buffer * @buf: The buffer to place the result into
--
Nigel Cunningham nigel at suspend2 dot net
PATCH 12/13 Suspend2 common header.
In reply to Nigel CunninghamDeclarations used by virtually all of the Suspend2 files, but which are not needed externally. That is, debugging and result set/clear macros and the enum for the result codes.
kernel/power/suspend2_common.h | 45 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-)
kernel/power/suspend2_common.h new file +45 -0
@@ -0,0 +1,45 @@ +/* +* kernel/power/suspend2_common.h +* +* Copyright (C) 2005-2006 Nigel Cunningham <[email protected]> +* +* This file is released under the GPLv2. +* +* Routines for talking to a userspace program that manages storage. +* +* The kernel side: +* - starts the userspace program; +* - sends messages telling it when to open and close the connection; +* - tells it when to quit; +* +* The user space side: +* - passes messages regarding status; +* +*/ + +#ifdef CONFIG_PM_DEBUG +#define set_debug_state (bit) (test_and_set_bit(bit, &suspend_debug_state)) +#define clear_debug_state (bit) (test_and_clear_bit(bit, &suspend_debug_state)) +#else +#define set_debug_state (bit) (0) +#define clear_debug_state (bit) (0) +#endif + +#define set_result_state (bit) (test_and_set_bit(bit, &suspend_result)) +#define clear_result_state (bit) (test_and_clear_bit(bit, &suspend_result)) + +enum { +SUSPEND_ABORT_REQUESTED =1 , +SUSPEND_NOSTORAGE_AVAILABLE , +SUSPEND_INSUFFICIENT_STORAGE , +SUSPEND_FREEZING_FAILED , +SUSPEND_UNEXPECTED_ALLOC , +SUSPEND_KEPT_IMAGE , +SUSPEND_WOULD_EAT_MEMORY , +SUSPEND_UNABLE_TO_FREE_ENOUGH_MEMORY , +SUSPEND_ENCRYPTION_SETUP_FAILED , +SUSPEND_PM_SEM , +}; + +extern unsigned int nr_suspends; +extern char resume2_file[256 ];
--
Nigel Cunningham nigel at suspend2 dot net
PATCH 13/13 Suspend2 include file
In reply to Nigel CunninghamAdd suspend2 header file.
include/linux/suspend2.h | 190 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 190 insertions(+), 0 deletions(-)
include/linux/suspend2.h new file +190 -0
@@ -0,0 +1,190 @@ +#ifndef _LINUX_SUSPEND2_H +#define _LINUX_SUSPEND2_H + +#include <linux/dyn_pageflags.h> + +/* arch/i386/mm/init.c */ +extern char __nosave_begin, __nosave_end; + +#define SECTOR_SIZE 512 + +/* kernel/power/main.c */ +extern unsigned long suspend_result; + +/* kernel/power/process.c */ +extern unsigned long suspend_debug_state; + +/* arch/i386/power/suspend2.c */ +extern unsigned long suspend_action; +extern int suspend_io_time[2 ][2 ]; + +extern dyn_pageflags_t pageset1_map; +extern dyn_pageflags_t pageset1_copy_map; + +#ifdef CONFIG_PM_DEBUG +#define test_debug_state (bit) (test_bit(bit, &suspend_debug_state)) +#else +#define test_debug_state (bit) (0) +#endif + +#define test_result_state (bit) (test_bit(bit, &suspend_result)) + +/* +* First status register - this is suspend's return code. +* +* All the rest are in kernel/power/suspend2_common.h +*/ +#define SUSPEND_ABORTED 0 + +/* Second status register - ditto */ +#define SUSPEND_RETRY_RESUME 0 + +/* Debug sections - if debugging compiled in */ +enum { +SUSPEND_ANY_SECTION , +SUSPEND_EAT_MEMORY , +SUSPEND_IO , +SUSPEND_HEADER , +SUSPEND_WRITER , +SUSPEND_MEMORY , +}; + +/* debugging levels. */ +#define SUSPEND_STATUS 0 +#define SUSPEND_ERROR 2 +#define SUSPEND_LOW 3 +#define SUSPEND_MEDIUM 4 +#define SUSPEND_HIGH 5 +#define SUSPEND_VERBOSE 6 + +/* Configuration flags */ +enum { +SUSPEND_REBOOT , +SUSPEND_PAUSE , +SUSPEND_SLOW , +SUSPEND_LOGALL , +SUSPEND_CAN_CANCEL , +SUSPEND_KEEP_IMAGE , +SUSPEND_FREEZER_TEST , +SUSPEND_SINGLESTEP , +SUSPEND_PAUSE_NEAR_PAGESET_END , +SUSPEND_TEST_FILTER_SPEED , +SUSPEND_TEST_BIO , +SUSPEND_NO_PAGESET2 , +}; + +#ifdef CONFIG_SUSPEND2 +#define test_action_state (bit) (test_bit(bit, &suspend_action)) +#define set_action_state (bit) (test_and_set_bit(bit, &suspend_action)) +#define clear_action_state (bit) (test_and_clear_bit(bit, &suspend_action)) +#else +#define test_action_state (bit) (0) +#endif + +extern void __suspend_message (unsigned long section,unsigned long level,int log_normally, +const char *fmt, ...); + +#ifdef CONFIG_PM_DEBUG +#define suspend_message(sn, lev, log, fmt, a...) \ +do { \ + if (test_debug_state(sn)) \ + __suspend_message(sn, lev, log, fmt, ##a); \ +} while(0) +#else /* CONFIG_PM_DEBUG */ +#define suspend_message(sn, lev, log, fmt, a...) \ +do { \ + if (lev == 0) \ + __suspend_message(sn, lev, log, fmt, ##a); \ +} while(0) +#endif /* CONFIG_PM_DEBUG */ + +/* Suspend 2 */ + +enum { +SUSPEND_CAN_SUSPEND , +SUSPEND_CAN_RESUME , +SUSPEND_RUNNING , +SUSPEND_RESUME_DEVICE_OK , +SUSPEND_NORESUME_SPECIFIED , +SUSPEND_SANITY_CHECK_PROMPT , +SUSPEND_PAGESET2_NOT_LOADED , +SUSPEND_CONTINUE_REQ , +SUSPEND_RESUMED_BEFORE , +SUSPEND_RESUME_NOT_DONE , +SUSPEND_BOOT_TIME , +SUSPEND_NOW_RESUMING , +SUSPEND_IGNORE_LOGLEVEL , +SUSPEND_TRYING_TO_RESUME , +SUSPEND_TRY_RESUME_RD , +SUSPEND_IGNORE_ROOTFS , +}; + +/* --------------------------------------------------------------------- */ +#ifdef CONFIG_SUSPEND2 + +/* Used in init dir files */ +extern unsigned long suspend_state; + +extern void suspend2_try_resume (void ); +extern int suspend_early_boot_message + (int can_erase_image,int default_answer,char *warning_reason, ...); +extern unsigned long suspend_update_status (unsigned long value,unsigned long maximum, +const char *fmt, ...); +extern void suspend_prepare_status (int clearbar,const char *fmt, ...); + +#define test_suspend_state (bit) \ + (test_bit(bit, &suspend_state)) + +#define clear_suspend_state (bit) \ + (clear_bit(bit, &suspend_state)) + +#define set_suspend_state (bit) \ + (set_bit(bit, &suspend_state)) + +extern void suspend2_try_suspend (void ); + +/* --------------------------------------------------------------------- */ +#else +/* --------------------------------------------------------------------- */ + +#define suspend_state (0) +#define clear_suspend_state (bit) do { } while (0) +#define test_suspend_state (bit) (0) +#define set_suspend_state (bit) do { } while(0) + +#define suspend2_try_resume () do { } while(0) +static inline int suspend_early_boot_message (int a,int b,char *c, ...) {return 0 ; } +static inline unsigned long suspend_update_status (unsigned long value,unsigned long maximum, +const char *fmt, ...) +{ +return maximum; +} +#define suspend_prepare_status (a, ...) do { } while(0) + +#endif /* CONFIG_SUSPEND2 */ + +#define test_and_set_suspend_state (bit) \ + (test_and_set_bit(bit, &suspend_state)) + +#define get_suspend_state () (suspend_state) + +#define restore_suspend_state (saved_state) \ + do { suspend_state = saved_state; } while(0) + +#if defined(CONFIG_SUSPEND2 ) && defined(CONFIG_ACPI ) +#include <acpi/acpi.h> +static inline int may_try_suspend2 (u32 state) +{ +if (state ==ACPI_STATE_S4 ) { +suspend2_try_suspend (); +return 1 ; + } +return 0 ; +} +#else +static inline int may_try_suspend2 (u32 state) +{ +return 0 ; +} +#endif +#endif /* _LINUX_SUSPEND2_H */
--
Nigel Cunningham nigel at suspend2 dot net