swsusp: let userland tools switch console on suspend
Subsystems (6)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/3 swsusp: let userland tools switch console on suspend
From: "Rafael J. Wysocki" <[email protected]>
Remove the console-switching code from the suspend part of the swsusp userland interface and let the userland tools switch the console.
--- kernel/power/user.c | 3 --- 1 files changed, 3 deletions(-)
kernel/power/user.c +0 -3
@@ -138,12 +138,10 @@ static int snapshot_ioctl(struct inode *if (data->frozen)break ;down (&pm_sem); -pm_prepare_console ();disable_nonboot_cpus ();if (freeze_processes ()) {thaw_processes ();enable_nonboot_cpus (); -pm_restore_console (); error = -EBUSY ; }up (&pm_sem);
@@ -157,7 +155,6 @@ static int snapshot_ioctl(struct inode *down (&pm_sem);thaw_processes ();enable_nonboot_cpus (); -pm_restore_console ();up (&pm_sem); data->frozen =0 ;break ;
PATCH 2/3 pm: check console before suspending devices
In reply to a message not in the archiveFrom: "Rafael J. Wysocki" <[email protected]>
It is unsafe to suspend devices if the hardware is controlled by X. Add an extra check to prevent this from happening.
--- drivers/base/power/suspend.c | 5 ++++- drivers/char/vt.c | 8 ++++++++ include/linux/vt_kern.h | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-)
drivers/base/power/suspend.c +4 -1
@@ -8,6 +8,7 @@* */ +#include <linux/vt_kern.h> #include <linux/device.h> #include <linux/kallsyms.h> #include <linux/pm.h>
@@ -65,7 +66,6 @@ int suspend_device(struct device * dev,return error; } -/** * device_suspend - Save state and stop all devices in system. * @state: Power state to put each device in.
@@ -85,6 +85,9 @@ int device_suspend(pm_message_t state) {int error =0 ; +if (!is_console_suspend_safe ()) +return -EINVAL ; +down (&dpm_sem);down (&dpm_list_sem);while (!list_empty (&dpm_active) && error ==0 ) {
drivers/char/vt.c +8 -0
@@ -3234,6 +3234,14 @@ void vcs_scr_writew(struct vc_data *vc, } } +/* It is unsafe to suspend devices while X has control of the +* hardware. Check if we are running on a kernel-controlled console. +*/ +int is_console_suspend_safe (void ) +{ +return vc_cons[fg_console].d->vc_mode ==KD_TEXT ; +} +/* * Visible symbols for modules */
include/linux/vt_kern.h +5 -0
@@ -73,6 +73,11 @@ int con_copy_unimap(struct vc_data *dst_int vt_waitactive (int vt);void change_console (struct vc_data *new_vc);void reset_vc (struct vc_data *vc); +#ifdef CONFIG_VT +int is_console_suspend_safe (void ); +#else +static inline int is_console_suspend_safe (void ) {return 1 ; } +#endif /* * vc_screen.c shares this temporary buffer with the console write code so that
PATCH 3/3 swsusp: add s2ram ioctl to userland interface
In reply to a message not in the archiveFrom: Luca Tettamanti <[email protected]>
Add the SNAPSHOT_S2RAM ioctl to the snapshot device.
This ioctl allows a userland application to make the system (previously frozen with the SNAPSHOT_FREE ioctl) enter the S3 state without freezing processes and disabling nonboot CPUs for the second time.
This will allow us to implement the suspend-to-disk-and-RAM (STDR) functionality in the userland suspend tools.
--- kernel/power/main.c | 2 +- kernel/power/power.h | 4 +++- kernel/power/user.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-)
kernel/power/main.c +1 -1
@@ -103,7 +103,7 @@ static int suspend_prepare(suspend_state } -static int suspend_enter (suspend_state_t state) +int suspend_enter (suspend_state_t state) {int error =0 ;unsigned long flags;
kernel/power/power.h +3 -1
@@ -77,7 +77,8 @@ int snapshot_image_loaded(struct snapsho#define SNAPSHOT_GET_SWAP_PAGE _IOR(SNAPSHOT_IOC_MAGIC, 8, void *)#define SNAPSHOT_FREE_SWAP_PAGES _IO(SNAPSHOT_IOC_MAGIC, 9)#define SNAPSHOT_SET_SWAP_FILE _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int) -#define SNAPSHOT_IOC_MAXNR 10 +#define SNAPSHOT_S2RAM _IO(SNAPSHOT_IOC_MAGIC, 11) +#define SNAPSHOT_IOC_MAXNR 11/** * The bitmap is used for tracing allocated swap pages
@@ -112,3 +113,4 @@ extern int swsusp_resume(void);extern int swsusp_read (void );extern int swsusp_write (void );extern void swsusp_close (void ); +extern int suspend_enter (suspend_state_t state);
kernel/power/user.c +36 -0
@@ -265,6 +265,42 @@ static int snapshot_ioctl(struct inode * }break ; +case SNAPSHOT_S2RAM : +if (!data->frozen) { + error = -EPERM ; +break ; + } + +if (down_trylock (&pm_sem)) { + error = -EBUSY ; +break ; + } + +if (pm_ops->prepare) { + error = pm_ops->prepare (PM_SUSPEND_MEM ); +if (error) + goto OutS3; + } + +/* Put devices to sleep */ + error =device_suspend (PMSG_SUSPEND ); +if (error) { +printk (KERN_ERR "Failed to suspend some devices.\n" ); + }else { +/* Enter S3, system is already frozen */ +suspend_enter (PM_SUSPEND_MEM ); + +/* Wake up devices */ +device_resume (); + } + +if (pm_ops->finish) + pm_ops->finish (PM_SUSPEND_MEM ); + +OutS3: +up (&pm_sem); +break ; +default : error = -ENOTTY ;