From patchwork Wed Feb 6 04:30:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 2101611 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 2CDC6DFE75 for ; Wed, 6 Feb 2013 04:30:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756999Ab3BFEaP (ORCPT ); Tue, 5 Feb 2013 23:30:15 -0500 Received: from mga02.intel.com ([134.134.136.20]:19511 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756944Ab3BFEaP (ORCPT ); Tue, 5 Feb 2013 23:30:15 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 05 Feb 2013 20:30:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.84,612,1355126400"; d="scan'208";a="281525697" Received: from unknown (HELO rzhang1-mobl4.ccr.corp.intel.com) ([10.255.20.57]) by orsmga002.jf.intel.com with ESMTP; 05 Feb 2013 20:30:12 -0800 From: Zhang Rui To: linux-pm@vger.kernel.org Cc: amit.daniel@samsung.com, gu1@aeroxteam.fr, hongbo.zhang@linaro.org, Zhang Rui Subject: [PATCH 2/5] Thermal: Introduce cpu cooling table Date: Wed, 6 Feb 2013 12:30:03 +0800 Message-Id: <1360125006-25018-3-git-send-email-rui.zhang@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1360125006-25018-1-git-send-email-rui.zhang@intel.com> References: <1360125006-25018-1-git-send-email-rui.zhang@intel.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org CPU cooling table is a cleaned cpufreq_frequency_table that 1. each entry represents a cooling state, aka, each entry has a different frequency. 2. does not have invalid entry. 3. does not have duplicate entry. 4. the frequencies of all the entries are in descending order. we should use this table inside thermal layer and thermal drivers. Signed-off-by: Zhang Rui --- drivers/thermal/cpu_cooling.c | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 455c77a..08f12c7 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -115,6 +115,69 @@ static int is_cpufreq_valid(int cpu) return !cpufreq_get_policy(&policy, cpu); } +/* + * get the cleaned cpufreq_frequency_table that + * 1) does not have invalid entries + * 2) does not have duplicate entries + * 3) the frequency of the entries are in descending order + */ +static struct cpufreq_frequency_table * +get_cpu_cooling_table(unsigned int cpu) +{ + int i = 0; + int level; + struct cpufreq_frequency_table *old, *new; + unsigned int freq = CPUFREQ_ENTRY_INVALID; + int descend = -1; + + old = cpufreq_frequency_get_table(cpu); + if (!old) + return ERR_PTR(-EINVAL); + + while (old[i].frequency != CPUFREQ_TABLE_END) + i++; + + i++; /* one more entry for CPUFREQ_TABLE_END */ + + new = kzalloc(i * sizeof(struct cpufreq_frequency_table), GFP_KERNEL); + if (!new) + return ERR_PTR(-ENOMEM); + + for (i = 0, level = 0; old[i].frequency != CPUFREQ_TABLE_END; i++) { + /* ignore invalid entry */ + if (old[i].frequency == CPUFREQ_ENTRY_INVALID) + continue; + + /* ignore duplicate entry */ + if (freq == old[i].frequency) + continue; + + /* found an valid entry */ + new[level].frequency = old[i].frequency; + + if (freq != CPUFREQ_ENTRY_INVALID && descend == -1) + descend = !!(freq > old[i].frequency); + + /* freq always equals the last valid frequency */ + freq = new[level].frequency; + + level++; + } + new[level].frequency = CPUFREQ_ENTRY_INVALID; + + /* convert to decending if in ascending order */ + if (!descend) { + for(i = 0; i < (level - i - 1); i++) { + int j = level - i - 1; + freq = new[i].frequency; + new[i].frequency = new[j].frequency; + new[j].frequency = freq; + } + } + + return new; +} + /** * get_cpu_frequency - get the absolute value of frequency from level. * @cpu: cpu for which frequency is fetched.