Skip to content

Commit 0ede470

Browse files
committed
Merge branch 'pm-sleep'
* pm-sleep: PM / hibernate: Iterate over set bits instead of PFNs in swsusp_free() PM / sleep: new suspend_resume trace event for console resume PM / sleep: Update test_suspend option documentation PM / sleep: Enhance test_suspend option with repeat capability PM / sleep: Support freeze as test_suspend option PM / sysfs: avoid shadowing variables
2 parents 88b42a4 + fdd64ed commit 0ede470

5 files changed

Lines changed: 89 additions & 33 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,11 +3303,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
33033303

33043304
tdfx= [HW,DRM]
33053305

3306-
test_suspend= [SUSPEND]
3306+
test_suspend= [SUSPEND][,N]
33073307
Specify "mem" (for Suspend-to-RAM) or "standby" (for
3308-
standby suspend) as the system sleep state to briefly
3309-
enter during system startup. The system is woken from
3310-
this state using a wakeup-capable RTC alarm.
3308+
standby suspend) or "freeze" (for suspend type freeze)
3309+
as the system sleep state during system startup with
3310+
the optional capability to repeat N number of times.
3311+
The system is woken from this state using a
3312+
wakeup-capable RTC alarm.
33113313

33123314
thash_entries= [KNL,NET]
33133315
Set number of hash buckets for TCP connection

‎drivers/base/power/sysfs.c‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@
9292
* wakeup_count - Report the number of wakeup events related to the device
9393
*/
9494

95-
static const char enabled[] = "enabled";
96-
static const char disabled[] = "disabled";
97-
9895
const char power_group_name[] = "power";
9996
EXPORT_SYMBOL_GPL(power_group_name);
10097

