Skip to content

Commit cf61d53

Browse files
lukaszluba-armrafaeljw
authored andcommitted
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>
1 parent d61c269 commit cf61d53

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

include/linux/energy_model.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd);
172172
void em_table_free(struct em_perf_table __rcu *table);
173173
int em_dev_compute_costs(struct device *dev, struct em_perf_state *table,
174174
int nr_states);
175+
int em_dev_update_chip_binning(struct device *dev);
175176

176177
/**
177178
* em_pd_get_efficient_state() - Get an efficient performance state from the EM
@@ -386,6 +387,10 @@ int em_dev_compute_costs(struct device *dev, struct em_perf_state *table,
386387
{
387388
return -EINVAL;
388389
}
390+
static inline int em_dev_update_chip_binning(struct device *dev)
391+
{
392+
return -EINVAL;
393+
}
389394
#endif
390395

391396
#endif

kernel/power/energy_model.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,3 +808,51 @@ static void em_update_workfn(struct work_struct *work)
808808
{
809809
em_check_capacity_update();
810810
}
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);

0 commit comments

Comments
 (0)