Skip to contentSkip to conversation

Make IPA use PM_EM

PATCH Superseded Quentin Perret 3 participants 19 messages May 15, 2019

Subsystems (2)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover Make IPA use PM_EM

Changes in v4:
**************
- Added Viresh's Acked-by to all 3 patches
- Improved commit message of patch 3/3 to explain how it has no functional impact on existing users (Eduardo)

Changes in v3:
**************
- Changed warning message for unordered tables to something more explicit (Viresh)
- Changed WARN() into a pr_err() for consistency

Changes in v2:
**************
- Fixed patch 01/03 to actually enable CONFIG_ENERGY_MODEL
- Added "depends on ENERGY_MODEL" to IPA (Daniel)
- Added check to bail out if the freq table is unsorted (Viresh)

Cover letter:
*************

The Intelligent Power Allocator (IPA) thermal governor uses an Energy Model (or EM) of the CPUs to re-distribute the power budget. To do so, it builds a table of <frequency, power> tuples where the power values are computed using the 'dynamic-power-coefficient' DT property. All of this is done in and only for the thermal subsystem, and more specifically for CPUs -- the power of other types of devices is obtained differently.

Recently, the CPU scheduler has seen the introduction of Energy Aware Scheduling (EAS) patches, which also rely on an EM of the CPUs. This EM, however, is managed by an independent framework, called PM_EM, aimed to be used by all kernel subsystems interested in the power consumed by CPUs, and not only the scheduler.

This patch series follows this logic and removes the (now redundant) thermal-specific EM computation code to migrate IPA to use PM_EM instead.

Doing so should have no visible functional impact for existing users of IPA since:

- during the 5.1 development cycle, a series of patches [1] introduced in PM_OPP some infrastructure (dev_pm_opp_of_register_em()) enabling the registration of EMs in PM_EM using the DT property used by IPA;

