mbox series

[v5,0/9] cpufreq: Add flag to auto-register as cooling device

Message ID cover.1548737236.git.amit.kucheria@linaro.org
Headers show
Series cpufreq: Add flag to auto-register as cooling device | expand

Message

Amit Kucheria Jan. 29, 2019, 4:55 a.m. UTC
Add a flag for cpufreq drivers to tell cpufreq core to auto-register
themselves as a thermal cooling device.

There series converts over all the drivers except arm_big_little.c.
Tested on SDM845 with the qcom-cpufreq-hw driver. Only compile-tested the
others.

Things needing fixing (but not a blocker for the series):
 - Look at how to detect that we're not in IKS mode in arm_big_little's
   .ready callback.

Changes since v4:
 - Added IS_ENABLED guards in cpufreq.c
 - Changed flag name to CPUFREQ_IS_COOLING_DEV
 - Collected various review tags

Changes since v3:
 - Got rid of wrapper function to register/unregister cooling devices.
   Directly call the function in cpufreq.c

Changes since v2:
 - Get rid of #ifdef'ery and let the pointer exist in all cases
 - Get rid of (!CPU_THERMAL || THERMAL) dependency in all cpufreq drivers'
   Kconfig

Changes since v1:
- Fix compilation failures with allmodconfig
- Get rid of #ifdef in cpufreq.c
- Removed miscellaneous patches and sent them separately
- Merged patches 1 and 2 from v1

Amit Kucheria (9):
  thermal: cpu_cooling: Require thermal core to be compiled in
  cpufreq: Auto-register the driver as a thermal cooling device if asked
  cpufreq: qcom-hw: Register as a cpufreq cooling device
  cpufreq: imx6q: Use auto-registration of thermal cooling device
  cpufreq: cpufreq-dt: Use auto-registration of thermal cooling device
  cpufreq: mediatek: Use auto-registration of thermal cooling device
  cpufreq: qoriq: Use auto-registration of thermal cooling device
  cpufreq: scmi: Use auto-registration of thermal cooling device
  cpufreq: scpi: Use auto-registration of thermal cooling device

 drivers/cpufreq/Kconfig            |  3 ---
 drivers/cpufreq/Kconfig.arm        |  5 -----
 drivers/cpufreq/cpufreq-dt.c       | 14 ++------------
 drivers/cpufreq/cpufreq.c          | 13 +++++++++++++
 drivers/cpufreq/imx6q-cpufreq.c    | 24 ++----------------------
 drivers/cpufreq/mediatek-cpufreq.c | 14 ++------------
 drivers/cpufreq/qcom-cpufreq-hw.c  |  3 ++-
 drivers/cpufreq/qoriq-cpufreq.c    | 15 ++-------------
 drivers/cpufreq/scmi-cpufreq.c     | 14 ++------------
 drivers/cpufreq/scpi-cpufreq.c     | 14 ++------------
 drivers/thermal/Kconfig            |  1 +
 include/linux/cpufreq.h            |  9 +++++++++
 12 files changed, 37 insertions(+), 92 deletions(-)

-- 
2.17.1

Comments

Rafael J. Wysocki Jan. 30, 2019, 11:53 p.m. UTC | #1
On Tuesday, January 29, 2019 5:55:07 AM CET Amit Kucheria wrote:
> The CPU cooling driver (cpu_cooling.c) allows the platform's cpufreq

> driver to register as a cooling device and cool down the platform by

> throttling the CPU frequency. In order to be able to auto-register a

> cpufreq driver as a cooling device from the cpufreq core, we need access

> to code inside cpu_cooling.c which, in turn, accesses code inside

> thermal core.

> 

> CPU_FREQ is a bool while THERMAL is tristate.  In some configurations

> (e.g. allmodconfig), CONFIG_THERMAL ends up as a module while

> CONFIG_CPU_FREQ is compiled in. This leads to following error:

> 

> drivers/cpufreq/cpufreq.o: In function `cpufreq_offline':

> cpufreq.c:(.text+0x407c): undefined reference to `cpufreq_cooling_unregister'

> drivers/cpufreq/cpufreq.o: In function `cpufreq_online':

> cpufreq.c:(.text+0x70c0): undefined reference to `of_cpufreq_cooling_register'

> 

> Given that platforms using CPU_THERMAL usually want it compiled-in so it

> is available early in boot, make CPU_THERMAL depend on THERMAL being

> compiled-in instead of allowing it to be a module.

> 

> As a result of this change, get rid of the ugly (!CPU_THERMAL ||

> THERMAL) dependency in all cpufreq drivers using CPU_THERMAL.

> 

> Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>

> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

> ---

>  drivers/cpufreq/Kconfig     | 3 ---

>  drivers/cpufreq/Kconfig.arm | 5 -----

>  drivers/thermal/Kconfig     | 1 +

>  3 files changed, 1 insertion(+), 8 deletions(-)

> 

> diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig

> index 608af20a3494..b22e6bba71f1 100644

> --- a/drivers/cpufreq/Kconfig

