From 8871fe3c256b8473813b619ae21928509f670e54 Mon Sep 17 00:00:00 2001
From: Chris Redpath <chris.redpath@arm.com>
Date: Fri, 22 Feb 2019 11:51:37 +0000
Subject: [PATCH] devlib/sched: Change order of CPU capacity algorithms

There are two ways we can load CPU capacity. Up until 4.14, supported
kernels did not have the /sys/devices/system/cpu/cpuX/cpu_capacity file
and the only way to read cpu capacity was by grepping the EM from
procfs sched_domain output. After 4.14, that route still exists but is
complicated due to a change in the format once support for
frequency-power models was merged.

In order to avoid rewriting the procfs EM grepping code, lets switch the
order of algorithms we try to use when loading CPU capacity. All newer
kernels provide the dedicated sysfs node and all kernels which do not
have this node use the old format for the EM in sched_domain output.

Signed-off-by: Chris Redpath <chris.redpath@arm.com>
---
 devlib/module/sched.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/devlib/module/sched.py b/devlib/module/sched.py
index a05725b..0f35fc1 100644
--- a/devlib/module/sched.py
+++ b/devlib/module/sched.py
@@ -440,10 +440,10 @@ class SchedModule(Module):
         sd_info = self.get_sd_info()
 
         for cpu in cpus:
-            if self.has_em(cpu, sd_info.cpus[cpu]):
-                capacities[cpu] = self.get_em_capacity(cpu, sd_info.cpus[cpu])
-            elif self.has_dmips_capacity(cpu):
+            if self.has_dmips_capacity(cpu):
                 capacities[cpu] = self.get_dmips_capacity(cpu)
+            elif self.has_em(cpu, sd_info.cpus[cpu]):
+                capacities[cpu] = self.get_em_capacity(cpu, sd_info.cpus[cpu])
             else:
                 if default != None:
                     capacities[cpu] = default