lkml.org 
[lkml]   [2021]   [Jan]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[RFC][PATCH 2/3] thermal: devfreq_cooling: add new callback to get user limit for min state
    Date
    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 --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 *);
    --
    2.17.1
    \
     
     \ /
      Last update: 2021-01-26 12:54    [W:4.470 / U:0.124 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site