From patchwork Wed Jul 29 01:03:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 6888751 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3C868C05AC for ; Wed, 29 Jul 2015 00:36:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1A20B2077D for ; Wed, 29 Jul 2015 00:36:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 111E8201DD for ; Wed, 29 Jul 2015 00:36:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751155AbbG2Agu (ORCPT ); Tue, 28 Jul 2015 20:36:50 -0400 Received: from v094114.home.net.pl ([79.96.170.134]:46662 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751131AbbG2Agt (ORCPT ); Tue, 28 Jul 2015 20:36:49 -0400 Received: from afeh52.neoplus.adsl.tpnet.pl (95.49.111.52) (HELO vostro.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer v0.80) id dcb2759643fb6e6b; Wed, 29 Jul 2015 02:36:48 +0200 From: "Rafael J. Wysocki" To: Linux PM list , Viresh Kumar Cc: Linux Kernel Mailing List , Russell King - ARM Linux Subject: [Update 2x][PATCH 7/7] cpufreq: Separate CPU device registration from CPU online Date: Wed, 29 Jul 2015 03:03:44 +0200 Message-ID: <3091538.g8dYBumqSx@vostro.rjw.lan> User-Agent: KMail/4.11.5 (Linux/4.1.0-rc5+; KDE/4.11.5; x86_64; ; ) In-Reply-To: <1702607.RH80fBCN6J@vostro.rjw.lan> References: <7868353.pEStq1MJ2a@vostro.rjw.lan> <1739669.kedIsxdRK2@vostro.rjw.lan> <1702607.RH80fBCN6J@vostro.rjw.lan> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafael J. Wysocki 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: Rafael J. Wysocki Suggested-by: Russell King Acked-by: Viresh Kumar --- cpufreq_online() returns an int and cpufreq_add_dev() propagates that to the caller in this version. That said I don't agree with using that to defer the platform device probing in cpufreq-dt. That's just over the top to me. --- drivers/cpufreq/cpufreq.c | 96 +++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 46 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-pm/drivers/cpufreq/cpufreq.c =================================================================== --- linux-pm.orig/drivers/cpufreq/cpufreq.c +++ linux-pm/drivers/cpufreq/cpufreq.c @@ -1191,36 +1191,15 @@ static void cpufreq_policy_free(struct c kfree(policy); } -/** - * 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) +static int cpufreq_online(unsigned int cpu) { - unsigned int j, cpu = dev->id; - int ret; struct cpufreq_policy *policy; - unsigned long flags; bool recover_policy; + unsigned long flags; + unsigned int j; + int ret; - pr_debug("adding CPU %u\n", 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; - } + pr_debug("%s: bringing CPU%u online\n", __func__, cpu); /* Check if this CPU already has a policy to manage it */ policy = per_cpu(cpufreq_cpu_data, cpu); @@ -1377,6 +1356,35 @@ out_free_policy: 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) { struct cpufreq_policy *policy; @@ -2340,27 +2348,23 @@ static int cpufreq_cpu_callback(struct n unsigned long action, void *hcpu) { unsigned int cpu = (unsigned long)hcpu; - struct device *dev; - dev = get_cpu_device(cpu); - if (dev) { - switch (action & ~CPU_TASKS_FROZEN) { - case CPU_ONLINE: - cpufreq_add_dev(dev, NULL); - break; - - case CPU_DOWN_PREPARE: - cpufreq_offline_prepare(cpu); - break; - - case CPU_POST_DEAD: - cpufreq_offline_finish(cpu); - break; - - case CPU_DOWN_FAILED: - cpufreq_add_dev(dev, NULL); - break; - } + switch (action & ~CPU_TASKS_FROZEN) { + case CPU_ONLINE: + cpufreq_online(cpu); + break; + + case CPU_DOWN_PREPARE: + cpufreq_offline_prepare(cpu); + break; + + case CPU_POST_DEAD: + cpufreq_offline_finish(cpu); + break; + + case CPU_DOWN_FAILED: + cpufreq_online(cpu); + break; } return NOTIFY_OK; }