Skip to content

Commit

Permalink
timer: Convert msleep to use hrtimers when active.
Browse files Browse the repository at this point in the history
  • Loading branch information
ckolivas authored and xanmod committed Oct 15, 2020
1 parent a2cbdf6 commit c79c34d
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions kernel/time/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,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);
Expand All @@ -2053,7 +2065,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);
Expand Down

0 comments on commit c79c34d

Please sign in to comment.