2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/suspend.h>
|
2007-10-26 06:05:05 +07:00
|
|
|
#include <linux/suspend_ioctls.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/utsname.h>
|
2008-01-16 11:17:00 +07:00
|
|
|
#include <linux/freezer.h>
|
2014-04-08 05:39:20 +07:00
|
|
|
#include <linux/compiler.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
struct swsusp_info {
|
|
|
|
struct new_utsname uts;
|
|
|
|
u32 version_code;
|
|
|
|
unsigned long num_physpages;
|
|
|
|
int cpus;
|
|
|
|
unsigned long image_pages;
|
2006-01-06 15:13:05 +07:00
|
|
|
unsigned long pages;
|
2006-03-23 18:00:03 +07:00
|
|
|
unsigned long size;
|
2014-04-08 05:39:20 +07:00
|
|
|
} __aligned(PAGE_SIZE);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-10-18 17:04:52 +07:00
|
|
|
#ifdef CONFIG_HIBERNATION
|
2010-09-21 00:44:56 +07:00
|
|
|
/* kernel/power/snapshot.c */
|
2011-05-15 16:38:48 +07:00
|
|
|
extern void __init hibernate_reserved_size_init(void);
|
2010-09-21 00:44:56 +07:00
|
|
|
extern void __init hibernate_image_size_init(void);
|
|
|
|
|
2007-10-18 17:04:52 +07:00
|
|
|
#ifdef CONFIG_ARCH_HIBERNATION_HEADER
|
|
|
|
/* Maximum size of architecture specific data in a hibernation header */
|
|
|
|
#define MAX_ARCH_HEADER_SIZE (sizeof(struct new_utsname) + 4)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-10-18 17:04:52 +07:00
|
|
|
extern int arch_hibernation_header_save(void *addr, unsigned int max_size);
|
|
|
|
extern int arch_hibernation_header_restore(void *addr);
|
|
|
|
|
|
|
|
static inline int init_header_complete(struct swsusp_info *info)
|
|
|
|
{
|
|
|
|
return arch_hibernation_header_save(info, MAX_ARCH_HEADER_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *check_image_kernel(struct swsusp_info *info)
|
|
|
|
{
|
|
|
|
return arch_hibernation_header_restore(info) ?
|
|
|
|
"architecture specific data" : NULL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ARCH_HIBERNATION_HEADER */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
x86 / hibernate: Use hlt_play_dead() when resuming from hibernation
On Intel hardware, native_play_dead() uses mwait_play_dead() by
default and only falls back to the other methods if that fails.
That also happens during resume from hibernation, when the restore
(boot) kernel runs disable_nonboot_cpus() to take all of the CPUs
except for the boot one offline.
However, that is problematic, because the address passed to
__monitor() in mwait_play_dead() is likely to be written to in the
last phase of hibernate image restoration and that causes the "dead"
CPU to start executing instructions again. Unfortunately, the page
containing the address in that CPU's instruction pointer may not be
valid any more at that point.
First, that page may have been overwritten with image kernel memory
contents already, so the instructions the CPU attempts to execute may
simply be invalid. Second, the page tables previously used by that
CPU may have been overwritten by image kernel memory contents, so the
address in its instruction pointer is impossible to resolve then.
A report from Varun Koyyalagunta and investigation carried out by
Chen Yu show that the latter sometimes happens in practice.
To prevent it from happening, temporarily change the smp_ops.play_dead
pointer during resume from hibernation so that it points to a special
"play dead" routine which uses hlt_play_dead() and avoids the
inadvertent "revivals" of "dead" CPUs this way.
A slightly unpleasant consequence of this change is that if the
system is hibernated with one or more CPUs offline, it will generally
draw more power after resume than it did before hibernation, because
the physical state entered by CPUs via hlt_play_dead() is higher-power
than the mwait_play_dead() one in the majority of cases. It is
possible to work around this, but it is unclear how much of a problem
that's going to be in practice, so the workaround will be implemented
later if it turns out to be necessary.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=106371
Reported-by: Varun Koyyalagunta <cpudebug@centtech.com>
Original-by: Chen Yu <yu.c.chen@intel.com>
Tested-by: Chen Yu <yu.c.chen@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
2016-07-14 08:55:23 +07:00
|
|
|
extern int hibernate_resume_nonboot_cpu_disable(void);
|
|
|
|
|
2007-05-07 04:50:52 +07:00
|
|
|
/*
|
|
|
|
* Keep some memory free so that I/O operations can succeed without paging
|
|
|
|
* [Might this be more than 4 MB?]
|
|
|
|
*/
|
|
|
|
#define PAGES_FOR_IO ((4096 * 1024) >> PAGE_SHIFT)
|
2007-10-18 17:04:52 +07:00
|
|
|
|
2007-05-07 04:50:52 +07:00
|
|
|
/*
|
|
|
|
* Keep 1 MB of memory free so that device drivers can allocate some pages in
|
|
|
|
* their .suspend() routines without breaking the suspend to disk.
|
|
|
|
*/
|
|
|
|
#define SPARE_PAGES ((1024 * 1024) >> PAGE_SHIFT)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-02-27 18:43:53 +07:00
|
|
|
asmlinkage int swsusp_save(void);
|
|
|
|
|
2009-06-10 06:27:49 +07:00
|
|
|
/* kernel/power/hibernate.c */
|
2011-12-02 04:33:10 +07:00
|
|
|
extern bool freezer_test_done;
|
|
|
|
|
2007-07-19 15:47:29 +07:00
|
|
|
extern int hibernation_snapshot(int platform_mode);
|
swsusp: introduce restore platform operations
At least on some machines it is necessary to prepare the ACPI firmware for the
restoration of the system memory state from the hibernation image if the
"platform" mode of hibernation has been used. Namely, in that cases we need
to disable the GPEs before replacing the "boot" kernel with the "frozen"
kernel (cf. http://bugzilla.kernel.org/show_bug.cgi?id=7887). After the
restore they will be re-enabled by hibernation_ops->finish(), but if the
restore fails, they have to be re-enabled by the restore code explicitly.
For this purpose we can introduce two additional hibernation operations,
called pre_restore() and restore_cleanup() and call them from the restore code
path. Still, they should be called if the "platform" mode of hibernation has
been used, so we need to pass the information about the hibernation mode from
the "frozen" kernel to the "boot" kernel in the image header.
Apparently, we can't drop the disabling of GPEs before the restore because of
Bug #7887 . We also can't do it unconditionally, because the GPEs wouldn't
have been enabled after a successful restore if the suspend had been done in
the 'shutdown' or 'reboot' mode.
In principle we could (and probably should) unconditionally disable the GPEs
before each snapshot creation *and* before the restore, but then we'd have to
unconditionally enable them after the snapshot creation as well as after the
restore (or restore failure) Still, for this purpose we'd need to modify
acpi_enter_sleep_state_prep() and acpi_leave_sleep_state() and we'd have to
introduce some mechanism synchronizing the disablind/enabling of the GPEs with
the device drivers' .suspend()/.resume() routines and with
disable_/enable_nonboot_cpus(). However, this would have affected the
suspend (ie. s2ram) code as well as the hibernation, which I'd like to avoid
in this patch series.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 15:47:30 +07:00
|
|
|
extern int hibernation_restore(int platform_mode);
|
2007-07-19 15:47:29 +07:00
|
|
|
extern int hibernation_platform_enter(void);
|
2010-09-21 00:44:56 +07:00
|
|
|
|
2016-07-10 07:12:10 +07:00
|
|
|
#ifdef CONFIG_DEBUG_RODATA
|
|
|
|
/* kernel/power/snapshot.c */
|
|
|
|
extern void enable_restore_image_protection(void);
|
|
|
|
#else
|
|
|
|
static inline void enable_restore_image_protection(void) {}
|
|
|
|
#endif /* CONFIG_DEBUG_RODATA */
|
|
|
|
|
2010-09-21 00:44:56 +07:00
|
|
|
#else /* !CONFIG_HIBERNATION */
|
|
|
|
|
2011-05-15 16:38:48 +07:00
|
|
|
static inline void hibernate_reserved_size_init(void) {}
|
2010-09-21 00:44:56 +07:00
|
|
|
static inline void hibernate_image_size_init(void) {}
|
|
|
|
#endif /* !CONFIG_HIBERNATION */
|
2006-12-07 11:34:35 +07:00
|
|
|
|
2007-05-03 00:27:07 +07:00
|
|
|
extern int pfn_is_nosave(unsigned long);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#define power_attr(_name) \
|
2007-11-02 19:47:53 +07:00
|
|
|
static struct kobj_attribute _name##_attr = { \
|
2005-04-17 05:20:36 +07:00
|
|
|
.attr = { \
|
|
|
|
.name = __stringify(_name), \
|
|
|
|
.mode = 0644, \
|
|
|
|
}, \
|
|
|
|
.show = _name##_show, \
|
|
|
|
.store = _name##_store, \
|
|
|
|
}
|
|
|
|
|
2016-01-02 09:09:16 +07:00
|
|
|
#define power_attr_ro(_name) \
|
|
|
|
static struct kobj_attribute _name##_attr = { \
|
|
|
|
.attr = { \
|
|
|
|
.name = __stringify(_name), \
|
|
|
|
.mode = S_IRUGO, \
|
|
|
|
}, \
|
|
|
|
.show = _name##_show, \
|
|
|
|
}
|
|
|
|
|
2006-02-01 18:05:07 +07:00
|
|
|
/* Preferred image size in bytes (default 500 MB) */
|
|
|
|
extern unsigned long image_size;
|
2011-05-15 16:38:48 +07:00
|
|
|
/* Size of memory reserved for drivers (default SPARE_PAGES x PAGE_SIZE) */
|
|
|
|
extern unsigned long reserved_size;
|
2006-03-23 17:59:59 +07:00
|
|
|
extern int in_suspend;
|
2006-03-23 18:00:00 +07:00
|
|
|
extern dev_t swsusp_resume_device;
|
2006-12-07 11:34:12 +07:00
|
|
|
extern sector_t swsusp_resume_block;
|
2006-03-23 17:59:59 +07:00
|
|
|
|
2005-10-31 05:59:56 +07:00
|
|
|
extern asmlinkage int swsusp_arch_suspend(void);
|
|
|
|
extern asmlinkage int swsusp_arch_resume(void);
|
|
|
|
|
2007-05-07 04:50:43 +07:00
|
|
|
extern int create_basic_memory_bitmaps(void);
|
|
|
|
extern void free_basic_memory_bitmaps(void);
|
2009-07-08 18:24:05 +07:00
|
|
|
extern int hibernate_preallocate_memory(void);
|
2006-03-23 17:59:59 +07:00
|
|
|
|
2006-09-26 13:32:46 +07:00
|
|
|
/**
|
|
|
|
* Auxiliary structure used for reading the snapshot image data and
|
|
|
|
* metadata from and writing them to the list of page backup entries
|
|
|
|
* (PBEs) which is the main data structure of swsusp.
|
|
|
|
*
|
|
|
|
* Using struct snapshot_handle we can transfer the image, including its
|
|
|
|
* metadata, as a continuous sequence of bytes with the help of
|
|
|
|
* snapshot_read_next() and snapshot_write_next().
|
|
|
|
*
|
|
|
|
* The code that writes the image to a storage or transfers it to
|
|
|
|
* the user land is required to use snapshot_read_next() for this
|
|
|
|
* purpose and it should not make any assumptions regarding the internal
|
|
|
|
* structure of the image. Similarly, the code that reads the image from
|
|
|
|
* a storage or transfers it from the user land is required to use
|
|
|
|
* snapshot_write_next().
|
|
|
|
*
|
|
|
|
* This may allow us to change the internal structure of the image
|
|
|
|
* in the future with considerably less effort.
|
|
|
|
*/
|
|
|
|
|
2006-03-23 17:59:59 +07:00
|
|
|
struct snapshot_handle {
|
2006-09-26 13:32:46 +07:00
|
|
|
unsigned int cur; /* number of the block of PAGE_SIZE bytes the
|
|
|
|
* next operation will refer to (ie. current)
|
|
|
|
*/
|
|
|
|
void *buffer; /* address of the block to read from
|
|
|
|
* or write to
|
|
|
|
*/
|
|
|
|
int sync_read; /* Set to one to notify the caller of
|
|
|
|
* snapshot_write_next() that it may
|
|
|
|
* need to call wait_on_bio_chain()
|
|
|
|
*/
|
2006-03-23 17:59:59 +07:00
|
|
|
};
|
|
|
|
|
2006-09-26 13:32:46 +07:00
|
|
|
/* This macro returns the address from/to which the caller of
|
|
|
|
* snapshot_read_next()/snapshot_write_next() is allowed to
|
|
|
|
* read/write data after the function returns
|
|
|
|
*/
|
2010-05-02 04:52:02 +07:00
|
|
|
#define data_of(handle) ((handle).buffer)
|
2006-03-23 17:59:59 +07:00
|
|
|
|
2006-09-26 13:32:54 +07:00
|
|
|
extern unsigned int snapshot_additional_pages(struct zone *zone);
|
2007-10-26 05:59:31 +07:00
|
|
|
extern unsigned long snapshot_get_image_size(void);
|
2010-05-02 04:52:02 +07:00
|
|
|
extern int snapshot_read_next(struct snapshot_handle *handle);
|
|
|
|
extern int snapshot_write_next(struct snapshot_handle *handle);
|
[PATCH] swsusp: Improve handling of highmem
Currently swsusp saves the contents of highmem pages by copying them to the
normal zone which is quite inefficient (eg. it requires two normal pages
to be used for saving one highmem page). This may be improved by using
highmem for saving the contents of saveable highmem pages.
Namely, during the suspend phase of the suspend-resume cycle we try to
allocate as many free highmem pages as there are saveable highmem pages.
If there are not enough highmem image pages to store the contents of all of
the saveable highmem pages, some of them will be stored in the "normal"
memory. Next, we allocate as many free "normal" pages as needed to store
the (remaining) image data. We use a memory bitmap to mark the allocated
free pages (ie. highmem as well as "normal" image pages).
Now, we use another memory bitmap to mark all of the saveable pages
(highmem as well as "normal") and the contents of the saveable pages are
copied into the image pages. Then, the second bitmap is used to save the
pfns corresponding to the saveable pages and the first one is used to save
their data.
During the resume phase the pfns of the pages that were saveable during the
suspend are loaded from the image and used to mark the "unsafe" page
frames. Next, we try to allocate as many free highmem page frames as to
load all of the image data that had been in the highmem before the suspend
and we allocate so many free "normal" page frames that the total number of
allocated free pages (highmem and "normal") is equal to the size of the
image. While doing this we have to make sure that there will be some extra
free "normal" and "safe" page frames for two lists of PBEs constructed
later.
Now, the image data are loaded, if possible, into their "original" page
frames. The image data that cannot be written into their "original" page
frames are loaded into "safe" page frames and their "original" kernel
virtual addresses, as well as the addresses of the "safe" pages containing
their copies, are stored in one of two lists of PBEs.
One list of PBEs is for the copies of "normal" suspend pages (ie. "normal"
pages that were saveable during the suspend) and it is used in the same way
as previously (ie. by the architecture-dependent parts of swsusp). The
other list of PBEs is for the copies of highmem suspend pages. The pages
in this list are restored (in a reversible way) right before the
arch-dependent code is called.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-12-07 11:34:18 +07:00
|
|
|
extern void snapshot_write_finalize(struct snapshot_handle *handle);
|
2006-09-26 13:32:54 +07:00
|
|
|
extern int snapshot_image_loaded(struct snapshot_handle *handle);
|
2006-03-23 18:00:00 +07:00
|
|
|
|
2007-05-07 04:50:45 +07:00
|
|
|
/* If unset, the snapshot device cannot be open. */
|
|
|
|
extern atomic_t snapshot_device_available;
|
|
|
|
|
2007-05-07 04:50:47 +07:00
|
|
|
extern sector_t alloc_swapdev_block(int swap);
|
|
|
|
extern void free_all_swap_pages(int swap);
|
|
|
|
extern int swsusp_swap_in_use(void);
|
2006-03-23 18:00:00 +07:00
|
|
|
|
swsusp: introduce restore platform operations
At least on some machines it is necessary to prepare the ACPI firmware for the
restoration of the system memory state from the hibernation image if the
"platform" mode of hibernation has been used. Namely, in that cases we need
to disable the GPEs before replacing the "boot" kernel with the "frozen"
kernel (cf. http://bugzilla.kernel.org/show_bug.cgi?id=7887). After the
restore they will be re-enabled by hibernation_ops->finish(), but if the
restore fails, they have to be re-enabled by the restore code explicitly.
For this purpose we can introduce two additional hibernation operations,
called pre_restore() and restore_cleanup() and call them from the restore code
path. Still, they should be called if the "platform" mode of hibernation has
been used, so we need to pass the information about the hibernation mode from
the "frozen" kernel to the "boot" kernel in the image header.
Apparently, we can't drop the disabling of GPEs before the restore because of
Bug #7887 . We also can't do it unconditionally, because the GPEs wouldn't
have been enabled after a successful restore if the suspend had been done in
the 'shutdown' or 'reboot' mode.
In principle we could (and probably should) unconditionally disable the GPEs
before each snapshot creation *and* before the restore, but then we'd have to
unconditionally enable them after the snapshot creation as well as after the
restore (or restore failure) Still, for this purpose we'd need to modify
acpi_enter_sleep_state_prep() and acpi_leave_sleep_state() and we'd have to
introduce some mechanism synchronizing the disablind/enabling of the GPEs with
the device drivers' .suspend()/.resume() routines and with
disable_/enable_nonboot_cpus(). However, this would have affected the
suspend (ie. s2ram) code as well as the hibernation, which I'd like to avoid
in this patch series.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 15:47:30 +07:00
|
|
|
/*
|
|
|
|
* Flags that can be passed from the hibernatig hernel to the "boot" kernel in
|
|
|
|
* the image header.
|
|
|
|
*/
|
|
|
|
#define SF_PLATFORM_MODE 1
|
2010-09-10 04:06:23 +07:00
|
|
|
#define SF_NOCOMPRESS_MODE 2
|
2011-10-14 04:58:07 +07:00
|
|
|
#define SF_CRC32_MODE 4
|
swsusp: introduce restore platform operations
At least on some machines it is necessary to prepare the ACPI firmware for the
restoration of the system memory state from the hibernation image if the
"platform" mode of hibernation has been used. Namely, in that cases we need
to disable the GPEs before replacing the "boot" kernel with the "frozen"
kernel (cf. http://bugzilla.kernel.org/show_bug.cgi?id=7887). After the
restore they will be re-enabled by hibernation_ops->finish(), but if the
restore fails, they have to be re-enabled by the restore code explicitly.
For this purpose we can introduce two additional hibernation operations,
called pre_restore() and restore_cleanup() and call them from the restore code
path. Still, they should be called if the "platform" mode of hibernation has
been used, so we need to pass the information about the hibernation mode from
the "frozen" kernel to the "boot" kernel in the image header.
Apparently, we can't drop the disabling of GPEs before the restore because of
Bug #7887 . We also can't do it unconditionally, because the GPEs wouldn't
have been enabled after a successful restore if the suspend had been done in
the 'shutdown' or 'reboot' mode.
In principle we could (and probably should) unconditionally disable the GPEs
before each snapshot creation *and* before the restore, but then we'd have to
unconditionally enable them after the snapshot creation as well as after the
restore (or restore failure) Still, for this purpose we'd need to modify
acpi_enter_sleep_state_prep() and acpi_leave_sleep_state() and we'd have to
introduce some mechanism synchronizing the disablind/enabling of the GPEs with
the device drivers' .suspend()/.resume() routines and with
disable_/enable_nonboot_cpus(). However, this would have affected the
suspend (ie. s2ram) code as well as the hibernation, which I'd like to avoid
in this patch series.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 15:47:30 +07:00
|
|
|
|
2009-06-10 06:27:49 +07:00
|
|
|
/* kernel/power/hibernate.c */
|
2006-03-23 18:00:01 +07:00
|
|
|
extern int swsusp_check(void);
|
|
|
|
extern void swsusp_free(void);
|
swsusp: introduce restore platform operations
At least on some machines it is necessary to prepare the ACPI firmware for the
restoration of the system memory state from the hibernation image if the
"platform" mode of hibernation has been used. Namely, in that cases we need
to disable the GPEs before replacing the "boot" kernel with the "frozen"
kernel (cf. http://bugzilla.kernel.org/show_bug.cgi?id=7887). After the
restore they will be re-enabled by hibernation_ops->finish(), but if the
restore fails, they have to be re-enabled by the restore code explicitly.
For this purpose we can introduce two additional hibernation operations,
called pre_restore() and restore_cleanup() and call them from the restore code
path. Still, they should be called if the "platform" mode of hibernation has
been used, so we need to pass the information about the hibernation mode from
the "frozen" kernel to the "boot" kernel in the image header.
Apparently, we can't drop the disabling of GPEs before the restore because of
Bug #7887 . We also can't do it unconditionally, because the GPEs wouldn't
have been enabled after a successful restore if the suspend had been done in
the 'shutdown' or 'reboot' mode.
In principle we could (and probably should) unconditionally disable the GPEs
before each snapshot creation *and* before the restore, but then we'd have to
unconditionally enable them after the snapshot creation as well as after the
restore (or restore failure) Still, for this purpose we'd need to modify
acpi_enter_sleep_state_prep() and acpi_leave_sleep_state() and we'd have to
introduce some mechanism synchronizing the disablind/enabling of the GPEs with
the device drivers' .suspend()/.resume() routines and with
disable_/enable_nonboot_cpus(). However, this would have affected the
suspend (ie. s2ram) code as well as the hibernation, which I'd like to avoid
in this patch series.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 15:47:30 +07:00
|
|
|
extern int swsusp_read(unsigned int *flags_p);
|
|
|
|
extern int swsusp_write(unsigned int flags);
|
2007-10-09 00:21:10 +07:00
|
|
|
extern void swsusp_close(fmode_t);
|
2012-06-16 05:09:58 +07:00
|
|
|
#ifdef CONFIG_SUSPEND
|
|
|
|
extern int swsusp_unmark(void);
|
|
|
|
#endif
|
2006-12-07 11:34:32 +07:00
|
|
|
|
|
|
|
struct timeval;
|
2007-07-19 15:47:36 +07:00
|
|
|
/* kernel/power/swsusp.c */
|
2014-10-31 01:04:53 +07:00
|
|
|
extern void swsusp_show_speed(ktime_t, ktime_t, unsigned int, char *);
|
2007-07-19 15:47:36 +07:00
|
|
|
|
2007-07-30 04:27:18 +07:00
|
|
|
#ifdef CONFIG_SUSPEND
|
2009-06-10 06:27:12 +07:00
|
|
|
/* kernel/power/suspend.c */
|
2014-09-03 06:21:03 +07:00
|
|
|
extern const char *pm_labels[];
|
2014-07-16 03:02:11 +07:00
|
|
|
extern const char *pm_states[];
|
2009-06-10 06:27:12 +07:00
|
|
|
|
2007-07-19 15:47:38 +07:00
|
|
|
extern int suspend_devices_and_enter(suspend_state_t state);
|
2007-07-30 04:27:18 +07:00
|
|
|
#else /* !CONFIG_SUSPEND */
|
|
|
|
static inline int suspend_devices_and_enter(suspend_state_t state)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
#endif /* !CONFIG_SUSPEND */
|
|
|
|
|
2009-06-10 06:27:12 +07:00
|
|
|
#ifdef CONFIG_PM_TEST_SUSPEND
|
|
|
|
/* kernel/power/suspend_test.c */
|
|
|
|
extern void suspend_test_start(void);
|
|
|
|
extern void suspend_test_finish(const char *label);
|
|
|
|
#else /* !CONFIG_PM_TEST_SUSPEND */
|
|
|
|
static inline void suspend_test_start(void) {}
|
|
|
|
static inline void suspend_test_finish(const char *label) {}
|
|
|
|
#endif /* !CONFIG_PM_TEST_SUSPEND */
|
|
|
|
|
2007-11-20 05:49:18 +07:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
/* kernel/power/main.c */
|
2016-06-20 13:52:27 +07:00
|
|
|
extern int __pm_notifier_call_chain(unsigned long val, int nr_to_call,
|
|
|
|
int *nr_calls);
|
2007-11-20 05:49:18 +07:00
|
|
|
extern int pm_notifier_call_chain(unsigned long val);
|
|
|
|
#endif
|
2007-11-20 05:36:20 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
int restore_highmem(void);
|
|
|
|
#else
|
|
|
|
static inline unsigned int count_highmem_pages(void) { return 0; }
|
|
|
|
static inline int restore_highmem(void) { return 0; }
|
|
|
|
#endif
|
Suspend: Testing facility (rev. 2)
Introduce sysfs attribute /sys/power/pm_test allowing one to test the suspend
core code. Namely, writing one of the strings:
freezer
devices
platform
processors
core
to this file causes the suspend code to work in one of the test modes defined as
follows:
freezer
- test the freezing of processes
devices
- test the freezing of processes and suspending of devices
platform
- test the freezing of processes, suspending of devices and platform global
control methods(*)
processors
- test the freezing of processes, suspending of devices, platform global
control methods and the disabling of nonboot CPUs
core
- test the freezing of processes, suspending of devices, platform global
control methods, the disabling of nonboot CPUs and suspending of
platform/system devices
(*) These are ACPI global control methods on ACPI systems
Then, if a suspend is started by normal means, the suspend core will perform
its normal operations up to the point indicated by given test level. Next, it
will wait for 5 seconds and carry out the resume operations needed to transition
the system back to the fully functional state.
Writing "none" to /sys/power/pm_test turns the testing off.
When open for reading, /sys/power/pm_test contains a space-separated list of all
available tests (including "none" that represents the normal functionality) in
which the current test level is indicated by square brackets.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Len Brown <len.brown@intel.com>
2007-11-20 05:41:19 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Suspend test levels
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
/* keep first */
|
|
|
|
TEST_NONE,
|
|
|
|
TEST_CORE,
|
|
|
|
TEST_CPUS,
|
|
|
|
TEST_PLATFORM,
|
|
|
|
TEST_DEVICES,
|
|
|
|
TEST_FREEZER,
|
|
|
|
/* keep last */
|
|
|
|
__TEST_AFTER_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TEST_FIRST TEST_NONE
|
|
|
|
#define TEST_MAX (__TEST_AFTER_LAST - 1)
|
2007-11-20 05:42:31 +07:00
|
|
|
|
|
|
|
extern int pm_test_level;
|
2008-01-16 11:17:00 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_SUSPEND_FREEZER
|
|
|
|
static inline int suspend_freeze_processes(void)
|
|
|
|
{
|
PM / Freezer: Thaw only kernel threads if freezing of kernel threads fails
If freezing of kernel threads fails, we are expected to automatically
thaw tasks in the error recovery path. However, at times, we encounter
situations in which we would like the automatic error recovery path
to thaw only the kernel threads, because we want to be able to do
some more cleanup before we thaw userspace. Something like:
error = freeze_kernel_threads();
if (error) {
/* Do some cleanup */
/* Only then thaw userspace tasks*/
thaw_processes();
}
An example of such a situation is where we freeze/thaw filesystems
during suspend/hibernation. There, if freezing of kernel threads
fails, we would like to thaw the frozen filesystems before thawing
the userspace tasks.
So, modify freeze_kernel_threads() to thaw only kernel threads in
case of freezing failure. And change suspend_freeze_processes()
accordingly. (At the same time, let us also get rid of the rather
cryptic usage of the conditional operator (:?) in that function.)
[rjw: In fact, this patch fixes a regression introduced during the
3.3 merge window, because without it thaw_processes() may be called
before swsusp_free() in some situations and that may lead to massive
memory allocation failures.]
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Nigel Cunningham <nigel@tuxonice.net>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2012-02-04 04:22:41 +07:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = freeze_processes();
|
|
|
|
/*
|
|
|
|
* freeze_processes() automatically thaws every task if freezing
|
|
|
|
* fails. So we need not do anything extra upon error.
|
|
|
|
*/
|
|
|
|
if (error)
|
2012-02-12 04:40:23 +07:00
|
|
|
return error;
|
PM / Freezer: Thaw only kernel threads if freezing of kernel threads fails
If freezing of kernel threads fails, we are expected to automatically
thaw tasks in the error recovery path. However, at times, we encounter
situations in which we would like the automatic error recovery path
to thaw only the kernel threads, because we want to be able to do
some more cleanup before we thaw userspace. Something like:
error = freeze_kernel_threads();
if (error) {
/* Do some cleanup */
/* Only then thaw userspace tasks*/
thaw_processes();
}
An example of such a situation is where we freeze/thaw filesystems
during suspend/hibernation. There, if freezing of kernel threads
fails, we would like to thaw the frozen filesystems before thawing
the userspace tasks.
So, modify freeze_kernel_threads() to thaw only kernel threads in
case of freezing failure. And change suspend_freeze_processes()
accordingly. (At the same time, let us also get rid of the rather
cryptic usage of the conditional operator (:?) in that function.)
[rjw: In fact, this patch fixes a regression introduced during the
3.3 merge window, because without it thaw_processes() may be called
before swsusp_free() in some situations and that may lead to massive
memory allocation failures.]
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Nigel Cunningham <nigel@tuxonice.net>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2012-02-04 04:22:41 +07:00
|
|
|
|
|
|
|
error = freeze_kernel_threads();
|
|
|
|
/*
|
|
|
|
* freeze_kernel_threads() thaws only kernel threads upon freezing
|
|
|
|
* failure. So we have to thaw the userspace tasks ourselves.
|
|
|
|
*/
|
|
|
|
if (error)
|
|
|
|
thaw_processes();
|
|
|
|
|
|
|
|
return error;
|
2008-01-16 11:17:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void suspend_thaw_processes(void)
|
|
|
|
{
|
|
|
|
thaw_processes();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline int suspend_freeze_processes(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void suspend_thaw_processes(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2012-04-30 03:53:22 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_PM_AUTOSLEEP
|
|
|
|
|
|
|
|
/* kernel/power/autosleep.c */
|
|
|
|
extern int pm_autosleep_init(void);
|
|
|
|
extern int pm_autosleep_lock(void);
|
|
|
|
extern void pm_autosleep_unlock(void);
|
|
|
|
extern suspend_state_t pm_autosleep_state(void);
|
|
|
|
extern int pm_autosleep_set_state(suspend_state_t state);
|
|
|
|
|
|
|
|
#else /* !CONFIG_PM_AUTOSLEEP */
|
|
|
|
|
|
|
|
static inline int pm_autosleep_init(void) { return 0; }
|
|
|
|
static inline int pm_autosleep_lock(void) { return 0; }
|
|
|
|
static inline void pm_autosleep_unlock(void) {}
|
|
|
|
static inline suspend_state_t pm_autosleep_state(void) { return PM_SUSPEND_ON; }
|
|
|
|
|
|
|
|
#endif /* !CONFIG_PM_AUTOSLEEP */
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_PM_WAKELOCKS
|
|
|
|
|
|
|
|
/* kernel/power/wakelock.c */
|
|
|
|
extern ssize_t pm_show_wakelocks(char *buf, bool show_active);
|
|
|
|
extern int pm_wake_lock(const char *buf);
|
|
|
|
extern int pm_wake_unlock(const char *buf);
|
|
|
|
|
|
|
|
#endif /* !CONFIG_PM_WAKELOCKS */
|