Energy Aware Scheduling starts when the scheduling domains are built if the
Energy Model is present and all conditions are met. However, in the typical
case of Arm/Arm64 systems, the Energy Model is provided after the scheduling
domains are first built at boot time, which results in EAS staying
disabled.

This commit fixes this issue by re-building the scheduling domain from the
arch topology driver, once CPUfreq is up and running and when the capacity
of the CPUs have been updated to their final value.

Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Signed-off-by: Quentin Perret <quentin.per...@arm.com>
---
 drivers/base/arch_topology.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index e7cb0c6ade81..7f9fa10ef940 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -15,6 +15,8 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/sched/topology.h>
+#include <linux/energy_model.h>
+#include <linux/cpuset.h>
 
 DEFINE_PER_CPU(unsigned long, freq_scale) = SCHED_CAPACITY_SCALE;
 
@@ -173,6 +175,9 @@ static cpumask_var_t cpus_to_visit;
 static void parsing_done_workfn(struct work_struct *work);
 static DECLARE_WORK(parsing_done_work, parsing_done_workfn);
 
+static void start_eas_workfn(struct work_struct *work);
+static DECLARE_WORK(start_eas_work, start_eas_workfn);
+
 static int
 init_cpu_capacity_callback(struct notifier_block *nb,
                           unsigned long val,
@@ -204,6 +209,7 @@ init_cpu_capacity_callback(struct notifier_block *nb,
                free_raw_capacity();
                pr_debug("cpu_capacity: parsing done\n");
                schedule_work(&parsing_done_work);
+               schedule_work(&start_eas_work);
        }
 
        return 0;
@@ -249,6 +255,19 @@ static void parsing_done_workfn(struct work_struct *work)
        free_cpumask_var(cpus_to_visit);
 }
 
+static void start_eas_workfn(struct work_struct *work)
+{
+       /* Make sure the EM knows about the updated CPU capacities. */
+       rcu_read_lock();
+       em_rescale_cpu_capacity();
+       rcu_read_unlock();
+
+       /* Inform the scheduler about the EM availability. */
+       cpus_read_lock();
+       rebuild_sched_domains();
+       cpus_read_unlock();
+}
+
 #else
 core_initcall(free_raw_capacity);
 #endif
-- 
2.17.0

Reply via email to