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

Commit 716d4bfe authored by Srivatsa Vaddagiri's avatar Srivatsa Vaddagiri Committed by Matt Wagantall
Browse files

arm64: topology: Define arch_get_cpu_efficiency() API for scheduler



On a HMP system, scheduler needs to know efficiency factor
(instructions-per-cycle) for various cpus. This is so that scheduler
can estimate bandwidth consumption of tasks on each cpu, based on
their efficiency factor.

This patch defines arch_get_cpu_efficiency() API in ARM64
architecture.  It depends on hard-coded "efficiency" factor for
various cpu types (available in 'table_efficiency' data structure) and
device-tree providing information on cpu-type for every cpu.

Change-Id: Ied43ead650ab85b63c232bec14dde500cbcc0f7a
Signed-off-by: default avatarSrivatsa Vaddagiri <vatsa@codeaurora.org>
[abhimany: rename POWER_{SCALE,SHIFT} to CAPACITY_{SCALE,SHIFT}]
Signed-off-by: default avatarAbhimanyu Kapur <abhimany@codeaurora.org>
parent 56d04a68
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -194,11 +194,11 @@ struct cpu_efficiency {
 * Table of relative efficiency of each processors
 * The efficiency value must fit in 20bit and the final
 * cpu_scale value must be in the range
 *   0 < cpu_scale < 3*SCHED_POWER_SCALE/2
 *   0 < cpu_scale < 3*SCHED_CAPACITY_SCALE/2
 * in order to return at most 1 when DIV_ROUND_CLOSEST
 * is used to compute the capacity of a CPU.
 * Processors that are not defined in the table,
 * use the default SCHED_POWER_SCALE value for cpu_scale.
 * use the default SCHED_CAPACITY_SCALE value for cpu_scale.
 */
static const struct cpu_efficiency table_efficiency[] = {
	{ "arm,cortex-a57", 3891 },
@@ -211,6 +211,13 @@ static unsigned long *__cpu_capacity;

static unsigned long middle_capacity = 1;

static DEFINE_PER_CPU(unsigned long, cpu_efficiency) = SCHED_CAPACITY_SCALE;

unsigned long arch_get_cpu_efficiency(int cpu)
{
	return per_cpu(cpu_efficiency, cpu);
}

/*
 * Iterate all CPUs' descriptor in DT and compute the efficiency
 * (as per table_efficiency). Also calculate a middle efficiency
@@ -290,6 +297,8 @@ static void __init parse_dt_cpu_power(void)
			continue;
		}

		per_cpu(cpu_efficiency, cpu) = cpu_eff->efficiency;

		rate = of_get_property(cn, "clock-frequency", &len);
		if (!rate || len != 4) {
			pr_err("%s: Missing clock-frequency property\n",
@@ -314,17 +323,17 @@ static void __init parse_dt_cpu_power(void)
	 * cpu_scale because all CPUs have the same capacity. Otherwise, we
	 * compute a middle_capacity factor that will ensure that the capacity
	 * of an 'average' CPU of the system will be as close as possible to
	 * SCHED_POWER_SCALE, which is the default value, but with the
	 * SCHED_CAPACITY_SCALE, which is the default value, but with the
	 * constraint explained near table_efficiency[].
	 */
	if (min_capacity == max_capacity)
		return;
	else if (4 * max_capacity < (3 * (max_capacity + min_capacity)))
		middle_capacity = (min_capacity + max_capacity)
				>> (SCHED_POWER_SHIFT+1);
				>> (SCHED_CAPACITY_SHIFT+1);
	else
		middle_capacity = ((max_capacity / 3)
				>> (SCHED_POWER_SHIFT-1)) + 1;
				>> (SCHED_CAPACITY_SHIFT-1)) + 1;
}

/*
@@ -438,7 +447,7 @@ static void __init reset_cpu_power(void)
	unsigned int cpu;

	for_each_possible_cpu(cpu)
		set_power_scale(cpu, SCHED_POWER_SCALE);
		set_power_scale(cpu, SCHED_CAPACITY_SCALE);
}

void __init init_cpu_topology(void)