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: 5435191 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 654809F1D4 for ; Thu, 4 Dec 2014 04:14:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 62DE720120 for ; Thu, 4 Dec 2014 04:14:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D7472024F for ; Thu, 4 Dec 2014 04:14:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752700AbaLDEOD (ORCPT ); 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-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=TAFZpxPlkJq8o2oXfaD8qdT8hL37yEm2geYzZYz/zWY=; b=Ll0BCe2AY5XJ1GuzPQQ9KYC80yqCpR4F3zsJBoWTSM3Cj+8hGAQc9n2siaUCSrRuje LcdpqmnavRsWEX3CB1Qag7lgthrsxjt3sj0UufCkT4tyoEc/G/D9bl6Q+ioAVyz9GzRV 2bURJPlPsrazCR2lf3MzvVGMcrA8zjoxpwjARJ9aLe5Llqh95sSAgwNjOhJumZkcc1rD OSESjtdWPXmvQO/UIOnBM01rwdSD6KzeHvPHOxzP/g+u4MuS298DmyMsmIOIfO3/FNpW 460vAIs3JlvImciWMSHmTu9lsHOxtOnNG7fNqPvqwoPEzkKpaeT7HMYqOhnN6JWtpJiH /L7A== X-Gm-Message-State: ALoCoQmDOB9dJ9ipF+5Ob+2ZV7remWL1V8rXMJy+90afnRaWMP6mQVb3R8VrTfQ12EW3U28Hl8MF 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: 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 | 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);