All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: daniel.lezcano@linaro.org, rui.zhang@intel.com
Cc: amitk@kernel.org, linux-kernel@vger.kernel.org,
	linux-pm@vger.kernel.org,
	Thara Gopinath <thara.gopinath@linaro.org>,
	Lukasz Luba <lukasz.luba@arm.com>
Subject: [PATCH v2 1/3] thermal/core: Precompute the delays from msecs to jiffies
Date: Wed, 16 Dec 2020 23:03:35 +0100	[thread overview]
Message-ID: <20201216220337.839878-1-daniel.lezcano@linaro.org> (raw)

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(+)

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


             reply	other threads:[~2020-12-16 22:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-16 22:03 Daniel Lezcano [this message]
2020-12-16 22:03 ` [PATCH v2 2/3] thermal/core: Use precomputed jiffies for the polling Daniel Lezcano
2020-12-18 15:06   ` Thara Gopinath
2021-01-19 21:27   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
2020-12-16 22:03 ` [PATCH v2 3/3] thermal/core: Remove ms based delay fields Daniel Lezcano
2020-12-17  0:02   ` kernel test robot
2020-12-17  0:02     ` kernel test robot
2020-12-17  0:24   ` kernel test robot
2020-12-17  0:24     ` kernel test robot
2020-12-17 18:32   ` Hans de Goede
2020-12-17 19:25     ` Daniel Lezcano
2020-12-18 10:16   ` Adam Thomson
2020-12-18 10:45     ` Daniel Lezcano
2021-01-19 21:27   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
2020-12-16 22:35 ` [PATCH v2 3/3] " Peter Kästle
2020-12-17  6:00   ` Daniel Lezcano
2020-12-18 15:05 ` [PATCH v2 1/3] thermal/core: Precompute the delays from msecs to jiffies Thara Gopinath
2021-01-19 21:27 ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201216220337.839878-1-daniel.lezcano@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=amitk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rui.zhang@intel.com \
    --cc=thara.gopinath@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.