Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PM: EM: Add em_dev_update_chip_binning()

Add a function which allows to modify easily the EM after the new voltage
information is available. The device drivers for the chip can adjust
the voltage values after setup. The voltage for the same frequency in OPP
can be different due to chip binning. The voltage impacts the power usage
and the EM power values can be updated to reflect that.

Reviewed-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>

authored by

Lukasz Luba and committed by
Rafael J. Wysocki
cf61d53b d61c2695

+53
+5
include/linux/energy_model.h
··· 172 172 void em_table_free(struct em_perf_table __rcu *table); 173 173 int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, 174 174 int nr_states); 175 + int em_dev_update_chip_binning(struct device *dev); 175 176 176 177 /** 177 178 * em_pd_get_efficient_state() - Get an efficient performance state from the EM ··· 384 383 static inline 385 384 int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, 386 385 int nr_states) 386 + { 387 + return -EINVAL; 388 + } 389 + static inline int em_dev_update_chip_binning(struct device *dev) 387 390 { 388 391 return -EINVAL; 389 392 }
+48
kernel/power/energy_model.c
··· 808 808 { 809 809 em_check_capacity_update(); 810 810 } 811 + 812 + /** 813 + * em_dev_update_chip_binning() - Update Energy Model after the new voltage 814 + * information is present in the OPPs. 815 + * @dev : Device for which the Energy Model has to be updated. 816 + * 817 + * This function allows to update easily the EM with new values available in 818 + * the OPP framework and DT. It can be used after the chip has been properly 819 + * verified by device drivers and the voltages adjusted for the 'chip binning'. 820 + */ 821 + int em_dev_update_chip_binning(struct device *dev) 822 + { 823 + struct em_perf_table __rcu *em_table; 824 + struct em_perf_domain *pd; 825 + int i, ret; 826 + 827 + if (IS_ERR_OR_NULL(dev)) 828 + return -EINVAL; 829 + 830 + pd = em_pd_get(dev); 831 + if (!pd) { 832 + dev_warn(dev, "Couldn't find Energy Model\n"); 833 + return -EINVAL; 834 + } 835 + 836 + em_table = em_table_dup(pd); 837 + if (!em_table) { 838 + dev_warn(dev, "EM: allocation failed\n"); 839 + return -ENOMEM; 840 + } 841 + 842 + /* Update power values which might change due to new voltage in OPPs */ 843 + for (i = 0; i < pd->nr_perf_states; i++) { 844 + unsigned long freq = em_table->state[i].frequency; 845 + unsigned long power; 846 + 847 + ret = dev_pm_opp_calc_power(dev, &power, &freq); 848 + if (ret) { 849 + em_table_free(em_table); 850 + return ret; 851 + } 852 + 853 + em_table->state[i].power = power; 854 + } 855 + 856 + return em_recalc_and_update(dev, pd, em_table); 857 + } 858 + EXPORT_SYMBOL_GPL(em_dev_update_chip_binning);