- the existing upstream cpufreq drivers marked with the 'CPUFREQ_IS_COOLING_DEV' flag all call dev_pm_opp_of_register_em(), which means they all support PM_EM (the only two exceptions are qoriq-cpufreq which doesn't in fact use an EM and scmi-cpufreq which already supports PM_EM without using the PM_OPP infrastructurei because it read power costs directly from firmware);

So, migrating IPA to using PM_EM should effectively be just plumbing since for the existing IPA users the PM_EM tables will contain the exact same power values that IPA used to compute on its own until now. The only new dependency is to compile in CONFIG_ENERGY_MODEL.

Why is this migration still a good thing ? For three main reasons.

1. it removes redundant code;

2. it introduces an abstraction layer between IPA and the EM computation. PM_EM offers to EAS and IPA (and potentially other clients) standardized EM tables and hides 'how' these tables have been obtained. PM_EM as of now supports power values either coming from the 'dynamic-power-coefficient' DT property or obtained directly from firmware using SCMI. The latter is a new feature for IPA and that comes 'for free' with the migration. This will also be true in the future every time PM_EM gets support for other ways of loading the EM. Moreover, PM_EM is documented and has a debugfs interface which should help adding support for new platforms.

3. it builds a consistent view of the EM of CPUs across kernel subsystems, which is a pre-requisite for any kind of future work aiming at a smarter power allocation using scheduler knowledge about the system for example.

[1] https://lore.kernel.org/lkml/[email protected]/

Quentin Perret (3):
arm64: defconfig: Enable CONFIG_ENERGY_MODEL PM / EM: Expose perf domain struct
thermal: cpu_cooling: Migrate to using the EM framework

 arch/arm64/configs/defconfig  |   1 +
 drivers/thermal/Kconfig       |   1 +
 drivers/thermal/cpu_cooling.c | 238 ++++++++++++----------------------
 include/linux/energy_model.h  |   3 +-
 4 files changed, 84 insertions(+), 159 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH v4 1/3 arm64: defconfig: Enable CONFIG_ENERGY_MODEL

The recently introduced Energy Model (EM) framework manages power cost tables for the CPUs of the system. Its only user right now is the scheduler, in the context of Energy Aware Scheduling (EAS).

However, the EM framework also offers a generic infrastructure that could replace subsystem-specific implementations of the same concepts, as this is the case in the thermal framework.

So, in order to prepare the migration of the thermal subsystem to use the EM framework, enable it in the default arm64 defconfig, which is the most commonly used architecture for IPA. This will also compile-in all of the EAS code, although it won't be enabled by default -- EAS requires to use the 'schedutil' CPUFreq governor while arm64 defaults to 'performance'.

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index 2d9c39033c1a..4881a752ab3f 100644
@@ -97,6 +97,7 @@ CONFIG_XEN=y
 CONFIG_COMPAT=y
 CONFIG_HIBERNATION=y
 CONFIG_WQ_POWER_EFFICIENT_DEFAULT=y
+CONFIG_ENERGY_MODEL=y
 CONFIG_ARM_CPUIDLE=y
 CONFIG_CPU_FREQ=y
 CONFIG_CPU_FREQ_STAT=y
Signature · 1 line
2.21.0
Acked-by on v4 1/3
#2 lore raw

Re: [PATCH v4 1/3] arm64: defconfig: Enable CONFIG_ENERGY_MODEL

Quoted 15 lines · Quentin Perret

The recently introduced Energy Model (EM) framework manages power cost tables for the CPUs of the system. Its only user right now is the scheduler, in the context of Energy Aware Scheduling (EAS).

However, the EM framework also offers a generic infrastructure that could replace subsystem-specific implementations of the same concepts, as this is the case in the thermal framework.

So, in order to prepare the migration of the thermal subsystem to use the EM framework, enable it in the default arm64 defconfig, which is the most commonly used architecture for IPA. This will also compile-in all of the EAS code, although it won't be enabled by default -- EAS requires to use the 'schedutil' CPUFreq governor while arm64 defaults to 'performance'.

Quoted 2 lines
Quoted 17 lines
---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index 2d9c39033c1a..4881a752ab3f 100644
@@ -97,6 +97,7 @@ CONFIG_XEN=y
 CONFIG_COMPAT=y
 CONFIG_HIBERNATION=y
 CONFIG_WQ_POWER_EFFICIENT_DEFAULT=y
+CONFIG_ENERGY_MODEL=y
 CONFIG_ARM_CPUIDLE=y
 CONFIG_CPU_FREQ=y
 CONFIG_CPU_FREQ_STAT=y
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#3 lore raw

Re: [PATCH v4 1/3] arm64: defconfig: Enable CONFIG_ENERGY_MODEL

Quoted 16 lines · Daniel Lezcano
Quoted 15 lines · Quentin Perret

The recently introduced Energy Model (EM) framework manages power cost tables for the CPUs of the system. Its only user right now is the scheduler, in the context of Energy Aware Scheduling (EAS).

However, the EM framework also offers a generic infrastructure that could replace subsystem-specific implementations of the same concepts, as this is the case in the thermal framework.

So, in order to prepare the migration of the thermal subsystem to use the EM framework, enable it in the default arm64 defconfig, which is the most commonly used architecture for IPA. This will also compile-in all of the EAS code, although it won't be enabled by default -- EAS requires to use the 'schedutil' CPUFreq governor while arm64 defaults to 'performance'.

Quoted 4 lines
Quoted 2 lines

Thanks !
Quentin

#4 lore raw

PATCH v4 2/3 PM / EM: Expose perf domain struct

In reply to Quentin Perret

In the current state, the perf_domain struct is fully defined only when CONFIG_ENERGY_MODEL=y. Since we need to write code that compiles both with or without that option in the thermal framework, make sure to actually define the struct regardless of the config option. That allows to avoid using stubbed accessor functions all the time in code paths that use the EM.

---
 include/linux/energy_model.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/energy_model.h +1 -2
index aa027f7bcb3e..fb32b86a467d 100644
@@ -9,7 +9,6 @@
 #include <linux/sched/topology.h>
 #include <linux/types.h>
 
-#ifdef CONFIG_ENERGY_MODEL
 /**
  * em_cap_state - Capacity state of a performance domain
  * @frequency:	The CPU frequency in KHz, for consistency with CPUFreq
@@ -40,6 +39,7 @@ struct em_perf_domain {
 	unsigned long cpus[0];
 };
 
+#ifdef CONFIG_ENERGY_MODEL
 #define EM_CPU_MAX_POWER 0xFFFF
 
 struct em_data_callback {
@@ -160,7 +160,6 @@ static inline int em_pd_nr_cap_states(struct em_perf_domain *pd)
 }
 
 #else
-struct em_perf_domain {};
 struct em_data_callback {};
 #define EM_DATA_CB(_active_power_cb) { }
 
Signature · 1 line
2.21.0
#5 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Quoted 9 lines · Quentin Perret

In the current state, the perf_domain struct is fully defined only when CONFIG_ENERGY_MODEL=y. Since we need to write code that compiles both with or without that option in the thermal framework, make sure to actually define the struct regardless of the config option. That allows to avoid using stubbed accessor functions all the time in code paths that use the EM.

This patch implies the cpu cooling device can be set without the energy model.

Isn't it possible to make a strong dependency for the cpu cooling device on the energy model option, add the energy model as default on arm arch and drop this patch?

After all, the cpu cooling is using the em framework.

Quoted 33 lines
---
 include/linux/energy_model.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/energy_model.h +1 -2
index aa027f7bcb3e..fb32b86a467d 100644
@@ -9,7 +9,6 @@
 #include <linux/sched/topology.h>
 #include <linux/types.h>
 
-#ifdef CONFIG_ENERGY_MODEL
 /**
  * em_cap_state - Capacity state of a performance domain
  * @frequency:	The CPU frequency in KHz, for consistency with CPUFreq
@@ -40,6 +39,7 @@ struct em_perf_domain {
 	unsigned long cpus[0];
 };
 
+#ifdef CONFIG_ENERGY_MODEL
 #define EM_CPU_MAX_POWER 0xFFFF
 
 struct em_data_callback {
@@ -160,7 +160,6 @@ static inline int em_pd_nr_cap_states(struct em_perf_domain *pd)
 }
 
 #else
-struct em_perf_domain {};
 struct em_data_callback {};
 #define EM_DATA_CB(_active_power_cb) { }
 
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#6 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Hi Daniel,

Quoted 11 lines · Daniel Lezcano
Quoted 9 lines · Quentin Perret

In the current state, the perf_domain struct is fully defined only when CONFIG_ENERGY_MODEL=y. Since we need to write code that compiles both with or without that option in the thermal framework, make sure to actually define the struct regardless of the config option. That allows to avoid using stubbed accessor functions all the time in code paths that use the EM.

Quoted 6 lines

This patch implies the cpu cooling device can be set without the energy model.

Isn't it possible to make a strong dependency for the cpu cooling device on the energy model option, add the energy model as default on arm arch and drop this patch?

Right, that should work too.

Quoted 1 line

After all, the cpu cooling is using the em framework.

The reason I did it that way is simply to keep things flexible. If you don't compile in THERMAL_GOV_POWER_ALLOCATOR, you will never use the EM for CPU thermal. So I thought it would be good to not mandate compiling in ENERGY_MODEL in this case -- that should save a bit of space.

But TBH I don't have a strong opinion on this one, so if everybody agrees it's fine to just make CPU_THERMAL depend on ENERGY_MODEL, I'm happy to drop this patch and fix patch 3/3. That would indeed simplify things a bit.

Thanks,
Quentin

#7 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Quoted 30 lines · Quentin Perret

Hi Daniel,

Quoted 11 lines · Daniel Lezcano
Quoted 9 lines · Quentin Perret

In the current state, the perf_domain struct is fully defined only when CONFIG_ENERGY_MODEL=y. Since we need to write code that compiles both with or without that option in the thermal framework, make sure to actually define the struct regardless of the config option. That allows to avoid using stubbed accessor functions all the time in code paths that use the EM.

Quoted 6 lines

This patch implies the cpu cooling device can be set without the energy model.

Isn't it possible to make a strong dependency for the cpu cooling device on the energy model option, add the energy model as default on arm arch and drop this patch?

Right, that should work too.

Quoted 1 line

After all, the cpu cooling is using the em framework.

The reason I did it that way is simply to keep things flexible. If you don't compile in THERMAL_GOV_POWER_ALLOCATOR, you will never use the EM for CPU thermal. So I thought it would be good to not mandate compiling in ENERGY_MODEL in this case -- that should save a bit of space.

Quoted 4 lines

But TBH I don't have a strong opinion on this one, so if everybody agrees it's fine to just make CPU_THERMAL depend on ENERGY_MODEL, I'm happy to drop this patch and fix patch 3/3. That would indeed simplify things a bit.

Ok in this case it will be better to drop the 2/3 and add a small series doing for the cpu_cooling.c

#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR

/* structure freq */

/* power2state */

/* state2power*/

/* getrequestedpower */

/* All functions needed for the above */

#endif

static struct thermal_cooling_device_ops cpufreq_cooling_ops = {

        .get_max_state          = cpufreq_get_max_state,
        .get_cur_state          = cpufreq_get_cur_state,
        .set_cur_state          = cpufreq_set_cur_state,
#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        .get_requested_power    = cpufreq_get_requested_power,
        .state2power            = cpufreq_state2power,
        .power2state            = cpufreq_power2state,

#endif
};

So you don't have to care about ENERGY_MODEL to be set as THERMAL_GOV_POWER_ALLOCATOR depends on it.

I think the result for cpu_cooling.c will be even more cleaner with the em change.

Signature · 11 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#8 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Quoted 61 lines · Daniel Lezcano
Quoted 30 lines · Quentin Perret

Hi Daniel,

Quoted 11 lines · Daniel Lezcano
Quoted 9 lines · Quentin Perret

In the current state, the perf_domain struct is fully defined only when CONFIG_ENERGY_MODEL=y. Since we need to write code that compiles both with or without that option in the thermal framework, make sure to actually define the struct regardless of the config option. That allows to avoid using stubbed accessor functions all the time in code paths that use the EM.

Quoted 6 lines

This patch implies the cpu cooling device can be set without the energy model.

Isn't it possible to make a strong dependency for the cpu cooling device on the energy model option, add the energy model as default on arm arch and drop this patch?

Right, that should work too.

Quoted 1 line

After all, the cpu cooling is using the em framework.

The reason I did it that way is simply to keep things flexible. If you don't compile in THERMAL_GOV_POWER_ALLOCATOR, you will never use the EM for CPU thermal. So I thought it would be good to not mandate compiling in ENERGY_MODEL in this case -- that should save a bit of space.

Quoted 4 lines

But TBH I don't have a strong opinion on this one, so if everybody agrees it's fine to just make CPU_THERMAL depend on ENERGY_MODEL, I'm happy to drop this patch and fix patch 3/3. That would indeed simplify things a bit.

Ok in this case it will be better to drop the 2/3 and add a small series doing for the cpu_cooling.c

#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR

/* structure freq */

/* power2state */

/* state2power*/

/* getrequestedpower */

/* All functions needed for the above */

#endif

static struct thermal_cooling_device_ops cpufreq_cooling_ops = {

        .get_max_state          = cpufreq_get_max_state,
        .get_cur_state          = cpufreq_get_cur_state,
        .set_cur_state          = cpufreq_set_cur_state,
#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        .get_requested_power    = cpufreq_get_requested_power,
        .state2power            = cpufreq_state2power,
        .power2state            = cpufreq_power2state,
Quoted 8 lines

#endif
};

So you don't have to care about ENERGY_MODEL to be set as THERMAL_GOV_POWER_ALLOCATOR depends on it.

I think the result for cpu_cooling.c will be even more cleaner with the em change.

OK, that works for me. I'll give it a go in v5.

Thanks !
Quentin

#9 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Quoted 65 lines · Quentin Perret
Quoted 64 lines · Daniel Lezcano
Quoted 30 lines · Quentin Perret

Hi Daniel,

Quoted 11 lines · Daniel Lezcano
Quoted 9 lines · Quentin Perret

In the current state, the perf_domain struct is fully defined only when CONFIG_ENERGY_MODEL=y. Since we need to write code that compiles both with or without that option in the thermal framework, make sure to actually define the struct regardless of the config option. That allows to avoid using stubbed accessor functions all the time in code paths that use the EM.

Quoted 6 lines

This patch implies the cpu cooling device can be set without the energy model.

Isn't it possible to make a strong dependency for the cpu cooling device on the energy model option, add the energy model as default on arm arch and drop this patch?

Right, that should work too.

Quoted 1 line

After all, the cpu cooling is using the em framework.

The reason I did it that way is simply to keep things flexible. If you don't compile in THERMAL_GOV_POWER_ALLOCATOR, you will never use the EM for CPU thermal. So I thought it would be good to not mandate compiling in ENERGY_MODEL in this case -- that should save a bit of space.

Quoted 4 lines

But TBH I don't have a strong opinion on this one, so if everybody agrees it's fine to just make CPU_THERMAL depend on ENERGY_MODEL, I'm happy to drop this patch and fix patch 3/3. That would indeed simplify things a bit.

Ok in this case it will be better to drop the 2/3 and add a small series doing for the cpu_cooling.c

#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR

/* structure freq */

/* power2state */

/* state2power*/

/* getrequestedpower */

/* All functions needed for the above */

#endif

static struct thermal_cooling_device_ops cpufreq_cooling_ops = {

        .get_max_state          = cpufreq_get_max_state,
        .get_cur_state          = cpufreq_get_cur_state,
        .set_cur_state          = cpufreq_set_cur_state,
#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        .get_requested_power    = cpufreq_get_requested_power,
        .state2power            = cpufreq_state2power,
        .power2state            = cpufreq_power2state,

#endif
};

Quoted 7 lines
Quoted 5 lines

So you don't have to care about ENERGY_MODEL to be set as THERMAL_GOV_POWER_ALLOCATOR depends on it.

I think the result for cpu_cooling.c will be even more cleaner with the em change.

OK, that works for me. I'll give it a go in v5.

Viresh what do you think ?

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#10 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Quoted 1 line · Daniel Lezcano

Viresh what do you think ?

I agree with your last suggestions. They do make sense.

Signature · 1 line
viresh
#11 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Quoted 4 lines · Viresh Kumar
Quoted 1 line · Daniel Lezcano

Viresh what do you think ?

I agree with your last suggestions. They do make sense.

Good :-)

