From patchwork Fri Nov 28 09:44:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 41691 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f72.google.com (mail-ee0-f72.google.com [74.125.83.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 23992244C2 for ; Fri, 28 Nov 2014 09:46:17 +0000 (UTC) Received: by mail-ee0-f72.google.com with SMTP id e53sf4042069eek.3 for ; Fri, 28 Nov 2014 01:46:16 -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=6uAZtrWHmXg8EDuQrWMz426wcWZoOqoHElBdhJrVrTQ=; b=cMpr+OVB01zfEyOPcX6i45UTHwNnHUCj2Fk25YXYjuB2rxckCDgRMJ3o2xWcPxAwly mnUhXO/Xf59xIpTXpjl7uNNa4Fqcq0oNlAuAlCqk9/vXjtUT3JNWeAfAkwIFKteyAMuV l2RP5HqpEvIsMppbtNit4zHh049BvOGUYm52b/S5NyqhSaEsTWbFmZ3hXCccKYElrajF tIeM4AY759r9Q/u5DmFkwZM3LbSLvyvFKgrZUyI6q5JI21q1ctyNZwn67eoRoW0KpKqw LwuDaA0bUXAbWG7tcX7Xhysb2AkFU+k5NacGYgqWjFcD1IbuD8QY1YKRjJVinJw9kV/b 98+w== X-Gm-Message-State: ALoCoQk6onZVwGJzOYZ4GIFcgYA43kUGwhBDTkaXDPXUTQ38mBEBP/d1p2YDXso2WAmR0J131567 X-Received: by 10.194.176.106 with SMTP id ch10mr162520wjc.6.1417167976373; Fri, 28 Nov 2014 01:46:16 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.37 with SMTP id ll5ls259211lac.53.gmail; Fri, 28 Nov 2014 01:46:16 -0800 (PST) X-Received: by 10.112.199.40 with SMTP id jh8mr43394443lbc.5.1417167975974; Fri, 28 Nov 2014 01:46:15 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id li1si9426328lab.112.2014.11.28.01.46.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Nov 2014 01:46:15 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id z11so5213469lbi.24 for ; Fri, 28 Nov 2014 01:46:15 -0800 (PST) X-Received: by 10.152.43.103 with SMTP id v7mr19538231lal.29.1417167975885; Fri, 28 Nov 2014 01:46:15 -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.184.201 with SMTP id ew9csp60547lbc; Fri, 28 Nov 2014 01:46:14 -0800 (PST) X-Received: by 10.66.242.1 with SMTP id wm1mr2344727pac.18.1417167974245; Fri, 28 Nov 2014 01:46:14 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vj10si15336419pbc.138.2014.11.28.01.46.10 for ; Fri, 28 Nov 2014 01:46:14 -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 S1751769AbaK1JqJ (ORCPT + 12 others); Fri, 28 Nov 2014 04:46:09 -0500 Received: from mail-pa0-f49.google.com ([209.85.220.49]:52091 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751394AbaK1JqI (ORCPT ); Fri, 28 Nov 2014 04:46:08 -0500 Received: by mail-pa0-f49.google.com with SMTP id eu11so6449671pac.8 for ; Fri, 28 Nov 2014 01:46:08 -0800 (PST) X-Received: by 10.68.68.227 with SMTP id z3mr15210852pbt.3.1417167968186; Fri, 28 Nov 2014 01:46:08 -0800 (PST) Received: from localhost ([122.167.111.40]) by mx.google.com with ESMTPSA id pc10sm9378576pbb.21.2014.11.28.01.46.07 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 28 Nov 2014 01:46:07 -0800 (PST) From: Viresh Kumar To: linux-pm@vger.kernel.org, edubezval@gmail.com Cc: linaro-kernel@lists.linaro.org, rui.zhang@intel.com, Viresh Kumar Subject: [PATCH 24/26] cpu_cooling: Store frequencies in descending order Date: Fri, 28 Nov 2014 15:14:18 +0530 Message-Id: X-Mailer: git-send-email 2.0.3.693.g996b0fd 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.217.179 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: , CPUFreq framework *doesn't* guarantee that frequencies present in cpufreq table will be in ascending or descending order. But cpu_cooling somehow assumes that. Probably because most of current users are creating this list from DT, which is done with the help of OPP layer. And OPP layer creates the list in ascending order of frequencies. But cpu_cooling can be used for other platforms too, which don't have frequencies arranged in any order. This patch tries to fix this issue by creating another list of valid frequencies in descending order. Care is also taken to throw warnings for duplicate entries. Later patches would use it to simplify code. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 07414c5..9a4a323 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -65,6 +65,7 @@ struct cpufreq_cooling_device { unsigned int cpufreq_state; unsigned int cpufreq_val; unsigned int max_level; + unsigned int *freq_table; /* In descending order */ struct cpumask allowed_cpus; struct list_head head; }; @@ -321,6 +322,20 @@ static struct notifier_block thermal_cpufreq_notifier_block = { .notifier_call = cpufreq_thermal_notifier, }; +static unsigned int find_next_max(struct cpufreq_frequency_table *table, + unsigned int prev_max) +{ + struct cpufreq_frequency_table *pos; + unsigned int max = 0; + + cpufreq_for_each_valid_entry(pos, table) { + if (pos->frequency > max && pos->frequency < prev_max) + max = pos->frequency; + } + + return max; +} + /** * __cpufreq_cooling_register - helper function to create cpufreq cooling device * @np: a valid struct device_node to the cooling device device tree node @@ -343,6 +358,7 @@ __cpufreq_cooling_register(struct device_node *np, struct cpufreq_cooling_device *cpufreq_dev; char dev_name[THERMAL_NAME_LENGTH]; struct cpufreq_frequency_table *pos, *table; + unsigned int freq, i; table = cpufreq_frequency_get_table(cpumask_first(clip_cpus)); if (!table) { @@ -358,6 +374,14 @@ __cpufreq_cooling_register(struct device_node *np, cpufreq_for_each_valid_entry(pos, table) cpufreq_dev->max_level++; + cpufreq_dev->freq_table = kmalloc(sizeof(*cpufreq_dev->freq_table) * + cpufreq_dev->max_level, GFP_KERNEL); + if (!cpufreq_dev->freq_table) { + return ERR_PTR(-ENOMEM); + cool_dev = ERR_PTR(-ENOMEM); + goto free_cdev; + } + /* max_level is an index, not a counter */ cpufreq_dev->max_level--; @@ -366,7 +390,7 @@ __cpufreq_cooling_register(struct device_node *np, cpufreq_dev->id = idr_alloc(&cpufreq_idr, NULL, 0, 0, GFP_KERNEL); if (unlikely(cpufreq_dev->id < 0)) { cool_dev = ERR_PTR(cpufreq_dev->id); - goto free_cdev; + goto free_table; } snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", @@ -377,6 +401,18 @@ __cpufreq_cooling_register(struct device_node *np, if (IS_ERR(cool_dev)) goto remove_idr; + /* Fill freq-table in descending order of frequencies */ + for (i = 0, freq = -1; i <= cpufreq_dev->max_level; i++) { + freq = find_next_max(table, freq); + cpufreq_dev->freq_table[i] = freq; + + /* Warn for duplicate entries */ + if (!freq) + pr_warn("%s: table has duplicate entries\n", __func__); + else + pr_debug("%s: freq:%u KHz\n", __func__, freq); + } + cpufreq_dev->cool_dev = cool_dev; INIT_LIST_HEAD(&cpufreq_dev->head); @@ -394,6 +430,8 @@ __cpufreq_cooling_register(struct device_node *np, remove_idr: idr_remove(&cpufreq_idr, cpufreq_dev->id); +free_table: + kfree(cpufreq_dev->freq_table); free_cdev: kfree(cpufreq_dev); @@ -467,6 +505,7 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) thermal_cooling_device_unregister(cpufreq_dev->cool_dev); idr_remove(&cpufreq_idr, cpufreq_dev->id); + kfree(cpufreq_dev->freq_table); kfree(cpufreq_dev); } EXPORT_SYMBOL_GPL(cpufreq_cooling_unregister);