Skip to content

Commit 4a6b1cf

Browse files
committed
PM: EM: Introduce em_adjust_cpu_capacity()
Add a function for updating the Energy Model for a CPU after its capacity has changed, which subsequently will be used by the intel_pstate driver. An EM_PERF_DOMAIN_ARTIFICIAL check is added to em_recalc_and_update() to prevent it from calling em_compute_costs() for an "artificial" perf domain with a NULL cb parameter which would cause it to crash. 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 3e3ba65 commit 4a6b1cf

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

include/linux/energy_model.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ int em_dev_compute_costs(struct device *dev, struct em_perf_state *table,
179179
int em_dev_update_chip_binning(struct device *dev);
180180
int em_update_performance_limits(struct em_perf_domain *pd,
181181
unsigned long freq_min_khz, unsigned long freq_max_khz);
182+
void em_adjust_cpu_capacity(unsigned int cpu);
182183
void em_rebuild_sched_domains(void);
183184

184185
/**
@@ -403,6 +404,7 @@ int em_update_performance_limits(struct em_perf_domain *pd,
403404
{
404405
return -EINVAL;
405406
}
407+
static inline void em_adjust_cpu_capacity(unsigned int cpu) {}
406408
static inline void em_rebuild_sched_domains(void) {}
407409
#endif
408410

kernel/power/energy_model.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,12 @@ static int em_recalc_and_update(struct device *dev, struct em_perf_domain *pd,
702702
{
703703
int ret;
704704

705-
ret = em_compute_costs(dev, em_table->state, NULL, pd->nr_perf_states,
706-
pd->flags);
707-
if (ret)
708-
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+
}
709711

710712
ret = em_dev_update_perf_domain(dev, em_table);
711713
if (ret)
@@ -755,6 +757,24 @@ static void em_adjust_new_capacity(unsigned int cpu, struct device *dev,
755757
em_recalc_and_update(dev, pd, em_table);
756758
}
757759

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+
758778
static void em_check_capacity_update(void)
759779
{
760780
cpumask_var_t cpu_done_mask;

0 commit comments

Comments
 (0)