Skip to contentSkip to conversation

PM: EM: Add function for registering a PD without capacity update

PATCH In review Rafael J. Wysocki 1 participant 2 messages Sep 5, 2025 – Sep 10, 2025

Subsystems (5)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 PM: EM: Add function for registering a PD without capacity update

From: Rafael J. Wysocki <[email protected]>

The intel_pstate driver manages CPU capacity changes itself and it does not need an update of the capacity of all CPUs in the system to be carried out after registering a PD.

Moreover, in some configurations (for instance, an SMT-capable hybrid x86 system booted with nosmt in the kernel command line) the em_check_capacity_update() call at the end of em_dev_register_perf_domain() always fails and reschedules itself to run once again in 1 s, so effectively it runs in vain every 1 s forever.

To address this, introduce a new variant of em_dev_register_perf_domain(), called em_dev_register_pd_no_update(), that does not invoke em_check_capacity_update(), and make intel_pstate use it instead of the original.

Fixes 7b010f9b9061 ("cpufreq: intel_pstate: EAS support for hybrid platforms")
Cc 6.16+ <[email protected]> # 6.16+

---

Normally, I would place the definition of em_dev_register_pd_no_update() before the definition of em_dev_register_perf_domain() which called it, but in this particular case that would cause the real change to be much harder to grasp.

---
 drivers/cpufreq/intel_pstate.c |    4 ++--
 include/linux/energy_model.h   |   10 ++++++++++
 kernel/power/energy_model.c    |   29 +++++++++++++++++++++++++----
 3 files changed, 37 insertions(+), 6 deletions(-)
