thermal/core: Precompute the delays from msecs to jiffies
authorDaniel Lezcano <daniel.lezcano@linaro.org>
Wed, 16 Dec 2020 22:03:35 +0000 (23:03 +0100)
committerDaniel Lezcano <daniel.lezcano@linaro.org>
Tue, 19 Jan 2021 21:23:38 +0000 (22:23 +0100)
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>
Reviewed-by: Thara Gopinath <thara.gopinath@linaro.org>
Link: https://lore.kernel.org/r/20201216220337.839878-1-daniel.lezcano@linaro.org
drivers/thermal/thermal_core.c
drivers/thermal/thermal_core.h
drivers/thermal/thermal_helpers.c
include/linux/thermal.h

index bcc2ea4f5482d7f08cb95da45b37067089ffbb14..2c41d4a0923f5bb813c7484cfd8b822a87d1c7c1 100644 (file)
@@ -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);
index e50c6b2909fe70c18e7e66ca6cf6f31c9ddf65a5..90f9a80c8b23857c40558218b962fab551621533 100644 (file)
@@ -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);
index c94bc824e5d36ab34594cc35e0bcf2444efc85d9..7f50f412e02a16f67f33d37974c87fc824130e1d 100644 (file)
@@ -175,6 +175,13 @@ exit:
        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)
 {
index 060a2160add406c8ac1f2f1984eea8a3d2cf051c..d1b82c70de692be003e8549fee8fcac36eb2c1bd 100644 (file)
@@ -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;