From 14be6e87e43466b20d88e6a12e01cd9cf40d40b1 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 8 Nov 2016 17:54:56 +1100 Subject: [PATCH] Make freezable timeouts not use the highres timers. --- include/linux/freezer.h | 7 +++++-- kernel/time/timer.c | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/linux/freezer.h b/include/linux/freezer.h index dd03e83..322395b 100644 --- a/include/linux/freezer.h +++ b/include/linux/freezer.h @@ -180,6 +180,8 @@ static inline void freezable_schedule_unsafe(void) freezer_count_unsafe(); } +extern signed long fschedule_timeout(signed long timeout); + /* * Like freezable_schedule_timeout(), but should not block the freezer. Do not * call this with locks held. @@ -188,7 +190,7 @@ static inline long freezable_schedule_timeout(long timeout) { long __retval; freezer_do_not_count(); - __retval = schedule_timeout(timeout); + __retval = fschedule_timeout(timeout); freezer_count(); return __retval; } @@ -201,7 +203,8 @@ static inline long freezable_schedule_timeout_interruptible(long timeout) { long __retval; freezer_do_not_count(); - __retval = schedule_timeout_interruptible(timeout); + __set_current_state(TASK_INTERRUPTIBLE); + __retval = fschedule_timeout(timeout); freezer_count(); return __retval; } diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 7651d47..0455ab7 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1709,7 +1709,7 @@ static void process_timeout(unsigned long __data) * * In all cases the return value is guaranteed to be non-negative. */ -signed long __sched schedule_timeout(signed long timeout) +static signed long __schedule_timeout(signed long timeout, bool freezable) { struct timer_list timer; unsigned long expire; @@ -1745,7 +1745,7 @@ signed long __sched schedule_timeout(signed long timeout) expire = timeout + jiffies; - if (timeout == 1 && hrtimer_resolution < NSEC_PER_SEC / HZ) { + if (timeout == 1 && !freezable && hrtimer_resolution < NSEC_PER_SEC / HZ) { /* * Special case 1 as being a request for the minimum timeout * and use highres timers to timeout after 1ms to workaround @@ -1769,8 +1769,20 @@ out_timeout: out: return timeout < 0 ? 0 : timeout; } + +signed long __sched schedule_timeout(signed long timeout) +{ + return __schedule_timeout(timeout, false); +} EXPORT_SYMBOL(schedule_timeout); +signed long __sched fschedule_timeout(signed long timeout) +{ + return __schedule_timeout(timeout, true); +} +EXPORT_SYMBOL(fschedule_timeout); + + /* * We can use __set_current_state() here because schedule_timeout() calls * schedule() unconditionally. @@ -1785,14 +1797,14 @@ EXPORT_SYMBOL(schedule_timeout_interruptible); signed long __sched schedule_timeout_killable(signed long timeout) { __set_current_state(TASK_KILLABLE); - return schedule_timeout(timeout); + return fschedule_timeout(timeout); } EXPORT_SYMBOL(schedule_timeout_killable); signed long __sched schedule_timeout_uninterruptible(signed long timeout) { __set_current_state(TASK_UNINTERRUPTIBLE); - return schedule_timeout(timeout); + return fschedule_timeout(timeout); } EXPORT_SYMBOL(schedule_timeout_uninterruptible); @@ -1803,7 +1815,7 @@ EXPORT_SYMBOL(schedule_timeout_uninterruptible); signed long __sched schedule_timeout_idle(signed long timeout) { __set_current_state(TASK_IDLE); - return schedule_timeout(timeout); + return fschedule_timeout(timeout); } EXPORT_SYMBOL(schedule_timeout_idle); -- 2.7.4