> +++ b/drivers/cpufreq/Kconfig

> @@ -207,8 +207,6 @@ comment "CPU frequency scaling drivers"

>  config CPUFREQ_DT

>  	tristate "Generic DT based cpufreq driver"

>  	depends on HAVE_CLK && OF

> -	# if CPU_THERMAL is on and THERMAL=m, CPUFREQ_DT cannot be =y:

> -	depends on !CPU_THERMAL || THERMAL

>  	select CPUFREQ_DT_PLATDEV

>  	select PM_OPP

>  	help

> @@ -327,7 +325,6 @@ endif

>  config QORIQ_CPUFREQ

>  	tristate "CPU frequency scaling driver for Freescale QorIQ SoCs"

>  	depends on OF && COMMON_CLK && (PPC_E500MC || ARM || ARM64)

> -	depends on !CPU_THERMAL || THERMAL

>  	select CLK_QORIQ

>  	help

>  	  This adds the CPUFreq driver support for Freescale QorIQ SoCs

> diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm

> index 688f10227793..ca8567c3152c 100644

> --- a/drivers/cpufreq/Kconfig.arm

> +++ b/drivers/cpufreq/Kconfig.arm

> @@ -29,8 +29,6 @@ config ARM_ARMADA_37XX_CPUFREQ

>  config ARM_BIG_LITTLE_CPUFREQ

>  	tristate "Generic ARM big LITTLE CPUfreq driver"

>  	depends on ARM_CPU_TOPOLOGY && HAVE_CLK

> -	# if CPU_THERMAL is on and THERMAL=m, ARM_BIT_LITTLE_CPUFREQ cannot be =y

> -	depends on !CPU_THERMAL || THERMAL

>  	select PM_OPP

>  	help

>  	  This enables the Generic CPUfreq driver for ARM big.LITTLE platforms.

> @@ -38,7 +36,6 @@ config ARM_BIG_LITTLE_CPUFREQ

>  config ARM_SCPI_CPUFREQ

>  	tristate "SCPI based CPUfreq driver"

>  	depends on ARM_SCPI_PROTOCOL && COMMON_CLK_SCPI

> -	depends on !CPU_THERMAL || THERMAL

>  	help

>  	  This adds the CPUfreq driver support for ARM platforms using SCPI

>  	  protocol for CPU power management.

> @@ -93,7 +90,6 @@ config ARM_KIRKWOOD_CPUFREQ

>  config ARM_MEDIATEK_CPUFREQ

>  	tristate "CPU Frequency scaling support for MediaTek SoCs"

>  	depends on ARCH_MEDIATEK && REGULATOR

> -	depends on !CPU_THERMAL || THERMAL

>  	select PM_OPP

>  	help

>  	  This adds the CPUFreq driver support for MediaTek SoCs.

> @@ -233,7 +229,6 @@ config ARM_SA1110_CPUFREQ

>  config ARM_SCMI_CPUFREQ

>  	tristate "SCMI based CPUfreq driver"

>  	depends on ARM_SCMI_PROTOCOL || COMPILE_TEST

> -	depends on !CPU_THERMAL || THERMAL

>  	select PM_OPP

>  	help

>  	  This adds the CPUfreq driver support for ARM platforms using SCMI

> diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig

> index 30323426902e..58bb7d72dc2b 100644

> --- a/drivers/thermal/Kconfig

> +++ b/drivers/thermal/Kconfig

> @@ -152,6 +152,7 @@ config CPU_THERMAL

>  	bool "generic cpu cooling support"

>  	depends on CPU_FREQ

>  	depends on THERMAL_OF

> +	depends on THERMAL=y

>  	help

>  	  This implements the generic cpu cooling mechanism through frequency

>  	  reduction. An ACPI version of this already exists

> 


Applied, thanks!
Rafael J. Wysocki Feb. 6, 2019, 10:32 a.m. UTC | #2
On Tuesday, January 29, 2019 5:55:06 AM CET Amit Kucheria wrote:
> Add a flag for cpufreq drivers to tell cpufreq core to auto-register

> themselves as a thermal cooling device.

> 

> There series converts over all the drivers except arm_big_little.c.

> Tested on SDM845 with the qcom-cpufreq-hw driver. Only compile-tested the

> others.

> 

> Things needing fixing (but not a blocker for the series):

>  - Look at how to detect that we're not in IKS mode in arm_big_little's

>    .ready callback.

> 

> Changes since v4:

>  - Added IS_ENABLED guards in cpufreq.c

>  - Changed flag name to CPUFREQ_IS_COOLING_DEV

>  - Collected various review tags

> 

> Changes since v3:

>  - Got rid of wrapper function to register/unregister cooling devices.

>    Directly call the function in cpufreq.c

> 

> Changes since v2:

>  - Get rid of #ifdef'ery and let the pointer exist in all cases

>  - Get rid of (!CPU_THERMAL || THERMAL) dependency in all cpufreq drivers'

>    Kconfig

> 

> Changes since v1:

> - Fix compilation failures with allmodconfig

