Skip to content

Commit e1b5a25

Browse files
committed
PM: EM: Introduce em_adjust_cpu_capacity()
JIRA: https://issues.redhat.com/browse/RHEL-112493 Conflicts: RHEL doesn't have upstream cf61d53 commit 4a6b1cf Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Date: Tue May 6 22:41:21 2025 +0200 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 <rafael.j.wysocki@intel.com> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com> Tested-by: Christian Loehle <christian.loehle@arm.com> Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com> Link: https://patch.msgid.link/3637203.iIbC2pHGDl@rjwysocki.net Signed-off-by: David Arcari <darcari@redhat.com>
1 parent bb938b2 commit e1b5a25

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
@@ -178,6 +178,7 @@ int em_dev_compute_costs(struct device *dev, struct em_perf_state *table,
178178
int nr_states);
179179
int em_update_performance_limits(struct em_perf_domain *pd,
180180
unsigned long freq_min_khz, unsigned long freq_max_khz);
181+
void em_adjust_cpu_capacity(unsigned int cpu);
181182
void em_rebuild_sched_domains(void);
182183

183184
/**
@@ -400,6 +401,7 @@ int em_update_performance_limits(struct em_perf_domain *pd,
400401
{
401402
return -EINVAL;
402403
}
404+
static inline void em_adjust_cpu_capacity(unsigned int cpu) {}
403405
static inline void em_rebuild_sched_domains(void) {}
404406
#endif
405407

kernel/power/energy_model.c

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

772-
ret = em_compute_costs(dev, em_table->state, NULL, pd->nr_perf_states,
773-
pd->flags);
774-
if (ret)
775-
goto free_em_table;
772+
if (!em_is_artificial(pd)) {
773+
ret = em_compute_costs(dev, em_table->state, NULL,
774+
pd->nr_perf_states, pd->flags);
775+
if (ret)
776+
goto free_em_table;
777+
}
776778

777779
ret = em_dev_update_perf_domain(dev, em_table);
778780
if (ret)
@@ -822,6 +824,24 @@ static void em_adjust_new_capacity(unsigned int cpu, struct device *dev,
822824
em_recalc_and_update(dev, pd, em_table);
823825
}
824826

827+
/**
828+
* em_adjust_cpu_capacity() - Adjust the EM for a CPU after a capacity update.
829+
* @cpu: Target CPU.
830+
*
831+
* Adjust the existing EM for @cpu after a capacity update under the assumption
832+
* that the capacity has been updated in the same way for all of the CPUs in
833+
* the same perf domain.
834+
*/
835+
void em_adjust_cpu_capacity(unsigned int cpu)
836+
{
837+
struct device *dev = get_cpu_device(cpu);
838+
struct em_perf_domain *pd;
839+
840+
pd = em_pd_get(dev);
841+
if (pd)
842+
em_adjust_new_capacity(cpu, dev, pd);
843+
}
844+
825845
static void em_check_capacity_update(void)
826846
{
827847
cpumask_var_t cpu_done_mask;

0 commit comments

Comments
 (0)