]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PM: EM: Find first CPU active while updating OPP efficiency
authorLukasz Luba <lukasz.luba@arm.com>
Thu, 8 Feb 2024 11:55:37 +0000 (11:55 +0000)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 8 Feb 2024 14:00:23 +0000 (15:00 +0100)
The Energy Model might be updated at runtime and the energy efficiency
for each OPP may change. Thus, there is a need to update also the
cpufreq framework and make it aligned to the new values. In order to
do that, use a first active CPU from the Performance Domain. This is
needed since the first CPU in the cpumask might be offline when we
run this code path.

Reviewed-by: Hongyan Xia <hongyan.xia2@arm.com>
Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Tested-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/power/energy_model.c

index 8c373b15187520b74b12e24d5cb9cefc3ebf1c3f..0c3220ff54f7411ca901d43939abde98337142c8 100644 (file)
@@ -243,12 +243,19 @@ em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table)
        struct em_perf_domain *pd = dev->em_pd;
        struct cpufreq_policy *policy;
        int found = 0;
-       int i;
+       int i, cpu;
 
        if (!_is_cpu_device(dev))
                return;
 
-       policy = cpufreq_cpu_get(cpumask_first(em_span_cpus(pd)));
+       /* Try to get a CPU which is active and in this PD */
+       cpu = cpumask_first_and(em_span_cpus(pd), cpu_active_mask);
+       if (cpu >= nr_cpu_ids) {
+               dev_warn(dev, "EM: No online CPU for CPUFreq policy\n");
+               return;
+       }
+
+       policy = cpufreq_cpu_get(cpu);
        if (!policy) {
                dev_warn(dev, "EM: Access to CPUFreq policy failed\n");
                return;