diff mbox series

[RFC,2/3] thermal: devfreq_cooling: add new callback to get user limit for min state

Message ID 20210126104001.20361-3-lukasz.luba@arm.com
State New
Headers show
Series New thermal interface allowing IPA to get max power | expand

Commit Message

Lukasz Luba Jan. 26, 2021, 10:40 a.m. UTC
User can limit the maximum frequency of the device via sysfs interface.
It limits also corresponding maximum allowed power consumption. The IPA
governor needs to know maximum power of the device to split the budget.
If the user limit is not provided, some power is wasted while it could
be added to other capable device. This new callback helps to solve such
scenario.

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 drivers/thermal/devfreq_cooling.c | 33 +++++++++++++++++++++++++++++++
 include/linux/thermal.h           |  1 +
 2 files changed, 34 insertions(+)
diff mbox series

Patch

diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c
index fed3121ff2a1..e13ef86191e8 100644
--- a/drivers/thermal/devfreq_cooling.c
+++ b/drivers/thermal/devfreq_cooling.c
@@ -64,6 +64,8 @@  struct devfreq_cooling_device {
 	struct em_perf_domain *em_pd;
 };
 
+static int get_perf_idx(struct em_perf_domain *em_pd, unsigned long freq);
+
 static int devfreq_cooling_get_max_state(struct thermal_cooling_device *cdev,
 					 unsigned long *state)
 {
@@ -74,6 +76,36 @@  static int devfreq_cooling_get_max_state(struct thermal_cooling_device *cdev,
 	return 0;
 }
 
+static int
+devfreq_cooling_get_user_min_state(struct thermal_cooling_device *cdev,
+				   unsigned long *state)
+{
+	struct devfreq_cooling_device *dfc = cdev->devdata;
+	struct devfreq *df = dfc->devfreq;
+	struct device *dev = df->dev.parent;
+	struct dev_pm_opp *opp;
+	unsigned long freq;
+	int ret;
+
+	mutex_lock(&df->lock);
+	freq = df->user_max_freq;
+	mutex_unlock(&df->lock);
+
+	opp = dev_pm_opp_find_freq_floor(dev, &freq);
+	if (IS_ERR(opp))
+		return -EINVAL;
+
+	dev_pm_opp_put(opp);
+
+	ret = get_perf_idx(dfc->em_pd, freq / 1000);
+	if (ret < 0)
+		return -EINVAL;
+
+	*state = dfc->max_state - ret;
+
+	return 0;
+}
+
 static int devfreq_cooling_get_cur_state(struct thermal_cooling_device *cdev,
 					 unsigned long *state)
 {
@@ -297,6 +329,7 @@  static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,
 
 static struct thermal_cooling_device_ops devfreq_cooling_ops = {
 	.get_max_state = devfreq_cooling_get_max_state,
+	.get_user_min_state = devfreq_cooling_get_user_min_state,
 	.get_cur_state = devfreq_cooling_get_cur_state,
 	.set_cur_state = devfreq_cooling_set_cur_state,
 };
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 6ac7bb1d2b1f..2af3149dd052 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -82,6 +82,7 @@  struct thermal_zone_device_ops {
 
 struct thermal_cooling_device_ops {
 	int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
+	int (*get_user_min_state) (struct thermal_cooling_device *, unsigned long *);
 	int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
 	int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
 	int (*get_requested_power)(struct thermal_cooling_device *, u32 *);