Skip to content

Commit

Permalink
Merge branch 'pm-cpufreq'
Browse files Browse the repository at this point in the history
* pm-cpufreq: (24 commits)
  cpufreq: Fix kobject memleak
  cpufreq: armada-37xx: fix frequency calculation for opp
  cpufreq: centrino: Fix centrino_setpolicy() kerneldoc comment
  cpufreq: qoriq: add support for lx2160a
  cpufreq: qoriq: Add ls1028a chip support
  cpufreq: Move ->get callback check outside of __cpufreq_get()
  cpufreq: Remove needless bios_limit check in show_bios_limit()
  drivers/cpufreq/acpi-cpufreq.c: This fixes the following checkpatch warning
  cpufreq: boost: Remove CONFIG_CPU_FREQ_BOOST_SW Kconfig option
  cpufreq: stats: Use lock by stat to replace global spin lock
  cpufreq: Remove cpufreq_driver check in cpufreq_boost_supported()
  cpufreq: maple: Remove redundant code from maple_cpufreq_init()
  cpufreq: ppc_cbe: fix possible object reference leak
  cpufreq: pmac32: fix possible object reference leak
  cpufreq/pasemi: fix possible object reference leak
  cpufreq: maple: fix possible object reference leak
  cpufreq: kirkwood: fix possible object reference leak
  cpufreq: imx6q: fix possible object reference leak
  cpufreq: ap806: fix possible object reference leak
  drivers/cpufreq: Convert some slow-path static_cpu_has() callers to boot_cpu_has()
  ...
  • Loading branch information
Rafael J. Wysocki committed May 6, 2019
2 parents 4566e2d + 4ebe36c commit 7d4a27c
Show file tree
Hide file tree
Showing 22 changed files with 216 additions and 93 deletions.
2 changes: 1 addition & 1 deletion drivers/acpi/processor_perflib.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag)
acpi_processor_ppc_ost(pr->handle, 0);
}
if (ret >= 0)
cpufreq_update_policy(pr->id);
cpufreq_update_limits(pr->id);
}

int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
Expand Down
4 changes: 0 additions & 4 deletions drivers/cpufreq/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ config CPU_FREQ_GOV_COMMON
select IRQ_WORK
bool

config CPU_FREQ_BOOST_SW
bool
depends on THERMAL

config CPU_FREQ_STAT
bool "CPU frequency transition statistics"
help
Expand Down
19 changes: 9 additions & 10 deletions drivers/cpufreq/acpi-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ static u32 get_cur_val(const struct cpumask *mask, struct acpi_cpufreq_data *dat

val = drv_read(data, mask);

pr_debug("get_cur_val = %u\n", val);
pr_debug("%s = %u\n", __func__, val);

return val;
}
Expand All @@ -378,7 +378,7 @@ static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
unsigned int freq;
unsigned int cached_freq;

pr_debug("get_cur_freq_on_cpu (%d)\n", cpu);
pr_debug("%s (%d)\n", __func__, cpu);

