mbox series

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

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

Message

Amit Kucheria Jan. 21, 2019, 3:40 p.m. UTC
Add a flag to be used by 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 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/cpufreq-dt.c       | 14 ++------------
 drivers/cpufreq/cpufreq.c          |  6 ++++++
 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            | 25 +++++++++++++++++++++++++
 10 files changed, 46 insertions(+), 84 deletions(-)

-- 
2.17.1

Comments

Viresh Kumar Jan. 23, 2019, 10:34 a.m. UTC | #1
On 21-01-19, 21:10, 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.

> 

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

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

> ---

>  drivers/thermal/Kconfig | 1 +

>  1 file changed, 1 insertion(+)

> 

> 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


Please remove all Kconfig crap, which gets fixed with this, as well in
this patch itself. Like:

diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index 10bc5c798d17..40f8cc323996 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -40,8 +40,6 @@ config ARM_ARMADA_8K_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.

-- 
viresh
Viresh Kumar Jan. 23, 2019, 10:36 a.m. UTC | #2
On 21-01-19, 21:10, Amit Kucheria wrote:
> @@ -151,6 +152,11 @@ struct cpufreq_policy {

>  

>  	/* For cpufreq driver's internal use */

>  	void			*driver_data;

> +

> +#ifdef CONFIG_CPU_THERMAL

> +	/* Pointer to the cooling device if used for thermal mitigation */

> +	struct thermal_cooling_device *cdev;

> +#endif

>  };

>  

>  /* Only for ACPI */

> @@ -386,6 +392,12 @@ struct cpufreq_driver {

>   */

>  #define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING	BIT(6)

>  

> +/*

> + * Set by drivers that want the core to automatically register the cpufreq

> + * driver as a thermal cooling device.

> + */

> +#define CPUFREQ_AUTO_REGISTER_COOLING_DEV	BIT(7)

> +

>  int cpufreq_register_driver(struct cpufreq_driver *driver_data);

>  int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);

>  

> @@ -415,6 +427,19 @@ cpufreq_verify_within_cpu_limits(struct cpufreq_policy *policy)

>  			policy->cpuinfo.max_freq);

>  }

>  

> +#ifdef CONFIG_CPU_THERMAL

> +static inline void register_cooling_device(struct cpufreq_policy *policy) {

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

> +}

> +

> +static inline void unregister_cooling_device(struct cpufreq_policy *policy) {

> +	cpufreq_cooling_unregister(policy->cdev);

> +	policy->cdev = NULL;

> +}

> +#else

> +static inline void register_cooling_device(struct cpufreq_policy *policy) {}

> +static inline void unregister_cooling_device(struct cpufreq_policy *policy) {}

> +#endif


The whole ifdef hackery here saves space for a pointer per policy.
Just get rid of it, it isn't worth it.

-- 
viresh
Rafael J. Wysocki Jan. 23, 2019, 10:53 a.m. UTC | #3
On Wed, Jan 23, 2019 at 11:44 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>

> On 23-01-19, 16:13, Viresh Kumar wrote:

> > On 23-01-19, 11:39, Rafael J. Wysocki wrote:

> > > On Wed, Jan 23, 2019 at 11:36 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:

> > > >

> > > > On 21-01-19, 21:10, Amit Kucheria wrote:

> > > > > @@ -151,6 +152,11 @@ struct cpufreq_policy {

> > > > >

> > > > >       /* For cpufreq driver's internal use */

> > > > >       void                    *driver_data;

> > > > > +

> > > > > +#ifdef CONFIG_CPU_THERMAL

> > > > > +     /* Pointer to the cooling device if used for thermal mitigation */

> > > > > +     struct thermal_cooling_device *cdev;

> > > > > +#endif

> > > > >  };

> > > > >

> > > > >  /* Only for ACPI */

> > > > > @@ -386,6 +392,12 @@ struct cpufreq_driver {

> > > > >   */

> > > > >  #define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING    BIT(6)

> > > > >

> > > > > +/*

> > > > > + * Set by drivers that want the core to automatically register the cpufreq

> > > > > + * driver as a thermal cooling device.

> > > > > + */

> > > > > +#define CPUFREQ_AUTO_REGISTER_COOLING_DEV    BIT(7)

> > > > > +

> > > > >  int cpufreq_register_driver(struct cpufreq_driver *driver_data);

> > > > >  int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);

> > > > >

> > > > > @@ -415,6 +427,19 @@ cpufreq_verify_within_cpu_limits(struct cpufreq_policy *policy)

> > > > >                       policy->cpuinfo.max_freq);

> > > > >  }

> > > > >

> > > > > +#ifdef CONFIG_CPU_THERMAL

> > > > > +static inline void register_cooling_device(struct cpufreq_policy *policy) {

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

> > > > > +}

> > > > > +

> > > > > +static inline void unregister_cooling_device(struct cpufreq_policy *policy) {

> > > > > +     cpufreq_cooling_unregister(policy->cdev);

> > > > > +     policy->cdev = NULL;

> > > > > +}

> > > > > +#else

> > > > > +static inline void register_cooling_device(struct cpufreq_policy *policy) {}

> > > > > +static inline void unregister_cooling_device(struct cpufreq_policy *policy) {}

> > > > > +#endif

> > > >

> > > > The whole ifdef hackery here saves space for a pointer per policy.

> > > > Just get rid of it, it isn't worth it.

> > >

> > > Is struct thermal_cooling_device defined if CONFIG_THERMAL is unset?

> >

> > No and it is defined in thermal.h without any ifdef stuff.

>

> I meant it is always available and doesn't depend on CONFIG_THERMAL.


OK

I guess we can live with an extra unused pointer per policy on
platforms with CONFIG_CPU_THERMAL unset.
Rafael J. Wysocki Jan. 23, 2019, 10:54 a.m. UTC | #4
On Wed, Jan 23, 2019 at 11:53 AM Amit Kucheria <amit.kucheria@linaro.org> wrote:
>

> On Wed, Jan 23, 2019 at 4:04 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:

> >

> > On 21-01-19, 21:10, 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.

> > >

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

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

> > > ---

> > >  drivers/thermal/Kconfig | 1 +

> > >  1 file changed, 1 insertion(+)

> > >

> > > 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

> >

> > Please remove all Kconfig crap, which gets fixed with this, as well in

> > this patch itself. Like:

>

> OK, I planned to if/when this series was accepted. Will send out a patch.


You can make it part of this series, though.