Skip to content

Commit 4cc7977

Browse files
rjwysockilenb
authored andcommitted
Hibernation: New testing facility (rev. 2)
Make it possible to test the hibernation core code with the help of the /sys/power/pm_test attribute introduced for suspend testing in the previous patch. Writing an appropriate string to this file causes the hibernation 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 (*) - the platform global control methods are only available on ACPI systems       and are only tested if the hibernation mode is set to "platform" Then, if a hibernation is started by normal means, the hibernation 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. 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>
1 parent 039a75c commit 4cc7977

2 files changed

Lines changed: 57 additions & 15 deletions

File tree

‎kernel/power/disk.c‎

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,35 @@ void hibernation_set_ops(struct platform_hibernation_ops *ops)
7070
mutex_unlock(&pm_mutex);
7171
}
7272

73+
#ifdef CONFIG_PM_DEBUG
74+
static void hibernation_debug_sleep(void)
75+
{
76+
printk(KERN_INFO "hibernation debug: Waiting for 5 seconds.\n");
77+
mdelay(5000);
78+
}
79+
80+
static int hibernation_testmode(int mode)
81+
{
82+
if (hibernation_mode == mode) {
83+
hibernation_debug_sleep();
84+
return 1;
85+
}
86+
return 0;
87+
}
88+
89+
static int hibernation_test(int level)
90+
{
91+
if (pm_test_level == level) {
92+
hibernation_debug_sleep();
93+
return 1;
94+
}
95+
return 0;
96+
}
97+
#else /* !CONFIG_PM_DEBUG */
98+
static int hibernation_testmode(int mode) { return 0; }
99+
static int hibernation_test(int level) { return 0; }
100+
#endif /* !CONFIG_PM_DEBUG */
101+
73102
/**
74103
* platform_start - tell the platform driver that we're starting
75104
* hibernation
@@ -167,6 +196,10 @@ int create_image(int platform_mode)
167196
goto Enable_irqs;
168197
}
169198

199+
if (hibernation_test(TEST_CORE))
200+
goto Power_up;
201+
202+
in_suspend = 1;
170203
save_processor_state();
171204
error = swsusp_arch_suspend();
172205
if (error)
@@ -175,6 +208,7 @@ int create_image(int platform_mode)
175208
restore_processor_state();
176209
if (!in_suspend)
177210
platform_leave(platform_mode);
211+
Power_up:
178212
/* NOTE: device_power_up() is just a resume() for devices
179213
* that suspended with irqs off ... no overall powerup.
180214
*/
@@ -211,24 +245,29 @@ int hibernation_snapshot(int platform_mode)
211245
if (error)
212246
goto Resume_console;
213247

214-
error = platform_pre_snapshot(platform_mode);
215-
if (error)
248+
if (hibernation_test(TEST_DEVICES))
216249
goto Resume_devices;
217250

251+
error = platform_pre_snapshot(platform_mode);
252+
if (error || hibernation_test(TEST_PLATFORM))
253+
goto Finish;
254+
218255
error = disable_nonboot_cpus();
219256
if (!error) {
220-
if (hibernation_mode != HIBERNATION_TEST) {
221-
in_suspend = 1;
222-
error = create_image(platform_mode);
223-
/* Control returns here after successful restore */
224-
} else {
225-
printk("swsusp debug: Waiting for 5 seconds.\n");
226-
mdelay(5000);
227-
}
257+
if (hibernation_test(TEST_CPUS))
258+
goto Enable_cpus;
259+
260+
if (hibernation_testmode(HIBERNATION_TEST))
261+
goto Enable_cpus;
262+
263+
error = create_image(platform_mode);
264+
/* Control returns here after successful restore */
228265
}
266+
Enable_cpus:
229267
enable_nonboot_cpus();
230-
Resume_devices:
268+
Finish:
231269
platform_finish(platform_mode);
270+
Resume_devices:
232271
device_resume();
233272
Resume_console:
234273
resume_console();
@@ -406,11 +445,12 @@ int hibernate(void)
406445
if (error)
407446
goto Finish;
408447

409-
if (hibernation_mode == HIBERNATION_TESTPROC) {
410-
printk("swsusp debug: Waiting for 5 seconds.\n");
411-
mdelay(5000);
448+
if (hibernation_test(TEST_FREEZER))
412449
goto Thaw;
413-
}
450+
451+
if (hibernation_testmode(HIBERNATION_TESTPROC))
452+
goto Thaw;
453+
414454
error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
415455
if (in_suspend && !error) {
416456
unsigned int flags = 0;

‎kernel/power/power.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,5 @@ enum {
206206

207207
#define TEST_FIRST TEST_NONE
208208
#define TEST_MAX (__TEST_AFTER_LAST - 1)
209+
210+
extern int pm_test_level;

0 commit comments

Comments
 (0)