From patchwork Tue May 12 06:50:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 48332 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A78F12121F for ; Tue, 12 May 2015 06:50:35 +0000 (UTC) Received: by lbos2 with SMTP id s2sf43883869lbo.2 for ; Mon, 11 May 2015 23:50:34 -0700 (PDT) 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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=wgxA5fwR+nhdHWCTEHZN49uR66cRHA4zWlDh2XJcr38=; b=gUkdjAbfV4rkpPii0qTk94tO+TAXaVjrkW2GycXPFky5KPaXtMGF+lkuWBRXFq242M W6vaH9jS2bHL40J+RMARZQBIqD5OUKEAkRgVJ8qvdc+VrsKW50IkiMpQAPKA5xadc1ov HXAIweFBs6Ozp+v/ExOadpqkyKzUvKRaqV0pSleFNndynH+FsAs6fYnsbjUpJxQgrWGq KyzzWQfjfcNcQWu0WGqZCamejYO07wYdkzsWvuCHr8zElCqC7aqcKMvWkBNt3BKeDL9Y EBhzaPpWcH5BHWFA7/f1Qjqx7NJswNlm+NloIIPbWyeRqqGuJHsUqjYForJYvPqHYOjn 4C2w== X-Gm-Message-State: ALoCoQn/HIWqPC6gHbWZ1ovqlju27C8MuHPfs4mPB6J1c0ys82gfpQArogwbvW250maK+uHc9Hhc X-Received: by 10.180.74.197 with SMTP id w5mr10189237wiv.5.1431413434444; Mon, 11 May 2015 23:50:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.203.133 with SMTP id kq5ls678608lac.102.gmail; Mon, 11 May 2015 23:50:34 -0700 (PDT) X-Received: by 10.152.42.164 with SMTP id p4mr10408633lal.3.1431413434206; Mon, 11 May 2015 23:50:34 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id g2si9733468laa.128.2015.05.11.23.50.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 May 2015 23:50:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by lagv1 with SMTP id v1so109817030lag.3 for ; Mon, 11 May 2015 23:50:34 -0700 (PDT) X-Received: by 10.152.27.98 with SMTP id s2mr10935485lag.106.1431413434057; Mon, 11 May 2015 23:50:34 -0700 (PDT) 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.108.230 with SMTP id hn6csp1904768lbb; Mon, 11 May 2015 23:50:32 -0700 (PDT) X-Received: by 10.70.129.202 with SMTP id ny10mr25399403pdb.107.1431413432087; Mon, 11 May 2015 23:50:32 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si21208833pdl.24.2015.05.11.23.50.31; Mon, 11 May 2015 23:50:32 -0700 (PDT) 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 S1752422AbbELGua (ORCPT + 11 others); Tue, 12 May 2015 02:50:30 -0400 Received: from mail-pd0-f177.google.com ([209.85.192.177]:35873 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752354AbbELGu3 (ORCPT ); Tue, 12 May 2015 02:50:29 -0400 Received: by pdea3 with SMTP id a3so173562958pde.3 for ; Mon, 11 May 2015 23:50:29 -0700 (PDT) X-Received: by 10.68.238.228 with SMTP id vn4mr25170088pbc.166.1431413429379; Mon, 11 May 2015 23:50:29 -0700 (PDT) Received: from localhost ([122.167.226.34]) by mx.google.com with ESMTPSA id c1sm15077612pdc.45.2015.05.11.23.50.25 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 11 May 2015 23:50:26 -0700 (PDT) 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, Srivatsa Bhat , Viresh Kumar Subject: [PATCH V4 01/14] cpufreq: Create for_each_{in}active_policy() Date: Tue, 12 May 2015 12:20:11 +0530 Message-Id: <2f5c97eddb463e27fa4b83b5f3ed2bd87b2ece6b.1431412012.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 In-Reply-To: <79f880aba9ad5159e070f2ca172139cb2c254430.1431065963.git.viresh.kumar@linaro.org> 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.42 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: , policy->cpus is cleared unconditionally now on hotplug-out of a CPU and it can be checked to know if a policy is active or not. Create helper routines to iterate over all active/inactive policies, based on policy->cpus field. Replace all instances of for_each_policy() with for_each_active_policy() to make them iterate only for active policies. (We haven't made changes yet to keep inactive policies in the same list, but that will be followed in a later patch). Signed-off-by: Viresh Kumar --- Hi Rafael, I have changed this patch based on your suggestions. Because of this, 3 more patches had rebase conflicts and am sending them again as well (In-reply-to the original messages). Because only 4 patches were affected, I am no sending the whole series again, please let me know if you want the whole series to be sent again. V3-V4: - Remove __temp from the arguments of for_each_[in]active_policies. - Simplified macros/next_policy, etc. - Other patches sent with this one, rebased on top of this one: - [PATCH V4 04/14] cpufreq: Don't traverse all active policies to find - [PATCH V4 05/14] cpufreq: Manage governor usage history with - [PATCH V4 06/14] cpufreq: Mark policy->governor = NULL for inactive drivers/cpufreq/cpufreq.c | 66 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 8cf0c0e7aea8..74d9fcbbe4f9 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -31,10 +31,62 @@ #include #include -/* Macros to iterate over lists */ -/* Iterate over online CPUs policies */ static LIST_HEAD(cpufreq_policy_list); -#define for_each_policy(__policy) \ + +static inline bool policy_is_inactive(struct cpufreq_policy *policy) +{ + return cpumask_empty(policy->cpus); +} + +static bool suitable_policy(struct cpufreq_policy *policy, bool active) +{ + return active == !policy_is_inactive(policy); +} + +/* Finds Next Acive/Inactive policy */ +static struct cpufreq_policy *next_policy(struct cpufreq_policy *policy, + bool active) +{ + do { + policy = list_next_entry(policy, policy_list); + + /* No more policies in the list */ + if (&policy->policy_list == &cpufreq_policy_list) + return NULL; + } while (!suitable_policy(policy, active)); + + return policy; +} + +static struct cpufreq_policy *first_policy(bool active) +{ + struct cpufreq_policy *policy; + + /* No policies in the list */ + if (list_empty(&cpufreq_policy_list)) + return NULL; + + policy = list_first_entry(&cpufreq_policy_list, typeof(*policy), + policy_list); + + if (!suitable_policy(policy, active)) + policy = next_policy(policy, active); + + return policy; +} + +/* Macros to iterate over CPU policies */ +#define for_each_suitable_policy(__policy, __active) \ + for (__policy = first_policy(__active); \ + __policy; \ + __policy = next_policy(__policy, __active)) + +#define for_each_active_policy(__policy) \ + for_each_suitable_policy(__policy, true) +#define for_each_inactive_policy(__policy) \ + for_each_suitable_policy(__policy, false) + +#define for_each_policy(__policy) \ list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) /* Iterate over governors */ @@ -1156,7 +1208,7 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) /* Check if this CPU already has a policy to manage it */ read_lock_irqsave(&cpufreq_driver_lock, flags); - for_each_policy(policy) { + for_each_active_policy(policy) { if (cpumask_test_cpu(cpu, policy->related_cpus)) { read_unlock_irqrestore(&cpufreq_driver_lock, flags); ret = cpufreq_add_policy_cpu(policy, cpu, dev); @@ -1674,7 +1726,7 @@ void cpufreq_suspend(void) pr_debug("%s: Suspending Governors\n", __func__); - for_each_policy(policy) { + for_each_active_policy(policy) { if (__cpufreq_governor(policy, CPUFREQ_GOV_STOP)) pr_err("%s: Failed to stop governor for policy: %p\n", __func__, policy); @@ -1708,7 +1760,7 @@ void cpufreq_resume(void) pr_debug("%s: Resuming Governors\n", __func__); - for_each_policy(policy) { + for_each_active_policy(policy) { if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) pr_err("%s: Failed to resume driver: %p\n", __func__, policy); @@ -2354,7 +2406,7 @@ static int cpufreq_boost_set_sw(int state) struct cpufreq_policy *policy; int ret = -EINVAL; - for_each_policy(policy) { + for_each_active_policy(policy) { freq_table = cpufreq_frequency_get_table(policy->cpu); if (freq_table) { ret = cpufreq_frequency_table_cpuinfo(policy,