From patchwork Fri Nov 28 09:44:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 5402501 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0F1B7BEEA8 for ; Fri, 28 Nov 2014 09:45:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0DCD720145 for ; Fri, 28 Nov 2014 09:45:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2E27B20123 for ; Fri, 28 Nov 2014 09:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751761AbaK1Jpu (ORCPT ); Fri, 28 Nov 2014 04:45:50 -0500 Received: from mail-pa0-f44.google.com ([209.85.220.44]:64386 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751427AbaK1Jpt (ORCPT ); Fri, 28 Nov 2014 04:45:49 -0500 Received: by mail-pa0-f44.google.com with SMTP id et14so6518635pad.31 for ; Fri, 28 Nov 2014 01:45:49 -0800 (PST) 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=xAZEa2WZ+c1GKeAwAkGiOUz7BCMTUm9sG/eesIE7EVs=; b=h1gepmjB2T3hUBm/eFukdy9om+j5R7hFQr+9X8hvZ7RREuCyDB48FD7p8cVpEuUmZZ zAycTaUN4zgj6eJybhm7ubxLh3DLD4kA6Kr/sKdwW+0kZmhUdyPcWI7e2lpda1d+WfO7 0D6aS91bKjTwa2RTNUfpfAToIv/qQqWhfXiSn3rkchuJ4Z0tSQSNrBUtfS4CN2/sq5Ro 4BRIbo51g4EUm0dmP2ilocaIkrUBoPiAKcjGuHjWnWigjm94gq5zg7GPJU7v271/M71a 2aHteJE/T3LXO2sQR7fopVFPxG6yNMAu4EilOYPBiN3aSgiglV3YKrx0FQKbf3l+Noog qBGA== X-Gm-Message-State: ALoCoQnfUlPgv7La/Avz9xAui3+1F8EYDWdA+/8swMRaMOULsBfPnPblL1QwqHfDnAb2XpLED2AY X-Received: by 10.66.231.141 with SMTP id tg13mr72959472pac.122.1417167949309; Fri, 28 Nov 2014 01:45:49 -0800 (PST) Received: from localhost ([122.167.111.40]) by mx.google.com with ESMTPSA id fn7sm9445249pad.38.2014.11.28.01.45.48 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 28 Nov 2014 01:45:48 -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 19/26] cpu_cooling: find max level during device registration Date: Fri, 28 Nov 2014 15:14:13 +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: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP CPU frequency tables don't update after the driver is registered and so we don't need to iterate over them to find total number of states every time cpufreq_get_max_state() is called. Do it once at boot time. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 5815abf..05712d5 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -52,6 +52,8 @@ * cooling devices. * @cpufreq_val: integer value representing the absolute value of the clipped * frequency. + * @max_level: maximum cooling level. One less than total number of valid + * cpufreq frequencies. * @allowed_cpus: all the cpus involved for this cpufreq_cooling_device. * * This structure is required for keeping information of each registered @@ -62,6 +64,7 @@ struct cpufreq_cooling_device { struct thermal_cooling_device *cool_dev; unsigned int cpufreq_state; unsigned int cpufreq_val; + unsigned int max_level; struct cpumask allowed_cpus; }; static DEFINE_IDR(cpufreq_idr); @@ -246,19 +249,9 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state) { struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; - struct cpumask *mask = &cpufreq_device->allowed_cpus; - unsigned int cpu; - unsigned int count = 0; - int ret; - cpu = cpumask_any(mask); - - ret = get_property(cpu, 0, &count, GET_MAXL); - - if (count > 0) - *state = count; - - return ret; + *state = cpufreq_device->max_level; + return 0; } /** @@ -351,11 +344,25 @@ __cpufreq_cooling_register(struct device_node *np, struct thermal_cooling_device *cool_dev; struct cpufreq_cooling_device *cpufreq_dev; char dev_name[THERMAL_NAME_LENGTH]; + struct cpufreq_frequency_table *pos, *table; + + table = cpufreq_frequency_get_table(cpumask_first(clip_cpus)); + if (!table) { + pr_debug("%s: CPUFreq table not found\n", __func__); + return ERR_PTR(-EPROBE_DEFER); + } cpufreq_dev = kzalloc(sizeof(*cool_dev), GFP_KERNEL); if (!cpufreq_dev) return ERR_PTR(-ENOMEM); + /* Find max levels */ + cpufreq_for_each_valid_entry(pos, table) + cpufreq_dev->max_level++; + + /* max_level is an index, not a counter */ + cpufreq_dev->max_level--; + cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); cpufreq_dev->id = idr_alloc(&cpufreq_idr, NULL, 0, 0, GFP_KERNEL);