diff mbox series

[v2,1/3] thermal/core: Precompute the delays from msecs to jiffies

Message ID 20201216220337.839878-1-daniel.lezcano@linaro.org
State Accepted
Commit 17d399cd9c8936909bc8936a5837b6da9af9c29e
Headers show
Series [v2,1/3] thermal/core: Precompute the delays from msecs to jiffies | expand

Commit Message

Daniel Lezcano Dec. 16, 2020, 10:03 p.m. UTC
The delays are stored in ms units and when the polling function is
called this delay is converted into jiffies at each call.

Instead of doing the conversion again and again, compute the jiffies
at init time and use the value directly when setting the polling.

Cc: Thara Gopinath <thara.gopinath@linaro.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>

---
 drivers/thermal/thermal_core.c    | 3 +++
 drivers/thermal/thermal_core.h    | 1 +
 drivers/thermal/thermal_helpers.c | 7 +++++++
 include/linux/thermal.h           | 7 +++++++
 4 files changed, 18 insertions(+)

-- 
2.25.1

Comments

Peter Kästle Dec. 16, 2020, 10:35 p.m. UTC | #1
16. Dezember 2020 23:04, "Daniel Lezcano" <daniel.lezcano@linaro.org> schrieb:

> The code does no longer use the ms unit based fields to set the

> delays as they are replaced by the jiffies.

> 

> Remove them and replace their user to use the jiffies version instead.

> 

> Cc: Thara Gopinath <thara.gopinath@linaro.org>

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

> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>

> ---

> drivers/platform/x86/acerhdf.c | 3 ++-


Reviewed-by: Peter Kästle <peter@piie.net>



> drivers/thermal/da9062-thermal.c | 4 ++--

> drivers/thermal/gov_power_allocator.c | 2 +-

> drivers/thermal/thermal_core.c | 4 +---

> drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 6 ++++--

> include/linux/thermal.h | 7 -------

> 6 files changed, 10 insertions(+), 16 deletions(-)

> 

> diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c

> index b6aa6e5514f4..6b8b3ab8db48 100644

> --- a/drivers/platform/x86/acerhdf.c

> +++ b/drivers/platform/x86/acerhdf.c

> @@ -336,7 +336,8 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal)

> pr_notice("interval changed to: %d\n", interval);

> 

> if (thermal)

> - thermal->polling_delay = interval*1000;

> + thermal->polling_delay_jiffies =

> + round_jiffies(msecs_to_jiffies(interval * 1000));

> 

> prev_interval = interval;

> }

> diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c

> index 4d74994f160a..180edec34e07 100644

> --- a/drivers/thermal/da9062-thermal.c

> +++ b/drivers/thermal/da9062-thermal.c

> @@ -95,7 +95,7 @@ static void da9062_thermal_poll_on(struct work_struct *work)

> thermal_zone_device_update(thermal->zone,

> THERMAL_EVENT_UNSPECIFIED);

> 

> - delay = msecs_to_jiffies(thermal->zone->passive_delay);

> + delay = thermal->zone->passive_delay_jiffies;

> queue_delayed_work(system_freezable_wq, &thermal->work, delay);

> return;

> }

> @@ -245,7 +245,7 @@ static int da9062_thermal_probe(struct platform_device *pdev)

> 

> dev_dbg(&pdev->dev,

> "TJUNC temperature polling period set at %d ms\n",

> - thermal->zone->passive_delay);

> + jiffies_to_msecs(thermal->zone->passive_delay_jiffies));

> 

> ret = platform_get_irq_byname(pdev, "THERMAL");

> if (ret < 0) {

> diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c

> index 7a4170a0b51f..f8c3d1e40b86 100644

> --- a/drivers/thermal/gov_power_allocator.c

> +++ b/drivers/thermal/gov_power_allocator.c

> @@ -258,7 +258,7 @@ static u32 pid_controller(struct thermal_zone_device *tz,

> * power being applied, slowing down the controller)

> */

> d = mul_frac(tz->tzp->k_d, err - params->prev_err);

> - d = div_frac(d, tz->passive_delay);

> + d = div_frac(d, jiffies_to_msecs(tz->passive_delay_jiffies));

> params->prev_err = err;

> 

> power_range = p + i + d;

> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c

> index d96c515af3cb..b2615449b18f 100644

> --- a/drivers/thermal/thermal_core.c

> +++ b/drivers/thermal/thermal_core.c

> @@ -313,7 +313,7 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)

> 

> if (!stop && tz->passive)

> thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies);

> - else if (!stop && tz->polling_delay)

> + else if (!stop && tz->polling_delay_jiffies)

> thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies);

> else

> thermal_zone_device_set_polling(tz, 0);

