From patchwork Tue Mar 4 03:43:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 25642 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A19E1206F3 for ; Tue, 4 Mar 2014 03:44:23 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rd18sf22907842iec.4 for ; Mon, 03 Mar 2014 19:44:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=2tohex/z2Jnw6wtbv3zmO0zwNACqAgBOUdkVpOnERaw=; b=HPzjgq5kbxOvW2KZhCj8LezRZp16ohSl2M74eOL/OtLmZAuuzI1UGtjMbfJPs/POXx 1D51nFAwj/vcsuv+XneIPL1SIs8g2g9tu9mEsXmsnJS2g/Dp7T1/FdNnKg9TLBO1T7G+ FJ+zIiq2IGAU7OSdmX1pxA1WKiAlFGHezFEPlJ3nNXjCMU3OmpxRGF1qPRta1ylOY58H vkihXBDSiPGkznQHyxyKtbDl9icY1Fehph5t9xQrrJj0H0vysK9IaGrafpQYl0gBQ8zg zzU4ARxIodl8bZrVk153HApQiHQMxtAQYxzBY/ju/g4jFao+J3lp1D0mIvA5YNI1Szpi OcKw== X-Gm-Message-State: ALoCoQlKgEzspODJc4e35Vymh4BJwkb7FbJtr65FB3q8zPnkAtzxpwCh6SfwGeZGEpFzLqLx80Mc X-Received: by 10.50.8.3 with SMTP id n3mr12416450iga.0.1393904662942; Mon, 03 Mar 2014 19:44:22 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.22.139 with SMTP id 11ls2388124qgn.84.gmail; Mon, 03 Mar 2014 19:44:22 -0800 (PST) X-Received: by 10.58.77.204 with SMTP id u12mr439072vew.29.1393904662818; Mon, 03 Mar 2014 19:44:22 -0800 (PST) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id si7si4202511vdc.63.2014.03.03.19.44.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Mar 2014 19:44:22 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.170; Received: by mail-ve0-f170.google.com with SMTP id pa12so4832248veb.15 for ; Mon, 03 Mar 2014 19:44:22 -0800 (PST) X-Received: by 10.220.147.16 with SMTP id j16mr449840vcv.28.1393904662627; Mon, 03 Mar 2014 19:44:22 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.130.193 with SMTP id u1csp98943vcs; Mon, 3 Mar 2014 19:44:22 -0800 (PST) X-Received: by 10.66.11.66 with SMTP id o2mr3438092pab.142.1393904661827; Mon, 03 Mar 2014 19:44:21 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wh10si12658973pab.75.2014.03.03.19.44.21; Mon, 03 Mar 2014 19:44:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756134AbaCDDoU (ORCPT + 11 others); Mon, 3 Mar 2014 22:44:20 -0500 Received: from mail-pa0-f51.google.com ([209.85.220.51]:34868 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756049AbaCDDoS (ORCPT ); Mon, 3 Mar 2014 22:44:18 -0500 Received: by mail-pa0-f51.google.com with SMTP id kq14so4698837pab.10 for ; Mon, 03 Mar 2014 19:44:17 -0800 (PST) X-Received: by 10.69.26.103 with SMTP id ix7mr23385499pbd.41.1393904657799; Mon, 03 Mar 2014 19:44:17 -0800 (PST) Received: from localhost (z88l218.static.ctm.net. [202.175.88.218]) by mx.google.com with ESMTPSA id my6sm41972244pbc.36.2014.03.03.19.44.14 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 03 Mar 2014 19:44:17 -0800 (PST) From: Viresh Kumar To: rjw@rjwysocki.net, skannan@codeaurora.org Cc: linaro-kernel@lists.linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, srivatsa.bhat@linux.vnet.ibm.com, Viresh Kumar Subject: [PATCH V2 1/3] cpufreq: move call to __find_governor() to cpufreq_init_policy() Date: Tue, 4 Mar 2014 11:43:59 +0800 Message-Id: <98b7ae22d936456bf830aa749556a115969cfa47.1393904428.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , We call __find_governor() during addition of first CPU of every policy from __cpufreq_add_dev() to find the last governor used for this CPU before it was hotplugged-out. After that we call cpufreq_parse_governor() in cpufreq_init_policy() either with this governor or default governor. And right after that policy->governor is set to NULL. There is no functional problem here with this code, but it is just that some of the code required in cpufreq_init_policy() is being called by its caller, i.e. __cpufreq_add_dev(). So, it would make more sense to get all these together at a single place to make code more readable. So, instead of doing this move the relevant parts to cpufreq_init_policy() policy only and initialize policy->governor to NULL at the beginning. In order to clean the code a bit more, some of the #ifdefs for CONFIG_HOTPLUG_CPU are also removed which used to maintain the last governor used for any CPU. Keeping that code wouldn't harm us much but would improve the cleanliness of code. Signed-off-by: Viresh Kumar --- V1->V2: - Improved commit logs - Removed unrelated whitespace changes - Removed some #ifdef CONFIG_HOTPLUG_CPU to clean code a bit. drivers/cpufreq/cpufreq.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 56b7b1b..fff2968 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -42,10 +42,8 @@ static DEFINE_RWLOCK(cpufreq_driver_lock); DEFINE_MUTEX(cpufreq_governor_lock); static LIST_HEAD(cpufreq_policy_list); -#ifdef CONFIG_HOTPLUG_CPU /* This one keeps track of the previously set governor of a removed CPU */ static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); -#endif static inline bool has_target(void) { @@ -879,18 +877,25 @@ err_out_kobj_put: static void cpufreq_init_policy(struct cpufreq_policy *policy) { + struct cpufreq_governor *gov = NULL; struct cpufreq_policy new_policy; int ret = 0; memcpy(&new_policy, policy, sizeof(*policy)); + /* Update governor of new_policy to the governor used before hotplug */ + gov = __find_governor(per_cpu(cpufreq_cpu_governor, policy->cpu)); + if (gov) + pr_debug("Restoring governor %s for cpu %d\n", + policy->governor->name, policy->cpu); + else + gov = CPUFREQ_DEFAULT_GOVERNOR; + + new_policy.governor = gov; + /* Use the default policy if its valid. */ if (cpufreq_driver->setpolicy) - cpufreq_parse_governor(policy->governor->name, - &new_policy.policy, NULL); - - /* assure that the starting sequence is run in cpufreq_set_policy */ - policy->governor = NULL; + cpufreq_parse_governor(gov->name, &new_policy.policy, NULL); /* set default policy */ ret = cpufreq_set_policy(policy, &new_policy); @@ -949,6 +954,8 @@ static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu) read_unlock_irqrestore(&cpufreq_driver_lock, flags); + policy->governor = NULL; + return policy; } @@ -1036,7 +1043,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, unsigned long flags; #ifdef CONFIG_HOTPLUG_CPU struct cpufreq_policy *tpolicy; - struct cpufreq_governor *gov; #endif if (cpu_is_offline(cpu)) @@ -1094,7 +1100,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, else policy->cpu = cpu; - policy->governor = CPUFREQ_DEFAULT_GOVERNOR; cpumask_copy(policy->cpus, cpumask_of(cpu)); init_completion(&policy->kobj_unregister); @@ -1179,15 +1184,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, blocking_notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_START, policy); -#ifdef CONFIG_HOTPLUG_CPU - gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu)); - if (gov) { - policy->governor = gov; - pr_debug("Restoring governor %s for cpu %d\n", - policy->governor->name, cpu); - } -#endif - if (!frozen) { ret = cpufreq_add_dev_interface(policy, dev); if (ret) @@ -1312,11 +1308,9 @@ static int __cpufreq_remove_dev_prepare(struct device *dev, } } -#ifdef CONFIG_HOTPLUG_CPU if (!cpufreq_driver->setpolicy) strncpy(per_cpu(cpufreq_cpu_governor, cpu), policy->governor->name, CPUFREQ_NAME_LEN); -#endif down_read(&policy->rwsem); cpus = cpumask_weight(policy->cpus); @@ -1955,9 +1949,7 @@ EXPORT_SYMBOL_GPL(cpufreq_register_governor); void cpufreq_unregister_governor(struct cpufreq_governor *governor) { -#ifdef CONFIG_HOTPLUG_CPU int cpu; -#endif if (!governor) return; @@ -1965,14 +1957,12 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor) if (cpufreq_disabled()) return; -#ifdef CONFIG_HOTPLUG_CPU for_each_present_cpu(cpu) { if (cpu_online(cpu)) continue; if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name)) strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0"); } -#endif mutex_lock(&cpufreq_governor_mutex); list_del(&governor->governor_list);