2020-12-18 15:07:04

by Thara Gopinath

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] thermal/core: Precompute the delays from msecs to jiffies



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 <[email protected]>
> Signed-off-by: Daniel Lezcano <[email protected]>
> Reviewed-by: Lukasz Luba <[email protected]>
> ---
> 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 <[email protected]>

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