cpuidle: teo: Avoid using "early hits" incorrectly
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 13 Nov 2019 00:03:24 +0000 (01:03 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Feb 2020 21:22:52 +0000 (21:22 +0000)
commitf42407a7906b295b6386719aaaf32928c4d24553
treefb1fe394efc88f219d9b1527edf2e8a1bbf52f42
parentc5e3c887dfc08249e091eef3ea6020cf43b9e49b
cpuidle: teo: Avoid using "early hits" incorrectly

[ Upstream commit 63f202e5edf161c2ccffa286a9a701e995427b15 ]

If the current state with the maximum "early hits" metric in
teo_select() is also the one "matching" the expected idle duration,
it will be used as the candidate one for selection even if its
"misses" metric is greater than its "hits" metric, which is not
correct.

In that case, the candidate state should be shallower than the
current one and its "early hits" metric should be the maximum
among the idle states shallower than the current one.

To make that happen, modify teo_select() to save the index of
the state whose "early hits" metric is the maximum for the
range of states below the current one and go back to that state
if it turns out that the current one should be rejected.

Fixes: 159e48560f51 ("cpuidle: teo: Fix "early hits" handling for disabled idle states")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/cpuidle/governors/teo.c