So, FWIW, the below compiles w/ or w/o THERMAL_GOV_POWER_ALLOCATOR. I'll test it and clean it up some more and put it as patch 1 in the series if that's OK.

Thanks,
Quentin

drivers/thermal/cpu_cooling.c +103 -106
index f7c1f49ec87f..ee431848ef71 100644
@@ -58,7 +58,9 @@
  */
 struct freq_table {
        u32 frequency;
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        u32 power;
+#endif
 };
 
 /**
@@ -109,28 +111,6 @@ static DEFINE_IDA(cpufreq_ida);
 static DEFINE_MUTEX(cooling_list_lock);
 static LIST_HEAD(cpufreq_cdev_list);
 
-/* Below code defines functions to be used for cpufreq as cooling device */
-
-/**
- * get_level: Find the level for a particular frequency
- * @cpufreq_cdev: cpufreq_cdev for which the property is required
- * @freq: Frequency
- *
- * Return: level corresponding to the frequency.
- */
-static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev,
-                              unsigned int freq)
-{
-       struct freq_table *freq_table = cpufreq_cdev->freq_table;
-       unsigned long level;
-
-       for (level = 1; level <= cpufreq_cdev->max_level; level++)
-               if (freq > freq_table[level].frequency)
-                       break;
-
-       return level - 1;
-}
-
 /**
  * cpufreq_thermal_notifier - notifier callback for cpufreq policy change.
  * @nb:        struct notifier_block * with callback info.
@@ -184,6 +164,27 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
        return NOTIFY_OK;
 }
 
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
+/**
+ * get_level: Find the level for a particular frequency
+ * @cpufreq_cdev: cpufreq_cdev for which the property is required
+ * @freq: Frequency
+ *
+ * Return: level corresponding to the frequency.
+ */
+static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev,
+                              unsigned int freq)
+{
+       struct freq_table *freq_table = cpufreq_cdev->freq_table;
+       unsigned long level;
+
+       for (level = 1; level <= cpufreq_cdev->max_level; level++)
+               if (freq > freq_table[level].frequency)
+                       break;
+
+       return level - 1;
+}
+
 /**
  * update_freq_table() - Update the freq table with power numbers
  * @cpufreq_cdev:      the cpufreq cooling device in which to update the table
@@ -333,80 +334,6 @@ static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_cdev,
        return (raw_cpu_power * cpufreq_cdev->last_load) / 100;
 }
 
-/* cpufreq cooling device callback functions are defined below */
-
-/**
- * cpufreq_get_max_state - callback function to get the max cooling state.
- * @cdev: thermal cooling device pointer.
- * @state: fill this variable with the max cooling state.
- *
- * Callback for the thermal cooling device to return the cpufreq
- * max cooling state.
- *
- * Return: 0 on success, an error code otherwise.
- */
-static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
-                                unsigned long *state)
-{
-       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
-
-       *state = cpufreq_cdev->max_level;
-       return 0;
-}
-
-/**
- * cpufreq_get_cur_state - callback function to get the current cooling state.
- * @cdev: thermal cooling device pointer.
- * @state: fill this variable with the current cooling state.
- *
- * Callback for the thermal cooling device to return the cpufreq
- * current cooling state.
- *
- * Return: 0 on success, an error code otherwise.
- */
-static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
-                                unsigned long *state)
-{
-       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
-
-       *state = cpufreq_cdev->cpufreq_state;
-
-       return 0;
-}
-
-/**
- * cpufreq_set_cur_state - callback function to set the current cooling state.
- * @cdev: thermal cooling device pointer.
- * @state: set this variable to the current cooling state.
- *
- * Callback for the thermal cooling device to change the cpufreq
- * current cooling state.
- *
- * Return: 0 on success, an error code otherwise.
- */
-static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
-                                unsigned long state)
-{
-       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
-       unsigned int clip_freq;
-
-       /* Request state should be less than max_level */
-       if (WARN_ON(state > cpufreq_cdev->max_level))
-               return -EINVAL;
-
-       /* Check if the old cooling action is same as new cooling action */
-       if (cpufreq_cdev->cpufreq_state == state)
-               return 0;
-
-       clip_freq = cpufreq_cdev->freq_table[state].frequency;
-       cpufreq_cdev->cpufreq_state = state;
-       cpufreq_cdev->clipped_freq = clip_freq;
-
-       cpufreq_update_policy(cpufreq_cdev->policy->cpu);
-
-       return 0;
-}
-
 /**
  * cpufreq_get_requested_power() - get the current power
  * @cdev:      &thermal_cooling_device pointer
@@ -551,22 +478,93 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
                                      power);
        return 0;
 }
+#endif /* CONFIG_THERMAL_GOV_POWER_ALLOCATOR */
+
+/* cpufreq cooling device callback functions are defined below */
+
+/**
+ * cpufreq_get_max_state - callback function to get the max cooling state.
+ * @cdev: thermal cooling device pointer.
+ * @state: fill this variable with the max cooling state.
+ *
+ * Callback for the thermal cooling device to return the cpufreq
+ * max cooling state.
+ *
+ * Return: 0 on success, an error code otherwise.
+ */
+static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
+                                unsigned long *state)
+{
+       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
+
+       *state = cpufreq_cdev->max_level;
+       return 0;
+}
+
+/**
+ * cpufreq_get_cur_state - callback function to get the current cooling state.
+ * @cdev: thermal cooling device pointer.
+ * @state: fill this variable with the current cooling state.
+ *
+ * Callback for the thermal cooling device to return the cpufreq
+ * current cooling state.
+ *
+ * Return: 0 on success, an error code otherwise.
+ */
+static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
+                                unsigned long *state)
+{
+       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
+
+       *state = cpufreq_cdev->cpufreq_state;
+
+       return 0;
+}
+
+/**
+ * cpufreq_set_cur_state - callback function to set the current cooling state.
+ * @cdev: thermal cooling device pointer.
+ * @state: set this variable to the current cooling state.
+ *
+ * Callback for the thermal cooling device to change the cpufreq
+ * current cooling state.
+ *
+ * Return: 0 on success, an error code otherwise.
+ */
+static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
+                                unsigned long state)
+{
+       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
+       unsigned int clip_freq;
+
+       /* Request state should be less than max_level */
+       if (WARN_ON(state > cpufreq_cdev->max_level))
+               return -EINVAL;
+
+       /* Check if the old cooling action is same as new cooling action */
+       if (cpufreq_cdev->cpufreq_state == state)
+               return 0;
+
+       clip_freq = cpufreq_cdev->freq_table[state].frequency;
+       cpufreq_cdev->cpufreq_state = state;
+       cpufreq_cdev->clipped_freq = clip_freq;
+
+       cpufreq_update_policy(cpufreq_cdev->policy->cpu);
+
+       return 0;
+}
 
 /* Bind cpufreq callbacks to thermal cooling device ops */
 
 static struct thermal_cooling_device_ops cpufreq_cooling_ops = {
-       .get_max_state = cpufreq_get_max_state,
-       .get_cur_state = cpufreq_get_cur_state,
-       .set_cur_state = cpufreq_set_cur_state,
-};
-
-static struct thermal_cooling_device_ops cpufreq_power_cooling_ops = {
        .get_max_state          = cpufreq_get_max_state,
        .get_cur_state          = cpufreq_get_cur_state,
        .set_cur_state          = cpufreq_set_cur_state,
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        .get_requested_power    = cpufreq_get_requested_power,
        .state2power            = cpufreq_state2power,
        .power2state            = cpufreq_power2state,
+#endif
 };
 
 /* Notifier for cpufreq policy change */