drivers/cpufreq/intel_pstate.c +2 -2
@@ -1034,8 +1034,8 @@ static bool hybrid_register_perf_domain(
 	if (!cpu_dev)
 		return false;
 
-	if (em_dev_register_perf_domain(cpu_dev, HYBRID_EM_STATE_COUNT, &cb,
-					cpumask_of(cpu), false))
+	if (em_dev_register_pd_no_update(cpu_dev, HYBRID_EM_STATE_COUNT, &cb,
+					 cpumask_of(cpu), false))
 		return false;
 
 	cpudata->pd_registered = true;
include/linux/energy_model.h +10 -0
@@ -171,6 +171,9 @@ int em_dev_update_perf_domain(struct dev
 int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
 				const struct em_data_callback *cb,
 				const cpumask_t *cpus, bool microwatts);
+int em_dev_register_pd_no_update(struct device *dev, unsigned int nr_states,
+				 const struct em_data_callback *cb,
+				 const cpumask_t *cpus, bool microwatts);
 void em_dev_unregister_perf_domain(struct device *dev);
 struct em_perf_table *em_table_alloc(struct em_perf_domain *pd);
 void em_table_free(struct em_perf_table *table);
@@ -350,6 +353,13 @@ int em_dev_register_perf_domain(struct d
 {
 	return -EINVAL;
 }
+static inline
+int em_dev_register_pd_no_update(struct device *dev, unsigned int nr_states,
+				 const struct em_data_callback *cb,
+				 const cpumask_t *cpus, bool microwatts)
+{
+	return -EINVAL;
+}
 static inline void em_dev_unregister_perf_domain(struct device *dev)
 {
 }
kernel/power/energy_model.c +25 -4
@@ -553,6 +553,30 @@ int em_dev_register_perf_domain(struct d
 				const struct em_data_callback *cb,
 				const cpumask_t *cpus, bool microwatts)
 {
+	int ret = em_dev_register_pd_no_update(dev, nr_states, cb, cpus, microwatts);
+
+	if (_is_cpu_device(dev))
+		em_check_capacity_update();
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(em_dev_register_perf_domain);
+
+/**
+ * em_dev_register_pd_no_update() - Register a perf domain for a device
+ * @dev : Device to register the PD for
+ * @nr_states : Number of performance states in the new PD
+ * @cb : Callback functions for populating the energy model
+ * @cpus : CPUs to include in the new PD (mandatory if @dev is a CPU device)
+ * @microwatts : Whether or not the power values in the EM will be in uW
+ *
+ * Like em_dev_register_perf_domain(), but does not trigger a CPU capacity
+ * update after registering the PD, even if @dev is a CPU device.
+ */
+int em_dev_register_pd_no_update(struct device *dev, unsigned int nr_states,
+				 const struct em_data_callback *cb,
+				 const cpumask_t *cpus, bool microwatts)
+{
 	struct em_perf_table *em_table;
 	unsigned long cap, prev_cap = 0;
 	unsigned long flags = 0;
@@ -636,12 +660,9 @@ int em_dev_register_perf_domain(struct d
 unlock:
 	mutex_unlock(&em_pd_mutex);
 
-	if (_is_cpu_device(dev))
-		em_check_capacity_update();
-
 	return ret;
 }
-EXPORT_SYMBOL_GPL(em_dev_register_perf_domain);
+EXPORT_SYMBOL_GPL(em_dev_register_pd_no_update);
 
 /**
  * em_dev_unregister_perf_domain() - Unregister Energy Model (EM) for a device
author maintainer
#1 lore raw
Quoted 18 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

The intel_pstate driver manages CPU capacity changes itself and it does not need an update of the capacity of all CPUs in the system to be carried out after registering a PD.

Moreover, in some configurations (for instance, an SMT-capable hybrid x86 system booted with nosmt in the kernel command line) the em_check_capacity_update() call at the end of em_dev_register_perf_domain() always fails and reschedules itself to run once again in 1 s, so effectively it runs in vain every 1 s forever.

To address this, introduce a new variant of em_dev_register_perf_domain(), called em_dev_register_pd_no_update(), that does not invoke em_check_capacity_update(), and make intel_pstate use it instead of the original.

Quoted 6 lines
Fixes 7b010f9b9061 ("cpufreq: intel_pstate: EAS support for hybrid platforms")
Cc 6.16+ <[email protected]> # 6.16+

I'd appreciate feedback on this.

Since it is 6.16-stable material, I'm inclined to just apply it and let it into the mainline.

Quoted 103 lines

---

Normally, I would place the definition of em_dev_register_pd_no_update() before the definition of em_dev_register_perf_domain() which called it, but in this particular case that would cause the real change to be much harder to grasp.

---
 drivers/cpufreq/intel_pstate.c |    4 ++--
 include/linux/energy_model.h   |   10 ++++++++++
 kernel/power/energy_model.c    |   29 +++++++++++++++++++++++++----
 3 files changed, 37 insertions(+), 6 deletions(-)
drivers/cpufreq/intel_pstate.c +2 -2
@@ -1034,8 +1034,8 @@ static bool hybrid_register_perf_domain(
        if (!cpu_dev)
                return false;
 
-       if (em_dev_register_perf_domain(cpu_dev, HYBRID_EM_STATE_COUNT, &cb,
-                                       cpumask_of(cpu), false))
+       if (em_dev_register_pd_no_update(cpu_dev, HYBRID_EM_STATE_COUNT, &cb,
+                                        cpumask_of(cpu), false))
                return false;
 
        cpudata->pd_registered = true;
include/linux/energy_model.h +10 -0
@@ -171,6 +171,9 @@ int em_dev_update_perf_domain(struct dev
 int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
                                const struct em_data_callback *cb,
                                const cpumask_t *cpus, bool microwatts);
+int em_dev_register_pd_no_update(struct device *dev, unsigned int nr_states,
+                                const struct em_data_callback *cb,
+                                const cpumask_t *cpus, bool microwatts);
 void em_dev_unregister_perf_domain(struct device *dev);
 struct em_perf_table *em_table_alloc(struct em_perf_domain *pd);
 void em_table_free(struct em_perf_table *table);
@@ -350,6 +353,13 @@ int em_dev_register_perf_domain(struct d
 {
        return -EINVAL;
 }
+static inline
+int em_dev_register_pd_no_update(struct device *dev, unsigned int nr_states,
+                                const struct em_data_callback *cb,
+                                const cpumask_t *cpus, bool microwatts)
+{
+       return -EINVAL;
+}
 static inline void em_dev_unregister_perf_domain(struct device *dev)
 {
 }
kernel/power/energy_model.c +25 -4
@@ -553,6 +553,30 @@ int em_dev_register_perf_domain(struct d
                                const struct em_data_callback *cb,
                                const cpumask_t *cpus, bool microwatts)
 {
+       int ret = em_dev_register_pd_no_update(dev, nr_states, cb, cpus, microwatts);
+
+       if (_is_cpu_device(dev))
+               em_check_capacity_update();
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(em_dev_register_perf_domain);
+
+/**
+ * em_dev_register_pd_no_update() - Register a perf domain for a device
+ * @dev : Device to register the PD for
+ * @nr_states : Number of performance states in the new PD
+ * @cb : Callback functions for populating the energy model
+ * @cpus : CPUs to include in the new PD (mandatory if @dev is a CPU device)
+ * @microwatts : Whether or not the power values in the EM will be in uW
+ *
+ * Like em_dev_register_perf_domain(), but does not trigger a CPU capacity
+ * update after registering the PD, even if @dev is a CPU device.
+ */
+int em_dev_register_pd_no_update(struct device *dev, unsigned int nr_states,
+                                const struct em_data_callback *cb,
+                                const cpumask_t *cpus, bool microwatts)
+{
        struct em_perf_table *em_table;
        unsigned long cap, prev_cap = 0;
        unsigned long flags = 0;
@@ -636,12 +660,9 @@ int em_dev_register_perf_domain(struct d
 unlock:
        mutex_unlock(&em_pd_mutex);
 
-       if (_is_cpu_device(dev))
-               em_check_capacity_update();
-
        return ret;
 }
-EXPORT_SYMBOL_GPL(em_dev_register_perf_domain);
+EXPORT_SYMBOL_GPL(em_dev_register_pd_no_update);
 
 /**
  * em_dev_unregister_perf_domain() - Unregister Energy Model (EM) for a device