From patchwork Wed Apr 19 05:28:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97606 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp160132qgf; Tue, 18 Apr 2017 22:34:51 -0700 (PDT) X-Received: by 10.98.17.92 with SMTP id z89mr1229005pfi.185.1492580091378; Tue, 18 Apr 2017 22:34:51 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91si1301211plh.326.2017.04.18.22.34.51; Tue, 18 Apr 2017 22:34:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1759843AbdDSFar (ORCPT + 12 others); Wed, 19 Apr 2017 01:30:47 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:35799 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759808AbdDSFam (ORCPT ); Wed, 19 Apr 2017 01:30:42 -0400 Received: by mail-pf0-f180.google.com with SMTP id v14so3352875pfd.2 for ; Tue, 18 Apr 2017 22:30: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=0neSwm3GeunsykDqJ2pcbUNZIJIHjCKvlI0nhtWjVKo=; b=HHKjuE70h+ddykbYntZ0mywSl/YExx3iadZxxl1KlaORusvi8VWbFQyOh8HltBlK3m mTTqst1BlgJHVBuNuDPZHKQeBN/D5gP2fOxxjEZ/hKnCcnBhuycxcMfOnqynmIjt+7Xb 3jQLxwOuPmoaoNjOwXZXU0OwA1Sqwbr5pAHEE= 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=0neSwm3GeunsykDqJ2pcbUNZIJIHjCKvlI0nhtWjVKo=; b=S/ugBdLAR0QMmghQ0SGxQomnv3lXD0HOvlOMIsA65CEvbP8WQwlrqoq9/S681qtR3q 5/D8MQ7Pli3RWhMHS0f7J36en5N+6QZjVRWYnWzprrYfTSbuzJisPN24breMGFtcFbo3 xJg1qXUVUPDBpqhgHmgZd/RAVujbgBceugUQjSWYjH/98PCAmBx4X/20ryt2+Df4pEqL anHEm/ATZ0Gwns4TM4uAUsECgQJ27eiTcmnz5l6fJcSRH+O5YsFCwGnyUP5pyWl5+5L+ R0zp9D4FEeNipwEt0pb56VVgD5PkBnKY7r6CEu17MjNJGK7njWnpogUb/6pCR6OQ0LW1 Mk0w== X-Gm-Message-State: AN3rC/78zPAdKNFhgh+H97PNs575EqFyvJaPy5A0c5kh9yqEdoInDNbC ABcI8TTPItduLWqM X-Received: by 10.98.79.23 with SMTP id d23mr1209934pfb.56.1492579840338; Tue, 18 Apr 2017 22:30:40 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id a187sm1659243pfa.59.2017.04.18.22.30.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:30:39 -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 V3 02/17] thermal: cpu_cooling: rearrange globals Date: Wed, 19 Apr 2017 10:58:57 +0530 Message-Id: <82d7a271bde0f9e4d5debd10a42ffb67b31aedad.1492579345.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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Just to make it look better. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index be29489dd247..ce94aafed25d 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -105,8 +105,8 @@ struct cpufreq_cooling_device { struct device *cpu_dev; get_static_t plat_get_static_power; }; -static DEFINE_IDA(cpufreq_ida); +static DEFINE_IDA(cpufreq_ida); static DEFINE_MUTEX(cooling_list_lock); static LIST_HEAD(cpufreq_dev_list); From patchwork Wed Apr 19 05:28:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97591 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159142qgf; Tue, 18 Apr 2017 22:30:54 -0700 (PDT) X-Received: by 10.84.214.143 with SMTP id j15mr1569386pli.6.1492579854257; Tue, 18 Apr 2017 22:30:54 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d8si1297031pfl.318.2017.04.18.22.30.54; Tue, 18 Apr 2017 22:30:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1759841AbdDSFat (ORCPT + 12 others); Wed, 19 Apr 2017 01:30:49 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:33497 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759832AbdDSFap (ORCPT ); Wed, 19 Apr 2017 01:30:45 -0400 Received: by mail-pg0-f41.google.com with SMTP id 63so7407818pgh.0 for ; Tue, 18 Apr 2017 22:30:44 -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=1vQDmXyENAS84ylTzV3bSIXJMXMUf4DjC9tPDdgar30=; b=j5JLL1dgwOXAb3uzNwnoCcMAPObZFN73gihVhXvGn0Frl//jzWRWcCDbDTAcQBk891 1/rRTHOpGE/XpW44SQfWypHSofuQGaMiKhBGwViTuUEc03ErV6Jq9FNWrS9tdDX+qYN3 JFeD78/XnKQDPofbNk92/gVyOQh8kuhSe0eYE= 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=1vQDmXyENAS84ylTzV3bSIXJMXMUf4DjC9tPDdgar30=; b=RngpIB/+Jn867KFgSl17dUKfEP/2a6DkUztxxtdbhwBAsnlBN1JYnT2vcwjmy6KtAV BWLxFYq83abDFMNu5EzT6xqC3W46c74Vg8tRQ1GIM1gB4aJ8EPCDds/YAbpqjWWJhPAo 3GtV8wWBB1yyOmCr4GrYze5sBng0T0coPb4iLQy08eHDHOTqdcz8FN9i1q5a4Y8rXeF9 lec7Em3gTF3z4lt1hzbkKXbSMWGAkkFqRxobVxcmHP2fgXRPssDt9gJd3ynfjMpqpb0M TJOqbEHJdMtWT2nni+gNQqEskrP3W+qGo56/QWM1tkIwfLAmb3QgcCF6Yrsc9+cWfK0V ospw== X-Gm-Message-State: AN3rC/5MW8rpn+XF+/N5MqBGKjJrqoW0G8ZywCiw0KZ2My3gE5uAhTEU B1OUbNctgkANhmG0 X-Received: by 10.99.163.67 with SMTP id v3mr1175448pgn.206.1492579844038; Tue, 18 Apr 2017 22:30:44 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id m4sm1671613pgm.25.2017.04.18.22.30.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:30:43 -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 V3 03/17] thermal: cpu_cooling: Name cpufreq cooling devices as cpufreq_cdev Date: Wed, 19 Apr 2017 10:58:58 +0530 Message-Id: <323c25bfc9454e54102b0956bae049365f1ba2bb.1492579345.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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Objects of "struct cpufreq_cooling_device" are named a bit inconsistently. Lets use cpufreq_cdev everywhere. Also note that the lists containing such devices is renamed similarly too. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 248 +++++++++++++++++++++--------------------- 1 file changed, 124 insertions(+), 124 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index ce94aafed25d..80a46a80817b 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -108,27 +108,27 @@ struct cpufreq_cooling_device { static DEFINE_IDA(cpufreq_ida); static DEFINE_MUTEX(cooling_list_lock); -static LIST_HEAD(cpufreq_dev_list); +static LIST_HEAD(cpufreq_cdev_list); /* Below code defines functions to be used for cpufreq as cooling device */ /** * get_level: Find the level for a particular frequency - * @cpufreq_dev: cpufreq_dev for which the property is required + * @cpufreq_cdev: cpufreq_cdev for which the property is required * @freq: Frequency * * Return: level on success, THERMAL_CSTATE_INVALID on error. */ -static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_dev, +static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, unsigned int freq) { unsigned long level; - for (level = 0; level <= cpufreq_dev->max_level; level++) { - if (freq == cpufreq_dev->freq_table[level]) + for (level = 0; level <= cpufreq_cdev->max_level; level++) { + if (freq == cpufreq_cdev->freq_table[level]) return level; - if (freq > cpufreq_dev->freq_table[level]) + if (freq > cpufreq_cdev->freq_table[level]) break; } @@ -148,12 +148,12 @@ static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_dev, */ unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) { - struct cpufreq_cooling_device *cpufreq_dev; + struct cpufreq_cooling_device *cpufreq_cdev; mutex_lock(&cooling_list_lock); - list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) { - if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) { - unsigned long level = get_level(cpufreq_dev, freq); + 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; @@ -183,14 +183,14 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, { struct cpufreq_policy *policy = data; unsigned long clipped_freq; - struct cpufreq_cooling_device *cpufreq_dev; + struct cpufreq_cooling_device *cpufreq_cdev; if (event != CPUFREQ_ADJUST) return NOTIFY_DONE; mutex_lock(&cooling_list_lock); - list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) { - if (!cpumask_test_cpu(policy->cpu, &cpufreq_dev->allowed_cpus)) + list_for_each_entry(cpufreq_cdev, &cpufreq_cdev_list, node) { + if (!cpumask_test_cpu(policy->cpu, &cpufreq_cdev->allowed_cpus)) continue; /* @@ -204,7 +204,7 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, * But, if clipped_freq is greater than policy->max, we don't * need to do anything. */ - clipped_freq = cpufreq_dev->clipped_freq; + clipped_freq = cpufreq_cdev->clipped_freq; if (policy->max > clipped_freq) cpufreq_verify_within_limits(policy, 0, clipped_freq); @@ -217,11 +217,11 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, /** * build_dyn_power_table() - create a dynamic power to frequency table - * @cpufreq_device: the cpufreq cooling device in which to store the table + * @cpufreq_cdev: the cpufreq cooling device in which to store the table * @capacitance: dynamic power coefficient for these cpus * * Build a dynamic power to frequency table for this cpu and store it - * in @cpufreq_device. This table will be used in cpu_power_to_freq() and + * 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. @@ -230,7 +230,7 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, * -ENOMEM if we run out of memory or -EAGAIN if an OPP was * added/enabled while the function was executing. */ -static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device, +static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_cdev, u32 capacitance) { struct power_table *power_table; @@ -239,10 +239,10 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device, int num_opps = 0, cpu, i, ret = 0; unsigned long freq; - for_each_cpu(cpu, &cpufreq_device->allowed_cpus) { + for_each_cpu(cpu, &cpufreq_cdev->allowed_cpus) { dev = get_cpu_device(cpu); if (!dev) { - dev_warn(&cpufreq_device->cool_dev->device, + dev_warn(&cpufreq_cdev->cool_dev->device, "No cpu device for cpu %d\n", cpu); continue; } @@ -295,9 +295,9 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device, goto free_power_table; } - cpufreq_device->cpu_dev = dev; - cpufreq_device->dyn_power_table = power_table; - cpufreq_device->dyn_power_table_entries = i; + cpufreq_cdev->cpu_dev = dev; + cpufreq_cdev->dyn_power_table = power_table; + cpufreq_cdev->dyn_power_table_entries = i; return 0; @@ -307,26 +307,26 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device, return ret; } -static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_device, +static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_cdev, u32 freq) { int i; - struct power_table *pt = cpufreq_device->dyn_power_table; + struct power_table *pt = cpufreq_cdev->dyn_power_table; - for (i = 1; i < cpufreq_device->dyn_power_table_entries; i++) + for (i = 1; i < cpufreq_cdev->dyn_power_table_entries; i++) if (freq < pt[i].frequency) break; return pt[i - 1].power; } -static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_device, +static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev, u32 power) { int i; - struct power_table *pt = cpufreq_device->dyn_power_table; + struct power_table *pt = cpufreq_cdev->dyn_power_table; - for (i = 1; i < cpufreq_device->dyn_power_table_entries; i++) + for (i = 1; i < cpufreq_cdev->dyn_power_table_entries; i++) if (power < pt[i].power) break; @@ -335,37 +335,37 @@ static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_device, /** * get_load() - get load for a cpu since last updated - * @cpufreq_device: &struct cpufreq_cooling_device for this cpu + * @cpufreq_cdev: &struct cpufreq_cooling_device for this cpu * @cpu: cpu number - * @cpu_idx: index of the cpu in cpufreq_device->allowed_cpus + * @cpu_idx: index of the cpu in cpufreq_cdev->allowed_cpus * * Return: The average load of cpu @cpu in percentage since this * function was last called. */ -static u32 get_load(struct cpufreq_cooling_device *cpufreq_device, int cpu, +static u32 get_load(struct cpufreq_cooling_device *cpufreq_cdev, int cpu, int cpu_idx) { u32 load; u64 now, now_idle, delta_time, delta_idle; now_idle = get_cpu_idle_time(cpu, &now, 0); - delta_idle = now_idle - cpufreq_device->time_in_idle[cpu_idx]; - delta_time = now - cpufreq_device->time_in_idle_timestamp[cpu_idx]; + delta_idle = now_idle - cpufreq_cdev->time_in_idle[cpu_idx]; + delta_time = now - cpufreq_cdev->time_in_idle_timestamp[cpu_idx]; if (delta_time <= delta_idle) load = 0; else load = div64_u64(100 * (delta_time - delta_idle), delta_time); - cpufreq_device->time_in_idle[cpu_idx] = now_idle; - cpufreq_device->time_in_idle_timestamp[cpu_idx] = now; + cpufreq_cdev->time_in_idle[cpu_idx] = now_idle; + cpufreq_cdev->time_in_idle_timestamp[cpu_idx] = now; return load; } /** * get_static_power() - calculate the static power consumed by the cpus - * @cpufreq_device: struct &cpufreq_cooling_device for this cpu cdev + * @cpufreq_cdev: struct &cpufreq_cooling_device for this cpu cdev * @tz: thermal zone device in which we're operating * @freq: frequency in KHz * @power: pointer in which to store the calculated static power @@ -378,25 +378,24 @@ static u32 get_load(struct cpufreq_cooling_device *cpufreq_device, int cpu, * * Return: 0 on success, -E* on failure. */ -static int get_static_power(struct cpufreq_cooling_device *cpufreq_device, +static int get_static_power(struct cpufreq_cooling_device *cpufreq_cdev, struct thermal_zone_device *tz, unsigned long freq, u32 *power) { struct dev_pm_opp *opp; unsigned long voltage; - struct cpumask *cpumask = &cpufreq_device->allowed_cpus; + struct cpumask *cpumask = &cpufreq_cdev->allowed_cpus; unsigned long freq_hz = freq * 1000; - if (!cpufreq_device->plat_get_static_power || - !cpufreq_device->cpu_dev) { + if (!cpufreq_cdev->plat_get_static_power || !cpufreq_cdev->cpu_dev) { *power = 0; return 0; } - opp = dev_pm_opp_find_freq_exact(cpufreq_device->cpu_dev, freq_hz, + opp = dev_pm_opp_find_freq_exact(cpufreq_cdev->cpu_dev, freq_hz, true); if (IS_ERR(opp)) { - dev_warn_ratelimited(cpufreq_device->cpu_dev, + dev_warn_ratelimited(cpufreq_cdev->cpu_dev, "Failed to find OPP for frequency %lu: %ld\n", freq_hz, PTR_ERR(opp)); return -EINVAL; @@ -406,31 +405,31 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_device, dev_pm_opp_put(opp); if (voltage == 0) { - dev_err_ratelimited(cpufreq_device->cpu_dev, + dev_err_ratelimited(cpufreq_cdev->cpu_dev, "Failed to get voltage for frequency %lu\n", freq_hz); return -EINVAL; } - return cpufreq_device->plat_get_static_power(cpumask, tz->passive_delay, - voltage, power); + return cpufreq_cdev->plat_get_static_power(cpumask, tz->passive_delay, + voltage, power); } /** * get_dynamic_power() - calculate the dynamic power - * @cpufreq_device: &cpufreq_cooling_device for this cdev + * @cpufreq_cdev: &cpufreq_cooling_device for this cdev * @freq: current frequency * * Return: the dynamic power consumed by the cpus described by - * @cpufreq_device. + * @cpufreq_cdev. */ -static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_device, +static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_cdev, unsigned long freq) { u32 raw_cpu_power; - raw_cpu_power = cpu_freq_to_power(cpufreq_device, freq); - return (raw_cpu_power * cpufreq_device->last_load) / 100; + raw_cpu_power = cpu_freq_to_power(cpufreq_cdev, freq); + return (raw_cpu_power * cpufreq_cdev->last_load) / 100; } /* cpufreq cooling device callback functions are defined below */ @@ -448,9 +447,9 @@ static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_device, static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state) { - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; + struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; - *state = cpufreq_device->max_level; + *state = cpufreq_cdev->max_level; return 0; } @@ -467,9 +466,9 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state) { - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; + struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; - *state = cpufreq_device->cpufreq_state; + *state = cpufreq_cdev->cpufreq_state; return 0; } @@ -487,21 +486,21 @@ static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) { - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; - unsigned int cpu = cpumask_any(&cpufreq_device->allowed_cpus); + 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 */ - if (WARN_ON(state > cpufreq_device->max_level)) + if (WARN_ON(state > cpufreq_cdev->max_level)) return -EINVAL; /* Check if the old cooling action is same as new cooling action */ - if (cpufreq_device->cpufreq_state == state) + if (cpufreq_cdev->cpufreq_state == state) return 0; - clip_freq = cpufreq_device->freq_table[state]; - cpufreq_device->cpufreq_state = state; - cpufreq_device->clipped_freq = clip_freq; + clip_freq = cpufreq_cdev->freq_table[state]; + cpufreq_cdev->cpufreq_state = state; + cpufreq_cdev->clipped_freq = clip_freq; cpufreq_update_policy(cpu); @@ -538,10 +537,10 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, unsigned long freq; int i = 0, cpu, ret; u32 static_power, dynamic_power, total_load = 0; - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; + struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; u32 *load_cpu = NULL; - cpu = cpumask_any_and(&cpufreq_device->allowed_cpus, cpu_online_mask); + cpu = cpumask_any_and(&cpufreq_cdev->allowed_cpus, cpu_online_mask); /* * All the CPUs are offline, thus the requested power by @@ -555,16 +554,16 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, freq = cpufreq_quick_get(cpu); if (trace_thermal_power_cpu_get_power_enabled()) { - u32 ncpus = cpumask_weight(&cpufreq_device->allowed_cpus); + u32 ncpus = cpumask_weight(&cpufreq_cdev->allowed_cpus); load_cpu = kcalloc(ncpus, sizeof(*load_cpu), GFP_KERNEL); } - for_each_cpu(cpu, &cpufreq_device->allowed_cpus) { + for_each_cpu(cpu, &cpufreq_cdev->allowed_cpus) { u32 load; if (cpu_online(cpu)) - load = get_load(cpufreq_device, cpu, i); + load = get_load(cpufreq_cdev, cpu, i); else load = 0; @@ -575,10 +574,10 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, i++; } - cpufreq_device->last_load = total_load; + cpufreq_cdev->last_load = total_load; - dynamic_power = get_dynamic_power(cpufreq_device, freq); - ret = get_static_power(cpufreq_device, tz, freq, &static_power); + dynamic_power = get_dynamic_power(cpufreq_cdev, freq); + ret = get_static_power(cpufreq_cdev, tz, freq, &static_power); if (ret) { kfree(load_cpu); return ret; @@ -586,7 +585,7 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, if (load_cpu) { trace_thermal_power_cpu_get_power( - &cpufreq_device->allowed_cpus, + &cpufreq_cdev->allowed_cpus, freq, load_cpu, i, dynamic_power, static_power); kfree(load_cpu); @@ -619,12 +618,12 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, cpumask_var_t cpumask; u32 static_power, dynamic_power; int ret; - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; + struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; if (!alloc_cpumask_var(&cpumask, GFP_KERNEL)) return -ENOMEM; - cpumask_and(cpumask, &cpufreq_device->allowed_cpus, cpu_online_mask); + cpumask_and(cpumask, &cpufreq_cdev->allowed_cpus, cpu_online_mask); num_cpus = cpumask_weight(cpumask); /* None of our cpus are online, so no power */ @@ -634,14 +633,14 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, goto out; } - freq = cpufreq_device->freq_table[state]; + freq = cpufreq_cdev->freq_table[state]; if (!freq) { ret = -EINVAL; goto out; } - dynamic_power = cpu_freq_to_power(cpufreq_device, freq) * num_cpus; - ret = get_static_power(cpufreq_device, tz, freq, &static_power); + 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; @@ -679,24 +678,24 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev, int ret; s32 dyn_power; u32 last_load, normalised_power, static_power; - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; + struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; - cpu = cpumask_any_and(&cpufreq_device->allowed_cpus, cpu_online_mask); + 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); - ret = get_static_power(cpufreq_device, tz, cur_freq, &static_power); + ret = get_static_power(cpufreq_cdev, tz, cur_freq, &static_power); if (ret) return ret; dyn_power = power - static_power; dyn_power = dyn_power > 0 ? dyn_power : 0; - last_load = cpufreq_device->last_load ?: 1; + last_load = cpufreq_cdev->last_load ?: 1; normalised_power = (dyn_power * 100) / last_load; - target_freq = cpu_power_to_freq(cpufreq_device, normalised_power); + target_freq = cpu_power_to_freq(cpufreq_cdev, normalised_power); *state = cpufreq_cooling_get_level(cpu, target_freq); if (*state == THERMAL_CSTATE_INVALID) { @@ -706,7 +705,7 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev, return -EINVAL; } - trace_thermal_power_cpu_limit(&cpufreq_device->allowed_cpus, + trace_thermal_power_cpu_limit(&cpufreq_cdev->allowed_cpus, target_freq, *state, power); return 0; } @@ -771,7 +770,7 @@ __cpufreq_cooling_register(struct device_node *np, { struct cpufreq_policy *policy; struct thermal_cooling_device *cool_dev; - struct cpufreq_cooling_device *cpufreq_dev; + struct cpufreq_cooling_device *cpufreq_cdev; char dev_name[THERMAL_NAME_LENGTH]; struct cpufreq_frequency_table *pos, *table; cpumask_var_t temp_mask; @@ -798,49 +797,49 @@ __cpufreq_cooling_register(struct device_node *np, goto put_policy; } - cpufreq_dev = kzalloc(sizeof(*cpufreq_dev), GFP_KERNEL); - if (!cpufreq_dev) { + cpufreq_cdev = kzalloc(sizeof(*cpufreq_cdev), GFP_KERNEL); + if (!cpufreq_cdev) { cool_dev = ERR_PTR(-ENOMEM); goto put_policy; } num_cpus = cpumask_weight(clip_cpus); - cpufreq_dev->time_in_idle = kcalloc(num_cpus, - sizeof(*cpufreq_dev->time_in_idle), + cpufreq_cdev->time_in_idle = kcalloc(num_cpus, + sizeof(*cpufreq_cdev->time_in_idle), GFP_KERNEL); - if (!cpufreq_dev->time_in_idle) { + if (!cpufreq_cdev->time_in_idle) { cool_dev = ERR_PTR(-ENOMEM); goto free_cdev; } - cpufreq_dev->time_in_idle_timestamp = - kcalloc(num_cpus, sizeof(*cpufreq_dev->time_in_idle_timestamp), + cpufreq_cdev->time_in_idle_timestamp = + kcalloc(num_cpus, sizeof(*cpufreq_cdev->time_in_idle_timestamp), GFP_KERNEL); - if (!cpufreq_dev->time_in_idle_timestamp) { + if (!cpufreq_cdev->time_in_idle_timestamp) { cool_dev = ERR_PTR(-ENOMEM); goto free_time_in_idle; } /* Find max levels */ cpufreq_for_each_valid_entry(pos, table) - cpufreq_dev->max_level++; + cpufreq_cdev->max_level++; - cpufreq_dev->freq_table = kmalloc(sizeof(*cpufreq_dev->freq_table) * - cpufreq_dev->max_level, GFP_KERNEL); - if (!cpufreq_dev->freq_table) { + cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * + cpufreq_cdev->max_level, GFP_KERNEL); + if (!cpufreq_cdev->freq_table) { cool_dev = ERR_PTR(-ENOMEM); goto free_time_in_idle_timestamp; } /* max_level is an index, not a counter */ - cpufreq_dev->max_level--; + cpufreq_cdev->max_level--; - cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); + cpumask_copy(&cpufreq_cdev->allowed_cpus, clip_cpus); if (capacitance) { - cpufreq_dev->plat_get_static_power = plat_static_func; + cpufreq_cdev->plat_get_static_power = plat_static_func; - ret = build_dyn_power_table(cpufreq_dev, capacitance); + ret = build_dyn_power_table(cpufreq_cdev, capacitance); if (ret) { cool_dev = ERR_PTR(ret); goto free_table; @@ -856,12 +855,12 @@ __cpufreq_cooling_register(struct device_node *np, cool_dev = ERR_PTR(ret); goto free_power_table; } - cpufreq_dev->id = ret; + cpufreq_cdev->id = ret; /* Fill freq-table in descending order of frequencies */ - for (i = 0, freq = -1; i <= cpufreq_dev->max_level; i++) { + for (i = 0, freq = -1; i <= cpufreq_cdev->max_level; i++) { freq = find_next_max(table, freq); - cpufreq_dev->freq_table[i] = freq; + cpufreq_cdev->freq_table[i] = freq; /* Warn for duplicate entries */ if (!freq) @@ -871,20 +870,21 @@ __cpufreq_cooling_register(struct device_node *np, } snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", - cpufreq_dev->id); + cpufreq_cdev->id); - cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev, + cool_dev = thermal_of_cooling_device_register(np, dev_name, + cpufreq_cdev, cooling_ops); if (IS_ERR(cool_dev)) goto remove_ida; - cpufreq_dev->clipped_freq = cpufreq_dev->freq_table[0]; - cpufreq_dev->cool_dev = cool_dev; + cpufreq_cdev->clipped_freq = cpufreq_cdev->freq_table[0]; + cpufreq_cdev->cool_dev = cool_dev; mutex_lock(&cooling_list_lock); /* Register the notifier for first cpufreq cooling device */ - first = list_empty(&cpufreq_dev_list); - list_add(&cpufreq_dev->node, &cpufreq_dev_list); + first = list_empty(&cpufreq_cdev_list); + list_add(&cpufreq_cdev->node, &cpufreq_cdev_list); mutex_unlock(&cooling_list_lock); if (first) @@ -894,17 +894,17 @@ __cpufreq_cooling_register(struct device_node *np, goto put_policy; remove_ida: - ida_simple_remove(&cpufreq_ida, cpufreq_dev->id); + ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id); free_power_table: - kfree(cpufreq_dev->dyn_power_table); + kfree(cpufreq_cdev->dyn_power_table); free_table: - kfree(cpufreq_dev->freq_table); + kfree(cpufreq_cdev->freq_table); free_time_in_idle_timestamp: - kfree(cpufreq_dev->time_in_idle_timestamp); + kfree(cpufreq_cdev->time_in_idle_timestamp); free_time_in_idle: - kfree(cpufreq_dev->time_in_idle); + kfree(cpufreq_cdev->time_in_idle); free_cdev: - kfree(cpufreq_dev); + kfree(cpufreq_cdev); put_policy: cpufreq_cpu_put(policy); free_cpumask: @@ -1029,30 +1029,30 @@ EXPORT_SYMBOL(of_cpufreq_power_cooling_register); */ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) { - struct cpufreq_cooling_device *cpufreq_dev; + struct cpufreq_cooling_device *cpufreq_cdev; bool last; if (!cdev) return; - cpufreq_dev = cdev->devdata; + cpufreq_cdev = cdev->devdata; mutex_lock(&cooling_list_lock); - list_del(&cpufreq_dev->node); + list_del(&cpufreq_cdev->node); /* Unregister the notifier for the last cpufreq cooling device */ - last = list_empty(&cpufreq_dev_list); + last = list_empty(&cpufreq_cdev_list); mutex_unlock(&cooling_list_lock); if (last) cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, CPUFREQ_POLICY_NOTIFIER); - thermal_cooling_device_unregister(cpufreq_dev->cool_dev); - ida_simple_remove(&cpufreq_ida, cpufreq_dev->id); - kfree(cpufreq_dev->dyn_power_table); - kfree(cpufreq_dev->time_in_idle_timestamp); - kfree(cpufreq_dev->time_in_idle); - kfree(cpufreq_dev->freq_table); - kfree(cpufreq_dev); + thermal_cooling_device_unregister(cpufreq_cdev->cool_dev); + 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); + kfree(cpufreq_cdev); } EXPORT_SYMBOL_GPL(cpufreq_cooling_unregister); From patchwork Wed Apr 19 05:29:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97594 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159235qgf; Tue, 18 Apr 2017 22:31:09 -0700 (PDT) X-Received: by 10.84.241.65 with SMTP id u1mr1575379plm.28.1492579869061; Tue, 18 Apr 2017 22:31:09 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si1294599pfb.367.2017.04.18.22.31.08; Tue, 18 Apr 2017 22:31:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1759908AbdDSFbF (ORCPT + 12 others); Wed, 19 Apr 2017 01:31:05 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:36604 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759885AbdDSFbC (ORCPT ); Wed, 19 Apr 2017 01:31:02 -0400 Received: by mail-pf0-f178.google.com with SMTP id 194so6972922pfv.3 for ; Tue, 18 Apr 2017 22:30:56 -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=4HJsZRN6zF5/LRAe1wDfyitNxbWDnwbtd4xl0aZuYT0=; b=Nym9QrmiBQA8ILZfaImKUrQLpqjeL9RyA055AwPr1UB/49odiLAWxgt/3zUeTkaIx5 qN7N/Js3bBZGcU7niqf/PFk8T5GyulElaxWfcsi1SthdzedED5FLXX8ovHUkuj+IrNAy rQEQMteVGiz8f1po3M19bfGAsAXqGC6MG8jRw= 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=4HJsZRN6zF5/LRAe1wDfyitNxbWDnwbtd4xl0aZuYT0=; b=ZeX2S8wnJ4cz5C2YShI+IkjlOxaV285/nMZ8YzYTX/MX/cUMrpqx+RuGMcmSduYAd0 gMtMMgv+QpDCg6vTEnmmT+v3lzStgQr9SGT62O4eiRQJbFnvxpBMz+R94UbFqLvHNTFj A+iJU7SLqhGJwy4YjVdOwd+BoQPw+QlBUBLKstuowV4zTGlmM+oTL0ZYOzufiE55Sa/i aHZcaDso4SVPBjc7AJjmyqLS/WQnsFESge1ewEMTaZJQMPryHhuvtpERfvm3tb4Xj9Ku zi5vsrPBVpWeCBp0E3mQOA4fEeEKmjmUj/sJqU+iMZKe3L0dCdAqoYbM634I9QOCbouI FB3w== X-Gm-Message-State: AN3rC/6t/kS7y5d2tchULWwRJX2UIHqPS1SH86KBvIHC5m8iavuLIKOh 6805r7W/GyxMd1wk X-Received: by 10.98.93.147 with SMTP id n19mr1220548pfj.226.1492579850770; Tue, 18 Apr 2017 22:30:50 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id x65sm1647411pfb.111.2017.04.18.22.30.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:30:50 -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 V3 05/17] thermal: cpu_cooling: remove cpufreq_cooling_get_level() Date: Wed, 19 Apr 2017 10:59:00 +0530 Message-Id: <04010983e89a99ad35fd754d3ca0577139ab8759.1492579345.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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 --- 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 Wed Apr 19 05:29:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97593 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159225qgf; Tue, 18 Apr 2017 22:31:08 -0700 (PDT) X-Received: by 10.98.13.134 with SMTP id 6mr1198749pfn.112.1492579868097; Tue, 18 Apr 2017 22:31:08 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si1294599pfb.367.2017.04.18.22.31.07; Tue, 18 Apr 2017 22:31:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1759884AbdDSFa4 (ORCPT + 12 others); Wed, 19 Apr 2017 01:30:56 -0400 Received: from mail-pg0-f46.google.com ([74.125.83.46]:33535 "EHLO mail-pg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759846AbdDSFay (ORCPT ); Wed, 19 Apr 2017 01:30:54 -0400 Received: by mail-pg0-f46.google.com with SMTP id 63so7409823pgh.0 for ; Tue, 18 Apr 2017 22:30:54 -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=RIBbV5INEApKwfzXtN1yzs39j/90oRovdZxl2OtKWZk=; b=Ev+f56tAeoLbkbPwVdjdx1U2TNJpTxv6D2QIulPzKJlLmpw7L17NIoEqacRh7ZLwgj 5CxqCnK0gsT+9JoDkh63+mLn/LLRXMzDja92dVOFDTicPSsSNX1Tu2ojJq3LmQxnJIdi E6zA+y5ChBCeDQC6dkv8l8dd0atCO+R+vf8vc= 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=RIBbV5INEApKwfzXtN1yzs39j/90oRovdZxl2OtKWZk=; b=arAg7nal8UD95gOXYcmQ4ywYvKnOyuk8uTu8drPufBPUaUGr95MWnACMxWvdyE6Mp6 rUhVEy+zTx4LM+Md+sAyL0Lib8fJJStbU+el2OHVh0+QZ2cyk+iGNL0LfHR2VEfj0ydA MNcdy2P8H2ITUkopJPtbv2O49vz/br9sUNQ0DW8pX5kYp9pQxAbe7xH+JqJlfi9+Qn5l 3lJ3KF7bXyIw4EEtgZ3daB3wfsq0D8wbgprWelUs1HIu/RyQ03R8cSoRcPQ0PwoSZ8O3 yB6C9ZTo5SWj+D7FJ0j9ByCcOqU6h+GVnIyrv4FJ38OTP+2IPtIA8NqZE6QegbS93onZ J7vA== X-Gm-Message-State: AN3rC/7r98RLtMaMQRTG+hzv+CWVyemisTTgS+jJ5DIRztLdDyytB99j Kbt0BA7ZyvVCdxKR X-Received: by 10.84.210.10 with SMTP id z10mr1531023plh.173.1492579854034; Tue, 18 Apr 2017 22:30:54 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id r77sm1651140pfe.105.2017.04.18.22.30.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:30:53 -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 V3 06/17] thermal: cpu_cooling: get rid of a variable in cpufreq_set_cur_state() Date: Wed, 19 Apr 2017 10:59:01 +0530 Message-Id: X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 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 'cpu' is used at only one place and there is no need to keep a separate variable for it. Signed-off-by: Viresh Kumar --- 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 Wed Apr 19 05:29:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97604 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159874qgf; Tue, 18 Apr 2017 22:33:41 -0700 (PDT) X-Received: by 10.98.214.12 with SMTP id r12mr1217569pfg.204.1492580021020; Tue, 18 Apr 2017 22:33:41 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u4si1301953pgo.283.2017.04.18.22.33.40; Tue, 18 Apr 2017 22:33:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1752160AbdDSFdj (ORCPT + 12 others); Wed, 19 Apr 2017 01:33:39 -0400 Received: from mail-pg0-f50.google.com ([74.125.83.50]:33565 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759918AbdDSFbH (ORCPT ); Wed, 19 Apr 2017 01:31:07 -0400 Received: by mail-pg0-f50.google.com with SMTP id 63so7411217pgh.0 for ; Tue, 18 Apr 2017 22:31:01 -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=PxP202jAQV4azWcUMI6cp/7N/7P84pLq+jAF9d/LMgc=; b=gS0256coPyHKdjX3MKfylsnLgwg0L6ND426ba16d6ZuAjM0P/rCsvmTQSvHBgiyfP8 v2qS7rLxUF2+8XTN2npgB/5NVvv4rtoyg/tdq+713MlSGGjVjR9B/iM50mg7V1CCgsQ5 zDUrReBz0mwtpnkXQfh36k202f2uZVr4FfQlE= 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=PxP202jAQV4azWcUMI6cp/7N/7P84pLq+jAF9d/LMgc=; b=NHEdiiyxlXz8bgFK22d9P4ujITTKZF73L9oyRrIWPmGqjR1s4Mb3SNEOTyNO1oI6Dp 2TC9vCiyfsuZQwUaXB3lVG0fzCNi221ZIa/e9asTa2NWUk+H7X69goR+5xln5w3WQ5Md NBiZ68rodQXI76ClJuPdzuuisZbJAbvOQx/4opBpxWYHVbNuLF2RllxQJFt0T1NZ+SO0 0K9Q1iUomCqnrxpzoLQv0ZB8dMITWlJgpeFcz3Jfdfj7EFryjMsxVLEj+1QaId1AeItx uzB6IaCNKd9V/X+419xMHeTGPtoKHXcaAs9G/u6kVlN7Ms+7WMCol9tZgIxLyhiFQw1b UpBg== X-Gm-Message-State: AN3rC/7U+lqBUXBfagkTJHMVn7SI4RQ0p9ZNZtfaE80bgzXD10g9BfjW mIu7a5DVgoF4xUW6 X-Received: by 10.84.232.205 with SMTP id x13mr1558854plm.153.1492579861475; Tue, 18 Apr 2017 22:31:01 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id a184sm1649294pfb.118.2017.04.18.22.31.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:31:00 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , "Rafael J. Wysocki" , Viresh Kumar , Amit Daniel Kachhap Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V3 08/17] cpufreq: create cpufreq_table_count_valid_entries() Date: Wed, 19 Apr 2017 10:59:03 +0530 Message-Id: <6bc9dc0dec11fae92122da51b8e4ecde4aca8cf0.1492579345.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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We need such a routine at two places already, lets create one. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq_stats.c | 13 ++++--------- drivers/thermal/cpu_cooling.c | 22 +++++++++------------- include/linux/cpufreq.h | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 22 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index f570ead62454..9c3d319dc129 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -170,11 +170,10 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy) unsigned int i = 0, count = 0, ret = -ENOMEM; struct cpufreq_stats *stats; unsigned int alloc_size; - struct cpufreq_frequency_table *pos, *table; + struct cpufreq_frequency_table *pos; - /* We need cpufreq table for creating stats table */ - table = policy->freq_table; - if (unlikely(!table)) + count = cpufreq_table_count_valid_entries(policy); + if (!count) return; /* stats already initialized */ @@ -185,10 +184,6 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy) if (!stats) return; - /* Find total allocation size */ - cpufreq_for_each_valid_entry(pos, table) - count++; - alloc_size = count * sizeof(int) + count * sizeof(u64); alloc_size += count * count * sizeof(int); @@ -205,7 +200,7 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy) stats->max_state = count; /* Find valid-unique entries */ - cpufreq_for_each_valid_entry(pos, table) + cpufreq_for_each_valid_entry(pos, policy->freq_table) if (freq_table_get_index(stats, pos->frequency) == -1) stats->freq_table[i++] = pos->frequency; diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 58e58065b650..55ff45c1e917 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -739,7 +739,6 @@ __cpufreq_cooling_register(struct device_node *np, struct thermal_cooling_device *cdev; struct cpufreq_cooling_device *cpufreq_cdev; char dev_name[THERMAL_NAME_LENGTH]; - struct cpufreq_frequency_table *pos, *table; unsigned int freq, i, num_cpus; int ret; struct thermal_cooling_device_ops *cooling_ops; @@ -750,9 +749,10 @@ __cpufreq_cooling_register(struct device_node *np, return ERR_PTR(-EINVAL); } - table = policy->freq_table; - if (!table) { - pr_debug("%s: CPUFreq table not found\n", __func__); + i = cpufreq_table_count_valid_entries(policy); + if (!i) { + pr_debug("%s: CPUFreq table not found or has no valid entries\n", + __func__); return ERR_PTR(-ENODEV); } @@ -777,20 +777,16 @@ __cpufreq_cooling_register(struct device_node *np, goto free_time_in_idle; } - /* Find max levels */ - cpufreq_for_each_valid_entry(pos, table) - cpufreq_cdev->max_level++; + /* max_level is an index, not a counter */ + cpufreq_cdev->max_level = i - 1; - cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * - cpufreq_cdev->max_level, GFP_KERNEL); + cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * i, + GFP_KERNEL); if (!cpufreq_cdev->freq_table) { cdev = ERR_PTR(-ENOMEM); goto free_time_in_idle_timestamp; } - /* max_level is an index, not a counter */ - cpufreq_cdev->max_level--; - cpumask_copy(&cpufreq_cdev->allowed_cpus, policy->related_cpus); if (capacitance) { @@ -816,7 +812,7 @@ __cpufreq_cooling_register(struct device_node *np, /* Fill freq-table in descending order of frequencies */ for (i = 0, freq = -1; i <= cpufreq_cdev->max_level; i++) { - freq = find_next_max(table, freq); + freq = find_next_max(policy->freq_table, freq); cpufreq_cdev->freq_table[i] = freq; /* Warn for duplicate entries */ diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 87165f06a307..affc13568af6 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -855,6 +855,20 @@ static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy, return -EINVAL; } } + +static inline int cpufreq_table_count_valid_entries(const struct cpufreq_policy *policy) +{ + struct cpufreq_frequency_table *pos; + int count = 0; + + if (unlikely(!policy->freq_table)) + return 0; + + cpufreq_for_each_valid_entry(pos, policy->freq_table) + count++; + + return count; +} #else static inline int cpufreq_boost_trigger_state(int state) { From patchwork Wed Apr 19 05:29:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97596 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159287qgf; Tue, 18 Apr 2017 22:31:21 -0700 (PDT) X-Received: by 10.98.73.12 with SMTP id w12mr1214463pfa.218.1492579880936; Tue, 18 Apr 2017 22:31:20 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c8si1324189plk.27.2017.04.18.22.31.20; Tue, 18 Apr 2017 22:31:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1759941AbdDSFbQ (ORCPT + 12 others); Wed, 19 Apr 2017 01:31:16 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:34550 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759928AbdDSFbM (ORCPT ); Wed, 19 Apr 2017 01:31:12 -0400 Received: by mail-pf0-f170.google.com with SMTP id c198so6999066pfc.1 for ; Tue, 18 Apr 2017 22:31: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=KRUaRVoRfxG62pNM6iIQGGxNkZmRngzrDe/tLpcZt4U=; b=OtWzDRFkAr1TETMnacUPeUQhBaAoWNH0DFN7eTEplPDnAfF6luwsAaJMp9m75qpaF3 aobek86uiYpva70T3uQez0yGRVLUzwfHEmkxbpHaKTh9l+/MAj69sIGg1ZshnwojVTfM TjsKHHkZHLZ03D9Ra3xT+kq6ni8vGciVDsecc= 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=KRUaRVoRfxG62pNM6iIQGGxNkZmRngzrDe/tLpcZt4U=; b=XIaVzIYO884Wdmmf2ue7SxUh2z7yF3FrQ6hdkCjorv38l5I90UPGNn2iedYs4qJpVO fKxCcy+hYFC5Y81zBb2Tgm5wpFrZheMRsjoLo1TLzD0vPWtLkf4I6WTGrsGMWabNmBk4 BTg1QrOFKDeTl/W1dQfAgmEGMC/KygrvDKiNTZKAvKAuxF11fEa00QLKLYiltBnilUFh wYCpqT48vuOCmYMd1LjrQL8GrPc7vHB4vQ/xhU6QM6bzpuSQoMLTbVF7FzM+d/RzwU+B Y5QZGuJS6bVzPYyfTLPRFw4dzUtJjiiBHEERV+m3WgDZuK44Z1dTjXO+PTgCxgqL3Hr7 VWjQ== X-Gm-Message-State: AN3rC/5ZsPOEZcOuTSUBZMDC2V72LndsiXx25aPklwHJ/IcaKMZGeJeE +I6msKL5ReWezQkh X-Received: by 10.84.216.10 with SMTP id m10mr1535982pli.79.1492579871477; Tue, 18 Apr 2017 22:31:11 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id 202sm1667558pgh.21.2017.04.18.22.31.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:31:10 -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 V3 11/17] thermal: cpu_cooling: get rid of 'allowed_cpus' Date: Wed, 19 Apr 2017 10:59:06 +0530 Message-Id: <4da549d2565a75420633850b6963fe50b3f02bad.1492579345.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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 --- drivers/thermal/cpu_cooling.c | 77 ++++++++++++------------------------------- 1 file changed, 21 insertions(+), 56 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 Tested-by: Lukasz Luba diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index ce387f62c93e..1097162f7f8a 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,7 @@ 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)) + if (policy != cpufreq_cdev->policy) continue; /* @@ -304,7 +302,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 +349,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 +466,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 +502,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 +538,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 +569,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 +612,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 +634,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 +753,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 Wed Apr 19 05:29:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97597 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159300qgf; Tue, 18 Apr 2017 22:31:24 -0700 (PDT) X-Received: by 10.84.224.198 with SMTP id k6mr1547427pln.15.1492579884268; Tue, 18 Apr 2017 22:31:24 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n1si1298015pld.289.2017.04.18.22.31.24; Tue, 18 Apr 2017 22:31:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1759950AbdDSFbV (ORCPT + 12 others); Wed, 19 Apr 2017 01:31:21 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:33619 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759940AbdDSFbQ (ORCPT ); Wed, 19 Apr 2017 01:31:16 -0400 Received: by mail-pg0-f45.google.com with SMTP id 63so7414066pgh.0 for ; Tue, 18 Apr 2017 22:31:15 -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=hYj4owkk/FVCSPL3ibJmJBRuqa7VXHZ1I9tu7aRbSqU=; b=dDuUmVguFfcxiEQcjSeNlOhB9NNRtXUUj8qEDLqgCEjU53kBBdULgKnLRNpf+QwDVS 9wH36qxSd4E3D981ZCts2Yed2SrQ1b0yBBlXwvyT+jLwgl+oyqvItAaUkHZfYMa3IWUO i/SvNlfBoKuvoHCBKJqNeUrDJXJm9gLq553g4= 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=hYj4owkk/FVCSPL3ibJmJBRuqa7VXHZ1I9tu7aRbSqU=; b=P6oJFFaD191HcPzhRorMbf9yE5zpAgN+nSav+wNd3mX3nNJYWpyVdQFJQM8/yqYPbR JyHUPn4CQx/Ojy77Jjj2OlsvG9eDszXmrtGjt4AkioblxltTUrk6XIEltTWWKYmRDWdd 06i1rxVjtCU+vcI2J0ohvccJSw6n/vFIbSiJzcCHyD39xTYRDuTQhjtcvbzEAwNYBQVI aMODUGHmDfIZSk3bFGCF3+aWEcvOuC7FPbYAol5dAuKAUylAy4vmeegjuFNREnWZSwnq zgMb/ek52RDiaN/I02RRyKLPuP5webvhxXBPRy5WDWlSiji7m0zqRsWieW/f98pckt0S PqkQ== X-Gm-Message-State: AN3rC/75rJherc2fRsZIvTHawwV6uUdPt08m5phdcsiwDYeHM9sNDoO6 XdGn1dgs0m9k5mvV X-Received: by 10.99.7.81 with SMTP id 78mr1147537pgh.131.1492579874810; Tue, 18 Apr 2017 22:31:14 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id b5sm1678511pfb.21.2017.04.18.22.31.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:31:14 -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 V3 12/17] thermal: cpu_cooling: merge frequency and power tables Date: Wed, 19 Apr 2017 10:59:07 +0530 Message-Id: <0f62df8e9f5c6fe596c82b9b7018508489f123ae.1492579345.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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 --- 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 1097162f7f8a..17d6d4635936 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; } @@ -185,28 +180,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)) { @@ -219,25 +211,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); @@ -248,54 +247,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; } /** @@ -462,7 +446,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; @@ -575,7 +559,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; @@ -753,31 +737,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) @@ -786,15 +759,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); @@ -811,8 +795,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: @@ -961,7 +943,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 Wed Apr 19 05:29:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97601 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159504qgf; Tue, 18 Apr 2017 22:32:10 -0700 (PDT) X-Received: by 10.99.115.30 with SMTP id o30mr1161083pgc.155.1492579930553; Tue, 18 Apr 2017 22:32:10 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f35si1321610plh.40.2017.04.18.22.32.10; Tue, 18 Apr 2017 22:32:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1760043AbdDSFcI (ORCPT + 12 others); Wed, 19 Apr 2017 01:32:08 -0400 Received: from mail-pg0-f48.google.com ([74.125.83.48]:36785 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760005AbdDSFbg (ORCPT ); Wed, 19 Apr 2017 01:31:36 -0400 Received: by mail-pg0-f48.google.com with SMTP id g2so7364269pge.3 for ; Tue, 18 Apr 2017 22:31:35 -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=TYewOflp+ZgeCPWZpNGFTuIIdeUnYo2pm6AtvbKhHRY=; b=jXUtNX3PA4/ukMC6WD2oMA1JHs0guz6w2tSQtILmMoyKQhuQqECo/2EZyyPLyWMX/S hU3I5AVddsfZZ88Qx+d4s1fGopdVZjCTPTp6oSedrgXOr1Xg41hG3rRYLB/A9XHXf6GR MFRcnvjpHJNWvbXMD3OCe/84qsNNvg1oynbto= 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=TYewOflp+ZgeCPWZpNGFTuIIdeUnYo2pm6AtvbKhHRY=; b=Sw/RWPaBYjcekTj51yg2prqE2lSKnnJSCmqd75nWPPjAeZqLDPyEAVkjsqd/4WYc4s amXD3S0dZhNOMP5ZNbwVGshqiKDMFg6wYdn3kZwgEzvJ1k649EmmNy6z+0EY+vOSRmeX GoCj71+OrJuSr7CSN2CzhLc/+Y9HbhQG9I/sLp3T2ZhsPP42p684el/b5OPjg5W3TWX4 BIYi8hRHwN24zPmfUI66nM68WNCPhyKleTgWHOPlNBeGaqa6Kvucc86wEPClHBk6/D3q 9V8KJ+nUWnq4V4d12GuJjsZvtj2mJ7PPWLFhJkUxm2TWcKEWSunfKTOOyaZ/mZO63DXv ritg== X-Gm-Message-State: AN3rC/4+xZAgj7NdBC5y8daGY95g+4zSUMu338x5OOcyhsiPxLoJmT0t oyAbniGaVhrQbVX7 X-Received: by 10.98.201.72 with SMTP id k69mr1218189pfg.74.1492579890324; Tue, 18 Apr 2017 22:31:30 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id j125sm1660073pgc.53.2017.04.18.22.31.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:31:29 -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 V3 15/17] thermal: cpu_cooling: don't store cpu_dev in cpufreq_cdev Date: Wed, 19 Apr 2017 10:59:10 +0530 Message-Id: <6b094de5e95d0d9c0d699a91fdb50847b379b955.1492579345.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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 --- 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 762ddfc4e654..c85b217d16c8 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; }; @@ -255,8 +253,6 @@ static int update_freq_table(struct cpufreq_cooling_device *cpufreq_cdev, freq_table[i].power = power; } - cpufreq_cdev->cpu_dev = dev; - return 0; } @@ -338,19 +334,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; } @@ -359,8 +358,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 Wed Apr 19 05:29: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: 97600 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159452qgf; Tue, 18 Apr 2017 22:31:58 -0700 (PDT) X-Received: by 10.98.59.201 with SMTP id w70mr1212792pfj.137.1492579918196; Tue, 18 Apr 2017 22:31:58 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f35si1321610plh.40.2017.04.18.22.31.57; Tue, 18 Apr 2017 22:31:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1760030AbdDSFbr (ORCPT + 12 others); Wed, 19 Apr 2017 01:31:47 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:34644 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760021AbdDSFbm (ORCPT ); Wed, 19 Apr 2017 01:31:42 -0400 Received: by mail-pf0-f177.google.com with SMTP id c198so7003720pfc.1 for ; Tue, 18 Apr 2017 22:31: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=TcRRIIV4XadGzbLL5B9iDM8jAWOYVIH6WcrXFP60LcI=; b=I85JRbonvefE1vcKw8750w/2OOSX6gZ17z0t92/8BJd9uONP3EgH5riOWYAKsP3g9O 5yc4klxsjdcrESHA/uuHwiYd6dfkCEmSL2fHM/68TG82Yb292R6H8CbvKZ1uWAUp3bbQ HELsoDaFeY1V8IGz9iiAN+7UEVxrbP/4tNEo0= 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=TcRRIIV4XadGzbLL5B9iDM8jAWOYVIH6WcrXFP60LcI=; b=QjpVnJfiBmavv5ddDApkyNbrDM7gsoZy5QzGSO0kN1hTFHSIFoX0t33FmtRdYztdcC 61oyvq2efkfLE/m3i/S/gkjQmUfJ+kJpfSed2E9gwX6i8dXWkxSuYZNLEDryk+7rDz+w BsCGYZoL0fC66Y21iFu+hIU4LT85YTORxiHBtV4VFQXvH02xWsdhoA41ALv6rekAWgij s1e06w280vpY8JsesCMdL6qrtshHAyXRbOcyE3YkNuYBaDh4EGaVvPxhTAatEvJs/xLQ 02gv+e+SK6pFonh0MZq5cMKY078HkLP8+fhOGZrqkqk68Pj/S7TQ97M6V+IKk2LAf39h qNDA== X-Gm-Message-State: AN3rC/60R3IXsl8C/cDrzrLpewT+qUc1VapeI1Fh8kA4GDeTm38NsLge b5IVVN3qauxlfZsi X-Received: by 10.98.204.93 with SMTP id a90mr1237360pfg.6.1492579897077; Tue, 18 Apr 2017 22:31:37 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id f6sm1674483pfe.57.2017.04.18.22.31.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:31:36 -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 V3 17/17] thermal: cpu_cooling: Rearrange struct cpufreq_cooling_device Date: Wed, 19 Apr 2017 10:59:12 +0530 Message-Id: <56b3e4d4209787d3b2292f04c90f1fd969fdf90c.1492579345.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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This shrinks the size of the structure on arm64 by 8 bytes by avoiding padding of 4 bytes at two places. Also add missing doc comment for freq_table Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index dc73405b04f2..05073c33ba20 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -75,17 +75,18 @@ struct time_in_idle { * struct cpufreq_cooling_device - data for cooling device with cpufreq * @id: unique integer value corresponding to each cpufreq_cooling_device * registered. - * @cdev: thermal_cooling_device pointer to keep track of the - * registered cooling device. - * @policy: cpufreq policy. + * @last_load: load measured by the latest call to cpufreq_get_requested_power() * @cpufreq_state: integer value representing the current state of cpufreq * cooling devices. * @clipped_freq: integer value representing the absolute value of the clipped * frequency. * @max_level: maximum cooling level. One less than total number of valid * cpufreq frequencies. + * @freq_table: Freq table in descending order of frequencies + * @cdev: thermal_cooling_device pointer to keep track of the + * registered cooling device. + * @policy: cpufreq policy. * @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 * @plat_get_static_power: callback to calculate the static power * @@ -94,14 +95,14 @@ struct time_in_idle { */ struct cpufreq_cooling_device { int id; - struct thermal_cooling_device *cdev; - struct cpufreq_policy *policy; + u32 last_load; unsigned int cpufreq_state; unsigned int clipped_freq; unsigned int max_level; struct freq_table *freq_table; /* In descending order */ + struct thermal_cooling_device *cdev; + struct cpufreq_policy *policy; struct list_head node; - u32 last_load; struct time_in_idle *idle_time; get_static_t plat_get_static_power; };