Skip to content

Commit

Permalink
cpuidle: poll_state: Revise loop termination condition
Browse files Browse the repository at this point in the history
If need_resched() returns "false", breaking out of the loop in
poll_idle() will cause a new idle state to be selected, so in fact
it usually doesn't make sense to spin in it longer than the target
residency of the second state.  [Note that the "polling" state is
used only if there is at least one "real" state defined in addition
to it, so the second state is always there.]  On the other hand,
breaking out of it early (say in case the next state is disabled)
shouldn't hurt as it is polling anyway.

For this reason, make the loop in poll_idle() break if the CPU has
been spinning longer than the target residency of the second state
(the "polling" state can only be state[0]).

Signed-off-by: Rafael J. Wysocki <[email protected]>
  • Loading branch information
rafaeljw committed Oct 4, 2018
1 parent 53812cd commit 01bad1c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/cpuidle/poll_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <linux/sched/clock.h>
#include <linux/sched/idle.h>

#define POLL_IDLE_TIME_LIMIT (TICK_NSEC / 16)
#define POLL_IDLE_RELAX_COUNT 200

static int __cpuidle poll_idle(struct cpuidle_device *dev,
Expand All @@ -21,6 +20,7 @@ static int __cpuidle poll_idle(struct cpuidle_device *dev,

local_irq_enable();
if (!current_set_polling_and_test()) {
u64 limit = (u64)drv->states[1].target_residency * NSEC_PER_USEC;
unsigned int loop_count = 0;

while (!need_resched()) {
Expand All @@ -29,7 +29,7 @@ static int __cpuidle poll_idle(struct cpuidle_device *dev,
continue;

loop_count = 0;
if (local_clock() - time_start > POLL_IDLE_TIME_LIMIT) {
if (local_clock() - time_start > limit) {
dev->poll_time_limit = true;
break;
}
Expand Down

0 comments on commit 01bad1c

Please sign in to comment.