Skip to content

Commit

Permalink
time: Special case calls of schedule_timeout(1) to use the min hrtime…
Browse files Browse the repository at this point in the history
…out of 1ms, working around low Hz resolutions.
  • Loading branch information
ckolivas authored and xanmod committed Feb 16, 2021
1 parent 07d208a commit 480a4d2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions kernel/time/timer.c
Expand Up @@ -1872,6 +1872,18 @@ signed long __sched schedule_timeout(signed long timeout)

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
timer.task = current;
timer_setup_on_stack(&timer.timer, process_timeout, 0);
__mod_timer(&timer.timer, expire, MOD_TIMER_NOTPENDING);
Expand All @@ -1880,10 +1892,10 @@ signed long __sched schedule_timeout(signed long timeout)

/* Remove the timer from the object tracker */
destroy_timer_on_stack(&timer.timer);

out_timeout:
timeout = expire - jiffies;

out:
out:
return timeout < 0 ? 0 : timeout;
}
EXPORT_SYMBOL(schedule_timeout);
Expand Down

0 comments on commit 480a4d2

Please sign in to comment.