> @@ -1307,8 +1307,6 @@ thermal_zone_device_register(const char *type, int trips, int mask,

> tz->device.class = &thermal_class;

> tz->devdata = devdata;

> tz->trips = trips;

> - tz->passive_delay = passive_delay;

> - tz->polling_delay = polling_delay;

> 

> thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);

> thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);

> diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c

> b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c

> index 2ce4b19f312a..f84375865c97 100644

> --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c

> +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c

> @@ -166,6 +166,7 @@ int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id,

> char *domain)

> {

> struct ti_thermal_data *data;

> + int interval;

> 

> data = ti_bandgap_get_sensor_data(bgp, id);

> 

> @@ -183,9 +184,10 @@ int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id,

> return PTR_ERR(data->ti_thermal);

> }

> 

> + interval = jiffies_to_msecs(data->ti_thermal->polling_delay_jiffies);

> +

> ti_bandgap_set_sensor_data(bgp, id, data);

> - ti_bandgap_write_update_interval(bgp, data->sensor_id,

> - data->ti_thermal->polling_delay);

> + ti_bandgap_write_update_interval(bgp, data->sensor_id, interval);

> 

> return 0;

> }

> diff --git a/include/linux/thermal.h b/include/linux/thermal.h

> index d1b82c70de69..1e686404951b 100644

> --- a/include/linux/thermal.h

> +++ b/include/linux/thermal.h

> @@ -115,13 +115,8 @@ struct thermal_cooling_device {

> * @devdata: private pointer for device private data

> * @trips: number of trip points the thermal zone supports

> * @trips_disabled; bitmap for disabled trips

> - * @passive_delay: number of milliseconds to wait between polls when

> - * performing passive cooling.

> * @passive_delay_jiffies: number of jiffies to wait between polls when

> * performing passive cooling.

> - * @polling_delay: number of milliseconds to wait between polls when

> - * checking whether trip points have been crossed (0 for

> - * interrupt driven systems)

> * @polling_delay_jiffies: number of jiffies to wait between polls when

> * checking whether trip points have been crossed (0 for

> * interrupt driven systems)

> @@ -162,8 +157,6 @@ struct thermal_zone_device {

> unsigned long trips_disabled; /* bitmap for disabled trips */

> unsigned long passive_delay_jiffies;

> unsigned long polling_delay_jiffies;

> - int passive_delay;

> - int polling_delay;

> int temperature;

> int last_temperature;

> int emul_temperature;

> -- 

> 2.25.1
Daniel Lezcano Dec. 17, 2020, 6 a.m. UTC | #2
On 16/12/2020 23:35, Peter Kästle wrote:
> 16. Dezember 2020 23:04, "Daniel Lezcano" <daniel.lezcano@linaro.org> schrieb:
> 
>> The code does no longer use the ms unit based fields to set the
>> delays as they are replaced by the jiffies.
>>
>> Remove them and replace their user to use the jiffies version instead.
>>
>> Cc: Thara Gopinath <thara.gopinath@linaro.org>
>> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
>> ---
>> drivers/platform/x86/acerhdf.c | 3 ++-
> 
> Reviewed-by: Peter Kästle <peter@piie.net>

Thanks for reviewing

  -- Daniel
Thara Gopinath Dec. 18, 2020, 3:05 p.m. UTC | #3
On 12/16/20 5:03 PM, Daniel Lezcano wrote:
> The delays are stored in ms units and when the polling function is

> called this delay is converted into jiffies at each call.

> 

> Instead of doing the conversion again and again, compute the jiffies

> at init time and use the value directly when setting the polling.

> 

> Cc: Thara Gopinath <thara.gopinath@linaro.org>

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

> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>

> ---

>   drivers/thermal/thermal_core.c    | 3 +++

>   drivers/thermal/thermal_core.h    | 1 +

>   drivers/thermal/thermal_helpers.c | 7 +++++++

>   include/linux/thermal.h           | 7 +++++++

>   4 files changed, 18 insertions(+)


Reviewed-by: Thara Gopinath <thara.gopinath@linaro.org>


> 

> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c

> index bcc2ea4f5482..2c41d4a0923f 100644

> --- a/drivers/thermal/thermal_core.c

> +++ b/drivers/thermal/thermal_core.c

> @@ -1315,6 +1315,9 @@ thermal_zone_device_register(const char *type, int trips, int mask,

>   	tz->passive_delay = passive_delay;

>   	tz->polling_delay = polling_delay;

>   

> +	thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);

> +	thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);

> +

>   	/* sys I/F */

>   	/* Add nodes that are always present via .groups */

>   	result = thermal_zone_create_device_groups(tz, mask);

> diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h

> index e50c6b2909fe..90f9a80c8b23 100644

> --- a/drivers/thermal/thermal_core.h

> +++ b/drivers/thermal/thermal_core.h

> @@ -123,6 +123,7 @@ int thermal_build_list_of_policies(char *buf);

>   

>   /* Helpers */

>   void thermal_zone_set_trips(struct thermal_zone_device *tz);

> +void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms);

