From db341e181e06ced57c9e9889611d1b59d112fadd Mon Sep 17 00:00:00 2001 From: Morten Rasmussen Date: Wed, 30 Mar 2016 14:20:12 +0100 Subject: [PATCH] sched/fair: Add energy_diff dead-zone margin It is not worth the overhead to migrate tasks for tiny insignificant energy savings. To prevent this, an energy margin is introduced in energy_diff() which effectively adds a dead-zone that rounds tiny energy differences to zero. Since no scale is enforced for energy model data the margin can't be absolute. Instead it is defined as +/-1.56% energy saving compared to the current total estimated energy consumption. Change-Id: I6be069c752c701fb825430896b3b768a7ab2fee4 Signed-off-by: Morten Rasmussen [rebase: on top of msm-google/android-msm-marlin-3.18, massage original patch which changes code in energy_diff() into __energy_diff() introduced by SchedTune] Signed-off-by: Dietmar Eggemann Signed-off-by: Chris Redpath (cherry picked from commit 780cb5a5fa47adf13d4fc2b77e8e94448cd56098) Signed-off-by: Chris Redpath --- kernel/sched/fair.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index ef16d4d3cc00..16f15549b5d0 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5149,6 +5149,7 @@ static inline int __energy_diff(struct energy_env *eenv) struct sched_domain *sd; struct sched_group *sg; int sd_cpu = -1, energy_before = 0, energy_after = 0; + int diff, margin; struct energy_env eenv_before = { .util_delta = 0, @@ -5198,6 +5199,16 @@ static inline int __energy_diff(struct energy_env *eenv) eenv->cap.before, eenv->cap.after, eenv->cap.delta, eenv->nrg.delta, eenv->payoff); + /* + * Dead-zone margin preventing too many migrations. + */ + + margin = eenv->nrg.before >> 6; /* ~1.56% */ + + diff = eenv->nrg.after - eenv->nrg.before; + + eenv->nrg.diff = (abs(diff) < margin) ? 0 : eenv->nrg.diff; + return eenv->nrg.diff; } -- 2.34.1