Skip to content

Commit 957d128

Browse files
fli24rafaeljw
authored andcommitted
suspend: enable freeze timeout configuration through sys
At present, the value of timeout for freezing is 20s, which is meaningless in case that one thread is frozen with mutex locked and another thread is trying to lock the mutex, as this time of freezing will fail unavoidably. And if there is no new wakeup event registered, the system will waste at most 20s for such meaningless trying of freezing. With this patch, the value of timeout can be configured to smaller value, so such meaningless trying of freezing will be aborted in earlier time, and later freezing can be also triggered in earlier time. And more power will be saved. In normal case on mobile phone, it costs real little time to freeze processes. On some platform, it only costs about 20ms to freeze user space processes and 10ms to freeze kernel freezable threads. Signed-off-by: Liu Chuansheng <chuansheng.liu@intel.com> Signed-off-by: Li Fei <fei.li@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 89a22da commit 957d128

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎Documentation/power/freezing-of-tasks.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,8 @@ since they ask the freezer to skip freezing this task, since it is anyway
223223
only after the entire suspend/hibernation sequence is complete.
224224
So, to summarize, use [un]lock_system_sleep() instead of directly using
225225
mutex_[un]lock(&pm_mutex). That would prevent freezing failures.
226+
227+
V. Miscellaneous
228+
/sys/power/pm_freeze_timeout controls how long it will cost at most to freeze
229+
all user space processes or all freezable kernel threads, in unit of millisecond.
230+
The default value is 20000, with range of unsigned integer.

‎include/linux/freezer.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ extern atomic_t system_freezing_cnt; /* nr of freezing conds in effect */
1212
extern bool pm_freezing; /* PM freezing in effect */
1313
extern bool pm_nosig_freezing; /* PM nosig freezing in effect */
1414

15+
/*
16+
* Timeout for stopping processes
17+
*/
18+
extern unsigned int freeze_timeout_msecs;
19+
1520
/*
1621
* Check if a process has been frozen
1722
*/

‎kernel/power/main.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,30 @@ power_attr(pm_trace_dev_match);
553553

554554
#endif /* CONFIG_PM_TRACE */
555555

556+
#ifdef CONFIG_FREEZER
557+
static ssize_t pm_freeze_timeout_show(struct kobject *kobj,
558+
struct kobj_attribute *attr, char *buf)
559+
{
560+
return sprintf(buf, "%u\n", freeze_timeout_msecs);
561+
}
562+
563+
static ssize_t pm_freeze_timeout_store(struct kobject *kobj,
564+
struct kobj_attribute *attr,
565+
const char *buf, size_t n)
566+
{
567+
unsigned long val;
568+
569+
if (kstrtoul(buf, 10, &val))
570+
return -EINVAL;
571+
572+
freeze_timeout_msecs = val;
573+
return n;
574+
}
575+
576+
power_attr(pm_freeze_timeout);
577+
578+
#endif /* CONFIG_FREEZER*/
579+
556580
static struct attribute * g[] = {
557581
&state_attr.attr,
558582
#ifdef CONFIG_PM_TRACE
@@ -575,6 +599,9 @@ static struct attribute * g[] = {
575599
#ifdef CONFIG_PM_SLEEP_DEBUG
576600
&pm_print_times_attr.attr,
577601
#endif
602+
#endif
603+
#ifdef CONFIG_FREEZER
604+
&pm_freeze_timeout_attr.attr,
578605
#endif
579606
NULL,
580607
};

‎kernel/power/process.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/*
2222
* Timeout for stopping processes
2323
*/
24-
#define TIMEOUT (20 * HZ)
24+
unsigned int __read_mostly freeze_timeout_msecs = 20 * MSEC_PER_SEC;
2525

2626
static int try_to_freeze_tasks(bool user_only)
2727
{
@@ -36,7 +36,7 @@ static int try_to_freeze_tasks(bool user_only)
3636

3737
do_gettimeofday(&start);
3838

39-
end_time = jiffies + TIMEOUT;
39+
end_time = jiffies + msecs_to_jiffies(freeze_timeout_msecs);
4040

4141
if (!user_only)
4242
freeze_workqueues_begin();

0 commit comments

Comments
 (0)