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: 69182 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp144456qgf; Thu, 2 Jun 2016 07:20:34 -0700 (PDT) X-Received: by 10.66.221.167 with SMTP id qf7mr5969613pac.94.1464877225282; Thu, 02 Jun 2016 07:20:25 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t8si25021741pay.32.2016.06.02.07.20.25; Thu, 02 Jun 2016 07:20:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161287AbcFBOT6 (ORCPT + 31 others); Thu, 2 Jun 2016 10:19:58 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:34030 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161267AbcFBOTy (ORCPT ); Thu, 2 Jun 2016 10:19:54 -0400 Received: by mail-pf0-f174.google.com with SMTP id 62so31941549pfd.1 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=TjjQUfn3/uWmYESCW74zsfOAGx8JXVe3Oxi8LxCsmcbA21/vDs23BD3zjlPZBn5JW6 vloj4a0a6ique7LmBeHyYGO+gQZOU+34hRQv3T4UMNdw6PbQ9c+2U7iUrjbc9ilVVmzc 5BrZkNulHUsElD/5qBavTUmE8qBMcduXk4dCeH876b+yo0fAw5cUSd3QpYX/h9CGVQvY zg2Qan4ADiAO9yzJ9tbV1skTD0Cyxju/t4sMz9snsww45/plcRuHUhrIMzgzxrCkxtJw hNAJOv8q4npcoJpjktkep2MIhsg0+JjPuFnc4L3Njg7J6kC/mDZzbuAptchPnZZTImpL FMdg== X-Gm-Message-State: ALyK8tIImHkvtMwgJQEbuJHSOgcsf/OfS4U4S1VHNGCFXOHuldtDd+gyBEpiRE9NMFtNnYvv 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.7.1.410.g6faf27b 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