Skip to content

Commit

Permalink
Merge branch 'opp/linux-next' of git://git.kernel.org/pub/scm/linux/k…
Browse files Browse the repository at this point in the history
…ernel/git/vireshk/pm into pm-opp

Pull operating performance points (OPP) framework updates for v5.1
from Viresh Kumar:

"This pull request contains following changes:

 - Introduced new OPP helper for power-estimation and used it in
   several cpufreq drivers (Quentin Perret, Matthias Kaehlcke, Dietmar
   Eggemann, and Yangtao Li).

 - OPP Debugfs cleanup (Greg KH).

 - OPP core cleanup (Viresh Kumar)."

* 'opp/linux-next' of git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm:
  cpufreq: OMAP: Register an Energy Model
  cpufreq: imx6q: Register an Energy Model
  opp: no need to check return value of debugfs_create functions
  cpufreq: mediatek: Register an Energy Model
  cpufreq: scmi: Register an Energy Model
  cpufreq: arm_big_little: Register an Energy Model
  cpufreq: scpi: Register an Energy Model
  cpufreq: dt: Register an Energy Model
  PM / OPP: Introduce a power estimation helper
  PM / OPP: Remove unused parameter of _generic_set_opp_clk_only()
  • Loading branch information
rafaeljw committed Feb 12, 2019
2 parents d139371 + a9a744d commit 78317ed
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 108 deletions.
2 changes: 2 additions & 0 deletions drivers/cpufreq/arm_big_little.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ static int bL_cpufreq_init(struct cpufreq_policy *policy)
policy->cpuinfo.transition_latency =
arm_bL_ops->get_transition_latency(cpu_dev);

dev_pm_opp_of_register_em(policy->cpus);

if (is_bL_switching_enabled())
per_cpu(cpu_last_req_freq, policy->cpu) = clk_get_cpu_rate(policy->cpu);

Expand Down
2 changes: 2 additions & 0 deletions drivers/cpufreq/cpufreq-dt.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ static int cpufreq_init(struct cpufreq_policy *policy)
policy->cpuinfo.transition_latency = transition_latency;
policy->dvfs_possible_from_any_cpu = true;

dev_pm_opp_of_register_em(policy->cpus);

return 0;

out_free_cpufreq_table:
Expand Down
1 change: 1 addition & 0 deletions drivers/cpufreq/imx6q-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ static int imx6q_cpufreq_init(struct cpufreq_policy *policy)
policy->clk = clks[ARM].clk;
ret = cpufreq_generic_init(policy, freq_table, transition_latency);
policy->suspend_freq = max_freq;
dev_pm_opp_of_register_em(policy->cpus);

return ret;
}
Expand Down
2 changes: 2 additions & 0 deletions drivers/cpufreq/mediatek-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ static int mtk_cpufreq_init(struct cpufreq_policy *policy)
policy->driver_data = info;
policy->clk = info->cpu_clk;

dev_pm_opp_of_register_em(policy->cpus);

return 0;
}

Expand Down
4 changes: 3 additions & 1 deletion drivers/cpufreq/omap-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ static int omap_cpu_init(struct cpufreq_policy *policy)

/* FIXME: what's the actual transition time? */
result = cpufreq_generic_init(policy, freq_table, 300 * 1000);
if (!result)
if (!result) {
dev_pm_opp_of_register_em(policy->cpus);
return 0;
}

freq_table_free();
fail:
Expand Down
39 changes: 36 additions & 3 deletions drivers/cpufreq/scmi-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <linux/cpufreq.h>
#include <linux/cpumask.h>
#include <linux/cpu_cooling.h>
#include <linux/energy_model.h>
#include <linux/export.h>
#include <linux/module.h>
#include <linux/pm_opp.h>
Expand Down Expand Up @@ -103,13 +104,42 @@ scmi_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
return 0;
}

static int __maybe_unused
scmi_get_cpu_power(unsigned long *power, unsigned long *KHz, int cpu)
{
struct device *cpu_dev = get_cpu_device(cpu);
unsigned long Hz;
int ret, domain;

if (!cpu_dev) {
pr_err("failed to get cpu%d device\n", cpu);
return -ENODEV;
}

domain = handle->perf_ops->device_domain_id(cpu_dev);
if (domain < 0)
return domain;

/* Get the power cost of the performance domain. */
Hz = *KHz * 1000;
ret = handle->perf_ops->est_power_get(handle, domain, &Hz, power);
if (ret)
return ret;

/* The EM framework specifies the frequency in KHz. */
*KHz = Hz / 1000;

return 0;
}

