PM / devfreq: Cache OPP table reference in devfreq
authorSaravana Kannan <saravanak@google.com>
Thu, 4 Feb 2021 08:14:23 +0000 (16:14 +0800)
committerViresh Kumar <viresh.kumar@linaro.org>
Thu, 4 Feb 2021 11:06:28 +0000 (16:36 +0530)
The OPP table can be used often in devfreq. Trying to get it each time can
be expensive, so cache it in the devfreq struct.

Signed-off-by: Saravana Kannan <saravanak@google.com>
Acked-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
[ Viresh: Added a blank line ]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
drivers/devfreq/devfreq.c
include/linux/devfreq.h

index 6aa10de792b33060cd9840c471d62c8f9e87737f..cefe84a10824ff0356e4492192144a6d17484820 100644 (file)
@@ -757,6 +757,9 @@ static void devfreq_dev_release(struct device *dev)
        if (devfreq->profile->exit)
                devfreq->profile->exit(devfreq->dev.parent);
 
+       if (devfreq->opp_table)
+               dev_pm_opp_put_opp_table(devfreq->opp_table);
+
        mutex_destroy(&devfreq->lock);
        kfree(devfreq);
 }
@@ -844,6 +847,10 @@ struct devfreq *devfreq_add_device(struct device *dev,
        }
 
        devfreq->suspend_freq = dev_pm_opp_get_suspend_opp_freq(dev);
+       devfreq->opp_table = dev_pm_opp_get_opp_table(dev);
+       if (IS_ERR(devfreq->opp_table))
+               devfreq->opp_table = NULL;
+
        atomic_set(&devfreq->suspend_count, 0);
 
        dev_set_name(&devfreq->dev, "%s", dev_name(dev));
index b6d3bae1c74d8e43dcfb674b2eb3402367ba1eaa..26ea0850be9bb0a4aecd2d6c25e1f269e7840ee8 100644 (file)
@@ -137,6 +137,7 @@ struct devfreq_stats {
  *             using devfreq.
  * @profile:   device-specific devfreq profile
  * @governor:  method how to choose frequency based on the usage.
+ * @opp_table: Reference to OPP table of dev.parent, if one exists.
  * @nb:                notifier block used to notify devfreq object that it should
  *             reevaluate operable frequencies. Devfreq users may use
  *             devfreq.nb to the corresponding register notifier call chain.
@@ -173,6 +174,7 @@ struct devfreq {
        struct device dev;
        struct devfreq_dev_profile *profile;
        const struct devfreq_governor *governor;
+       struct opp_table *opp_table;
        struct notifier_block nb;
        struct delayed_work work;