From a5a8a9e45d02c2bfabb06c13278c4bd3895267c0 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 5 Nov 2016 09:27:36 +1100 Subject: [PATCH 05/18] Special case calls of schedule_timeout(1) to use the min hrtimeout of 1ms, working around low Hz resolutions. --- kernel/time/timer.c | 17 +++++++++++++++-- 1 file changed, 15 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.835577214 +1000 +++ linux-4.11-ck1/kernel/time/timer.c 2017-05-12 13:25:54.835577214 +1000 @@ -1709,6 +1709,19 @@ signed long __sched schedule_timeout(sig expire = timeout + jiffies; +#ifdef CONFIG_HIGH_RES_TIMERS + if (timeout == 1 && 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 + * the granularity of low Hz tick timers. + */ + if (!schedule_min_hrtimeout()) + return 0; + goto out_timeout; + } +#endif + setup_timer_on_stack(&timer, process_timeout, (unsigned long)current); __mod_timer(&timer, expire, false); schedule(); @@ -1716,10 +1729,10 @@ signed long __sched schedule_timeout(sig /* Remove the timer from the object tracker */ destroy_timer_on_stack(&timer); - +out_timeout: timeout = expire - jiffies; - out: +out: return timeout < 0 ? 0 : timeout; } EXPORT_SYMBOL(schedule_timeout);