From patchwork Tue Jan 27 08:36:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 43822 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 840D32409D for ; Tue, 27 Jan 2015 08:37:13 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id c13sf6813454eek.1 for ; Tue, 27 Jan 2015 00:37:12 -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:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=+505PdKfGy1s63+WEUvpIyJVH6+Ot//gZ4leMUepSa8=; b=kgPzXps6t0yo6GrLw508qxvLPu9/rpm+OMl/urF7mtpsMtYYr7MWwK+8hMgPwUTuIw 4oBduRzQlpkYTBdG6OzGYQp8CJkw/LUCXZDdzZ5oVjv3LdsIQGFadPEzEY2N4WVWYRLJ amRslfYZ7+nO2O7hETSQncJEGgZPzyo+mx2BNfGT5rcUQ9iulBGt8V79J8hjoNN0HFP+ z9wQ9/f8pK7WS+zd6l8Le8te5ulb6uVr6daZtpWhbj0u1m48bv8RTY0XKJ8/VO8NI9qT 5bMnYkg4nMrpTNxc0fhWEn9MZ/ey4uSWKCEGTMX2OFFH7VGY08GaAzML6bRh76HRT13P f/2A== X-Gm-Message-State: ALoCoQlNDhSiztxXt4RXu3BSIm9KBW/QNvKPvNYLf92S4OeQX0vK4Qiujxt+wgeIV7m4/8Vtq7lq X-Received: by 10.112.13.161 with SMTP id i1mr30804lbc.20.1422347832779; Tue, 27 Jan 2015 00:37:12 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.195 with SMTP id c3ls2760lab.61.gmail; Tue, 27 Jan 2015 00:37:12 -0800 (PST) X-Received: by 10.152.7.229 with SMTP id m5mr139006laa.80.1422347832500; Tue, 27 Jan 2015 00:37:12 -0800 (PST) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id ld5si574329lbb.29.2015.01.27.00.37.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Jan 2015 00:37:12 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id hv19so11917295lab.13 for ; Tue, 27 Jan 2015 00:37:12 -0800 (PST) X-Received: by 10.152.44.228 with SMTP id h4mr88007lam.31.1422347832352; Tue, 27 Jan 2015 00:37:12 -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.112.35.133 with SMTP id h5csp1025479lbj; Tue, 27 Jan 2015 00:37:11 -0800 (PST) X-Received: by 10.66.170.208 with SMTP id ao16mr90821pac.1.1422347828690; Tue, 27 Jan 2015 00:37:08 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vr2si685254pbc.134.2015.01.27.00.37.06; Tue, 27 Jan 2015 00:37:08 -0800 (PST) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757836AbbA0IhF (ORCPT + 11 others); Tue, 27 Jan 2015 03:37:05 -0500 Received: from mail-pd0-f177.google.com ([209.85.192.177]:40573 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754074AbbA0IhE (ORCPT ); Tue, 27 Jan 2015 03:37:04 -0500 Received: by mail-pd0-f177.google.com with SMTP id y13so17567723pdi.8 for ; Tue, 27 Jan 2015 00:37:03 -0800 (PST) X-Received: by 10.66.156.35 with SMTP id wb3mr217058pab.70.1422347823667; Tue, 27 Jan 2015 00:37:03 -0800 (PST) Received: from localhost ([122.178.198.250]) by mx.google.com with ESMTPSA id k5sm844917pdb.14.2015.01.27.00.37.02 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 27 Jan 2015 00:37:03 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, sboyd@codeaurora.org, prarit@redhat.com, skannan@codeaurora.org, Viresh Kumar Subject: [PATCH 06/18] cpufreq: Reuse policy list instead of per-cpu variable 'cpufreq_cpu_data' Date: Tue, 27 Jan 2015 14:06:12 +0530 Message-Id: X-Mailer: git-send-email 2.3.0.rc0.44.ga94655d In-Reply-To: References: In-Reply-To: References: 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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) 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: , Managing a per-cpu variable (cpufreq_cpu_data) for keeping track of policy structures is a bit overdone. Apart from wasting some bytes of memory to save these pointers for each cpu, it also makes the code much more complex. It would be much better if we have a single place which needs updates on addition/removal of a policy. We already have a list of active-policies and that can be used instead of this per-cpu variable. Lets do it. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 124 ++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 66 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 4ad1e46891b5..7f947287ba46 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -49,11 +49,9 @@ static LIST_HEAD(cpufreq_governor_list); /** * The "cpufreq driver" - the arch- or hardware-dependent low - * level driver of CPUFreq support, and its spinlock. This lock - * also protects the cpufreq_cpu_data array. + * level driver of CPUFreq support, and its spinlock. */ static struct cpufreq_driver *cpufreq_driver; -static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); static DEFINE_RWLOCK(cpufreq_driver_lock); DEFINE_MUTEX(cpufreq_governor_lock); @@ -157,6 +155,54 @@ u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy) } EXPORT_SYMBOL_GPL(get_cpu_idle_time); +/* Only for cpufreq core internal use */ +struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu) +{ + struct cpufreq_policy *policy; + + for_each_policy(policy) + if (cpumask_test_cpu(cpu, policy->cpus)) + return policy; + + return NULL; +} + +struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) +{ + struct cpufreq_policy *policy = NULL; + unsigned long flags; + + if (cpu >= nr_cpu_ids) + return NULL; + + if (!down_read_trylock(&cpufreq_rwsem)) + return NULL; + + /* get the cpufreq driver */ + read_lock_irqsave(&cpufreq_driver_lock, flags); + + if (cpufreq_driver) { + policy = cpufreq_cpu_get_raw(cpu); + if (policy) + kobject_get(&policy->kobj); + } + + read_unlock_irqrestore(&cpufreq_driver_lock, flags); + + if (!policy) + up_read(&cpufreq_rwsem); + + return policy; +} +EXPORT_SYMBOL_GPL(cpufreq_cpu_get); + +void cpufreq_cpu_put(struct cpufreq_policy *policy) +{ + kobject_put(&policy->kobj); + up_read(&cpufreq_rwsem); +} +EXPORT_SYMBOL_GPL(cpufreq_cpu_put); + /* * This is a generic cpufreq init() routine which can be used by cpufreq * drivers of SMP systems. It will do following: @@ -190,7 +236,7 @@ EXPORT_SYMBOL_GPL(cpufreq_generic_init); unsigned int cpufreq_generic_get(unsigned int cpu) { - struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); + struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu); if (!policy || IS_ERR(policy->clk)) { pr_err("%s: No %s associated to cpu: %d\n", @@ -202,49 +248,6 @@ unsigned int cpufreq_generic_get(unsigned int cpu) } EXPORT_SYMBOL_GPL(cpufreq_generic_get); -/* Only for cpufreq core internal use */ -struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu) -{ - return per_cpu(cpufreq_cpu_data, cpu); -} - -struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) -{ - struct cpufreq_policy *policy = NULL; - unsigned long flags; - - if (cpu >= nr_cpu_ids) - return NULL; - - if (!down_read_trylock(&cpufreq_rwsem)) - return NULL; - - /* get the cpufreq driver */ - read_lock_irqsave(&cpufreq_driver_lock, flags); - - if (cpufreq_driver) { - /* get the CPU */ - policy = per_cpu(cpufreq_cpu_data, cpu); - if (policy) - kobject_get(&policy->kobj); - } - - read_unlock_irqrestore(&cpufreq_driver_lock, flags); - - if (!policy) - up_read(&cpufreq_rwsem); - - return policy; -} -EXPORT_SYMBOL_GPL(cpufreq_cpu_get); - -void cpufreq_cpu_put(struct cpufreq_policy *policy) -{ - kobject_put(&policy->kobj); - up_read(&cpufreq_rwsem); -} -EXPORT_SYMBOL_GPL(cpufreq_cpu_put); - /********************************************************************* * EXTERNALLY AFFECTING FREQUENCY CHANGES * *********************************************************************/ @@ -964,7 +967,6 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu, struct device *dev) { int ret = 0; - unsigned long flags; if (has_target()) { ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP); @@ -975,13 +977,7 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, } down_write(&policy->rwsem); - - write_lock_irqsave(&cpufreq_driver_lock, flags); - cpumask_set_cpu(cpu, policy->cpus); - per_cpu(cpufreq_cpu_data, cpu) = policy; - write_unlock_irqrestore(&cpufreq_driver_lock, flags); - up_write(&policy->rwsem); if (has_target()) { @@ -1105,7 +1101,7 @@ static int update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu, static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) { - unsigned int j, cpu = dev->id; + unsigned int cpu = dev->id; int ret = -ENOMEM; struct cpufreq_policy *policy; unsigned long flags; @@ -1202,8 +1198,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) } write_lock_irqsave(&cpufreq_driver_lock, flags); - for_each_cpu(j, policy->cpus) - per_cpu(cpufreq_cpu_data, j) = policy; + list_add(&policy->policy_list, &cpufreq_policy_list); write_unlock_irqrestore(&cpufreq_driver_lock, flags); if (cpufreq_driver->get && !cpufreq_driver->setpolicy) { @@ -1265,10 +1260,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) CPUFREQ_CREATE_POLICY, policy); } - write_lock_irqsave(&cpufreq_driver_lock, flags); - list_add(&policy->policy_list, &cpufreq_policy_list); - write_unlock_irqrestore(&cpufreq_driver_lock, flags); - cpufreq_init_policy(policy); if (!recover_policy) { @@ -1292,8 +1283,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) err_out_unregister: err_get_freq: write_lock_irqsave(&cpufreq_driver_lock, flags); - for_each_cpu(j, policy->cpus) - per_cpu(cpufreq_cpu_data, j) = NULL; + list_del(&policy->policy_list); write_unlock_irqrestore(&cpufreq_driver_lock, flags); if (!recover_policy) { @@ -1340,7 +1330,10 @@ static int __cpufreq_remove_dev_prepare(struct device *dev, pr_debug("%s: unregistering CPU %u\n", __func__, cpu); - policy = per_cpu(cpufreq_cpu_data, cpu); + read_lock_irqsave(&cpufreq_driver_lock, flags); + policy = cpufreq_cpu_get_raw(cpu); + read_unlock_irqrestore(&cpufreq_driver_lock, flags); + if (!policy) { pr_debug("%s: No cpu_data found\n", __func__); return -EINVAL; @@ -1404,7 +1397,7 @@ static int __cpufreq_remove_dev_finish(struct device *dev, struct cpufreq_policy *policy; read_lock_irqsave(&cpufreq_driver_lock, flags); - policy = per_cpu(cpufreq_cpu_data, cpu); + policy = cpufreq_cpu_get_raw(cpu); read_unlock_irqrestore(&cpufreq_driver_lock, flags); if (!policy) { @@ -1460,7 +1453,6 @@ static int __cpufreq_remove_dev_finish(struct device *dev, } } - per_cpu(cpufreq_cpu_data, cpu) = NULL; return 0; }