@@ -674,17 +672,16 @@ __cpufreq_cooling_register(struct device_node *np,
                        pr_debug("%s: freq:%u KHz\n", __func__, freq);
        }
 
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        if (capacitance) {
                ret = update_freq_table(cpufreq_cdev, capacitance);
                if (ret) {
                        cdev = ERR_PTR(ret);
                        goto remove_ida;
                }
-
-               cooling_ops = &cpufreq_power_cooling_ops;
-       } else {
-               cooling_ops = &cpufreq_cooling_ops;
        }
+#endif
+       cooling_ops = &cpufreq_cooling_ops;
 
        cdev = thermal_of_cooling_device_register(np, dev_name, cpufreq_cdev,
                                                  cooling_ops);
#12 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Quoted 276 lines · Quentin Perret
Quoted 4 lines · Viresh Kumar
Quoted 1 line · Daniel Lezcano

Viresh what do you think ?

I agree with your last suggestions. They do make sense.

Good :-)

So, FWIW, the below compiles w/ or w/o THERMAL_GOV_POWER_ALLOCATOR. I'll test it and clean it up some more and put it as patch 1 in the series if that's OK.

Thanks,
Quentin

drivers/thermal/cpu_cooling.c +101 -102
index f7c1f49ec87f..ee431848ef71 100644
@@ -58,7 +58,9 @@
  */
 struct freq_table {
        u32 frequency;
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        u32 power;
+#endif
 };
 
 /**
@@ -109,28 +111,6 @@ static DEFINE_IDA(cpufreq_ida);
 static DEFINE_MUTEX(cooling_list_lock);
 static LIST_HEAD(cpufreq_cdev_list);
 
-/* Below code defines functions to be used for cpufreq as cooling device */
-
-/**
- * get_level: Find the level for a particular frequency
- * @cpufreq_cdev: cpufreq_cdev for which the property is required
- * @freq: Frequency
- *
- * Return: level corresponding to the frequency.
- */
-static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev,
-                              unsigned int freq)
-{
-       struct freq_table *freq_table = cpufreq_cdev->freq_table;
-       unsigned long level;
-
-       for (level = 1; level <= cpufreq_cdev->max_level; level++)
-               if (freq > freq_table[level].frequency)
-                       break;
-
-       return level - 1;
-}
-
 /**
  * cpufreq_thermal_notifier - notifier callback for cpufreq policy change.
  * @nb:        struct notifier_block * with callback info.
@@ -184,6 +164,27 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
        return NOTIFY_OK;
 }
 
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
+/**
+ * get_level: Find the level for a particular frequency
+ * @cpufreq_cdev: cpufreq_cdev for which the property is required
+ * @freq: Frequency
+ *
+ * Return: level corresponding to the frequency.
+ */
+static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev,
+                              unsigned int freq)
+{
+       struct freq_table *freq_table = cpufreq_cdev->freq_table;
+       unsigned long level;
+
+       for (level = 1; level <= cpufreq_cdev->max_level; level++)
+               if (freq > freq_table[level].frequency)
+                       break;
+
+       return level - 1;
+}
+
 /**
  * update_freq_table() - Update the freq table with power numbers
  * @cpufreq_cdev:      the cpufreq cooling device in which to update the table
@@ -333,80 +334,6 @@ static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_cdev,
        return (raw_cpu_power * cpufreq_cdev->last_load) / 100;
 }
 
-/* cpufreq cooling device callback functions are defined below */
-
-/**
- * cpufreq_get_max_state - callback function to get the max cooling state.
- * @cdev: thermal cooling device pointer.
- * @state: fill this variable with the max cooling state.
- *
- * Callback for the thermal cooling device to return the cpufreq
- * max cooling state.
- *
- * Return: 0 on success, an error code otherwise.
- */
-static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
-                                unsigned long *state)
-{
-       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
-
-       *state = cpufreq_cdev->max_level;
-       return 0;
-}
-
-/**
- * cpufreq_get_cur_state - callback function to get the current cooling state.
- * @cdev: thermal cooling device pointer.
- * @state: fill this variable with the current cooling state.
- *
- * Callback for the thermal cooling device to return the cpufreq
- * current cooling state.
- *
- * Return: 0 on success, an error code otherwise.
- */
-static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
-                                unsigned long *state)
-{
-       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
-
-       *state = cpufreq_cdev->cpufreq_state;
-
-       return 0;
-}
-
-/**
- * cpufreq_set_cur_state - callback function to set the current cooling state.
- * @cdev: thermal cooling device pointer.
- * @state: set this variable to the current cooling state.
- *
- * Callback for the thermal cooling device to change the cpufreq
- * current cooling state.
- *
- * Return: 0 on success, an error code otherwise.
- */
-static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
-                                unsigned long state)
-{
-       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
-       unsigned int clip_freq;
-
-       /* Request state should be less than max_level */
-       if (WARN_ON(state > cpufreq_cdev->max_level))
-               return -EINVAL;
-
-       /* Check if the old cooling action is same as new cooling action */
-       if (cpufreq_cdev->cpufreq_state == state)
-               return 0;
-
-       clip_freq = cpufreq_cdev->freq_table[state].frequency;
-       cpufreq_cdev->cpufreq_state = state;
-       cpufreq_cdev->clipped_freq = clip_freq;
-
-       cpufreq_update_policy(cpufreq_cdev->policy->cpu);
-
-       return 0;
-}
-
 /**
  * cpufreq_get_requested_power() - get the current power
  * @cdev:      &thermal_cooling_device pointer
@@ -551,22 +478,93 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
                                      power);
        return 0;
 }
+#endif /* CONFIG_THERMAL_GOV_POWER_ALLOCATOR */
+
+/* cpufreq cooling device callback functions are defined below */
+
+/**
+ * cpufreq_get_max_state - callback function to get the max cooling state.
+ * @cdev: thermal cooling device pointer.
+ * @state: fill this variable with the max cooling state.
+ *
+ * Callback for the thermal cooling device to return the cpufreq
+ * max cooling state.
+ *
+ * Return: 0 on success, an error code otherwise.
+ */
+static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
+                                unsigned long *state)
+{
+       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
+
+       *state = cpufreq_cdev->max_level;
+       return 0;
+}
+
+/**
+ * cpufreq_get_cur_state - callback function to get the current cooling state.
+ * @cdev: thermal cooling device pointer.
+ * @state: fill this variable with the current cooling state.
+ *
+ * Callback for the thermal cooling device to return the cpufreq
+ * current cooling state.
+ *
+ * Return: 0 on success, an error code otherwise.
+ */
+static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
+                                unsigned long *state)
+{
+       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
+
+       *state = cpufreq_cdev->cpufreq_state;
+
+       return 0;
+}
+
+/**
+ * cpufreq_set_cur_state - callback function to set the current cooling state.
+ * @cdev: thermal cooling device pointer.
+ * @state: set this variable to the current cooling state.
+ *
+ * Callback for the thermal cooling device to change the cpufreq
+ * current cooling state.
+ *
+ * Return: 0 on success, an error code otherwise.
+ */
+static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
+                                unsigned long state)
+{
+       struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
+       unsigned int clip_freq;
+
+       /* Request state should be less than max_level */
+       if (WARN_ON(state > cpufreq_cdev->max_level))
+               return -EINVAL;
+
+       /* Check if the old cooling action is same as new cooling action */
+       if (cpufreq_cdev->cpufreq_state == state)
+               return 0;
+
+       clip_freq = cpufreq_cdev->freq_table[state].frequency;
+       cpufreq_cdev->cpufreq_state = state;
+       cpufreq_cdev->clipped_freq = clip_freq;
+
+       cpufreq_update_policy(cpufreq_cdev->policy->cpu);
+
+       return 0;
+}
 
 /* Bind cpufreq callbacks to thermal cooling device ops */
 
 static struct thermal_cooling_device_ops cpufreq_cooling_ops = {
-       .get_max_state = cpufreq_get_max_state,
-       .get_cur_state = cpufreq_get_cur_state,
-       .set_cur_state = cpufreq_set_cur_state,
-};
-
-static struct thermal_cooling_device_ops cpufreq_power_cooling_ops = {
        .get_max_state          = cpufreq_get_max_state,
        .get_cur_state          = cpufreq_get_cur_state,
        .set_cur_state          = cpufreq_set_cur_state,
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        .get_requested_power    = cpufreq_get_requested_power,
        .state2power            = cpufreq_state2power,
        .power2state            = cpufreq_power2state,
+#endif
 };
 
 /* Notifier for cpufreq policy change */