policy = cpufreq_cpu_get_raw(cpu);
if (unlikely(!policy))
Expand Down Expand Up @@ -458,8 +458,7 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy,
if (acpi_pstate_strict) {
if (!check_freqs(policy, mask,
policy->freq_table[index].frequency)) {
pr_debug("acpi_cpufreq_target failed (%d)\n",
policy->cpu);
pr_debug("%s (%d)\n", __func__, policy->cpu);
result = -EAGAIN;
}
}
Expand Down Expand Up @@ -573,7 +572,7 @@ static int cpufreq_boost_down_prep(unsigned int cpu)
static int __init acpi_cpufreq_early_init(void)
{
unsigned int i;
pr_debug("acpi_cpufreq_early_init\n");
pr_debug("%s\n", __func__);

acpi_perf_data = alloc_percpu(struct acpi_processor_performance);
if (!acpi_perf_data) {
Expand Down Expand Up @@ -657,7 +656,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
static int blacklisted;
#endif

pr_debug("acpi_cpufreq_cpu_init\n");
pr_debug("%s\n", __func__);

#ifdef CONFIG_SMP
if (blacklisted)
Expand Down Expand Up @@ -856,7 +855,7 @@ static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy)
{
struct acpi_cpufreq_data *data = policy->driver_data;

pr_debug("acpi_cpufreq_cpu_exit\n");
pr_debug("%s\n", __func__);

policy->fast_switch_possible = false;
policy->driver_data = NULL;
Expand All @@ -881,7 +880,7 @@ static int acpi_cpufreq_resume(struct cpufreq_policy *policy)
{
struct acpi_cpufreq_data *data = policy->driver_data;

pr_debug("acpi_cpufreq_resume\n");
pr_debug("%s\n", __func__);

data->resume = 1;

Expand Down Expand Up @@ -954,7 +953,7 @@ static int __init acpi_cpufreq_init(void)
if (cpufreq_get_current_driver())
return -EEXIST;

pr_debug("acpi_cpufreq_init\n");
pr_debug("%s\n", __func__);

ret = acpi_cpufreq_early_init();
if (ret)
Expand Down Expand Up @@ -991,7 +990,7 @@ static int __init acpi_cpufreq_init(void)

static void __exit acpi_cpufreq_exit(void)
{
pr_debug("acpi_cpufreq_exit\n");
pr_debug("%s\n", __func__);

acpi_cpufreq_boost_exit();

Expand Down
2 changes: 1 addition & 1 deletion drivers/cpufreq/amd_freq_sensitivity.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static int __init amd_freq_sensitivity_init(void)
PCI_DEVICE_ID_AMD_KERNCZ_SMBUS, NULL);

if (!pcidev) {
if (!static_cpu_has(X86_FEATURE_PROC_FEEDBACK))
if (!boot_cpu_has(X86_FEATURE_PROC_FEEDBACK))
return -ENODEV;
}

Expand Down
22 changes: 19 additions & 3 deletions drivers/cpufreq/armada-37xx-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ static int __init armada37xx_cpufreq_driver_init(void)
struct armada_37xx_dvfs *dvfs;
struct platform_device *pdev;
unsigned long freq;
unsigned int cur_frequency;
unsigned int cur_frequency, base_frequency;
struct regmap *nb_pm_base, *avs_base;
struct device *cpu_dev;
int load_lvl, ret;
struct clk *clk;
struct clk *clk, *parent;

nb_pm_base =
syscon_regmap_lookup_by_compatible("marvell,armada-3700-nb-pm");
Expand Down Expand Up @@ -399,6 +399,22 @@ static int __init armada37xx_cpufreq_driver_init(void)
return PTR_ERR(clk);
}

parent = clk_get_parent(clk);
if (IS_ERR(parent)) {
dev_err(cpu_dev, "Cannot get parent clock for CPU0\n");
clk_put(clk);
return PTR_ERR(parent);
}

/* Get parent CPU frequency */
base_frequency = clk_get_rate(parent);

if (!base_frequency) {
dev_err(cpu_dev, "Failed to get parent clock rate for CPU\n");
clk_put(clk);
return -EINVAL;
}

/* Get nominal (current) CPU frequency */
cur_frequency = clk_get_rate(clk);
if (!cur_frequency) {
Expand Down Expand Up @@ -431,7 +447,7 @@ static int __init armada37xx_cpufreq_driver_init(void)
for (load_lvl = ARMADA_37XX_DVFS_LOAD_0; load_lvl < LOAD_LEVEL_NR;
load_lvl++) {
unsigned long u_volt = avs_map[dvfs->avs[load_lvl]] * 1000;
freq = cur_frequency / dvfs->divider[load_lvl];
freq = base_frequency / dvfs->divider[load_lvl];
ret = dev_pm_opp_add(cpu_dev, freq, u_volt);
if (ret)
goto remove_opp;
Expand Down
1 change: 1 addition & 0 deletions drivers/cpufreq/armada-8k-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ static int __init armada_8k_cpufreq_init(void)
of_node_put(node);
return -ENODEV;
}
of_node_put(node);

nb_cpus = num_possible_cpus();
freq_tables = kcalloc(nb_cpus, sizeof(*freq_tables), GFP_KERNEL);
Expand Down
100 changes: 73 additions & 27 deletions drivers/cpufreq/cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@

static LIST_HEAD(cpufreq_policy_list);

static inline bool policy_is_inactive(struct cpufreq_policy *policy)
{
return cpumask_empty(policy->cpus);
}

/* Macros to iterate over CPU policies */
#define for_each_suitable_policy(__policy, __active) \
list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) \
Expand Down Expand Up @@ -250,6 +245,51 @@ void cpufreq_cpu_put(struct cpufreq_policy *policy)
}
EXPORT_SYMBOL_GPL(cpufreq_cpu_put);

/**
* cpufreq_cpu_release - Unlock a policy and decrement its usage counter.
* @policy: cpufreq policy returned by cpufreq_cpu_acquire().
*/
void cpufreq_cpu_release(struct cpufreq_policy *policy)
{
if (WARN_ON(!policy))
return;

lockdep_assert_held(&policy->rwsem);

up_write(&policy->rwsem);

cpufreq_cpu_put(policy);
}

/**
* cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it.
* @cpu: CPU to find the policy for.
*
* Call cpufreq_cpu_get() to get a reference on the cpufreq policy for @cpu and
* if the policy returned by it is not NULL, acquire its rwsem for writing.
* Return the policy if it is active or release it and return NULL otherwise.
*
* The policy returned by this function has to be released with the help of
* cpufreq_cpu_release() in order to release its rwsem and balance its usage
* counter properly.
*/
struct cpufreq_policy *cpufreq_cpu_acquire(unsigned int cpu)
{
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);

if (!policy)
return NULL;

down_write(&policy->rwsem);

if (policy_is_inactive(policy)) {
cpufreq_cpu_release(policy);
return NULL;
}

return policy;
}

