@@ -233,6 +233,10 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table,
233233 unsigned long prev_cost = ULONG_MAX ;
234234 int i , ret ;
235235
236+ /* This is needed only for CPUs and EAS skip other devices */
237+ if (!_is_cpu_device (dev ))
238+ return 0 ;
239+
236240 /* Compute the cost of each performance state. */
237241 for (i = nr_states - 1 ; i >= 0 ; i -- ) {
238242 unsigned long power_res , cost ;
@@ -698,10 +702,12 @@ static int em_recalc_and_update(struct device *dev, struct em_perf_domain *pd,
698702{
699703 int ret ;
700704
701- ret = em_compute_costs (dev , em_table -> state , NULL , pd -> nr_perf_states ,
702- pd -> flags );
703- if (ret )
704- goto free_em_table ;
705+ if (!em_is_artificial (pd )) {
706+ ret = em_compute_costs (dev , em_table -> state , NULL ,
707+ pd -> nr_perf_states , pd -> flags );
708+ if (ret )
709+ goto free_em_table ;
710+ }
705711
706712 ret = em_dev_update_perf_domain (dev , em_table );
707713 if (ret )
@@ -721,10 +727,24 @@ static int em_recalc_and_update(struct device *dev, struct em_perf_domain *pd,
721727 * Adjustment of CPU performance values after boot, when all CPUs capacites
722728 * are correctly calculated.
723729 */
724- static void em_adjust_new_capacity (struct device * dev ,
730+ static void em_adjust_new_capacity (unsigned int cpu , struct device * dev ,
725731 struct em_perf_domain * pd )
726732{
733+ unsigned long cpu_capacity = arch_scale_cpu_capacity (cpu );
727734 struct em_perf_table * em_table ;
735+ struct em_perf_state * table ;
736+ unsigned long em_max_perf ;
737+
738+ rcu_read_lock ();
739+ table = em_perf_state_from_pd (pd );
740+ em_max_perf = table [pd -> nr_perf_states - 1 ].performance ;
741+ rcu_read_unlock ();
742+
743+ if (em_max_perf == cpu_capacity )
744+ return ;
745+
746+ pr_debug ("updating cpu%d cpu_cap=%lu old capacity=%lu\n" , cpu ,
747+ cpu_capacity , em_max_perf );
728748
729749 em_table = em_table_dup (pd );
730750 if (!em_table ) {
@@ -737,12 +757,27 @@ static void em_adjust_new_capacity(struct device *dev,
737757 em_recalc_and_update (dev , pd , em_table );
738758}
739759
760+ /**
761+ * em_adjust_cpu_capacity() - Adjust the EM for a CPU after a capacity update.
762+ * @cpu: Target CPU.
763+ *
764+ * Adjust the existing EM for @cpu after a capacity update under the assumption
765+ * that the capacity has been updated in the same way for all of the CPUs in
766+ * the same perf domain.
767+ */
768+ void em_adjust_cpu_capacity (unsigned int cpu )
769+ {
770+ struct device * dev = get_cpu_device (cpu );
771+ struct em_perf_domain * pd ;
772+
773+ pd = em_pd_get (dev );
774+ if (pd )
775+ em_adjust_new_capacity (cpu , dev , pd );
776+ }
777+
740778static void em_check_capacity_update (void )
741779{
742780 cpumask_var_t cpu_done_mask ;
743- struct em_perf_state * table ;
744- struct em_perf_domain * pd ;
745- unsigned long cpu_capacity ;
746781 int cpu ;
747782
748783 if (!zalloc_cpumask_var (& cpu_done_mask , GFP_KERNEL )) {
@@ -753,7 +788,7 @@ static void em_check_capacity_update(void)
753788 /* Check if CPUs capacity has changed than update EM */
754789 for_each_possible_cpu (cpu ) {
755790 struct cpufreq_policy * policy ;
756- unsigned long em_max_perf ;
791+ struct em_perf_domain * pd ;
757792 struct device * dev ;
758793
759794 if (cpumask_test_cpu (cpu , cpu_done_mask ))
@@ -776,24 +811,7 @@ static void em_check_capacity_update(void)
776811 cpumask_or (cpu_done_mask , cpu_done_mask ,
777812 em_span_cpus (pd ));
778813
779- cpu_capacity = arch_scale_cpu_capacity (cpu );
780-
781- rcu_read_lock ();
782- table = em_perf_state_from_pd (pd );
783- em_max_perf = table [pd -> nr_perf_states - 1 ].performance ;
784- rcu_read_unlock ();
785-
786- /*
787- * Check if the CPU capacity has been adjusted during boot
788- * and trigger the update for new performance values.
789- */
790- if (em_max_perf == cpu_capacity )
791- continue ;
792-
793- pr_debug ("updating cpu%d cpu_cap=%lu old capacity=%lu\n" ,
794- cpu , cpu_capacity , em_max_perf );
795-
796- em_adjust_new_capacity (dev , pd );
814+ em_adjust_new_capacity (cpu , dev , pd );
797815 }
798816
799817 free_cpumask_var (cpu_done_mask );
0 commit comments