From 73f57583b14a09713ac45aa770182231e008cb58 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 4 Nov 2016 09:25:54 +1100 Subject: [PATCH 06/18] Convert msleep to use hrtimers when active. --- kernel/time/timer.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) Index: linux-4.11-ck1/kernel/time/timer.c =================================================================== --- linux-4.11-ck1.orig/kernel/time/timer.c 2017-05-12 13:25:54.955576774 +1000 +++ linux-4.11-ck1/kernel/time/timer.c 2017-05-12 13:25:54.955576774 +1000 @@ -1852,7 +1852,19 @@ void __init init_timers(void) */ void msleep(unsigned int msecs) { - unsigned long timeout = msecs_to_jiffies(msecs) + 1; + int jiffs = msecs_to_jiffies(msecs); + unsigned long timeout; + + /* + * Use high resolution timers where the resolution of tick based + * timers is inadequate. + */ + if (jiffs < 5 && hrtimer_resolution < NSEC_PER_SEC / HZ) { + while (msecs) + msecs = schedule_msec_hrtimeout_uninterruptible(msecs); + return; + } + timeout = msecs_to_jiffies(msecs) + 1; while (timeout) timeout = schedule_timeout_uninterruptible(timeout); @@ -1866,7 +1878,15 @@ EXPORT_SYMBOL(msleep); */ unsigned long msleep_interruptible(unsigned int msecs) { - unsigned long timeout = msecs_to_jiffies(msecs) + 1; + int jiffs = msecs_to_jiffies(msecs); + unsigned long timeout; + + if (jiffs < 5 && hrtimer_resolution < NSEC_PER_SEC / HZ) { + while (msecs && !signal_pending(current)) + msecs = schedule_msec_hrtimeout_interruptible(msecs); + return msecs; + } + timeout = msecs_to_jiffies(msecs) + 1; while (timeout && !signal_pending(current)) timeout = schedule_timeout_interruptible(timeout);