From patchwork Thu Dec 4 04:12:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 41904 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0719025E88 for ; Thu, 4 Dec 2014 04:14:08 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id d49sf10502708eek.0 for ; Wed, 03 Dec 2014 20:14:07 -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=hLwdaV+FCazaabNcPThDc8zjExXfalmqZuFeSpv5gRU=; b=mOFkuU8KitFDWC//Ujr3eaENTnajL1IWfj6H9GY1ABGH1sY8kTB0HOro1wEszzb3kW ggFGIbkopygcpqXlxh3+S/5Dek+IbwT4/pXi4TiyZSPgt6+CfFSytahxE5N8+/Cqfm55 /x+birgg4DOzob5k+nSQ3/P9lu836MGy/S2G+rJo1KfVwImk8rpf7zMUyt7kPm+wO7Qc X8SeqWQ/ytYlWNkPubYmRlCNXF6cWOEdTSHqJqWbjBeo/rW/TtosWyNVtkXtZd09URYg VzzGvfzj8GxtyChXiNla9ywsLrg2177b9kI3iOa2k46lXuHk4f4jVnTuPQwAQY2vcaWs 0laQ== X-Gm-Message-State: ALoCoQkhuJKySR731eM9bSCIc00C74fnoCLgDI6hqjYIOS4fu3QuvnJrM3cdHH+cRchsESkCw+sc X-Received: by 10.180.98.165 with SMTP id ej5mr18635420wib.1.1417666447316; Wed, 03 Dec 2014 20:14:07 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.242.161 with SMTP id wr1ls198299lac.48.gmail; Wed, 03 Dec 2014 20:14:06 -0800 (PST) X-Received: by 10.112.42.198 with SMTP id q6mr7146316lbl.69.1417666446968; Wed, 03 Dec 2014 20:14:06 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id q5si24614823lbp.93.2014.12.03.20.14.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Dec 2014 20:14:06 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id ge10so13777790lab.17 for ; Wed, 03 Dec 2014 20:14:06 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr7195356laz.71.1417666446892; Wed, 03 Dec 2014 20:14:06 -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 ew9csp781099lbc; Wed, 3 Dec 2014 20:14:06 -0800 (PST) X-Received: by 10.68.130.66 with SMTP id oc2mr22039249pbb.134.1417666445183; Wed, 03 Dec 2014 20:14:05 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id df1si18139882pdb.237.2014.12.03.20.14.04 for ; Wed, 03 Dec 2014 20:14:05 -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 S1752700AbaLDEOD (ORCPT + 12 others); Wed, 3 Dec 2014 23:14:03 -0500 Received: from mail-pd0-f179.google.com ([209.85.192.179]:48398 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752582AbaLDEOC (ORCPT ); Wed, 3 Dec 2014 23:14:02 -0500 Received: by mail-pd0-f179.google.com with SMTP id w10so16922944pde.38 for ; Wed, 03 Dec 2014 20:14:02 -0800 (PST) X-Received: by 10.70.47.6 with SMTP id z6mr15096449pdm.82.1417666442049; Wed, 03 Dec 2014 20:14:02 -0800 (PST) Received: from localhost ([122.166.92.172]) by mx.google.com with ESMTPSA id nz4sm4836119pdb.69.2014.12.03.20.14.00 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 03 Dec 2014 20:14:01 -0800 (PST) From: Viresh Kumar To: linux-pm@vger.kernel.org, edubezval@gmail.com Cc: linaro-kernel@lists.linaro.org, rui.zhang@intel.com, amit.daniel@samsung.com, javi.merino@arm.com, Viresh Kumar Subject: [PATCH V2 20/26] thermal: cpu_cooling: find max level during device registration Date: Thu, 4 Dec 2014 09:42:02 +0530 Message-Id: <2deba357b8ab9cead52eba262a294b0b33e29691.1417664938.git.viresh.kumar@linaro.org> 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.215.44 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: , 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 | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 2c4c485..d34cc5b 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; struct list_head node; }; @@ -283,19 +286,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; } /** @@ -385,9 +378,11 @@ __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; int ret; - if (!cpufreq_frequency_get_table(cpumask_first(clip_cpus))) { + 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); } @@ -404,6 +399,13 @@ __cpufreq_cooling_register(struct device_node *np, goto free_cdev; } + /* 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); ret = get_idr(&cpufreq_idr, &cpufreq_dev->id);