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.

Signed-off-by: Alexandre Frade <kernel@xanmod.org>
  • Loading branch information
ckolivas authored and xanmod committed Aug 31, 2021
1 parent d918ad3 commit 489c979
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions kernel/time/timer.c
Expand Up @@ -1875,6 +1875,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 @@ -1883,10 +1895,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 489c979

Please sign in to comment.