From patchwork Fri Nov 28 09:44:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 41692 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CBB02244C2 for ; Fri, 28 Nov 2014 09:46:19 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id r20sf4054912wiv.5 for ; Fri, 28 Nov 2014 01:46:19 -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=qv69VHxBBBjZZr5j0gsNqxSSkZjrkPdX2UQYs2D+9bg=; b=Y8OqdRfs1KtvCv9N5N7yt2XObFP/9Goowag/J4fGeHQhTU2vLYWifjwAVC6a7/S/IC PbbU/AFRWyfbJmQTlO0n/tf3cr/sOkNtxLzAt2LLvl2cXsaoXTjGYL32E042X+TrhNm+ +kZCideUclLyEB2gbTILKpxwoCO08IgNTWmRc4KX/BHjV3+qQF0zgKOmuu5beOpOsUmP EpE0d0mWjw2/cf5ud8T03aWlJwglinYK5nQYyRIEpp0+ZyYouf6/Z1TyP6W+LbV8zUyP MWkaB437VLZiF/HGZjTnPq5vwhjYqJavrjZ3Jl7vLTIbLgdrOSzluyi7jd2UXzf7I2LV 3zCA== X-Gm-Message-State: ALoCoQl4SY/vKUf58ct8Zu1MTGV3cK9H7hrT2ohtV6XHKMHRl8YmKq14yfwoi2cko2DBkgOBFLIH X-Received: by 10.152.18.136 with SMTP id w8mr6370456lad.5.1417167979097; Fri, 28 Nov 2014 01:46:19 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.134 with SMTP id ay6ls90169lab.107.gmail; Fri, 28 Nov 2014 01:46:18 -0800 (PST) X-Received: by 10.152.2.41 with SMTP id 9mr42069029lar.47.1417167978952; Fri, 28 Nov 2014 01:46:18 -0800 (PST) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id uf7si9437505lac.99.2014.11.28.01.46.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Nov 2014 01:46:18 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id gq15so5332435lab.4 for ; Fri, 28 Nov 2014 01:46:18 -0800 (PST) X-Received: by 10.152.37.69 with SMTP id w5mr42243053laj.67.1417167978858; Fri, 28 Nov 2014 01:46:18 -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 ew9csp60550lbc; Fri, 28 Nov 2014 01:46:16 -0800 (PST) X-Received: by 10.68.160.66 with SMTP id xi2mr71833268pbb.132.1417167975334; Fri, 28 Nov 2014 01:46:15 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gv6si15272421pac.208.2014.11.28.01.46.14 for ; Fri, 28 Nov 2014 01:46:15 -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 S1751780AbaK1JqN (ORCPT + 12 others); Fri, 28 Nov 2014 04:46:13 -0500 Received: from mail-pd0-f177.google.com ([209.85.192.177]:61415 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751394AbaK1JqM (ORCPT ); Fri, 28 Nov 2014 04:46:12 -0500 Received: by mail-pd0-f177.google.com with SMTP id ft15so6377510pdb.36 for ; Fri, 28 Nov 2014 01:46:12 -0800 (PST) X-Received: by 10.66.191.135 with SMTP id gy7mr71485240pac.95.1417167971915; Fri, 28 Nov 2014 01:46:11 -0800 (PST) Received: from localhost ([122.167.111.40]) by mx.google.com with ESMTPSA id al4sm9379747pbc.19.2014.11.28.01.46.10 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 28 Nov 2014 01:46:11 -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 25/26] cpu_cooling: Use cpufreq_dev->freq_table for finding level/freq Date: Fri, 28 Nov 2014 15:14:19 +0530 Message-Id: <8c0412592bfd5524e638252a42edaf08f81f0976.1417167599.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.45 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: , get_property() was an over complicated beast with BUGs. It used to believe that cpufreq table is present in ascending or descending order, which might not always be true. Previous patch has created another freq table in descending order for us and we better use it now. With that get_property() simply goes away and another helper get_level() comes in. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 96 +++++++------------------------------------ 1 file changed, 14 insertions(+), 82 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 9a4a323..db4c001 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -80,85 +80,27 @@ static struct cpufreq_cooling_device *notify_device; /* Below code defines functions to be used for cpufreq as cooling device */ -enum cpufreq_cooling_property { - GET_LEVEL, - GET_FREQ, -}; - /** - * get_property - fetch a property of interest for a given cpu. + * get_level: Find the level for a particular frequency * @cpufreq_dev: cpufreq_dev for which the property is required - * @input: query parameter - * @output: query return - * @property: type of query (frequency, level) - * - * This is the common function to - * 1. translate frequency to cooling state - * 2. translate cooling state to frequency + * @freq: Frequency * - * Note that the code may be not in good shape - * but it is written in this way in order to: - * a) reduce duplicate code as most of the code can be shared. - * b) make sure the logic is consistent when translating between - * cooling states and frequencies. - * - * Return: 0 on success, -EINVAL when invalid parameters are passed. + * Returns: level on success, THERMAL_CSTATE_INVALID on error. */ -static int get_property(struct cpufreq_cooling_device *cpufreq_dev, - unsigned long input, unsigned int *output, - enum cpufreq_cooling_property property) +static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_dev, + unsigned int freq) { - int i; - unsigned long level = 0; - unsigned int freq = CPUFREQ_ENTRY_INVALID; - int descend = -1; - struct cpufreq_frequency_table *pos, *table; - - if (!output) - return -EINVAL; + unsigned long level; - table = cpufreq_frequency_get_table(cpumask_first(&cpufreq_dev->allowed_cpus)); - if (!table) - return -EINVAL; + for (level = 0; level <= cpufreq_dev->max_level; level++) { + if (freq == cpufreq_dev->freq_table[level]) + return level; - cpufreq_for_each_valid_entry(pos, table) { - /* ignore duplicate entry */ - if (freq == pos->frequency) - continue; - - /* get the frequency order */ - if (freq != CPUFREQ_ENTRY_INVALID && descend == -1) - descend = freq > pos->frequency; - - freq = pos->frequency; + if (freq > cpufreq_dev->freq_table[level]) + break; } - if (property == GET_FREQ) - level = descend ? input : (cpufreq_dev->max_level - input); - - i = 0; - cpufreq_for_each_valid_entry(pos, table) { - /* ignore duplicate entry */ - if (freq == pos->frequency) - continue; - - /* now we have a valid frequency entry */ - freq = pos->frequency; - - if (property == GET_LEVEL && (unsigned int)input == freq) { - /* get level by frequency */ - *output = descend ? i : (cpufreq_dev->max_level - i); - return 0; - } - if (property == GET_FREQ && level == i) { - /* get frequency by level */ - *output = freq; - return 0; - } - i++; - } - - return -EINVAL; + return THERMAL_CSTATE_INVALID; } /** @@ -179,14 +121,8 @@ unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) mutex_lock(&cooling_cpufreq_lock); list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, head) { if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) { - unsigned int val; - mutex_unlock(&cooling_cpufreq_lock); - if (get_property(cpufreq_dev, (unsigned long)freq, &val, - GET_LEVEL)) - return THERMAL_CSTATE_INVALID; - - return (unsigned long)val; + return get_level(cpufreq_dev, freq); } } mutex_unlock(&cooling_cpufreq_lock); @@ -289,16 +225,12 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; unsigned int cpu = cpumask_any(&cpufreq_device->allowed_cpus); unsigned int clip_freq; - int ret = 0; /* Check if the old cooling action is same as new cooling action */ if (cpufreq_device->cpufreq_state == state) return 0; - ret = get_property(cpufreq_device, state, &clip_freq, GET_FREQ); - if (ret) - return ret; - + clip_freq = cpufreq_device->freq_table[state]; cpufreq_device->cpufreq_state = state; cpufreq_device->cpufreq_val = clip_freq; notify_device = cpufreq_device;