Skip to content

Commit 3e3ba65

Browse files
committed
PM: EM: Move CPU capacity check to em_adjust_new_capacity()
Move the check of the CPU capacity currently stored in the energy model against the arch_scale_cpu_capacity() value to em_adjust_new_capacity() so it will be done regardless of where the latter is called from. This will be useful when a new em_adjust_new_capacity() caller is added subsequently. While at it, move the pd local variable declaration in em_check_capacity_update() into the loop in which it is used. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Tested-by: Christian Loehle <[email protected]> Reviewed-by: Dietmar Eggemann <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent c9b83cb commit 3e3ba65

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

kernel/power/energy_model.c

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,24 @@ static int em_recalc_and_update(struct device *dev, struct em_perf_domain *pd,
725725
* Adjustment of CPU performance values after boot, when all CPUs capacites
726726
* are correctly calculated.
727727
*/
728-
static void em_adjust_new_capacity(struct device *dev,
728+
static void em_adjust_new_capacity(unsigned int cpu, struct device *dev,
729729
struct em_perf_domain *pd)
730730
{
731+
unsigned long cpu_capacity = arch_scale_cpu_capacity(cpu);
731732
struct em_perf_table *em_table;
733+
struct em_perf_state *table;
734+
unsigned long em_max_perf;
735+
736+
rcu_read_lock();
737+
table = em_perf_state_from_pd(pd);
738+
em_max_perf = table[pd->nr_perf_states - 1].performance;
739+
rcu_read_unlock();
740+
741+
if (em_max_perf == cpu_capacity)
742+
return;
743+
744+
pr_debug("updating cpu%d cpu_cap=%lu old capacity=%lu\n", cpu,
745+
cpu_capacity, em_max_perf);
732746

733747
em_table = em_table_dup(pd);
734748
if (!em_table) {
@@ -744,9 +758,6 @@ static void em_adjust_new_capacity(struct device *dev,
744758
static void em_check_capacity_update(void)
745759
{
746760
cpumask_var_t cpu_done_mask;
747-
struct em_perf_state *table;
748-
struct em_perf_domain *pd;
749-
unsigned long cpu_capacity;
750761
int cpu;
751762

752763
if (!zalloc_cpumask_var(&cpu_done_mask, GFP_KERNEL)) {
@@ -757,7 +768,7 @@ static void em_check_capacity_update(void)
757768
/* Check if CPUs capacity has changed than update EM */
758769
for_each_possible_cpu(cpu) {
759770
struct cpufreq_policy *policy;
760-
unsigned long em_max_perf;
771+
struct em_perf_domain *pd;
761772
struct device *dev;
762773

763774
if (cpumask_test_cpu(cpu, cpu_done_mask))
@@ -780,24 +791,7 @@ static void em_check_capacity_update(void)
780791
cpumask_or(cpu_done_mask, cpu_done_mask,
781792
em_span_cpus(pd));
782793

783-
cpu_capacity = arch_scale_cpu_capacity(cpu);
784-
785-
rcu_read_lock();
786-
table = em_perf_state_from_pd(pd);
787-
em_max_perf = table[pd->nr_perf_states - 1].performance;
788-
rcu_read_unlock();
789-
790-
/*
791-
* Check if the CPU capacity has been adjusted during boot
792-
* and trigger the update for new performance values.
793-
*/
794-
if (em_max_perf == cpu_capacity)
795-
continue;
796-
797-
pr_debug("updating cpu%d cpu_cap=%lu old capacity=%lu\n",
798-
cpu, cpu_capacity, em_max_perf);
799-
800-
em_adjust_new_capacity(dev, pd);
794+
em_adjust_new_capacity(cpu, dev, pd);
801795
}
802796

803797
free_cpumask_var(cpu_done_mask);

0 commit comments

Comments
 (0)