static int scmi_cpufreq_init(struct cpufreq_policy *policy)
{
int ret;
int ret, nr_opp;
unsigned int latency;
struct device *cpu_dev;
struct scmi_data *priv;
struct cpufreq_frequency_table *freq_table;
struct em_data_callback em_cb = EM_DATA_CB(scmi_get_cpu_power);

cpu_dev = get_cpu_device(policy->cpu);
if (!cpu_dev) {
Expand All @@ -136,8 +166,8 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
return ret;
}

ret = dev_pm_opp_get_opp_count(cpu_dev);
if (ret <= 0) {
nr_opp = dev_pm_opp_get_opp_count(cpu_dev);
if (nr_opp <= 0) {
dev_dbg(cpu_dev, "OPP table is not ready, deferring probe\n");
ret = -EPROBE_DEFER;
goto out_free_opp;
Expand Down Expand Up @@ -171,6 +201,9 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
policy->cpuinfo.transition_latency = latency;

policy->fast_switch_possible = true;

em_register_perf_domain(policy->cpus, nr_opp, &em_cb);

return 0;

out_free_priv:
Expand Down
3 changes: 3 additions & 0 deletions drivers/cpufreq/scpi-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ static int scpi_cpufreq_init(struct cpufreq_policy *policy)
policy->cpuinfo.transition_latency = latency;

policy->fast_switch_possible = false;

dev_pm_opp_of_register_em(policy->cpus);

return 0;

out_free_cpufreq_table:
Expand Down
22 changes: 7 additions & 15 deletions drivers/opp/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,8 @@ static int _set_opp_voltage(struct device *dev, struct regulator *reg,
return ret;
}

static inline int
_generic_set_opp_clk_only(struct device *dev, struct clk *clk,
unsigned long old_freq, unsigned long freq)
static inline int _generic_set_opp_clk_only(struct device *dev, struct clk *clk,
unsigned long freq)
{
int ret;

Expand Down Expand Up @@ -572,7 +571,7 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table,
}

/* Change frequency */
ret = _generic_set_opp_clk_only(dev, opp_table->clk, old_freq, freq);
ret = _generic_set_opp_clk_only(dev, opp_table->clk, freq);
if (ret)
goto restore_voltage;

Expand All @@ -586,7 +585,7 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table,
return 0;

restore_freq:
if (_generic_set_opp_clk_only(dev, opp_table->clk, freq, old_freq))
if (_generic_set_opp_clk_only(dev, opp_table->clk, old_freq))
dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
__func__, old_freq);
restore_voltage:
Expand Down Expand Up @@ -759,7 +758,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
opp->supplies);
} else {
/* Only frequency scaling */
ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq);
ret = _generic_set_opp_clk_only(dev, clk, freq);
}

/* Scaling down? Configure required OPPs after frequency */
Expand Down Expand Up @@ -793,7 +792,6 @@ static struct opp_device *_add_opp_dev_unlocked(const struct device *dev,
struct opp_table *opp_table)
{
struct opp_device *opp_dev;
int ret;

opp_dev = kzalloc(sizeof(*opp_dev), GFP_KERNEL);
if (!opp_dev)
Expand All @@ -805,10 +803,7 @@ static struct opp_device *_add_opp_dev_unlocked(const struct device *dev,
list_add(&opp_dev->node, &opp_table->dev_list);

/* Create debugfs entries for the opp_table */
ret = opp_debug_register(opp_dev, opp_table);
if (ret)
dev_err(dev, "%s: Failed to register opp debugfs (%d)\n",
__func__, ret);
opp_debug_register(opp_dev, opp_table);

return opp_dev;
}
Expand Down Expand Up @@ -1229,10 +1224,7 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
new_opp->opp_table = opp_table;
kref_init(&new_opp->kref);

ret = opp_debug_create_one(new_opp, opp_table);
if (ret)
dev_err(dev, "%s: Failed to register opp to debugfs (%d)\n",
__func__, ret);
opp_debug_create_one(new_opp, opp_table);

if (!_opp_supported_by_regulators(new_opp, opp_table)) {
new_opp->available = false;
Expand Down
110 changes: 29 additions & 81 deletions drivers/opp/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void opp_debug_remove_one(struct dev_pm_opp *opp)
debugfs_remove_recursive(opp->dentry);
}

static bool opp_debug_create_supplies(struct dev_pm_opp *opp,
static void opp_debug_create_supplies(struct dev_pm_opp *opp,
struct opp_table *opp_table,
struct dentry *pdentry)
{
Expand All @@ -50,30 +50,21 @@ static bool opp_debug_create_supplies(struct dev_pm_opp *opp,
/* Create per-opp directory */
d = debugfs_create_dir(name, pdentry);

if (!d)
return false;
debugfs_create_ulong("u_volt_target", S_IRUGO, d,
&opp->supplies[i].u_volt);

if (!debugfs_create_ulong("u_volt_target", S_IRUGO, d,
&opp->supplies[i].u_volt))
return false;
debugfs_create_ulong("u_volt_min", S_IRUGO, d,
&opp->supplies[i].u_volt_min);

if (!debugfs_create_ulong("u_volt_min", S_IRUGO, d,
&opp->supplies[i].u_volt_min))
return false;
debugfs_create_ulong("u_volt_max", S_IRUGO, d,
&opp->supplies[i].u_volt_max);

if (!debugfs_create_ulong("u_volt_max", S_IRUGO, d,
&opp->supplies[i].u_volt_max))
return false;

if (!debugfs_create_ulong("u_amp", S_IRUGO, d,
&opp->supplies[i].u_amp))
return false;
debugfs_create_ulong("u_amp", S_IRUGO, d,
&opp->supplies[i].u_amp);
}

return true;
}

int opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table)
void opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table)
{
struct dentry *pdentry = opp_table->dentry;
struct dentry *d;
Expand All @@ -95,40 +86,23 @@ int opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table)