> - Get rid of #ifdef in cpufreq.c

> - Removed miscellaneous patches and sent them separately

> - Merged patches 1 and 2 from v1

> 

> Amit Kucheria (9):

>   thermal: cpu_cooling: Require thermal core to be compiled in

>   cpufreq: Auto-register the driver as a thermal cooling device if asked

>   cpufreq: qcom-hw: Register as a cpufreq cooling device

>   cpufreq: imx6q: Use auto-registration of thermal cooling device

>   cpufreq: cpufreq-dt: Use auto-registration of thermal cooling device

>   cpufreq: mediatek: Use auto-registration of thermal cooling device

>   cpufreq: qoriq: Use auto-registration of thermal cooling device

>   cpufreq: scmi: Use auto-registration of thermal cooling device

>   cpufreq: scpi: Use auto-registration of thermal cooling device

> 

>  drivers/cpufreq/Kconfig            |  3 ---

>  drivers/cpufreq/Kconfig.arm        |  5 -----

>  drivers/cpufreq/cpufreq-dt.c       | 14 ++------------

>  drivers/cpufreq/cpufreq.c          | 13 +++++++++++++

>  drivers/cpufreq/imx6q-cpufreq.c    | 24 ++----------------------

>  drivers/cpufreq/mediatek-cpufreq.c | 14 ++------------

>  drivers/cpufreq/qcom-cpufreq-hw.c  |  3 ++-

>  drivers/cpufreq/qoriq-cpufreq.c    | 15 ++-------------

>  drivers/cpufreq/scmi-cpufreq.c     | 14 ++------------

>  drivers/cpufreq/scpi-cpufreq.c     | 14 ++------------

>  drivers/thermal/Kconfig            |  1 +

>  include/linux/cpufreq.h            |  9 +++++++++

>  12 files changed, 37 insertions(+), 92 deletions(-)

> 

> 


I've applied the series, thanks!
Matthias Brugger Feb. 6, 2019, 1:55 p.m. UTC | #3
On 29/01/2019 05:55, Amit Kucheria wrote:
> Use the CPUFREQ_IS_COOLING_DEV flag to allow cpufreq core to

> automatically register as a thermal cooling device.

> 

> This allows removal of boiler plate code from the driver.

> 

> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>

> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

> Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>


Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>


> ---

>  drivers/cpufreq/mediatek-cpufreq.c | 14 ++------------

>  1 file changed, 2 insertions(+), 12 deletions(-)

> 

> diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c

> index eb8920d39818..4229fcc31310 100644

> --- a/drivers/cpufreq/mediatek-cpufreq.c

> +++ b/drivers/cpufreq/mediatek-cpufreq.c

> @@ -14,7 +14,6 @@

>  

>  #include <linux/clk.h>

>  #include <linux/cpu.h>

> -#include <linux/cpu_cooling.h>

>  #include <linux/cpufreq.h>

>  #include <linux/cpumask.h>

>  #include <linux/module.h>

> @@ -48,7 +47,6 @@ struct mtk_cpu_dvfs_info {

>  	struct regulator *sram_reg;

>  	struct clk *cpu_clk;

>  	struct clk *inter_clk;

> -	struct thermal_cooling_device *cdev;

>  	struct list_head list_head;

>  	int intermediate_voltage;

>  	bool need_voltage_tracking;

> @@ -307,13 +305,6 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,

>  

>  #define DYNAMIC_POWER "dynamic-power-coefficient"

>  

> -static void mtk_cpufreq_ready(struct cpufreq_policy *policy)

> -{

> -	struct mtk_cpu_dvfs_info *info = policy->driver_data;

> -

> -	info->cdev = of_cpufreq_cooling_register(policy);

> -}

> -

>  static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)

>  {

>  	struct device *cpu_dev;

> @@ -472,7 +463,6 @@ static int mtk_cpufreq_exit(struct cpufreq_policy *policy)

>  {

>  	struct mtk_cpu_dvfs_info *info = policy->driver_data;

>  

> -	cpufreq_cooling_unregister(info->cdev);

>  	dev_pm_opp_free_cpufreq_table(info->cpu_dev, &policy->freq_table);

>  

>  	return 0;

> @@ -480,13 +470,13 @@ static int mtk_cpufreq_exit(struct cpufreq_policy *policy)

>  

>  static struct cpufreq_driver mtk_cpufreq_driver = {

>  	.flags = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK |

> -		 CPUFREQ_HAVE_GOVERNOR_PER_POLICY,

> +		 CPUFREQ_HAVE_GOVERNOR_PER_POLICY |

> +		 CPUFREQ_IS_COOLING_DEV,

>  	.verify = cpufreq_generic_frequency_table_verify,

>  	.target_index = mtk_cpufreq_set_target,

>  	.get = cpufreq_generic_get,

>  	.init = mtk_cpufreq_init,

>  	.exit = mtk_cpufreq_exit,

> -	.ready = mtk_cpufreq_ready,

>  	.name = "mtk-cpufreq",

>  	.attr = cpufreq_generic_attr,

>  };

>