Skip to content

Commit

Permalink
cpufreq: Use cpuhp_setup_state_nocalls_cpuslocked()
Browse files Browse the repository at this point in the history
cpufreq holds get_online_cpus() while invoking cpuhp_setup_state_nocalls()
to make subsys_interface_register() and the registration of hotplug calls
atomic versus cpu hotplug.

cpuhp_setup_state_nocalls() invokes get_online_cpus() as well. This is
correct, but prevents the conversion of the hotplug locking to a percpu
rwsem.

Use cpuhp_setup/remove_state_nocalls_cpuslocked() to avoid the nested
call. Convert *_online_cpus() to the new interfaces while at it.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
Acked-by: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Cc: linux-pm@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/20170524081547.731628408@linutronix.de
  • Loading branch information
Sebastian Andrzej Siewior authored and Thomas Gleixner committed May 26, 2017
1 parent 547efea commit a92551e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions drivers/cpufreq/cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,15 +887,15 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
struct freq_attr *fattr = to_attr(attr);
ssize_t ret = -EINVAL;

get_online_cpus();
cpus_read_lock();

if (cpu_online(policy->cpu)) {
down_write(&policy->rwsem);
ret = fattr->store(policy, buf, count);
up_write(&policy->rwsem);
}

put_online_cpus();
cpus_read_unlock();

return ret;
}
Expand Down Expand Up @@ -2441,7 +2441,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
pr_debug("trying to register driver %s\n", driver_data->name);

/* Protect against concurrent CPU online/offline. */
get_online_cpus();
cpus_read_lock();

write_lock_irqsave(&cpufreq_driver_lock, flags);
if (cpufreq_driver) {
Expand Down Expand Up @@ -2473,9 +2473,10 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
goto err_if_unreg;
}

ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "cpufreq:online",
cpuhp_cpufreq_online,
cpuhp_cpufreq_offline);
ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN,
"cpufreq:online",
cpuhp_cpufreq_online,
cpuhp_cpufreq_offline);
if (ret < 0)
goto err_if_unreg;
hp_online = ret;
Expand All @@ -2493,7 +2494,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
cpufreq_driver = NULL;
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
out:
put_online_cpus();
cpus_read_unlock();
return ret;
}
EXPORT_SYMBOL_GPL(cpufreq_register_driver);
Expand All @@ -2516,17 +2517,17 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver)
pr_debug("unregistering driver %s\n", driver->name);

/* Protect against concurrent cpu hotplug */
get_online_cpus();
cpus_read_lock();
subsys_interface_unregister(&cpufreq_interface);
remove_boost_sysfs_file();
cpuhp_remove_state_nocalls(hp_online);
cpuhp_remove_state_nocalls_cpuslocked(hp_online);

write_lock_irqsave(&cpufreq_driver_lock, flags);

cpufreq_driver = NULL;

write_unlock_irqrestore(&cpufreq_driver_lock, flags);
put_online_cpus();
cpus_read_unlock();

return 0;
}
Expand Down

0 comments on commit a92551e

Please sign in to comment.