From patchwork Tue Apr 25 10:27:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 98188 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1879834qgf; Tue, 25 Apr 2017 03:28:44 -0700 (PDT) X-Received: by 10.84.239.8 with SMTP id w8mr37707901plk.73.1493116124824; Tue, 25 Apr 2017 03:28:44 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c129si3836718pfa.91.2017.04.25.03.28.44; Tue, 25 Apr 2017 03:28:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1429631AbdDYK2i (ORCPT + 10 others); Tue, 25 Apr 2017 06:28:38 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:35569 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1429541AbdDYK1v (ORCPT ); Tue, 25 Apr 2017 06:27:51 -0400 Received: by mail-pf0-f170.google.com with SMTP id v14so21408078pfd.2 for ; Tue, 25 Apr 2017 03:27:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=3FKmQHXJDyOjg3YeMO0kZTkp30nsbdUkwv3cJiCvk88=; b=VqYQsMwJHc0sRO+RG1NJqWofk4qAWg7try1vb4r1sn8NtMI9F7aHVLHAwoVxBshym1 lXaHqkMCPk8usNLacoZqeO+2df2RYj5Cw6O7FbmQg/AcrkXEMaSuKMhOAqfRIRUyMR4O 2TRIlbzEMhkjCSgrzBfaDlweWdueB+djkwmLI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=3FKmQHXJDyOjg3YeMO0kZTkp30nsbdUkwv3cJiCvk88=; b=nP9FNbF7b4Oeu6NatH36/Ibe9Jn4qcEYD/m5jdNMFMhdPOn7gjGEJRVPGikd3Sae2t L9PqmQvwrRH3y5VKkdFoksyKsUErH0qLlIKZip33DXv2Z3cEAyDKE9Q9gQirXJGi60BT eZxPLnp1/hpLA1OcQlQq99p1ZU4LB9vXekJNWNcABbNURPxk08gGiQX0UTARQyhIi+eP jwBkkdNs+2ofJ2kJTeWTYemBUwSUsF3QxnCHm61r3czrckKLAZnHyXyrdjHLWo180y4d fplI1UB7QwvtWhF6mKywBIeAaqJNL9z110MOkcAdRNVm5pYJ1Ji7kqgBxEwyVa8TYWq1 Eagw== X-Gm-Message-State: AN3rC/6vBUyoMows0tGoMrl0AKMr9xRwSGdb8twAa0CjKIMBA2U2OvJo 3iay8E9f5fZrunRp X-Received: by 10.84.238.137 with SMTP id v9mr37290956plk.189.1493116065633; Tue, 25 Apr 2017 03:27:45 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id q85sm35746071pfj.112.2017.04.25.03.27.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 03:27:44 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V4 05/17] thermal: cpu_cooling: remove cpufreq_cooling_get_level() Date: Tue, 25 Apr 2017 15:57:12 +0530 Message-Id: <04010983e89a99ad35fd754d3ca0577139ab8759.1493115651.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is only one user of cpufreq_cooling_get_level() and that already has pointer to the cpufreq_cdev structure. It can directly call get_level() instead and we can get rid of cpufreq_cooling_get_level(). Signed-off-by: Viresh Kumar Tested-by: Lukasz Luba --- drivers/thermal/cpu_cooling.c | 33 +-------------------------------- include/linux/cpu_cooling.h | 6 ------ 2 files changed, 1 insertion(+), 38 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index f1e784c22c5a..1f4b6a719d05 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -136,37 +136,6 @@ static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, } /** - * cpufreq_cooling_get_level - for a given cpu, return the cooling level. - * @cpu: cpu for which the level is required - * @freq: the frequency of interest - * - * This function will match the cooling level corresponding to the - * requested @freq and return it. - * - * Return: The matched cooling level on success or THERMAL_CSTATE_INVALID - * otherwise. - */ -unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) -{ - struct cpufreq_cooling_device *cpufreq_cdev; - - mutex_lock(&cooling_list_lock); - list_for_each_entry(cpufreq_cdev, &cpufreq_cdev_list, node) { - if (cpumask_test_cpu(cpu, &cpufreq_cdev->allowed_cpus)) { - unsigned long level = get_level(cpufreq_cdev, freq); - - mutex_unlock(&cooling_list_lock); - return level; - } - } - mutex_unlock(&cooling_list_lock); - - pr_err("%s: cpu:%d not part of any cooling device\n", __func__, cpu); - return THERMAL_CSTATE_INVALID; -} -EXPORT_SYMBOL_GPL(cpufreq_cooling_get_level); - -/** * cpufreq_thermal_notifier - notifier callback for cpufreq policy change. * @nb: struct notifier_block * with callback info. * @event: value showing cpufreq event for which this function invoked. @@ -697,7 +666,7 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev, normalised_power = (dyn_power * 100) / last_load; target_freq = cpu_power_to_freq(cpufreq_cdev, normalised_power); - *state = cpufreq_cooling_get_level(cpu, target_freq); + *state = get_level(cpufreq_cdev, target_freq); if (*state == THERMAL_CSTATE_INVALID) { dev_err_ratelimited(&cdev->device, "Failed to convert %dKHz for cpu %d into a cdev state\n", diff --git a/include/linux/cpu_cooling.h b/include/linux/cpu_cooling.h index c156f5082758..96c5e4c2f9c8 100644 --- a/include/linux/cpu_cooling.h +++ b/include/linux/cpu_cooling.h @@ -82,7 +82,6 @@ of_cpufreq_power_cooling_register(struct device_node *np, */ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev); -unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq); #else /* !CONFIG_CPU_THERMAL */ static inline struct thermal_cooling_device * cpufreq_cooling_register(const struct cpumask *clip_cpus) @@ -117,11 +116,6 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) { return; } -static inline -unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) -{ - return THERMAL_CSTATE_INVALID; -} #endif /* CONFIG_CPU_THERMAL */ #endif /* __CPU_COOLING_H__ */ From patchwork Tue Apr 25 10:27:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 98187 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1879747qgf; Tue, 25 Apr 2017 03:28:26 -0700 (PDT) X-Received: by 10.84.224.136 with SMTP id s8mr37486805plj.93.1493116106912; Tue, 25 Apr 2017 03:28:26 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y206si21883928pfb.368.2017.04.25.03.28.26; Tue, 25 Apr 2017 03:28:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1429585AbdDYK2Q (ORCPT + 10 others); Tue, 25 Apr 2017 06:28:16 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:33399 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1429549AbdDYK1z (ORCPT ); Tue, 25 Apr 2017 06:27:55 -0400 Received: by mail-pg0-f42.google.com with SMTP id 63so26531111pgh.0 for ; Tue, 25 Apr 2017 03:27:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=NTzDNKUrxJo+mZYQHO8GQIv2DC6SjIGm3QsFjjU5HB8=; b=SHkHbfdO6nf8Kxzv/cb9+gZ2jCmtaR8EdNgnOdEQjhB2FHkAZj9BevSWZfN4+bHUo+ Tu1mA255RJEs70sIF+qH3FGud9aMhCfX7aqWxB9Ai6r7ZgBWl4okKWoyW8tDD+/NojVp VKtbgxHUenKpXdi8Tm7SrltCFI/M44Ym1vzMk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=NTzDNKUrxJo+mZYQHO8GQIv2DC6SjIGm3QsFjjU5HB8=; b=dNQpmDf2a8/6owNN4oZU7Jy8eNtF5GznnobhOT+yokmzniypOK5P0HUyJt9+AXVmJI ivjVUKmToNQhuLAni53PO/GtGDG1hM22lN4EKa4qjO5YCMnxDpGGik0KhMTYhjfDeWkp HXH9rHgTt2dkcg1Zz266pT8bjWiIKZ9mn2/1iqq8faJzXLN0C9Xdrr5DnI0ybK+mdwFS JSIVkVWjWPpIvuv9ca/VDwFhGMLVNmv3cyfpwZ75MWrb4neAeftyYLQHQKOx0sUsRT9w UxGiFNM1sRbt7pmpsKLzDsLXRIbvfSpF7xywexmaffACTmbsyK78EAou6+LzQuCJje3k ogZg== X-Gm-Message-State: AN3rC/6ln/8CMI0WfythVQcQUvU7n0x0xK1RJoIlRwgo9AphxCyMTItC svQhD3eyTItEmc3E X-Received: by 10.99.115.30 with SMTP id o30mr28150257pgc.155.1493116069002; Tue, 25 Apr 2017 03:27:49 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id p7sm18627608pfb.125.2017.04.25.03.27.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 03:27:48 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V4 06/17] thermal: cpu_cooling: get rid of a variable in cpufreq_set_cur_state() Date: Tue, 25 Apr 2017 15:57:13 +0530 Message-Id: X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'cpu' is used at only one place and there is no need to keep a separate variable for it. Signed-off-by: Viresh Kumar Tested-by: Lukasz Luba --- drivers/thermal/cpu_cooling.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 1f4b6a719d05..002b48dc6bea 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -456,7 +456,6 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) { struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; - unsigned int cpu = cpumask_any(&cpufreq_cdev->allowed_cpus); unsigned int clip_freq; /* Request state should be less than max_level */ @@ -471,7 +470,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, cpufreq_cdev->cpufreq_state = state; cpufreq_cdev->clipped_freq = clip_freq; - cpufreq_update_policy(cpu); + cpufreq_update_policy(cpumask_any(&cpufreq_cdev->allowed_cpus)); return 0; } From patchwork Tue Apr 25 10:27:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 98198 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1880851qgf; Tue, 25 Apr 2017 03:31:33 -0700 (PDT) X-Received: by 10.84.222.8 with SMTP id w8mr37431420pls.103.1493116293894; Tue, 25 Apr 2017 03:31:33 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v37si4674233plg.227.2017.04.25.03.31.33; Tue, 25 Apr 2017 03:31:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1176616AbdDYKbZ (ORCPT + 10 others); Tue, 25 Apr 2017 06:31:25 -0400 Received: from mail-pg0-f50.google.com ([74.125.83.50]:36107 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1429567AbdDYK2G (ORCPT ); Tue, 25 Apr 2017 06:28:06 -0400 Received: by mail-pg0-f50.google.com with SMTP id g2so26438506pge.3 for ; Tue, 25 Apr 2017 03:28:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=aToqOncvUb3fhanrOlGuMX2MgJIDAzomj2BarJDd/4s=; b=aNZ8zHE4qTngh387h+qN8t0QRc7oHu6+0O9b6sIons9azAd51neC/zhDvr9vu7uSx+ BANnaiS+BiuNkdF4YgbEoSAFhzhomGbvGRisgv5k2OLjEzCWK0nF3V+P2XsCdA3aFbmv rMlOdObnLAYHd9vYftYmDhwVw6eaVU5SY+s/8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=aToqOncvUb3fhanrOlGuMX2MgJIDAzomj2BarJDd/4s=; b=VC8ZsBLbaQRIIadv9Tjd/heN1RKbBi5G9utg0GHW4BSQqkt+JSaJEuPyy4NEKoIt5m BfrKyXlr1jD4J2CzI1ETUiaZjWEfGSoM7BhCGQwJU9+A2CEr2WfnE4D+87JEQjdksY77 n6KAmd2OWAnlSRoBk0lroE7UKjep34KnaoQsVZUlrc6P3X9v1bpmGHhmzkRI1sB2s8OE IQ7ARqZXHQp+Rdb+mTVeEZ2aaN+HjJcCqRNkW7C2PXwNd1WYManQPwlP/meMK8Qdh0mV ASGw50O1JCbvEJ2imHK5fn50tRyKDFUfnRkthrK0a8MKqi0PicGt73fT86CS3dU2XJS1 OTSw== X-Gm-Message-State: AN3rC/7dm79ur1+UxHGpx5IrBA95K7OwZN+abUluOZykNXuxn22tXmAs Jg+Nkdor/hihpGk/ X-Received: by 10.99.123.7 with SMTP id w7mr14316476pgc.82.1493116079833; Tue, 25 Apr 2017 03:27:59 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id p28sm35773003pfd.53.2017.04.25.03.27.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 03:27:59 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V4 09/17] thermal: cpu_cooling: store cpufreq policy Date: Tue, 25 Apr 2017 15:57:16 +0530 Message-Id: X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cpufreq policy can be used by the cpu_cooling driver, lets store it in the cpufreq_cooling_device structure. Signed-off-by: Viresh Kumar Tested-by: Lukasz Luba --- drivers/thermal/cpu_cooling.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 55ff45c1e917..7dddc7443f5d 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -67,6 +67,7 @@ struct power_table { * registered. * @cdev: thermal_cooling_device pointer to keep track of the * registered cooling device. + * @policy: cpufreq policy. * @cpufreq_state: integer value representing the current state of cpufreq * cooling devices. * @clipped_freq: integer value representing the absolute value of the clipped @@ -91,6 +92,7 @@ struct power_table { struct cpufreq_cooling_device { int id; struct thermal_cooling_device *cdev; + struct cpufreq_policy *policy; unsigned int cpufreq_state; unsigned int clipped_freq; unsigned int max_level; @@ -760,6 +762,7 @@ __cpufreq_cooling_register(struct device_node *np, if (!cpufreq_cdev) return ERR_PTR(-ENOMEM); + cpufreq_cdev->policy = policy; num_cpus = cpumask_weight(policy->related_cpus); cpufreq_cdev->time_in_idle = kcalloc(num_cpus, sizeof(*cpufreq_cdev->time_in_idle), From patchwork Tue Apr 25 10:27:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 98195 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1880559qgf; Tue, 25 Apr 2017 03:30:50 -0700 (PDT) X-Received: by 10.98.34.212 with SMTP id p81mr28941916pfj.118.1493116250579; Tue, 25 Apr 2017 03:30:50 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y12si21872879pgo.307.2017.04.25.03.30.50; Tue, 25 Apr 2017 03:30:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946489AbdDYKan (ORCPT + 10 others); Tue, 25 Apr 2017 06:30:43 -0400 Received: from mail-pg0-f48.google.com ([74.125.83.48]:34054 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1429587AbdDYK2R (ORCPT ); Tue, 25 Apr 2017 06:28:17 -0400 Received: by mail-pg0-f48.google.com with SMTP id v1so14830395pgv.1 for ; Tue, 25 Apr 2017 03:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=MBW/0Pl7IcuDpxmCN48kkO5KwZJ3/bWHs+Ah7QYhdWQ=; b=DMyekOn3RYgacPs6TlL69X8M+ZjJd98no/JFCSGrUz/PmqLxRag8XkZKv7QSAQQqwn 2eIteMUKtzav84y48C5LzCIJn6UwwHHstqA0LCp+PPDrmZ2dY2FFRJPXvdXqrClUxOIL nsl/E+5j0orafvxo/PSopbdoMuAyHVoYZ3DSM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=MBW/0Pl7IcuDpxmCN48kkO5KwZJ3/bWHs+Ah7QYhdWQ=; b=CkWvLa6vjxNhrR6LynLxAITirQLzrpatwtVsvF0P9NiW/iDbMSc6EwAMetjWvIMmhI HyfKoK+kqosEY0gArm3yk7KNxcmXtHziUC9rsKAK89JO/xzSPxXYVhB/Urm7zWK2AW4K q900JZwJc1hARoh5jXE7n4zs4MfGMTTp3go4cQuemB04Cx6hCoPgI/WJW+pkeD9fhqD1 2z1btxQpp7ecJzIbL1SlmTJ7TttRvpdYykbSglAjfJQxImEGTvXBbW8C4VQcf6v4x8OJ PBcqUKC2uSrrfsXTVeZpOO9Ee20j7tGGYUdv0Q3RghVzUAx9zksu1iAUkr9RD1uHgXVN GdrA== X-Gm-Message-State: AN3rC/6JSplbY334FdxacGpxAWxx0Bj2K/BivAWxHfYgt1vehBtDyPPj 9rw8CTNV0ClrUIFiqqjTfw== X-Received: by 10.98.96.65 with SMTP id u62mr28450500pfb.186.1493116086349; Tue, 25 Apr 2017 03:28:06 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id x5sm35735228pfd.94.2017.04.25.03.28.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 03:28:05 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V4 11/17] thermal: cpu_cooling: get rid of 'allowed_cpus' Date: Tue, 25 Apr 2017 15:57:18 +0530 Message-Id: <570cffa784e4ea02d9ee0923814fdad3fa0a697f.1493115651.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'allowed_cpus' is a copy of policy->related_cpus and can be replaced by it directly. At some places we are only concerned about online CPUs and policy->cpus can be used there. Signed-off-by: Viresh Kumar Tested-by: Lukasz Luba --- drivers/thermal/cpu_cooling.c | 81 +++++++++++++------------------------------ 1 file changed, 25 insertions(+), 56 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index ce387f62c93e..94e7121817bf 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -74,7 +74,6 @@ struct power_table { * 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. * @node: list_head to link all cpufreq_cooling_device together. * @last_load: load measured by the latest call to cpufreq_get_requested_power() * @time_in_idle: previous reading of the absolute time that this cpu was idle @@ -97,7 +96,6 @@ struct cpufreq_cooling_device { unsigned int clipped_freq; unsigned int max_level; unsigned int *freq_table; /* In descending order */ - struct cpumask allowed_cpus; struct list_head node; u32 last_load; u64 *time_in_idle; @@ -161,7 +159,11 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, mutex_lock(&cooling_list_lock); list_for_each_entry(cpufreq_cdev, &cpufreq_cdev_list, node) { - if (!cpumask_test_cpu(policy->cpu, &cpufreq_cdev->allowed_cpus)) + /* + * A new copy of the policy is sent to the notifier and can't + * compare that directly. + */ + if (policy->cpu != cpufreq_cdev->policy->cpu) continue; /* @@ -304,7 +306,7 @@ static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev, * get_load() - get load for a cpu since last updated * @cpufreq_cdev: &struct cpufreq_cooling_device for this cpu * @cpu: cpu number - * @cpu_idx: index of the cpu in cpufreq_cdev->allowed_cpus + * @cpu_idx: index of the cpu in time_in_idle* * * Return: The average load of cpu @cpu in percentage since this * function was last called. @@ -351,7 +353,7 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_cdev, { struct dev_pm_opp *opp; unsigned long voltage; - struct cpumask *cpumask = &cpufreq_cdev->allowed_cpus; + struct cpumask *cpumask = cpufreq_cdev->policy->related_cpus; unsigned long freq_hz = freq * 1000; if (!cpufreq_cdev->plat_get_static_power || !cpufreq_cdev->cpu_dev) { @@ -468,7 +470,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, cpufreq_cdev->cpufreq_state = state; cpufreq_cdev->clipped_freq = clip_freq; - cpufreq_update_policy(cpumask_any(&cpufreq_cdev->allowed_cpus)); + cpufreq_update_policy(cpufreq_cdev->policy->cpu); return 0; } @@ -504,28 +506,18 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, int i = 0, cpu, ret; u32 static_power, dynamic_power, total_load = 0; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; + struct cpufreq_policy *policy = cpufreq_cdev->policy; u32 *load_cpu = NULL; - cpu = cpumask_any_and(&cpufreq_cdev->allowed_cpus, cpu_online_mask); - - /* - * All the CPUs are offline, thus the requested power by - * the cdev is 0 - */ - if (cpu >= nr_cpu_ids) { - *power = 0; - return 0; - } - - freq = cpufreq_quick_get(cpu); + freq = cpufreq_quick_get(policy->cpu); if (trace_thermal_power_cpu_get_power_enabled()) { - u32 ncpus = cpumask_weight(&cpufreq_cdev->allowed_cpus); + u32 ncpus = cpumask_weight(policy->related_cpus); load_cpu = kcalloc(ncpus, sizeof(*load_cpu), GFP_KERNEL); } - for_each_cpu(cpu, &cpufreq_cdev->allowed_cpus) { + for_each_cpu(cpu, policy->related_cpus) { u32 load; if (cpu_online(cpu)) @@ -550,9 +542,9 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, } if (load_cpu) { - trace_thermal_power_cpu_get_power( - &cpufreq_cdev->allowed_cpus, - freq, load_cpu, i, dynamic_power, static_power); + trace_thermal_power_cpu_get_power(policy->related_cpus, freq, + load_cpu, i, dynamic_power, + static_power); kfree(load_cpu); } @@ -581,38 +573,22 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, unsigned long state, u32 *power) { unsigned int freq, num_cpus; - cpumask_var_t cpumask; u32 static_power, dynamic_power; int ret; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; - if (!alloc_cpumask_var(&cpumask, GFP_KERNEL)) - return -ENOMEM; - - cpumask_and(cpumask, &cpufreq_cdev->allowed_cpus, cpu_online_mask); - num_cpus = cpumask_weight(cpumask); - - /* None of our cpus are online, so no power */ - if (num_cpus == 0) { - *power = 0; - ret = 0; - goto out; - } + num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus); freq = cpufreq_cdev->freq_table[state]; - if (!freq) { - ret = -EINVAL; - goto out; - } + if (!freq) + return -EINVAL; dynamic_power = cpu_freq_to_power(cpufreq_cdev, freq) * num_cpus; ret = get_static_power(cpufreq_cdev, tz, freq, &static_power); if (ret) - goto out; + return ret; *power = static_power + dynamic_power; -out: - free_cpumask_var(cpumask); return ret; } @@ -640,19 +616,14 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev, struct thermal_zone_device *tz, u32 power, unsigned long *state) { - unsigned int cpu, cur_freq, target_freq; + unsigned int cur_freq, target_freq; int ret; s32 dyn_power; u32 last_load, normalised_power, static_power; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; + struct cpufreq_policy *policy = cpufreq_cdev->policy; - cpu = cpumask_any_and(&cpufreq_cdev->allowed_cpus, cpu_online_mask); - - /* None of our cpus are online */ - if (cpu >= nr_cpu_ids) - return -ENODEV; - - cur_freq = cpufreq_quick_get(cpu); + cur_freq = cpufreq_quick_get(policy->cpu); ret = get_static_power(cpufreq_cdev, tz, cur_freq, &static_power); if (ret) return ret; @@ -667,12 +638,12 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev, if (*state == THERMAL_CSTATE_INVALID) { dev_err_ratelimited(&cdev->device, "Failed to convert %dKHz for cpu %d into a cdev state\n", - target_freq, cpu); + target_freq, policy->cpu); return -EINVAL; } - trace_thermal_power_cpu_limit(&cpufreq_cdev->allowed_cpus, - target_freq, *state, power); + trace_thermal_power_cpu_limit(policy->related_cpus, target_freq, *state, + power); return 0; } @@ -786,8 +757,6 @@ __cpufreq_cooling_register(struct device_node *np, goto free_time_in_idle_timestamp; } - cpumask_copy(&cpufreq_cdev->allowed_cpus, policy->related_cpus); - if (capacitance) { cpufreq_cdev->plat_get_static_power = plat_static_func; From patchwork Tue Apr 25 10:27:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 98190 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1880044qgf; Tue, 25 Apr 2017 03:29:28 -0700 (PDT) X-Received: by 10.84.224.70 with SMTP id a6mr37519412plt.25.1493116168793; Tue, 25 Apr 2017 03:29:28 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l12si21879097plk.280.2017.04.25.03.29.28; Tue, 25 Apr 2017 03:29:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1429682AbdDYK3N (ORCPT + 10 others); Tue, 25 Apr 2017 06:29:13 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:36355 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1176807AbdDYK2Z (ORCPT ); Tue, 25 Apr 2017 06:28:25 -0400 Received: by mail-pf0-f169.google.com with SMTP id 194so25042689pfv.3 for ; Tue, 25 Apr 2017 03:28:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=FjjJYjYds5tg+U8zgOnehCXyiKeO+B6ioBHUA40RiJ4=; b=g1JdWbQ342UyQE1EpDWUSOCrbU981vOLzhjbbb+aSqFDU4qRDqIgmSRWhTU9urG/93 egJtjAD+pmQGtmerqVfACAUZSl7bYy7xOzr0ih9iNGG8ZJ9BB6nBugnGtZObQw1+BWFB cf5dxTJ9hS+OorQiXZz77eCB5JpZ+kcP+a8lQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=FjjJYjYds5tg+U8zgOnehCXyiKeO+B6ioBHUA40RiJ4=; b=U5ByxSjvIrtHZj0Brp8nhcYMJtaRqwdLOojfXGCyYIIZA8Kc/Z0pPLNx6OPr+2hzqA VOysa5OxvyiElcxLc/POFqNk8z0p9VFDexoJgp2asDSc9JHV22rzheAILvteuCKpK9JU Ibl1+UvBCMYAJ7AmR4HLZT8De+vnHi0QUOEAr8gvpDO69lzlRZ8iBwszLWPMDTYgTojc oC98+l4J0NQXQsjE7IJw7ew6+6QHNOs+Hi2AVH9wy/zOLDHOtxBVQ8bZohwDFfPp9hmi ZvQGHklWPx0gaaYf4AM1pNkeYDIpgbS9BulYTXrVVp1B1zdQbppt52+QAD/VCCdPQGqt W3sA== X-Gm-Message-State: AN3rC/7bV+Oflr2TucgVaZiy9Qa/BbmMqiJA0nkJSE1nZARrJJhggt2G qlSVptZpm0NUtTXR X-Received: by 10.84.204.133 with SMTP id b5mr12154806ple.98.1493116089627; Tue, 25 Apr 2017 03:28:09 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id s89sm35713666pfi.79.2017.04.25.03.28.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 03:28:09 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V4 12/17] thermal: cpu_cooling: merge frequency and power tables Date: Tue, 25 Apr 2017 15:57:19 +0530 Message-Id: X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cpu_cooling driver keeps two tables: - freq_table: table of frequencies in descending order, built from policy->freq_table. - power_table: table of frequencies and power in ascending order, built from OPP table. If the OPPs are used for the CPU device then both these tables are actually built using the OPP core and should have the same frequency entries. And there is no need to keep separate tables for this. Lets merge them both. Note that the new table is in descending order of frequencies and so the 'for' loops were required to be fixed at few places to make it work. Signed-off-by: Viresh Kumar Tested-by: Lukasz Luba --- drivers/thermal/cpu_cooling.c | 153 ++++++++++++++++++------------------------ 1 file changed, 67 insertions(+), 86 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 94e7121817bf..67ec52d5f7fc 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -49,14 +49,14 @@ */ /** - * struct power_table - frequency to power conversion + * struct freq_table - frequency table along with power entries * @frequency: frequency in KHz * @power: power in mW * * This structure is built when the cooling device registers and helps - * in translating frequency to power and viceversa. + * in translating frequency to power and vice versa. */ -struct power_table { +struct freq_table { u32 frequency; u32 power; }; @@ -79,9 +79,6 @@ struct power_table { * @time_in_idle: previous reading of the absolute time that this cpu was idle * @time_in_idle_timestamp: wall time of the last invocation of * get_cpu_idle_time_us() - * @dyn_power_table: array of struct power_table for frequency to power - * conversion, sorted in ascending order. - * @dyn_power_table_entries: number of entries in the @dyn_power_table array * @cpu_dev: the cpu_device of policy->cpu. * @plat_get_static_power: callback to calculate the static power * @@ -95,13 +92,11 @@ struct cpufreq_cooling_device { unsigned int cpufreq_state; unsigned int clipped_freq; unsigned int max_level; - unsigned int *freq_table; /* In descending order */ + struct freq_table *freq_table; /* In descending order */ struct list_head node; u32 last_load; u64 *time_in_idle; u64 *time_in_idle_timestamp; - struct power_table *dyn_power_table; - int dyn_power_table_entries; struct device *cpu_dev; get_static_t plat_get_static_power; }; @@ -125,10 +120,10 @@ static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, unsigned long level; for (level = 0; level <= cpufreq_cdev->max_level; level++) { - if (freq == cpufreq_cdev->freq_table[level]) + if (freq == cpufreq_cdev->freq_table[level].frequency) return level; - if (freq > cpufreq_cdev->freq_table[level]) + if (freq > cpufreq_cdev->freq_table[level].frequency) break; } @@ -189,28 +184,25 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, } /** - * build_dyn_power_table() - create a dynamic power to frequency table - * @cpufreq_cdev: the cpufreq cooling device in which to store the table + * update_freq_table() - Update the freq table with power numbers + * @cpufreq_cdev: the cpufreq cooling device in which to update the table * @capacitance: dynamic power coefficient for these cpus * - * Build a dynamic power to frequency table for this cpu and store it - * in @cpufreq_cdev. This table will be used in cpu_power_to_freq() and - * cpu_freq_to_power() to convert between power and frequency - * efficiently. Power is stored in mW, frequency in KHz. The - * resulting table is in ascending order. + * Update the freq table with power numbers. This table will be used in + * cpu_power_to_freq() and cpu_freq_to_power() to convert between power and + * frequency efficiently. Power is stored in mW, frequency in KHz. The + * resulting table is in descending order. * * Return: 0 on success, -EINVAL if there are no OPPs for any CPUs, - * -ENOMEM if we run out of memory or -EAGAIN if an OPP was - * added/enabled while the function was executing. + * or -ENOMEM if we run out of memory. */ -static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_cdev, - u32 capacitance) +static int update_freq_table(struct cpufreq_cooling_device *cpufreq_cdev, + u32 capacitance) { - struct power_table *power_table; + struct freq_table *freq_table = cpufreq_cdev->freq_table; struct dev_pm_opp *opp; struct device *dev = NULL; - int num_opps = 0, cpu = cpufreq_cdev->policy->cpu, i, ret = 0; - unsigned long freq; + int num_opps = 0, cpu = cpufreq_cdev->policy->cpu, i; dev = get_cpu_device(cpu); if (unlikely(!dev)) { @@ -223,25 +215,32 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_cdev, if (num_opps < 0) return num_opps; - if (num_opps == 0) + /* + * The cpufreq table is also built from the OPP table and so the count + * should match. + */ + if (num_opps != cpufreq_cdev->max_level + 1) { + dev_warn(dev, "Number of OPPs not matching with max_levels\n"); return -EINVAL; + } - power_table = kcalloc(num_opps, sizeof(*power_table), GFP_KERNEL); - if (!power_table) - return -ENOMEM; - - for (freq = 0, i = 0; - opp = dev_pm_opp_find_freq_ceil(dev, &freq), !IS_ERR(opp); - freq++, i++) { - u32 freq_mhz, voltage_mv; + for (i = 0; i <= cpufreq_cdev->max_level; i++) { + unsigned long freq = freq_table[i].frequency * 1000; + u32 freq_mhz = freq_table[i].frequency / 1000; u64 power; + u32 voltage_mv; - if (i >= num_opps) { - ret = -EAGAIN; - goto free_power_table; + /* + * Find ceil frequency as 'freq' may be slightly lower than OPP + * freq due to truncation while converting to kHz. + */ + opp = dev_pm_opp_find_freq_ceil(dev, &freq); + if (IS_ERR(opp)) { + dev_err(dev, "failed to get opp for %lu frequency\n", + freq); + return -EINVAL; } - freq_mhz = freq / 1000000; voltage_mv = dev_pm_opp_get_voltage(opp) / 1000; dev_pm_opp_put(opp); @@ -252,54 +251,39 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_cdev, power = (u64)capacitance * freq_mhz * voltage_mv * voltage_mv; do_div(power, 1000000000); - /* frequency is stored in power_table in KHz */ - power_table[i].frequency = freq / 1000; - /* power is stored in mW */ - power_table[i].power = power; - } - - if (i != num_opps) { - ret = PTR_ERR(opp); - goto free_power_table; + freq_table[i].power = power; } cpufreq_cdev->cpu_dev = dev; - cpufreq_cdev->dyn_power_table = power_table; - cpufreq_cdev->dyn_power_table_entries = i; return 0; - -free_power_table: - kfree(power_table); - - return ret; } static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_cdev, u32 freq) { int i; - struct power_table *pt = cpufreq_cdev->dyn_power_table; + struct freq_table *freq_table = cpufreq_cdev->freq_table; - for (i = 1; i < cpufreq_cdev->dyn_power_table_entries; i++) - if (freq < pt[i].frequency) + for (i = 1; i <= cpufreq_cdev->max_level; i++) + if (freq > freq_table[i].frequency) break; - return pt[i - 1].power; + return freq_table[i - 1].power; } static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev, u32 power) { int i; - struct power_table *pt = cpufreq_cdev->dyn_power_table; + struct freq_table *freq_table = cpufreq_cdev->freq_table; - for (i = 1; i < cpufreq_cdev->dyn_power_table_entries; i++) - if (power < pt[i].power) + for (i = 1; i <= cpufreq_cdev->max_level; i++) + if (power > freq_table[i].power) break; - return pt[i - 1].frequency; + return freq_table[i - 1].frequency; } /** @@ -466,7 +450,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, if (cpufreq_cdev->cpufreq_state == state) return 0; - clip_freq = cpufreq_cdev->freq_table[state]; + clip_freq = cpufreq_cdev->freq_table[state].frequency; cpufreq_cdev->cpufreq_state = state; cpufreq_cdev->clipped_freq = clip_freq; @@ -579,7 +563,7 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus); - freq = cpufreq_cdev->freq_table[state]; + freq = cpufreq_cdev->freq_table[state].frequency; if (!freq) return -EINVAL; @@ -757,31 +741,20 @@ __cpufreq_cooling_register(struct device_node *np, goto free_time_in_idle_timestamp; } - if (capacitance) { - cpufreq_cdev->plat_get_static_power = plat_static_func; - - ret = build_dyn_power_table(cpufreq_cdev, capacitance); - if (ret) { - cdev = ERR_PTR(ret); - goto free_table; - } - - cooling_ops = &cpufreq_power_cooling_ops; - } else { - cooling_ops = &cpufreq_cooling_ops; - } - ret = ida_simple_get(&cpufreq_ida, 0, 0, GFP_KERNEL); if (ret < 0) { cdev = ERR_PTR(ret); - goto free_power_table; + goto free_table; } cpufreq_cdev->id = ret; + snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", + cpufreq_cdev->id); + /* Fill freq-table in descending order of frequencies */ for (i = 0, freq = -1; i <= cpufreq_cdev->max_level; i++) { freq = find_next_max(policy->freq_table, freq); - cpufreq_cdev->freq_table[i] = freq; + cpufreq_cdev->freq_table[i].frequency = freq; /* Warn for duplicate entries */ if (!freq) @@ -790,15 +763,26 @@ __cpufreq_cooling_register(struct device_node *np, pr_debug("%s: freq:%u KHz\n", __func__, freq); } - snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", - cpufreq_cdev->id); + if (capacitance) { + cpufreq_cdev->plat_get_static_power = plat_static_func; + + ret = update_freq_table(cpufreq_cdev, capacitance); + if (ret) { + cdev = ERR_PTR(ret); + goto remove_ida; + } + + cooling_ops = &cpufreq_power_cooling_ops; + } else { + cooling_ops = &cpufreq_cooling_ops; + } cdev = thermal_of_cooling_device_register(np, dev_name, cpufreq_cdev, cooling_ops); if (IS_ERR(cdev)) goto remove_ida; - cpufreq_cdev->clipped_freq = cpufreq_cdev->freq_table[0]; + cpufreq_cdev->clipped_freq = cpufreq_cdev->freq_table[0].frequency; cpufreq_cdev->cdev = cdev; mutex_lock(&cooling_list_lock); @@ -815,8 +799,6 @@ __cpufreq_cooling_register(struct device_node *np, remove_ida: ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id); -free_power_table: - kfree(cpufreq_cdev->dyn_power_table); free_table: kfree(cpufreq_cdev->freq_table); free_time_in_idle_timestamp: @@ -965,7 +947,6 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) thermal_cooling_device_unregister(cpufreq_cdev->cdev); ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id); - kfree(cpufreq_cdev->dyn_power_table); kfree(cpufreq_cdev->time_in_idle_timestamp); kfree(cpufreq_cdev->time_in_idle); kfree(cpufreq_cdev->freq_table); From patchwork Tue Apr 25 10:27:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 98189 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1879960qgf; Tue, 25 Apr 2017 03:29:10 -0700 (PDT) X-Received: by 10.99.103.193 with SMTP id b184mr28445103pgc.35.1493116150795; Tue, 25 Apr 2017 03:29:10 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e74si21923809pfk.123.2017.04.25.03.29.10; Tue, 25 Apr 2017 03:29:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1429667AbdDYK3B (ORCPT + 10 others); Tue, 25 Apr 2017 06:29:01 -0400 Received: from mail-pf0-f173.google.com ([209.85.192.173]:35662 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1429602AbdDYK2X (ORCPT ); Tue, 25 Apr 2017 06:28:23 -0400 Received: by mail-pf0-f173.google.com with SMTP id v14so21412645pfd.2 for ; Tue, 25 Apr 2017 03:28:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=0Jlmf4FuluAnQVKoycN7UYrWlFocEoPFkctRntRNylA=; b=O2pSkFvkI7E0VY5/bL+e3UNRV78F4w+nU+y/CEjBGPIKNG/AFjdZBQD5Nhbmrs7BCj hI+8GiyWqQaKFNro+inrVNSopfabvlncgGuFALkAeumcsByISw+Bq/wIOn9sAx07AjvZ 3m1FbW/6vzZvIzsu9ga2M744TlxHPyNSIpPE0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=0Jlmf4FuluAnQVKoycN7UYrWlFocEoPFkctRntRNylA=; b=I6cpYWBSQFjRk29UN1ANCPtop0kJQSBcTXOtpE+F7thzCxc/0yq8ZSyFk1TkWVn8kg i/UGylejtIC7kfO5Mg6jfj9PT4Gt5sqQCheFt6TV2hzKFn99mHWnGmrRpt0v8zP8mPiK L5om6cPoPpcADdTyK9QVKXJXw1QOkDJe9hsTALtKU2Z2l+gZIrv9ABsiqsZX0rv/qhEH i5K6h82dyBSZ18oJ9Y5vyw9jnc2XQUBhixR2p06sF+A7QrlaO5E0bVAZ20MhQvVrwPK2 Hi9j33m5HJyz6/CvlVllkWG1e0YUfHMVW99N4pny3ITS81SL+v7Yu3l5ItEfVI4O/f3r Mhow== X-Gm-Message-State: AN3rC/6mOIUHJXuQuuA3dwfZrmfZe5bCFD2kcOhBfP7yWMW59QXfM54V 68iCbrM/9N0IK+hU X-Received: by 10.98.90.6 with SMTP id o6mr9509512pfb.101.1493116092855; Tue, 25 Apr 2017 03:28:12 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id e71sm21681554pgc.17.2017.04.25.03.28.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 03:28:12 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V4 13/17] thermal: cpu_cooling: create structure for idle time stats Date: Tue, 25 Apr 2017 15:57:20 +0530 Message-Id: X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We keep two arrays for idle time stats and allocate memory for them separately. It would be much easier to follow if we create an array of idle stats structure instead and allocate it once. Signed-off-by: Viresh Kumar Tested-by: Lukasz Luba --- drivers/thermal/cpu_cooling.c | 53 ++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 28 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 67ec52d5f7fc..11735dba1456 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -62,6 +62,16 @@ struct freq_table { }; /** + * struct time_in_idle - Idle time stats + * @time: previous reading of the absolute time that this cpu was idle + * @timestamp: wall time of the last invocation of get_cpu_idle_time_us() + */ +struct time_in_idle { + u64 time; + u64 timestamp; +}; + +/** * struct cpufreq_cooling_device - data for cooling device with cpufreq * @id: unique integer value corresponding to each cpufreq_cooling_device * registered. @@ -76,9 +86,7 @@ struct freq_table { * cpufreq frequencies. * @node: list_head to link all cpufreq_cooling_device together. * @last_load: load measured by the latest call to cpufreq_get_requested_power() - * @time_in_idle: previous reading of the absolute time that this cpu was idle - * @time_in_idle_timestamp: wall time of the last invocation of - * get_cpu_idle_time_us() + * @idle_time: idle time stats * @cpu_dev: the cpu_device of policy->cpu. * @plat_get_static_power: callback to calculate the static power * @@ -95,8 +103,7 @@ struct cpufreq_cooling_device { struct freq_table *freq_table; /* In descending order */ struct list_head node; u32 last_load; - u64 *time_in_idle; - u64 *time_in_idle_timestamp; + struct time_in_idle *idle_time; struct device *cpu_dev; get_static_t plat_get_static_power; }; @@ -300,18 +307,19 @@ static u32 get_load(struct cpufreq_cooling_device *cpufreq_cdev, int cpu, { u32 load; u64 now, now_idle, delta_time, delta_idle; + struct time_in_idle *idle_time = &cpufreq_cdev->idle_time[cpu_idx]; now_idle = get_cpu_idle_time(cpu, &now, 0); - delta_idle = now_idle - cpufreq_cdev->time_in_idle[cpu_idx]; - delta_time = now - cpufreq_cdev->time_in_idle_timestamp[cpu_idx]; + delta_idle = now_idle - idle_time->time; + delta_time = now - idle_time->timestamp; if (delta_time <= delta_idle) load = 0; else load = div64_u64(100 * (delta_time - delta_idle), delta_time); - cpufreq_cdev->time_in_idle[cpu_idx] = now_idle; - cpufreq_cdev->time_in_idle_timestamp[cpu_idx] = now; + idle_time->time = now_idle; + idle_time->timestamp = now; return load; } @@ -715,22 +723,14 @@ __cpufreq_cooling_register(struct device_node *np, cpufreq_cdev->policy = policy; num_cpus = cpumask_weight(policy->related_cpus); - cpufreq_cdev->time_in_idle = kcalloc(num_cpus, - sizeof(*cpufreq_cdev->time_in_idle), - GFP_KERNEL); - if (!cpufreq_cdev->time_in_idle) { + cpufreq_cdev->idle_time = kcalloc(num_cpus, + sizeof(*cpufreq_cdev->idle_time), + GFP_KERNEL); + if (!cpufreq_cdev->idle_time) { cdev = ERR_PTR(-ENOMEM); goto free_cdev; } - cpufreq_cdev->time_in_idle_timestamp = - kcalloc(num_cpus, sizeof(*cpufreq_cdev->time_in_idle_timestamp), - GFP_KERNEL); - if (!cpufreq_cdev->time_in_idle_timestamp) { - cdev = ERR_PTR(-ENOMEM); - goto free_time_in_idle; - } - /* max_level is an index, not a counter */ cpufreq_cdev->max_level = i - 1; @@ -738,7 +738,7 @@ __cpufreq_cooling_register(struct device_node *np, GFP_KERNEL); if (!cpufreq_cdev->freq_table) { cdev = ERR_PTR(-ENOMEM); - goto free_time_in_idle_timestamp; + goto free_idle_time; } ret = ida_simple_get(&cpufreq_ida, 0, 0, GFP_KERNEL); @@ -801,10 +801,8 @@ __cpufreq_cooling_register(struct device_node *np, ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id); free_table: kfree(cpufreq_cdev->freq_table); -free_time_in_idle_timestamp: - kfree(cpufreq_cdev->time_in_idle_timestamp); -free_time_in_idle: - kfree(cpufreq_cdev->time_in_idle); +free_idle_time: + kfree(cpufreq_cdev->idle_time); free_cdev: kfree(cpufreq_cdev); return cdev; @@ -947,8 +945,7 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) thermal_cooling_device_unregister(cpufreq_cdev->cdev); ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id); - kfree(cpufreq_cdev->time_in_idle_timestamp); - kfree(cpufreq_cdev->time_in_idle); + kfree(cpufreq_cdev->idle_time); kfree(cpufreq_cdev->freq_table); kfree(cpufreq_cdev); } From patchwork Tue Apr 25 10:27:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 98194 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1880465qgf; Tue, 25 Apr 2017 03:30:36 -0700 (PDT) X-Received: by 10.98.36.202 with SMTP id k71mr2516298pfk.156.1493116236603; Tue, 25 Apr 2017 03:30:36 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p19si21860772pgd.368.2017.04.25.03.30.36; Tue, 25 Apr 2017 03:30:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1429713AbdDYKa3 (ORCPT + 10 others); Tue, 25 Apr 2017 06:30:29 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:36387 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1429592AbdDYK2U (ORCPT ); Tue, 25 Apr 2017 06:28:20 -0400 Received: by mail-pf0-f181.google.com with SMTP id 194so25044408pfv.3 for ; Tue, 25 Apr 2017 03:28:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=gmcuKfAaTwE6fjQLuoSrANA8JXr4pACdiTJxT/ybg4w=; b=iGoPTHCsj1kux1Qm0opb0hTH+91WwB6ZlM6bQvCGGfAkaqg0btlJTmfHACf9jj1ppj FNY+z7OHaMQ+ECoP1FxHuRpo469B/p4jXtADqz65UIuuqE4EjrX/DxMIESTGROgIYFS9 2K/J/sDh7efmkNA96zoXaSCEZZwyo+Vznd5Ps= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=gmcuKfAaTwE6fjQLuoSrANA8JXr4pACdiTJxT/ybg4w=; b=IfGLgS89Z582yebbYyF5+/XFWfUunBfF8rVKVtI2ytC7eCoChACxDnrjUebSiUjFXy qw0O1LtHYizIj+MRQcJxBIQbyKgibsJhhQ6kNoU/zHvX8r7lpJvWb3EueUVAYd8zXF6i DKHnBXw9fMuwM8OS5tHPZcj44Buk/uaEOUMSo22KLz2Yf6dyD6Ws6kd1BTEA+7f2mZ4W FGg1msJFf627Mu1gv4J8iCNSatpSV0+pPRD/IVM8J6fOMsGLveh2jb94Nd+zeONVPRA6 KOMKjHD2+dLsO9tAO7i99R4RcLQZf28iljGAXqzfdgJZy4hmyoA4xVOcEMFJ6vngTAOT na5w== X-Gm-Message-State: AN3rC/59zXUiMPTzGqej9X69DdGP+6A30Se9O3BIOjRGCRexrp5sBymc AArrK7/Yb6tfzDdI X-Received: by 10.98.215.94 with SMTP id v30mr28039348pfl.121.1493116099528; Tue, 25 Apr 2017 03:28:19 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id f6sm35746469pfe.57.2017.04.25.03.28.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 03:28:18 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V4 15/17] thermal: cpu_cooling: don't store cpu_dev in cpufreq_cdev Date: Tue, 25 Apr 2017 15:57:22 +0530 Message-Id: <95fe301b41364b0b5316ab270698a40e88b7fc66.1493115651.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'cpu_dev' is used by only one function, get_static_power(), and it wouldn't be time consuming to get the cpu device structure within it. This would help removing cpu_dev from struct cpufreq_cooling_device. Signed-off-by: Viresh Kumar Tested-by: Lukasz Luba --- drivers/thermal/cpu_cooling.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 2c2d76ac04c3..bfa9731e7cdb 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -87,7 +87,6 @@ struct time_in_idle { * @node: list_head to link all cpufreq_cooling_device together. * @last_load: load measured by the latest call to cpufreq_get_requested_power() * @idle_time: idle time stats - * @cpu_dev: the cpu_device of policy->cpu. * @plat_get_static_power: callback to calculate the static power * * This structure is required for keeping information of each registered @@ -104,7 +103,6 @@ struct cpufreq_cooling_device { struct list_head node; u32 last_load; struct time_in_idle *idle_time; - struct device *cpu_dev; get_static_t plat_get_static_power; }; @@ -259,8 +257,6 @@ static int update_freq_table(struct cpufreq_cooling_device *cpufreq_cdev, freq_table[i].power = power; } - cpufreq_cdev->cpu_dev = dev; - return 0; } @@ -342,19 +338,22 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_cdev, { struct dev_pm_opp *opp; unsigned long voltage; - struct cpumask *cpumask = cpufreq_cdev->policy->related_cpus; + struct cpufreq_policy *policy = cpufreq_cdev->policy; + struct cpumask *cpumask = policy->related_cpus; unsigned long freq_hz = freq * 1000; + struct device *dev; - if (!cpufreq_cdev->plat_get_static_power || !cpufreq_cdev->cpu_dev) { + if (!cpufreq_cdev->plat_get_static_power) { *power = 0; return 0; } - opp = dev_pm_opp_find_freq_exact(cpufreq_cdev->cpu_dev, freq_hz, - true); + dev = get_cpu_device(policy->cpu); + WARN_ON(!dev); + + opp = dev_pm_opp_find_freq_exact(dev, freq_hz, true); if (IS_ERR(opp)) { - dev_warn_ratelimited(cpufreq_cdev->cpu_dev, - "Failed to find OPP for frequency %lu: %ld\n", + dev_warn_ratelimited(dev, "Failed to find OPP for frequency %lu: %ld\n", freq_hz, PTR_ERR(opp)); return -EINVAL; } @@ -363,8 +362,7 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_cdev, dev_pm_opp_put(opp); if (voltage == 0) { - dev_err_ratelimited(cpufreq_cdev->cpu_dev, - "Failed to get voltage for frequency %lu\n", + dev_err_ratelimited(dev, "Failed to get voltage for frequency %lu\n", freq_hz); return -EINVAL; } From patchwork Tue Apr 25 10:27:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 98192 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1880206qgf; Tue, 25 Apr 2017 03:29:59 -0700 (PDT) X-Received: by 10.99.145.200 with SMTP id l191mr28046620pge.123.1493116199170; Tue, 25 Apr 2017 03:29:59 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h15si21874159plk.313.2017.04.25.03.29.58; Tue, 25 Apr 2017 03:29:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946477AbdDYK3q (ORCPT + 10 others); Tue, 25 Apr 2017 06:29:46 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:35698 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1176469AbdDYK2m (ORCPT ); Tue, 25 Apr 2017 06:28:42 -0400 Received: by mail-pf0-f170.google.com with SMTP id v14so21414448pfd.2 for ; Tue, 25 Apr 2017 03:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=JfbMSbicd9dGkyTY35BPm2YPIqRBgsjujao2cuz+Dbs=; b=YRwNmcagKWHP1Dx3eSKFoIbzViyM7Pp4uv5e9u5Y7/X/NycU8+FAaPb3Ox/9OsVQWa M/AWG7Cd1BjEd6am6NR6b/0Z0ykgVFX7a/qJB6SRpI33K2ICOMLRdbozCAf28y2Q1I8H EAdN1D7neEUo+HDZArykydSOnwzYsWnwrYe7g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=JfbMSbicd9dGkyTY35BPm2YPIqRBgsjujao2cuz+Dbs=; b=Bfv4QP3VJKgRekXRJ2qs9MkDNKqOvNqvlTgnGFsnu2dVA0pd+u/8POTglP5D59S2Rl tGWlBDUmY2buRmvjxZMtvKIU/VHrv/VrVy2l5QzIcZexB1D8otkyfH1mwPnfdyNIP61Z TkBk+S6qvx/Y+6H8urgAo+I7h2Og1wI1moKW7YniSXvzIfPAFJ1RGpnHltvVauw7WxCh e+evipRbnRKgSSBuPsHmUKxXjO4b+h3nRqc5vMoVSnOcfH6J2UF4VzaQFCTYk8fY3byB C91CB0A+PDMJmGye8xr3Gwd1yOSWWzDUqj2DzVisUIuFNNzuelyiliKI+s2gZFuXbH4U IVOw== X-Gm-Message-State: AN3rC/5gBlSrGG1KYCWpiNwTC+EgSsG4asu6shYKC3rinQEo6sD9dnF1 gGTs0ZCG3qxIhCUL X-Received: by 10.99.6.14 with SMTP id 14mr27548224pgg.83.1493116102805; Tue, 25 Apr 2017 03:28:22 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id e13sm35763300pfb.30.2017.04.25.03.28.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 03:28:22 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V4 16/17] thermal: cpu_cooling: 'freq' can't be zero in cpufreq_state2power() Date: Tue, 25 Apr 2017 15:57:23 +0530 Message-Id: <98df049ab5f1d13ebb497e922229f0e8b8160606.1493115651.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The frequency table shouldn't have any zero frequency entries and so such a check isn't required. Though it would be better to make sure 'state' is within limits. Signed-off-by: Viresh Kumar Tested-by: Lukasz Luba --- drivers/thermal/cpu_cooling.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index bfa9731e7cdb..9cbf7bdbeb7a 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -564,12 +564,13 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, int ret; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; + /* Request state should be less than max_level */ + if (WARN_ON(state > cpufreq_cdev->max_level)) + return -EINVAL; + num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus); freq = cpufreq_cdev->freq_table[state].frequency; - if (!freq) - return -EINVAL; - dynamic_power = cpu_freq_to_power(cpufreq_cdev, freq) * num_cpus; ret = get_static_power(cpufreq_cdev, tz, freq, &static_power); if (ret)