Skip to content

Commit

Permalink
PM / Autosleep: add timeout after exiting suspend
Browse files Browse the repository at this point in the history
By adding uninterruptible timeout after exiting suspend, it avoids
entering new automatic suspend without any delay. This allows to
other processes to respond to the exit from suspend and is required
in some cases to make automatic suspend to work and not get cancelled
by wakelocks filed by other threads during the next suspend attempt.
  • Loading branch information
rinigus committed Nov 11, 2019
1 parent 6eb403f commit 6ed1fe4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions kernel/power/autosleep.c
Expand Up @@ -26,6 +26,7 @@ static struct wakeup_source *autosleep_ws;
static void try_to_suspend(struct work_struct *work)
{
unsigned int initial_count, final_count;
int error;

if (!pm_get_wakeup_count(&initial_count, true))
goto out;
Expand All @@ -43,23 +44,26 @@ static void try_to_suspend(struct work_struct *work)
return;
}
if (autosleep_state >= PM_SUSPEND_MAX)
hibernate();
error = hibernate();
else
pm_suspend(autosleep_state);
error = pm_suspend(autosleep_state);

mutex_unlock(&autosleep_lock);

if (!pm_get_wakeup_count(&final_count, false))
goto out;
if (!error)
error = pm_get_wakeup_count(&final_count, false);

/*
* If the wakeup occured for an unknown reason, wait to prevent the
* system from trying to suspend and waking up in a tight loop.
* Add extra wait in this case.
*/
if (final_count == initial_count)
schedule_timeout_uninterruptible(HZ / 2);
if (error || final_count == initial_count)
schedule_timeout_uninterruptible(msecs_to_jiffies(250));

out:
/* always add timeout to prevent tight loop of suspend and waking up */
schedule_timeout_uninterruptible(msecs_to_jiffies(250));
queue_up_suspend_work();
}

Expand Down

2 comments on commit 6ed1fe4

@Thaodan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this go to upstream?

@rinigus
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, it is a hack. Let's see if we need it on 4.14

Please sign in to comment.