@@ -674,17 +672,16 @@ __cpufreq_cooling_register(struct device_node *np,
                        pr_debug("%s: freq:%u KHz\n", __func__, freq);
        }
 
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        if (capacitance) {
                ret = update_freq_table(cpufreq_cdev, capacitance);
                if (ret) {

drivers/thermal/cpu_cooling.c __cpufreq_cooling_register(struct device_node *np, · line 684

Quoted 10 lines
drivers/thermal/cpu_cooling.c +2 -4
                        cdev = ERR_PTR(ret);
                        goto remove_ida;
                }
-
-               cooling_ops = &cpufreq_power_cooling_ops;
-       } else {
-               cooling_ops = &cpufreq_cooling_ops;
        }
+#endif
+       cooling_ops = &cpufreq_cooling_ops;

Argh, that is actually broken with !capacitance and THERMAL_GOV_POWER_ALLOCATOR=y ... Perhaps it's best to keep the two thermal_cooling_device_ops struct separated in the end.

Quoted 3 lines
drivers/thermal/cpu_cooling.c +0 -0
        cdev = thermal_of_cooling_device_register(np, dev_name, cpufreq_cdev,
                                                  cooling_ops);
#13 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Quoted 1 line · Quentin Perret

On Wednesday 15 May 2019 at 11:40:44 (+0100), Quentin Perret wrote:

[ ... ]

Quoted 10 lines
Quoted 10 lines
drivers/thermal/cpu_cooling.c +1 -3
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        if (capacitance) {
                ret = update_freq_table(cpufreq_cdev, capacitance);
                if (ret) {
                        cdev = ERR_PTR(ret);
                        goto remove_ida;
                }
-
-               cooling_ops = &cpufreq_power_cooling_ops;
-       } else {
Quoted 8 lines

drivers/thermal/cpu_cooling.c __cpufreq_cooling_register(struct device_node *np, · line 684

Quoted 4 lines
drivers/thermal/cpu_cooling.c +2 -1
-               cooling_ops = &cpufreq_cooling_ops;
        }
+#endif
+       cooling_ops = &cpufreq_cooling_ops;

Argh, that is actually broken with !capacitance and THERMAL_GOV_POWER_ALLOCATOR=y ... Perhaps it's best to keep the two thermal_cooling_device_ops struct separated in the end.

Or alternatively you can keep one structure but instead of filling the state2power,power2state and getrequestedpower fields in the declaration, you fill them in the if (capacitance) block, no?

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#14 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Quoted 24 lines · Daniel Lezcano
Quoted 1 line · Quentin Perret

On Wednesday 15 May 2019 at 11:40:44 (+0100), Quentin Perret wrote:

[ ... ]

Quoted 10 lines
Quoted 10 lines
drivers/thermal/cpu_cooling.c +1 -3
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        if (capacitance) {
                ret = update_freq_table(cpufreq_cdev, capacitance);
                if (ret) {
                        cdev = ERR_PTR(ret);
                        goto remove_ida;
                }
-
-               cooling_ops = &cpufreq_power_cooling_ops;
-       } else {
Quoted 8 lines

drivers/thermal/cpu_cooling.c __cpufreq_cooling_register(struct device_node *np, · line 684

Quoted 4 lines
drivers/thermal/cpu_cooling.c +2 -1
-               cooling_ops = &cpufreq_cooling_ops;
        }
+#endif
+       cooling_ops = &cpufreq_cooling_ops;

Argh, that is actually broken with !capacitance and THERMAL_GOV_POWER_ALLOCATOR=y ... Perhaps it's best to keep the two thermal_cooling_device_ops struct separated in the end.

Quoted 3 lines

Or alternatively you can keep one structure but instead of filling the state2power,power2state and getrequestedpower fields in the declaration, you fill them in the if (capacitance) block, no?

Something like the below ? Yes, that works too. I'll write a proper patch and send that next week or so.

Thanks,
Quentin

--->8---

/* Bind cpufreq callbacks to thermal cooling device ops */

static struct thermal_cooling_device_ops cpufreq_cooling_ops = {

-       .get_max_state = cpufreq_get_max_state,
-       .get_cur_state = cpufreq_get_cur_state,
-       .set_cur_state = cpufreq_set_cur_state,
-};
-
-static struct thermal_cooling_device_ops cpufreq_power_cooling_ops = {
        .get_max_state          = cpufreq_get_max_state,
        .get_cur_state          = cpufreq_get_cur_state,
        .set_cur_state          = cpufreq_set_cur_state,
-       .get_requested_power    = cpufreq_get_requested_power,
-       .state2power            = cpufreq_state2power,
-       .power2state            = cpufreq_power2state,

};

/* Notifier for cpufreq policy change */
@@ -674,18 +667,19 @@ __cpufreq_cooling_register(struct device_node *np,

                        pr_debug("%s: freq:%u KHz\n", __func__, freq);
        }

+ cooling_ops = &cpufreq_cooling_ops;
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR

        if (capacitance) {
                ret = update_freq_table(cpufreq_cdev, capacitance);
                if (ret) {
                        cdev = ERR_PTR(ret);
                        goto remove_ida;
                }
-
-               cooling_ops = &cpufreq_power_cooling_ops;
-       } else {
-               cooling_ops = &cpufreq_cooling_ops;
+               cooling_ops->get_requested_power = cpufreq_get_requested_power;
+               cooling_ops->state2power = cpufreq_state2power;
+               cooling_ops->power2state = cpufreq_power2state;
        }
-
+#endif
        cdev = thermal_of_cooling_device_register(np, dev_name, cpufreq_cdev,
                                                  cooling_ops);
        if (IS_ERR(cdev))
#15 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Quoted 25 lines · Quentin Perret
Quoted 24 lines · Daniel Lezcano
Quoted 1 line · Quentin Perret

On Wednesday 15 May 2019 at 11:40:44 (+0100), Quentin Perret wrote:

[ ... ]

Quoted 18 lines
Quoted 4 lines
drivers/thermal/cpu_cooling.c +1 -0
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        if (capacitance) {
                ret = update_freq_table(cpufreq_cdev, capacitance);
                if (ret) {

drivers/thermal/cpu_cooling.c __cpufreq_cooling_register(struct device_node *np, · line 684

Quoted 10 lines
drivers/thermal/cpu_cooling.c +2 -4
                        cdev = ERR_PTR(ret);
                        goto remove_ida;
                }
-
-               cooling_ops = &cpufreq_power_cooling_ops;
-       } else {
-               cooling_ops = &cpufreq_cooling_ops;
        }
+#endif
+       cooling_ops = &cpufreq_cooling_ops;

Argh, that is actually broken with !capacitance and THERMAL_GOV_POWER_ALLOCATOR=y ... Perhaps it's best to keep the two thermal_cooling_device_ops struct separated in the end.

Quoted 6 lines
Quoted 3 lines

Or alternatively you can keep one structure but instead of filling the state2power,power2state and getrequestedpower fields in the declaration, you fill them in the if (capacitance) block, no?

Something like the below ? Yes, that works too. I'll write a proper patch and send that next week or so.

Yes, exactly. And IMHO, that helps for the understanding of code also.

Quoted 46 lines

--->8---

/* Bind cpufreq callbacks to thermal cooling device ops */

static struct thermal_cooling_device_ops cpufreq_cooling_ops = {

drivers/thermal/cpu_cooling.c +6 -14
-       .get_max_state = cpufreq_get_max_state,
-       .get_cur_state = cpufreq_get_cur_state,
-       .set_cur_state = cpufreq_set_cur_state,
-};
-
-static struct thermal_cooling_device_ops cpufreq_power_cooling_ops = {
        .get_max_state          = cpufreq_get_max_state,
        .get_cur_state          = cpufreq_get_cur_state,
        .set_cur_state          = cpufreq_set_cur_state,
-       .get_requested_power    = cpufreq_get_requested_power,
-       .state2power            = cpufreq_state2power,
-       .power2state            = cpufreq_power2state,
 };
 
 /* Notifier for cpufreq policy change */
@@ -674,18 +667,19 @@ __cpufreq_cooling_register(struct device_node *np,
                        pr_debug("%s: freq:%u KHz\n", __func__, freq);
        }
 
+       cooling_ops = &cpufreq_cooling_ops;
+#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
        if (capacitance) {
                ret = update_freq_table(cpufreq_cdev, capacitance);
                if (ret) {
                        cdev = ERR_PTR(ret);
                        goto remove_ida;
                }
-
-               cooling_ops = &cpufreq_power_cooling_ops;
-       } else {
-               cooling_ops = &cpufreq_cooling_ops;
+               cooling_ops->get_requested_power = cpufreq_get_requested_power;
+               cooling_ops->state2power = cpufreq_state2power;
+               cooling_ops->power2state = cpufreq_power2state;
        }
-
+#endif
        cdev = thermal_of_cooling_device_register(np, dev_name, cpufreq_cdev,
                                                  cooling_ops);
        if (IS_ERR(cdev))
Signature · 11 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#16 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

In reply to Quentin Perret
Quoted 21 lines · Quentin Perret
Quoted 4 lines · Viresh Kumar
Quoted 1 line · Daniel Lezcano

Viresh what do you think ?

I agree with your last suggestions. They do make sense.

Good :-)

So, FWIW, the below compiles w/ or w/o THERMAL_GOV_POWER_ALLOCATOR. I'll test it and clean it up some more and put it as patch 1 in the series if that's OK.

Thanks,
Quentin

drivers/thermal/cpu_cooling.c +0 -0
index f7c1f49ec87f..ee431848ef71 100644

drivers/thermal/cpu_cooling.c line 60

Quoted 3 lines
drivers/thermal/cpu_cooling.c +0 -0
@@ -58,7 +58,9 @@
  */
 struct freq_table {
        u32 frequency;

I suspect we will have a problem here as cpufreq_set_cur_state uses the frequency and when switching to EM, we will still need a freq table.

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#17 lore raw

Re: [PATCH v4 2/3] PM / EM: Expose perf domain struct

Quoted 17 lines · Daniel Lezcano
Quoted 16 lines · Quentin Perret
Quoted 4 lines · Viresh Kumar
Quoted 1 line · Daniel Lezcano

Viresh what do you think ?

I agree with your last suggestions. They do make sense.

Good :-)

So, FWIW, the below compiles w/ or w/o THERMAL_GOV_POWER_ALLOCATOR. I'll test it and clean it up some more and put it as patch 1 in the series if that's OK.

Thanks,
Quentin

Quoted 11 lines

drivers/thermal/cpu_cooling.c line 60

Quoted 8 lines
drivers/thermal/cpu_cooling.c +0 -0
index f7c1f49ec87f..ee431848ef71 100644
@@ -58,7 +58,9 @@
  */
 struct freq_table {
        u32 frequency;

I suspect we will have a problem here as cpufreq_set_cur_state uses the frequency and when switching to EM, we will still need a freq table.

Indeed, I'll need a bit of ifdefery in the get_state_freq() function introduced in patch 3, but nothing too horrible I hope.

Thanks,
Quentin

#18 lore raw

PATCH v4 3/3 thermal: cpu_cooling: Migrate to using the EM framework

In reply to Quentin Perret

The newly introduced Energy Model framework manages power cost tables in a generic way. Moreover, it supports several types of models since the tables can come from DT or firmware (through SCMI) for example. On the other hand, the cpu_cooling subsystem manages its own power cost tables using only DT data.

In order to avoid the duplication of data in the kernel, and in order to enable IPA with EMs coming from more than just DT, remove the private tables from cpu_cooling.c and migrate it to using the centralized EM framework. Doing so should have no visible functional impact for existing users of IPA since:

- recent extenstions to the the PM_OPP infrastructure enable the registration of EMs in PM_EM using the DT property used by IPA;

- the existing upstream cpufreq drivers marked with the 'CPUFREQ_IS_COOLING_DEV' flag all use the aforementioned PM_OPP infrastructure, which means they all support PM_EM. The only two exceptions are qoriq-cpufreq which doesn't in fact use an EM and scmi-cpufreq which doesn't use DT for power costs.

For existing users of cpu_cooling, PM_EM tables will contain the exact same power values that IPA used to compute on its own until now. The only new dependency for them is to compile in CONFIG_ENERGY_MODEL.

The case where the thermal subsystem is used without an Energy Model (cpufreq_cooling_ops) is handled by looking directly at CPUFreq's frequency table which is already a dependency for cpu_cooling.c anyway. Since the thermal framework expects the cooling states in a particular order, bail out whenever the CPUFreq table is unsorted, since that is fairly uncommon in general, and there are currently no users of cpu_cooling for this use-case.

---
 drivers/thermal/Kconfig       |   1 +
 drivers/thermal/cpu_cooling.c | 238 ++++++++++++----------------------
 2 files changed, 82 insertions(+), 157 deletions(-)
drivers/thermal/Kconfig +1 -0
index 653aa27a25a4..d695bd33c440 100644
@@ -144,6 +144,7 @@ config THERMAL_GOV_USER_SPACE
 
 config THERMAL_GOV_POWER_ALLOCATOR
 	bool "Power allocator thermal governor"
+	depends on ENERGY_MODEL
 	help
 	  Enable this to manage platform thermals by dynamically
 	  allocating and limiting power to devices.
drivers/thermal/cpu_cooling.c +81 -157

402 lines not on this page · raw message

Signature · 1 line
2.21.0