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: 41686 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F40BB244C2 for ; Fri, 28 Nov 2014 09:45:54 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id hs14sf469899lab.1 for ; Fri, 28 Nov 2014 01:45:53 -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=GpKBbPxKRcg4AV+wzTNp9rQhTx4P1HFEVrW0UAadPVo=; b=chwwab0+cEnYYahMKDVVgNk7ooEtzQkoD2cE6Bxcu2vvU0WgXQsrMpNgaP18v1rdBV ZtNuodr7Zie78MtI5NPISvJZ7qyM3kOcGQr3EFNqThUjpvc2jK/tiW28W2DbkXelPJZl Hkq0pW9fRuYDJJh1jbAXBo8QzxVWSBoYJEVeRTr+4QJSerSf+ifFXlNOuL0kifsEWlg1 BRe4PIZEs3ubwaPnglE83xDhWzmrPGJo1ZXojh6pVZ+kkOemWn5ZpgWj3KOI5htMDyQz yA10DSVppLjOgNQhS/xfCYo3IIg5RYdBbfHLzZ5lNfyNH8xGib34WpMRJbSRTutWWj9N D2rg== X-Gm-Message-State: ALoCoQn72nv8jCgXH41NMKD9pvrsb7wDxqEzA4ZEI/G9RWMmfkghgRCSOKM/gJ2/zSt/upR9i4oh X-Received: by 10.180.189.116 with SMTP id gh20mr9753675wic.2.1417167953920; Fri, 28 Nov 2014 01:45:53 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.71 with SMTP id da7ls923953lad.31.gmail; Fri, 28 Nov 2014 01:45:53 -0800 (PST) X-Received: by 10.152.205.74 with SMTP id le10mr31105537lac.96.1417167953629; Fri, 28 Nov 2014 01:45:53 -0800 (PST) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id b3si9432163laa.104.2014.11.28.01.45.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Nov 2014 01:45:53 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id s18so5462347lam.1 for ; Fri, 28 Nov 2014 01:45:53 -0800 (PST) X-Received: by 10.153.7.170 with SMTP id dd10mr42507612lad.44.1417167953535; Fri, 28 Nov 2014 01:45:53 -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 ew9csp60506lbc; Fri, 28 Nov 2014 01:45:52 -0800 (PST) X-Received: by 10.68.255.195 with SMTP id as3mr72169717pbd.38.1417167951910; Fri, 28 Nov 2014 01:45:51 -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.45.51 for ; Fri, 28 Nov 2014 01:45:51 -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 S1751761AbaK1Jpu (ORCPT + 12 others); 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-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: 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.42 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 | 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);