Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90f82902 authored by Joonwoo Park's avatar Joonwoo Park
Browse files

sched: EAS: fix incorrect energy delta calculation due to rounding error



In order to calculate energy difference we currently iterates CPUs under
the same sched doamin to accumulate total energy cost and compare before
and after :

  for_each_domain(cpu)
          total_energy_before += (cpu_util * power) >> SCHED_CAPACITY_SHIFT;

  for_each_domain(cpu)
          total_energy_after += (cpu_util * power) >> SCHED_CAPACITY_SHIFT;

Doing such can incorrectly calculate and report abs(delta) > 0 when
there is actually no energy delta between before and after because the
same total accumulated cpu_util of all the CPUs can be distributed
differently before and after and it causes different amount of rounding
error.

Fix such incorrectness by shifting just once with accumulated
total_energy.

Change-Id: I82f1e2e358367058960938b4ef81714f57e921cf
Signed-off-by: default avatarJoonwoo Park <joonwoop@codeaurora.org>
parent 2ae888b3
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -5383,7 +5383,7 @@ static unsigned long __cpu_norm_util(int cpu, unsigned long capacity, int delta)
	if (util >= capacity)
		return SCHED_CAPACITY_SCALE;

	return (util << SCHED_CAPACITY_SHIFT)/capacity;
	return DIV_ROUND_UP(util << SCHED_CAPACITY_SHIFT, capacity);
}

static inline int task_util(struct task_struct *p)
@@ -5534,7 +5534,8 @@ static int group_idle_state(struct sched_group *sg)
static int sched_group_energy(struct energy_env *eenv)
{
	struct sched_domain *sd;
	int cpu, total_energy = 0;
	int cpu;
	u64 total_energy = 0;
	struct cpumask visit_cpus;
	struct sched_group *sg;

@@ -5600,11 +5601,9 @@ static int sched_group_energy(struct energy_env *eenv)

				idle_idx = group_idle_state(sg);
				group_util = group_norm_util(eenv, sg);
				sg_busy_energy = (group_util * sg->sge->cap_states[cap_idx].power)
								>> SCHED_CAPACITY_SHIFT;
				sg_busy_energy = (group_util * sg->sge->cap_states[cap_idx].power);
				sg_idle_energy = ((SCHED_CAPACITY_SCALE-group_util)
								* sg->sge->idle_states[idle_idx].power)
								>> SCHED_CAPACITY_SHIFT;
								* sg->sge->idle_states[idle_idx].power);

				total_energy += sg_busy_energy + sg_idle_energy;

@@ -5621,7 +5620,7 @@ static int sched_group_energy(struct energy_env *eenv)
		continue;
	}

	eenv->energy = total_energy;
	eenv->energy = total_energy >> SCHED_CAPACITY_SHIFT;
	return 0;
}