@@ -336,11 +333,14 @@ static DEVICE_ATTR(pm_qos_remote_wakeup, 0644,
336333
#endif /* CONFIG_PM_RUNTIME */
337334

338335
#ifdef CONFIG_PM_SLEEP
336+
static const char _enabled[] = "enabled";
337+
static const char _disabled[] = "disabled";
338+
339339
static ssize_t
340340
wake_show(struct device * dev, struct device_attribute *attr, char * buf)
341341
{
342342
return sprintf(buf, "%s\n", device_can_wakeup(dev)
343-
? (device_may_wakeup(dev) ? enabled : disabled)
343+
? (device_may_wakeup(dev) ? _enabled : _disabled)
344344
: "");
345345
}
346346

@@ -357,11 +357,11 @@ wake_store(struct device * dev, struct device_attribute *attr,
357357
cp = memchr(buf, '\n', n);
358358
if (cp)
359359
len = cp - buf;
360-
if (len == sizeof enabled - 1
361-
&& strncmp(buf, enabled, sizeof enabled - 1) == 0)
360+
if (len == sizeof _enabled - 1
361+
&& strncmp(buf, _enabled, sizeof _enabled - 1) == 0)
362362
device_set_wakeup_enable(dev, 1);
363-
else if (len == sizeof disabled - 1
364-
&& strncmp(buf, disabled, sizeof disabled - 1) == 0)
363+
else if (len == sizeof _disabled - 1
364+
&& strncmp(buf, _disabled, sizeof _disabled - 1) == 0)
365365
device_set_wakeup_enable(dev, 0);
366366
else
367367
return -EINVAL;
@@ -570,7 +570,8 @@ static ssize_t async_show(struct device *dev, struct device_attribute *attr,
570570
char *buf)
571571
{
572572
return sprintf(buf, "%s\n",
573-
device_async_suspend_enabled(dev) ? enabled : disabled);
573+
device_async_suspend_enabled(dev) ?
574+
_enabled : _disabled);
574575
}
575576

576577
static ssize_t async_store(struct device *dev, struct device_attribute *attr,
@@ -582,9 +583,10 @@ static ssize_t async_store(struct device *dev, struct device_attribute *attr,
582583
cp = memchr(buf, '\n', n);
583584
if (cp)
584585
len = cp - buf;
585-
if (len == sizeof enabled - 1 && strncmp(buf, enabled, len) == 0)
586+
if (len == sizeof _enabled - 1 && strncmp(buf, _enabled, len) == 0)
586587
device_enable_async_suspend(dev);
587-
else if (len == sizeof disabled - 1 && strncmp(buf, disabled, len) == 0)
588+
else if (len == sizeof _disabled - 1 &&
589+
strncmp(buf, _disabled, len) == 0)
588590
device_disable_async_suspend(dev);
589591
else
590592
return -EINVAL;

‎kernel/power/snapshot.c‎

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,14 @@ static void memory_bm_clear_bit(struct memory_bitmap *bm, unsigned long pfn)
725725
clear_bit(bit, addr);
726726
}
727727

728+
static void memory_bm_clear_current(struct memory_bitmap *bm)
729+
{
730+
int bit;
731+
732+
bit = max(bm->cur.node_bit - 1, 0);
733+
clear_bit(bit, bm->cur.node->data);
734+
}
735+
728736
static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn)
729737
{
730738
void *addr;
@@ -1333,23 +1341,39 @@ static struct memory_bitmap copy_bm;
13331341

13341342
void swsusp_free(void)
13351343
{
1336-
struct zone *zone;
1337-
unsigned long pfn, max_zone_pfn;
1344+
unsigned long fb_pfn, fr_pfn;
13381345

1339-
for_each_populated_zone(zone) {
1340-
max_zone_pfn = zone_end_pfn(zone);
1341-
for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++)
1342-
if (pfn_valid(pfn)) {
1343-
struct page *page = pfn_to_page(pfn);
1344-
1345-
if (swsusp_page_is_forbidden(page) &&
1346-
swsusp_page_is_free(page)) {
1347-
swsusp_unset_page_forbidden(page);
1348-
swsusp_unset_page_free(page);
1349-
__free_page(page);
1350-
}
1351-
}
1346+
if (!forbidden_pages_map || !free_pages_map)
1347+
goto out;
1348+
1349+
memory_bm_position_reset(forbidden_pages_map);
1350+
memory_bm_position_reset(free_pages_map);
1351+
1352+
loop:
1353+
fr_pfn = memory_bm_next_pfn(free_pages_map);
1354+
fb_pfn = memory_bm_next_pfn(forbidden_pages_map);
1355+
1356+
/*
1357+
* Find the next bit set in both bitmaps. This is guaranteed to
1358+
* terminate when fb_pfn == fr_pfn == BM_END_OF_MAP.
1359+
*/
1360+
do {
1361+
if (fb_pfn < fr_pfn)
1362+
fb_pfn = memory_bm_next_pfn(forbidden_pages_map);
1363+
if (fr_pfn < fb_pfn)
1364+
fr_pfn = memory_bm_next_pfn(free_pages_map);
1365+
} while (fb_pfn != fr_pfn);
1366+
1367+
if (fr_pfn != BM_END_OF_MAP && pfn_valid(fr_pfn)) {
1368+
struct page *page = pfn_to_page(fr_pfn);
1369+
1370+
memory_bm_clear_current(forbidden_pages_map);
1371+
memory_bm_clear_current(free_pages_map);
1372+
__free_page(page);
1373+
goto loop;
13521374
}
1375+
1376+
out:
13531377
nr_copy_pages = 0;
13541378
nr_meta_pages = 0;
13551379
restore_pblist = NULL;

‎kernel/power/suspend.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ int suspend_devices_and_enter(suspend_state_t state)
361361
suspend_test_start();
362362
dpm_resume_end(PMSG_RESUME);
363363
suspend_test_finish("resume devices");
364+
trace_suspend_resume(TPS("resume_console"), state, true);
364365
resume_console();
366+
trace_suspend_resume(TPS("resume_console"), state, false);
365367

366368
Close:
367369
platform_suspend_end(state);

‎kernel/power/suspend_test.c‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#define TEST_SUSPEND_SECONDS 10
2323

2424
static unsigned long suspend_test_start_time;
25+
static u32 test_repeat_count_max = 1;
26+
static u32 test_repeat_count_current;
2527

2628
void suspend_test_start(void)
2729
{
@@ -74,6 +76,7 @@ static void __init test_wakealarm(struct rtc_device *rtc, suspend_state_t state)
7476
int status;
7577

7678
/* this may fail if the RTC hasn't been initialized */
79+
repeat:
7780
status = rtc_read_time(rtc, &alm.time);
7881
if (status < 0) {
7982
printk(err_readtime, dev_name(&rtc->dev), status);
@@ -100,10 +103,21 @@ static void __init test_wakealarm(struct rtc_device *rtc, suspend_state_t state)
100103
if (state == PM_SUSPEND_STANDBY) {
101104
printk(info_test, pm_states[state]);
102105
status = pm_suspend(state);
106+
if (status < 0)
107+
state = PM_SUSPEND_FREEZE;
103108
}
109+
if (state == PM_SUSPEND_FREEZE) {
110+
printk(info_test, pm_states[state]);
111+
status = pm_suspend(state);
112+
}
113+
104114
if (status < 0)
105115
printk(err_suspend, status);
106116

117+
test_repeat_count_current++;
118+
if (test_repeat_count_current < test_repeat_count_max)
119+
goto repeat;
120+
107121
/* Some platforms can't detect that the alarm triggered the
108122
* wakeup, or (accordingly) disable it after it afterwards.
109123
* It's supposed to give oneshot behavior; cope.
@@ -137,16 +151,28 @@ static char warn_bad_state[] __initdata =
137151
static int __init setup_test_suspend(char *value)
138152
{
139153
int i;
154+
char *repeat;
155+
char *suspend_type;
140156

141-
/* "=mem" ==> "mem" */
157+
/* example : "=mem[,N]" ==> "mem[,N]" */
142158
value++;
159+
suspend_type = strsep(&value, ",");
160+
if (!suspend_type)
161+
return 0;
162+
163+
repeat = strsep(&value, ",");
164+
if (repeat) {
165+
if (kstrtou32(repeat, 0, &test_repeat_count_max))
166+
return 0;
167+
}
168+
143169
for (i = 0; pm_labels[i]; i++)
144-
if (!strcmp(pm_labels[i], value)) {
170+
if (!strcmp(pm_labels[i], suspend_type)) {
145171
test_state_label = pm_labels[i];
146172
return 0;
147173
}
148174

149-
printk(warn_bad_state, value);
175+
printk(warn_bad_state, suspend_type);
150176
return 0;
151177
}
152178
__setup("test_suspend", setup_test_suspend);

0 commit comments

Comments
 (0)