From patchwork Thu Jun 2 14:19:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 9150101 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BDEDC60751 for ; Thu, 2 Jun 2016 14:20:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE427282E8 for ; Thu, 2 Jun 2016 14:20:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2191282EE; Thu, 2 Jun 2016 14:20:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 166F0282E8 for ; Thu, 2 Jun 2016 14:20:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161269AbcFBOT5 (ORCPT ); Thu, 2 Jun 2016 10:19:57 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:36198 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161242AbcFBOTy (ORCPT ); Thu, 2 Jun 2016 10:19:54 -0400 Received: by mail-pf0-f175.google.com with SMTP id f144so31941677pfa.3 for ; Thu, 02 Jun 2016 07:19:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Myuavs0TanihX6024tZiNQtq2W+QZBjq3vHriQyhVn8=; b=Yy4Nd4TY0xPJ2jdQqn1a/mSmia5RCpwNY9RohsEORbzBU3yUr/Uv26rFeH1um6+OtP YhuphZ6srhlUWKwMMAT7HgUIinMjo+nTsYpqvutatmSbFy4ABn4M0Rxo+VcT0/4Kt4h0 D4k/poOpjVquq9baZ7JAlRCc4wHdnOtjT2oe4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=Myuavs0TanihX6024tZiNQtq2W+QZBjq3vHriQyhVn8=; b=b9bFtcioeJOAk+uujO2ZJpUYkNDpwDxI7mqkuSm5g9H868w3RywLcNd52mHddb6LuM QOMPeAeAVj3KU0DUBybnG+TA6Udjj3LoFseTtfqQqhH9uO4RqBlCwifoHbKj09VRpvlU H0mJnOcT2BZSjVFZAsKcIcVyBR6kbdVMdJtzS/1akAPtwDpbnkCIaIDjpxZRgeHzPb7O CXLZmkwKRoMrbwB/7LpjUHUcQgH58DhpEFm/j/Frz2SJ1Qpr5+s2o0Fjozwa5qTCX3k1 5HPj197u1fkNsuDIJaHwsNLJmCD0CDfT5DuJjr0b1ZnQi+DyPT4U0Le6gy3GDG95C1/S 73BQ== X-Gm-Message-State: ALyK8tLeOE3EMZKM6ApPoLIMtUv9zZ8la/UXG3qon225Rd9hg1o2Co34++ly7VmEpPbbw8kf X-Received: by 10.98.56.141 with SMTP id f135mr4937256pfa.159.1464877193559; Thu, 02 Jun 2016 07:19:53 -0700 (PDT) Received: from localhost ([122.167.17.193]) by smtp.gmail.com with ESMTPSA id 14sm1292706pfu.83.2016.06.02.07.19.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jun 2016 07:19:52 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Eremin-Solenikov , Kevin Hilman , Krzysztof Kozlowski , Kukjin Kim , Sekhar Nori , Shawn Guo , Steven Miao Subject: [PATCH 10/11] cpufreq: Keep a single (sorted) freq_table Date: Thu, 2 Jun 2016 19:49:10 +0530 Message-Id: <468e26b3f145e251299711acdd74172107740b7b.1464876460.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now that all drivers providing ->target_index() callback are updated to use 'index' only for indexing into policy->freq_table, we can safely avoid keeping two separate freq-tables. Which also means that cpufreq core doesn't use the freq_table passed to cpufreq_table_validate_and_show(), once that routine has returned. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 6 +----- drivers/cpufreq/freq_table.c | 36 ++++++++++++++---------------------- include/linux/cpufreq.h | 9 ++------- 3 files changed, 17 insertions(+), 34 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 10c5f7abc205..47983cb0601d 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1143,7 +1143,7 @@ static void cpufreq_policy_exit(struct cpufreq_policy *policy) return; cpufreq_driver->exit(policy); - free_sorted_freq_table(policy); + kfree(policy->freq_table); policy->freq_table = NULL; } @@ -1188,10 +1188,6 @@ static int cpufreq_online(unsigned int cpu) goto out_free_policy; } - ret = create_sorted_freq_table(policy); - if (ret) - goto out_exit_policy; - down_write(&policy->rwsem); if (new_policy) { diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c index 15c4a2462c68..7afe2c017267 100644 --- a/drivers/cpufreq/freq_table.c +++ b/drivers/cpufreq/freq_table.c @@ -350,20 +350,11 @@ static int next_larger(struct cpufreq_policy *policy, unsigned int freq, return index; } -void free_sorted_freq_table(struct cpufreq_policy *policy) -{ - kfree(policy->sorted_freq_table); - policy->sorted_freq_table = NULL; -} - -int create_sorted_freq_table(struct cpufreq_policy *policy) +static int create_sorted_freq_table(struct cpufreq_policy *policy, + struct cpufreq_frequency_table *table) { struct cpufreq_frequency_table *pos, *new_table; unsigned int freq, index, i, count = 0; - struct cpufreq_frequency_table *table = policy->freq_table; - - if (!table) - return 0; cpufreq_for_each_valid_entry(pos, table) count++; @@ -380,31 +371,32 @@ int create_sorted_freq_table(struct cpufreq_policy *policy) if (index == -EINVAL) break; - /* - * driver_data of the sorted table points to the index of the - * unsorted table. - */ - new_table[i].driver_data = index; new_table[i].frequency = table[index].frequency; + new_table[i].driver_data = table[index].driver_data; + new_table[i].flags = table[index].flags; freq = table[index].frequency; } new_table[i].frequency = CPUFREQ_TABLE_END; - policy->sorted_freq_table = new_table; + policy->freq_table = new_table; return 0; } int cpufreq_table_validate_and_show(struct cpufreq_policy *policy, - struct cpufreq_frequency_table *table) + struct cpufreq_frequency_table *table) { - int ret = cpufreq_frequency_table_cpuinfo(policy, table); + int ret; + + if (!table) + return -EINVAL; - if (!ret) - policy->freq_table = table; + ret = cpufreq_frequency_table_cpuinfo(policy, table); + if (ret) + return ret; - return ret; + return create_sorted_freq_table(policy, table); } EXPORT_SYMBOL_GPL(cpufreq_table_validate_and_show); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 5aabec611e87..9df7c569cfbb 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -87,7 +87,6 @@ struct cpufreq_policy { struct cpufreq_user_policy user_policy; struct cpufreq_frequency_table *freq_table; - struct cpufreq_frequency_table *sorted_freq_table; struct list_head policy_list; struct kobject kobj; @@ -593,8 +592,6 @@ static inline void dev_pm_opp_free_cpufreq_table(struct device *dev, int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy, struct cpufreq_frequency_table *table); -int create_sorted_freq_table(struct cpufreq_policy *policy); -void free_sorted_freq_table(struct cpufreq_policy *policy); int cpufreq_frequency_table_verify(struct cpufreq_policy *policy, struct cpufreq_frequency_table *table); @@ -616,10 +613,8 @@ static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation) { - int index = cpufreq_find_target_index(policy, policy->sorted_freq_table, - target_freq, relation); - - return policy->sorted_freq_table[index].driver_data; + return cpufreq_find_target_index(policy, policy->freq_table, + target_freq, relation); } #ifdef CONFIG_CPU_FREQ