/* Create per-opp directory */
d = debugfs_create_dir(name, pdentry);
if (!d)
return -ENOMEM;

if (!debugfs_create_bool("available", S_IRUGO, d, &opp->available))
return -ENOMEM;

if (!debugfs_create_bool("dynamic", S_IRUGO, d, &opp->dynamic))
return -ENOMEM;

if (!debugfs_create_bool("turbo", S_IRUGO, d, &opp->turbo))
return -ENOMEM;

if (!debugfs_create_bool("suspend", S_IRUGO, d, &opp->suspend))
return -ENOMEM;

if (!debugfs_create_u32("performance_state", S_IRUGO, d, &opp->pstate))
return -ENOMEM;

if (!debugfs_create_ulong("rate_hz", S_IRUGO, d, &opp->rate))
return -ENOMEM;
debugfs_create_bool("available", S_IRUGO, d, &opp->available);
debugfs_create_bool("dynamic", S_IRUGO, d, &opp->dynamic);
debugfs_create_bool("turbo", S_IRUGO, d, &opp->turbo);
debugfs_create_bool("suspend", S_IRUGO, d, &opp->suspend);
debugfs_create_u32("performance_state", S_IRUGO, d, &opp->pstate);
debugfs_create_ulong("rate_hz", S_IRUGO, d, &opp->rate);
debugfs_create_ulong("clock_latency_ns", S_IRUGO, d,
&opp->clock_latency_ns);

if (!opp_debug_create_supplies(opp, opp_table, d))
return -ENOMEM;

if (!debugfs_create_ulong("clock_latency_ns", S_IRUGO, d,
&opp->clock_latency_ns))
return -ENOMEM;
opp_debug_create_supplies(opp, opp_table, d);

opp->dentry = d;
return 0;
}

static int opp_list_debug_create_dir(struct opp_device *opp_dev,
struct opp_table *opp_table)
static void opp_list_debug_create_dir(struct opp_device *opp_dev,
struct opp_table *opp_table)
{
const struct device *dev = opp_dev->dev;
struct dentry *d;
Expand All @@ -137,36 +111,21 @@ static int opp_list_debug_create_dir(struct opp_device *opp_dev,

/* Create device specific directory */
d = debugfs_create_dir(opp_table->dentry_name, rootdir);
if (!d) {
dev_err(dev, "%s: Failed to create debugfs dir\n", __func__);
return -ENOMEM;
}

opp_dev->dentry = d;
opp_table->dentry = d;

return 0;
}

static int opp_list_debug_create_link(struct opp_device *opp_dev,
struct opp_table *opp_table)
static void opp_list_debug_create_link(struct opp_device *opp_dev,
struct opp_table *opp_table)
{
const struct device *dev = opp_dev->dev;
char name[NAME_MAX];
struct dentry *d;

opp_set_dev_name(opp_dev->dev, name);

/* Create device specific directory link */
d = debugfs_create_symlink(name, rootdir, opp_table->dentry_name);
if (!d) {
dev_err(dev, "%s: Failed to create link\n", __func__);
return -ENOMEM;
}

opp_dev->dentry = d;

return 0;
opp_dev->dentry = debugfs_create_symlink(name, rootdir,
opp_table->dentry_name);
}

/**
Expand All @@ -177,20 +136,13 @@ static int opp_list_debug_create_link(struct opp_device *opp_dev,
* Dynamically adds device specific directory in debugfs 'opp' directory. If the
* device-opp is shared with other devices, then links will be created for all
* devices except the first.
*
* Return: 0 on success, otherwise negative error.
*/
int opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table)
void opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table)
{
if (!rootdir) {
pr_debug("%s: Uninitialized rootdir\n", __func__);
return -EINVAL;
}

if (opp_table->dentry)
return opp_list_debug_create_link(opp_dev, opp_table);

return opp_list_debug_create_dir(opp_dev, opp_table);
opp_list_debug_create_link(opp_dev, opp_table);
else
opp_list_debug_create_dir(opp_dev, opp_table);
}

static void opp_migrate_dentry(struct opp_device *opp_dev,
Expand Down Expand Up @@ -252,10 +204,6 @@ static int __init opp_debug_init(void)
{
/* Create /sys/kernel/debug/opp directory */
rootdir = debugfs_create_dir("opp", NULL);
if (!rootdir) {
pr_err("%s: Failed to create root directory\n", __func__);
return -ENOMEM;
}

return 0;
}
Expand Down
Loading

0 comments on commit 78317ed

Please sign in to comment.