/*********************************************************************
* EXTERNALLY AFFECTING FREQUENCY CHANGES *
*********************************************************************/
Expand Down Expand Up @@ -669,9 +709,6 @@ static ssize_t show_scaling_cur_freq(struct cpufreq_policy *policy, char *buf)
return ret;
}

static int cpufreq_set_policy(struct cpufreq_policy *policy,
struct cpufreq_policy *new_policy);

/**
* cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
*/
Expand Down Expand Up @@ -857,11 +894,9 @@ static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
{
unsigned int limit;
int ret;
if (cpufreq_driver->bios_limit) {
ret = cpufreq_driver->bios_limit(policy->cpu, &limit);
if (!ret)
return sprintf(buf, "%u\n", limit);
}
ret = cpufreq_driver->bios_limit(policy->cpu, &limit);
if (!ret)
return sprintf(buf, "%u\n", limit);
return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
}

Expand Down Expand Up @@ -1098,6 +1133,7 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
cpufreq_global_kobject, "policy%u", cpu);
if (ret) {
pr_err("%s: failed to init policy->kobj: %d\n", __func__, ret);
kobject_put(&policy->kobj);
goto err_free_real_cpus;
}

Expand Down Expand Up @@ -1550,7 +1586,7 @@ static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
{
unsigned int ret_freq = 0;

if (unlikely(policy_is_inactive(policy)) || !cpufreq_driver->get)
if (unlikely(policy_is_inactive(policy)))
return ret_freq;

ret_freq = cpufreq_driver->get(policy->cpu);
Expand Down Expand Up @@ -1588,7 +1624,8 @@ unsigned int cpufreq_get(unsigned int cpu)

if (policy) {
down_read(&policy->rwsem);
ret_freq = __cpufreq_get(policy);
if (cpufreq_driver->get)
ret_freq = __cpufreq_get(policy);
up_read(&policy->rwsem);

cpufreq_cpu_put(policy);
Expand Down Expand Up @@ -2229,8 +2266,8 @@ EXPORT_SYMBOL(cpufreq_get_policy);
*
* The cpuinfo part of @policy is not updated by this function.
*/
static int cpufreq_set_policy(struct cpufreq_policy *policy,
struct cpufreq_policy *new_policy)
int cpufreq_set_policy(struct cpufreq_policy *policy,
struct cpufreq_policy *new_policy)
{
struct cpufreq_governor *old_gov;
int ret;
Expand Down Expand Up @@ -2337,17 +2374,12 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
*/
void cpufreq_update_policy(unsigned int cpu)
{
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);
struct cpufreq_policy new_policy;

if (!policy)
return;

down_write(&policy->rwsem);

if (policy_is_inactive(policy))
goto unlock;

/*
* BIOS might change freq behind our back
* -> ask driver for current freq and notify governors about a change
Expand All @@ -2364,12 +2396,26 @@ void cpufreq_update_policy(unsigned int cpu)
cpufreq_set_policy(policy, &new_policy);

unlock:
up_write(&policy->rwsem);

cpufreq_cpu_put(policy);
cpufreq_cpu_release(policy);
}
EXPORT_SYMBOL(cpufreq_update_policy);

/**
* cpufreq_update_limits - Update policy limits for a given CPU.
* @cpu: CPU to update the policy limits for.
*
* Invoke the driver's ->update_limits callback if present or call
* cpufreq_update_policy() for @cpu.
*/
void cpufreq_update_limits(unsigned int cpu)
{
if (cpufreq_driver->update_limits)
cpufreq_driver->update_limits(cpu);
else
cpufreq_update_policy(cpu);
}
EXPORT_SYMBOL_GPL(cpufreq_update_limits);

/*********************************************************************
* BOOST *
*********************************************************************/
Expand Down Expand Up @@ -2426,7 +2472,7 @@ int cpufreq_boost_trigger_state(int state)

static bool cpufreq_boost_supported(void)
{
return likely(cpufreq_driver) && cpufreq_driver->set_boost;
return cpufreq_driver->set_boost;
}

static int create_boost_sysfs_file(void)
Expand Down
2 changes: 2 additions & 0 deletions drivers/cpufreq/cpufreq_governor.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
/* Failure, so roll back. */
pr_err("initialization failed (dbs_data kobject init error %d)\n", ret);

kobject_put(&dbs_data->attr_set.kobj);

policy->governor_data = NULL;

if (!have_governor_per_policy())
Expand Down
Loading

0 comments on commit 7d4a27c

Please sign in to comment.