>   

>   /* sysfs I/F */

>   int thermal_zone_create_device_groups(struct thermal_zone_device *, int);

> diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c

> index c94bc824e5d3..7f50f412e02a 100644

> --- a/drivers/thermal/thermal_helpers.c

> +++ b/drivers/thermal/thermal_helpers.c

> @@ -175,6 +175,13 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz)

>   	mutex_unlock(&tz->lock);

>   }

>   

> +void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms)

> +{

> +	*delay_jiffies = msecs_to_jiffies(delay_ms);

> +	if (delay_ms > 1000)

> +		*delay_jiffies = round_jiffies(*delay_jiffies);

> +}

> +

>   static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,

>   				       int target)

>   {

> diff --git a/include/linux/thermal.h b/include/linux/thermal.h

> index 060a2160add4..d1b82c70de69 100644

> --- a/include/linux/thermal.h

> +++ b/include/linux/thermal.h

> @@ -117,9 +117,14 @@ struct thermal_cooling_device {

>    * @trips_disabled;	bitmap for disabled trips

>    * @passive_delay:	number of milliseconds to wait between polls when

>    *			performing passive cooling.

> + * @passive_delay_jiffies: number of jiffies to wait between polls when

> + *			performing passive cooling.

>    * @polling_delay:	number of milliseconds to wait between polls when

>    *			checking whether trip points have been crossed (0 for

>    *			interrupt driven systems)

> + * @polling_delay_jiffies: number of jiffies to wait between polls when

> + *			checking whether trip points have been crossed (0 for

> + *			interrupt driven systems)

>    * @temperature:	current temperature.  This is only for core code,

>    *			drivers should use thermal_zone_get_temp() to get the

>    *			current temperature

> @@ -155,6 +160,8 @@ struct thermal_zone_device {

>   	void *devdata;

>   	int trips;

>   	unsigned long trips_disabled;	/* bitmap for disabled trips */

> +	unsigned long passive_delay_jiffies;

> +	unsigned long polling_delay_jiffies;

>   	int passive_delay;

>   	int polling_delay;

>   	int temperature;

> 


-- 
Warm Regards
Thara
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index bcc2ea4f5482..2c41d4a0923f 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1315,6 +1315,9 @@  thermal_zone_device_register(const char *type, int trips, int mask,
 	tz->passive_delay = passive_delay;
 	tz->polling_delay = polling_delay;
 
+	thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);
+	thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);
+
 	/* sys I/F */
 	/* Add nodes that are always present via .groups */
 	result = thermal_zone_create_device_groups(tz, mask);
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index e50c6b2909fe..90f9a80c8b23 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -123,6 +123,7 @@  int thermal_build_list_of_policies(char *buf);
 
 /* Helpers */
 void thermal_zone_set_trips(struct thermal_zone_device *tz);
+void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms);
 
 /* sysfs I/F */
 int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c
index c94bc824e5d3..7f50f412e02a 100644
--- a/drivers/thermal/thermal_helpers.c
+++ b/drivers/thermal/thermal_helpers.c
@@ -175,6 +175,13 @@  void thermal_zone_set_trips(struct thermal_zone_device *tz)
 	mutex_unlock(&tz->lock);
 }
 
+void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms)
+{
+	*delay_jiffies = msecs_to_jiffies(delay_ms);
+	if (delay_ms > 1000)
+		*delay_jiffies = round_jiffies(*delay_jiffies);
+}
+
 static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,
 				       int target)
 {
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 060a2160add4..d1b82c70de69 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -117,9 +117,14 @@  struct thermal_cooling_device {
  * @trips_disabled;	bitmap for disabled trips
  * @passive_delay:	number of milliseconds to wait between polls when
  *			performing passive cooling.
+ * @passive_delay_jiffies: number of jiffies to wait between polls when
+ *			performing passive cooling.
  * @polling_delay:	number of milliseconds to wait between polls when
  *			checking whether trip points have been crossed (0 for
  *			interrupt driven systems)
+ * @polling_delay_jiffies: number of jiffies to wait between polls when
+ *			checking whether trip points have been crossed (0 for
+ *			interrupt driven systems)
  * @temperature:	current temperature.  This is only for core code,
  *			drivers should use thermal_zone_get_temp() to get the
  *			current temperature
@@ -155,6 +160,8 @@  struct thermal_zone_device {
 	void *devdata;
 	int trips;
 	unsigned long trips_disabled;	/* bitmap for disabled trips */
+	unsigned long passive_delay_jiffies;
+	unsigned long polling_delay_jiffies;
 	int passive_delay;
 	int polling_delay;
 	int temperature;