Commit 0b275352 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

cpufreq: Separate CPU device registration from CPU online

To separate the CPU online interface from the CPU device
registration, split cpufreq_online() out of cpufreq_add_dev()
and make cpufreq_cpu_callback() call the former, while
cpufreq_add_dev() itself will only be used as the CPU device
addition subsystem interface callback.
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Suggested-by: default avatarRussell King <linux@arm.linux.org.uk>
Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
parent 22794280
...@@ -1191,36 +1191,15 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy, bool notify) ...@@ -1191,36 +1191,15 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy, bool notify)
kfree(policy); kfree(policy);
} }
/** static int cpufreq_online(unsigned int cpu)
* cpufreq_add_dev - add a CPU device
*
* Adds the cpufreq interface for a CPU device.
*
* The Oracle says: try running cpufreq registration/unregistration concurrently
* with with cpu hotplugging and all hell will break loose. Tried to clean this
* mess up, but more thorough testing is needed. - Mathieu
*/
static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
{ {
unsigned int j, cpu = dev->id;
int ret;
struct cpufreq_policy *policy; struct cpufreq_policy *policy;
unsigned long flags;
bool recover_policy; bool recover_policy;
unsigned long flags;
unsigned int j;
int ret;
pr_debug("adding CPU %u\n", cpu); pr_debug("%s: bringing CPU%u online\n", __func__, cpu);
if (cpu_is_offline(cpu)) {
/*
* Only possible if we are here from the subsys_interface add
* callback. A hotplug notifier will follow and we will handle
* it as CPU online then. For now, just create the sysfs link,
* unless there is no policy or the link is already present.
*/
policy = per_cpu(cpufreq_cpu_data, cpu);
return policy && !cpumask_test_and_set_cpu(cpu, policy->real_cpus)
? add_cpu_dev_symlink(policy, cpu) : 0;
}
/* Check if this CPU already has a policy to manage it */ /* Check if this CPU already has a policy to manage it */
policy = per_cpu(cpufreq_cpu_data, cpu); policy = per_cpu(cpufreq_cpu_data, cpu);
...@@ -1377,6 +1356,35 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) ...@@ -1377,6 +1356,35 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
return ret; return ret;
} }
/**
* cpufreq_add_dev - the cpufreq interface for a CPU device.
* @dev: CPU device.
* @sif: Subsystem interface structure pointer (not used)
*/
static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
{
unsigned cpu = dev->id;
int ret;
dev_dbg(dev, "%s: adding CPU%u\n", __func__, cpu);
if (cpu_online(cpu)) {
ret = cpufreq_online(cpu);
} else {
/*
* A hotplug notifier will follow and we will handle it as CPU
* online then. For now, just create the sysfs link, unless
* there is no policy or the link is already present.
*/
struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
ret = policy && !cpumask_test_and_set_cpu(cpu, policy->real_cpus)
? add_cpu_dev_symlink(policy, cpu) : 0;
}
return ret;
}
static void cpufreq_offline_prepare(unsigned int cpu) static void cpufreq_offline_prepare(unsigned int cpu)
{ {
struct cpufreq_policy *policy; struct cpufreq_policy *policy;
...@@ -2340,27 +2348,23 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb, ...@@ -2340,27 +2348,23 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
unsigned long action, void *hcpu) unsigned long action, void *hcpu)
{ {
unsigned int cpu = (unsigned long)hcpu; unsigned int cpu = (unsigned long)hcpu;
struct device *dev;
dev = get_cpu_device(cpu); switch (action & ~CPU_TASKS_FROZEN) {
if (dev) { case CPU_ONLINE:
switch (action & ~CPU_TASKS_FROZEN) { cpufreq_online(cpu);
case CPU_ONLINE: break;
cpufreq_add_dev(dev, NULL);
break;
case CPU_DOWN_PREPARE: case CPU_DOWN_PREPARE:
cpufreq_offline_prepare(cpu); cpufreq_offline_prepare(cpu);
break; break;
case CPU_POST_DEAD: case CPU_POST_DEAD:
cpufreq_offline_finish(cpu); cpufreq_offline_finish(cpu);
break; break;
case CPU_DOWN_FAILED: case CPU_DOWN_FAILED:
cpufreq_add_dev(dev, NULL); cpufreq_online(cpu);
break; break;
}
} }
return NOTIFY_OK; return NOTIFY_OK;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment