From patchwork Mon Apr 17 06:01:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97492 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1212531qgf; Sun, 16 Apr 2017 23:03:00 -0700 (PDT) X-Received: by 10.98.148.2 with SMTP id m2mr10220814pfe.28.1492408980380; Sun, 16 Apr 2017 23:03:00 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y67si10036543pfj.22.2017.04.16.23.02.59; Sun, 16 Apr 2017 23:03:00 -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 S932645AbdDQGCr (ORCPT + 12 others); Mon, 17 Apr 2017 02:02:47 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:33408 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932810AbdDQGCo (ORCPT ); Mon, 17 Apr 2017 02:02:44 -0400 Received: by mail-pf0-f176.google.com with SMTP id s16so61535562pfs.0 for ; Sun, 16 Apr 2017 23:02: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=R/nCdBoYFzlttycp21aPwBW7xgWIZPpWNbAyzQbNzcA=; b=UJ4xXWKlUaXtpIFf08VsACV4Rzw6uRnfJ3ouaQBvsi3jEtSmpjLNBVKcQBzpqGbBRk Zs/mbHXLFf1WRvpK350DZcej8vU0nZUoceJmFj1YUCxbZmsYhKxyqQP6YUtDCg2IMz0P iNhHcifjIcQakhPKHpLr0b7r6KM5xQC/m7e3o= 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=R/nCdBoYFzlttycp21aPwBW7xgWIZPpWNbAyzQbNzcA=; b=W/Se777Rh7qUi0l8lpfpY2FuqZEMmzTYUoljnpkXLO2hYUkksJrjt8phL0gWr6ePFG rmmY8ivVyMXfH0xGcVTsMVSFFitrHaNB11gJer6BVBH7H6DXLR7NVZMIKuDI+vLrg69t WsaMmKE9Kz593Namn7zRGneNKycsheSnlcJJrRRPOC29RHfXsXkqz/8bH67G+G3eq6Gt KhpM0D7IMeoqWQ0Rla+bjwsXOWvpseKhRYq92ieFO3PbxBZfg59jEcTLDYRoXe8eSK2y 4FhyUhu4zVM6zvl3BODdeqFyHgWZpnD02foKVoaR8dNImso4sX+3JABcspUdRNhRQADx 6o5g== X-Gm-Message-State: AN3rC/5r3AZPak2wFD0pnkUs3dNFktimpoPKACJwI8ihre4AOx1aOCCv mig8IeNWQWllhU0K X-Received: by 10.84.168.4 with SMTP id e4mr13543864plb.138.1492408964282; Sun, 16 Apr 2017 23:02:44 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id 133sm15274661pfy.106.2017.04.16.23.02.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Apr 2017 23:02:43 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , 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 , "4 . 2+" Subject: [PATCH V2 01/17] thermal: cpu_cooling: Avoid accessing potentially freed structures Date: Mon, 17 Apr 2017 11:31:46 +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 After the lock is dropped, it is possible that the cpufreq_dev gets freed before we call get_level() and that can cause kernel to crash. Drop the lock after we are done using the structure. Cc: 4.2+ # 4.2+ Fixes: 02373d7c69b4 ("thermal: cpu_cooling: fix lockdep problems in cpu_cooling") Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 69d0f430b2d1..be29489dd247 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -153,8 +153,10 @@ unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) 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); + mutex_unlock(&cooling_list_lock); - return get_level(cpufreq_dev, freq); + return level; } } mutex_unlock(&cooling_list_lock); From patchwork Mon Apr 17 06:01:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97493 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1212535qgf; Sun, 16 Apr 2017 23:03:01 -0700 (PDT) X-Received: by 10.99.60.3 with SMTP id j3mr10160782pga.61.1492408981007; Sun, 16 Apr 2017 23:03:01 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y67si10036543pfj.22.2017.04.16.23.03.00; Sun, 16 Apr 2017 23:03:00 -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 S932843AbdDQGCy (ORCPT + 12 others); Mon, 17 Apr 2017 02:02:54 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:33668 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932646AbdDQGCw (ORCPT ); Mon, 17 Apr 2017 02:02:52 -0400 Received: by mail-pg0-f43.google.com with SMTP id 63so7461268pgh.0 for ; Sun, 16 Apr 2017 23:02:52 -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=Auhs6p+T2cOxRFH4LFdB1HBaWdBnk8M1HEGCW/bVYs1gckDWqzxXljKpIjoLylb69F CSwI9AEJyGLWdAEp3aKpdnaIsvmvnL9mZatT9wrLHKc2Ka0HIimnga7UwJFFZ5VVNIzm dJOFpK9MNE0gspwdljWYyXY0UsPClfNNcN8J0= 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=BB0G0cVEVei5dnbf4V6vgG34QM2dY2B8A+AWVXfV9VMZntiGIcQI7l3BPCqBdRCuPS jqUHZxqUBf0QVRjVMBRr22Z4w5H13ZODlOFssw/dGJT88Sm+lnMrJtDCkOHhyVFSGs2z U5qdn8wWoJzdg+vWx2imR4Wv5fqFC0lPGNSyqWrh63Ongkbpq3B/j5ZcRN1l0F+dVI98 fecyJleB0JRQeQx2stJDaAUVTbQMJSLUB+hsJ3HfPlMND34OnWscaDooCuE1Ntx3HUJ8 SavWisfq9lAcFxKn++qQh2BO7Pa861EWcdNAvlnqH5G3VnH/MoeDq9918RePG+907iRa PYfQ== X-Gm-Message-State: AN3rC/5NPe0A9nU9mApZybknCu1YgtgywE7+ZHneT8OjwQxQfrR/MQ2c 4bwQLreYWNacBJuF X-Received: by 10.98.41.199 with SMTP id p190mr9920993pfp.266.1492408971426; Sun, 16 Apr 2017 23:02:51 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id o17sm15289236pfa.98.2017.04.16.23.02.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Apr 2017 23:02:50 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , 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 Subject: [PATCH V2 03/17] thermal: cpu_cooling: Name cpufreq cooling devices as cpufreq_cdev Date: Mon, 17 Apr 2017 11:31:48 +0530 Message-Id: <323c25bfc9454e54102b0956bae049365f1ba2bb.1492408342.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 Mon Apr 17 06:01:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97496 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1212609qgf; Sun, 16 Apr 2017 23:03:20 -0700 (PDT) X-Received: by 10.84.217.202 with SMTP id d10mr13506146plj.135.1492409000029; Sun, 16 Apr 2017 23:03:20 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v19si10043557pfd.309.2017.04.16.23.03.19; Sun, 16 Apr 2017 23:03: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 S932919AbdDQGDN (ORCPT + 12 others); Mon, 17 Apr 2017 02:03:13 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:33499 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932865AbdDQGDK (ORCPT ); Mon, 17 Apr 2017 02:03:10 -0400 Received: by mail-pf0-f171.google.com with SMTP id s16so61540158pfs.0 for ; Sun, 16 Apr 2017 23:03:10 -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=Pw7X0xYKMMh5/ID2VMnNWBBP3THCeTog2qEsd4qpCH8=; b=h0d0nhHS/bFwg9FmUDCKV8sFDlT+dVrhF5gHVLggYA+7cVfpbbKWTpDbCW0f4cQ+x6 HbcR7mV/49Tuja+X928/HFu8Vt1VsjiFqIn8v9T3FgcG6j2zh0nwMCXy1JuKn7v+tqE3 O7guSc8W0C5nbsvKQeOmAjX08y4NUX1PJjIJM= 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=Pw7X0xYKMMh5/ID2VMnNWBBP3THCeTog2qEsd4qpCH8=; b=RdOqALbm76FmzcFGp4fkm6bG6ODDVTZzPriKZDWbcmCwbI3xhh3EEJTmZiQOMrstRp 4pqwOO38J8SlforFSuCF4c5lueWPqYFKir35heGWGhqItXc6l9eUm8XX175XQ4KfgTIv GA46OSgD7OWQQ1tn4MouK084UDK/yUQZ0P7nVpLHrWkBAGszxSyWykCl+TdU+PO5MwtG q2O6GuNa85HIi+cSkizYFQhHLns+jaQteGjNDznoibxpJ+QWbRr35mBZV3YIso3ClBvA VZc87CznkGkp7VJlbyRv/Hlxa0G7POcIYkGVQvGEXsL62Cq8dSGt4bLsWfRcyAAai8Ui IHiw== X-Gm-Message-State: AN3rC/64NZ/KabF3WQvv2WGBy/xbhKbtpXA+b6kWbZ2lv6BFZhVgIWw7 QhMajCK6aueXly5b X-Received: by 10.99.117.8 with SMTP id q8mr10051198pgc.106.1492408989911; Sun, 16 Apr 2017 23:03:09 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id o10sm15283775pfe.78.2017.04.16.23.03.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Apr 2017 23:03:09 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , "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 Subject: [PATCH V2 08/17] cpufreq: create cpufreq_table_count_valid_entries() Date: Mon, 17 Apr 2017 11:31:53 +0530 Message-Id: <359e9dc250c2b24a8aad0551e939d5ed8a779c22.1492408342.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 23b0d3cf853a..48fc5447bbf6 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -739,15 +739,15 @@ __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; bool first; - 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); } @@ -772,20 +772,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) { @@ -811,7 +807,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 Mon Apr 17 06:01:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97498 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1212652qgf; Sun, 16 Apr 2017 23:03:31 -0700 (PDT) X-Received: by 10.98.150.211 with SMTP id s80mr10245914pfk.15.1492409011015; Sun, 16 Apr 2017 23:03:31 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5si10024993plt.253.2017.04.16.23.03.30; Sun, 16 Apr 2017 23:03:31 -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 S932951AbdDQGDV (ORCPT + 12 others); Mon, 17 Apr 2017 02:03:21 -0400 Received: from mail-pg0-f48.google.com ([74.125.83.48]:36747 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932941AbdDQGDS (ORCPT ); Mon, 17 Apr 2017 02:03:18 -0400 Received: by mail-pg0-f48.google.com with SMTP id g2so67321019pge.3 for ; Sun, 16 Apr 2017 23:03:13 -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=m18ZzdhPtd13lUc4s8u4z9Uul/OeL2k08NZLvcSB1bw=; b=H4LbZo/A5AZ3w3DzMPoC4EX/ln3z/tlQx3nFPZUUZHqvx16Zizu/YHFDvxCYHCo+nF PorrRZN3Fpq006SRrUglddikI+rJ+4/kQNtUWmePkLqj7j54loiJfS9qbkG3TfvYX4n9 cb6wC0j5xTC8d6mE0rGQ1QkECao69NcH3sJcQ= 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=m18ZzdhPtd13lUc4s8u4z9Uul/OeL2k08NZLvcSB1bw=; b=UGBhb6tbCZTOu8tlj2bbbKw00iu0aD1LondqVoyUit56mt5DaXChy/xGa07ArLaJD6 il87K4IynPlnqLK+K8yrg5BNwaHYJR/9hYyGC8yvU/qp96ID83PKEzaeY4HhoMK7oU/U /HPE6q7e61YYJfaBfLkX7vGB7JmAAuzdYG/7i4yiJHuA1ph2k/96Mf7mJVAACpNaPtCn C1EirxcW5aVaj0K51eCdKuYSr1lZ11uduzae7wbw3WuKaifIrG/9BSoRrKWx0UiazRGk YHqKD9jrAPungiweVeCDFIO/N+CW3B7C5SaWJpGeu95phsFNaBx50SEv1Vnejeq/2AZK Nldg== X-Gm-Message-State: AN3rC/7E/1Pt1e+J6urtyeQ0ccmt/gECF6EGC3AGZKVelhBW8twR1u2q yXwqj32fWX/78TbI X-Received: by 10.84.179.99 with SMTP id a90mr13415667plc.26.1492408993184; Sun, 16 Apr 2017 23:03:13 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id b8sm15375240pgn.51.2017.04.16.23.03.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Apr 2017 23:03:12 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , 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 Subject: [PATCH V2 09/17] thermal: cpu_cooling: store cpufreq policy Date: Mon, 17 Apr 2017 11:31:54 +0530 Message-Id: <43bc32f0c5fc796fd90f3c2310bb04a8226ccf64.1492408342.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 cpufreq policy can be used by the cpu_cooling driver, lets store it in the cpufreq_cooling_device structure. Signed-off-by: Viresh Kumar --- 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 48fc5447bbf6..bc018c628c93 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; @@ -827,6 +829,7 @@ __cpufreq_cooling_register(struct device_node *np, cpufreq_cdev->clipped_freq = cpufreq_cdev->freq_table[0]; cpufreq_cdev->cdev = cdev; + cpufreq_cdev->policy = policy; mutex_lock(&cooling_list_lock); /* Register the notifier for first cpufreq cooling device */ From patchwork Mon Apr 17 06:01:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97500 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1212659qgf; Sun, 16 Apr 2017 23:03:32 -0700 (PDT) X-Received: by 10.84.225.129 with SMTP id u1mr13572160plj.123.1492409011972; Sun, 16 Apr 2017 23:03:31 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5si10024993plt.253.2017.04.16.23.03.31; Sun, 16 Apr 2017 23:03:31 -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 S932968AbdDQGDZ (ORCPT + 12 others); Mon, 17 Apr 2017 02:03:25 -0400 Received: from mail-pg0-f48.google.com ([74.125.83.48]:33752 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932961AbdDQGDW (ORCPT ); Mon, 17 Apr 2017 02:03:22 -0400 Received: by mail-pg0-f48.google.com with SMTP id 63so7465797pgh.0 for ; Sun, 16 Apr 2017 23:03:21 -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=uTyV3zKwtfiKGloebR8qhIzsNQawmYQUjzmaGDwWons=; b=AOwH7qvAGvhD/+M6X3z8Xzvu21TH26aejQMXut/Qx+vgQoTcDL0SOwO6HanWdevwwf 061CIPrkBuHVk9GYC1zm666aakD3x06FgIPqUnBntAgBluAVa44fFvDClHMrJ9l0ZbcU nG4MDLaLeFnfNEx9BOPk/QkH6LmJWzOpux8l8= 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=uTyV3zKwtfiKGloebR8qhIzsNQawmYQUjzmaGDwWons=; b=mwYb+WV0ZvvE4blESV00n2qP1tlMX4RxDQB4nTkQF/FCGEGrEaqDmg0RXQ/TPlDxj8 QpaV38LpU9LVpByr7SNexsEMZexM8/rXxHKiwMRZUchpaJn3KhYUDlrbayq5Az0U6zYc Mbbu7ZJFuzOVEAYgaiOTIht8GVLxyTSOrNJ+dds+n3QZLW3QOiGd7HtQFfnHP8SbNK7f 6d/VJ2AjPCOcIAk7RwZKxVxsg/ukq5AagbKlyMzsrAsucAO92Mg2qR7+pGISr0q5u5B0 VCoyHhNfu9hJR+M+iyTClJUJypZ+xDtI7JR+gHrXFKPTmtvBqR+RackEX9gqilmhgfin lLwg== X-Gm-Message-State: AN3rC/4BO/34evgaVU2+KG3XcnlqpUT4M8Tx9onfTricGPw/4lFUGY3d 204mvf4Hof3hWqqe X-Received: by 10.98.42.14 with SMTP id q14mr9905392pfq.229.1492408996426; Sun, 16 Apr 2017 23:03:16 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id o1sm15268691pfb.122.2017.04.16.23.03.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Apr 2017 23:03:15 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , 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 Subject: [PATCH V2 10/17] thermal: cpu_cooling: OPPs are registered for all CPUs Date: Mon, 17 Apr 2017 11:31:55 +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 The OPPs are registered for all CPUs of a cpufreq policy now and we don't need to run the loop in build_dyn_power_table(). Just check for the policy->cpu and we should be fine. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index bc018c628c93..3c6b63e7a257 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -83,7 +83,7 @@ struct power_table { * @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 first cpu_device from @allowed_cpus that has OPPs registered + * @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 @@ -207,24 +207,20 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_cdev, struct power_table *power_table; struct dev_pm_opp *opp; struct device *dev = NULL; - int num_opps = 0, cpu, i, ret = 0; + int num_opps = 0, cpu = cpufreq_cdev->policy->cpu, i, ret = 0; unsigned long freq; - for_each_cpu(cpu, &cpufreq_cdev->allowed_cpus) { - dev = get_cpu_device(cpu); - if (!dev) { - dev_warn(&cpufreq_cdev->cdev->device, - "No cpu device for cpu %d\n", cpu); - continue; - } - - num_opps = dev_pm_opp_get_opp_count(dev); - if (num_opps > 0) - break; - else if (num_opps < 0) - return num_opps; + dev = get_cpu_device(cpu); + if (unlikely(!dev)) { + dev_warn(&cpufreq_cdev->cdev->device, + "No cpu device for cpu %d\n", cpu); + return -ENODEV; } + num_opps = dev_pm_opp_get_opp_count(dev); + if (num_opps < 0) + return num_opps; + if (num_opps == 0) return -EINVAL; From patchwork Mon Apr 17 06:01:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97503 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1212764qgf; Sun, 16 Apr 2017 23:03:56 -0700 (PDT) X-Received: by 10.98.17.92 with SMTP id z89mr10306789pfi.185.1492409036181; Sun, 16 Apr 2017 23:03:56 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g26si10020227pge.96.2017.04.16.23.03.55; Sun, 16 Apr 2017 23:03:56 -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 S933007AbdDQGDo (ORCPT + 12 others); Mon, 17 Apr 2017 02:03:44 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:33764 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932975AbdDQGDa (ORCPT ); Mon, 17 Apr 2017 02:03:30 -0400 Received: by mail-pg0-f53.google.com with SMTP id 63so7466473pgh.0 for ; Sun, 16 Apr 2017 23:03:25 -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=r9Msy1o9PQ0gaTkhXv265SwLQodumER9mJtX76d35M0=; b=Bfm6Kvg95CKAytW9D6b95S2yYrAvC7SBqoPXfrRapqyrmU7CGp3CWgsATGZ+joKABz 8lVDYK6J4dtBSLH9guMqXnVW9CcRuniS+7c7320EzQxn78/NpICgHZlkyh43nmjrTEq8 vWMjIVQpKMkGsZNmfbgJcLKTUEk7dNn90uFcY= 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=r9Msy1o9PQ0gaTkhXv265SwLQodumER9mJtX76d35M0=; b=XpmHzwq4h5vYJYPx7RdZg8kMfxoiyJH7FeVQHaHBV7jpf5gJ59MNtrq67ctktnTZAb n4boeXOOBYG4ZxQxq/sEXxqnDGdaaeXlHFeftKYtiV5fOVBUN6VKV/8CPKjg9Q+B3xqY s5S1HbVMT2lgTewQ1BHzf+wD8TIIj3a1tJ7rM4yHiFGnCU2SiWLMW4Wp5jXeYJkTkUKs CFfkjHOZOouKY0JFdgO90W+WNgWY4x8PDYzOXMfRHy2lQvBTCqKNMWt3uc/xPu4KjegQ oA8RG4oEDAW83TzHWjjxECDNWcEa3Rck6v/KF3ZHB/0IgFY+aecy3cur/7K9TblFzhzW P2YA== X-Gm-Message-State: AN3rC/52r+dgo1eQmsz3ZJKDiWc7duKH/gmmMJZG0I0H7wchECGI8Bm/ bL1hOYEPDWSJgKCt X-Received: by 10.84.230.230 with SMTP id e93mr13670314plk.187.1492408999631; Sun, 16 Apr 2017 23:03:19 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id y123sm15315624pfg.52.2017.04.16.23.03.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Apr 2017 23:03:19 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , 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 Subject: [PATCH V2 11/17] thermal: cpu_cooling: get rid of 'allowed_cpus' Date: Mon, 17 Apr 2017 11:31:56 +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 '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 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 3c6b63e7a257..37a1605a4d7a 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; } @@ -780,8 +747,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 Mon Apr 17 06:01:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97502 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1212757qgf; Sun, 16 Apr 2017 23:03:55 -0700 (PDT) X-Received: by 10.98.72.86 with SMTP id v83mr2079330pfa.29.1492409035549; Sun, 16 Apr 2017 23:03:55 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g26si10020227pge.96.2017.04.16.23.03.55; Sun, 16 Apr 2017 23:03:55 -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 S932967AbdDQGDe (ORCPT + 12 others); Mon, 17 Apr 2017 02:03:34 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:36808 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932989AbdDQGDc (ORCPT ); Mon, 17 Apr 2017 02:03:32 -0400 Received: by mail-pg0-f43.google.com with SMTP id g2so67324276pge.3 for ; Sun, 16 Apr 2017 23:03:32 -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=DWPc9OP4YILOJaC/aFXluQxItm3LNrgmYWqZRjNNVY8=; b=fSvZChuohLJgqKaaHirtYvvztydQgpLVf5n9qUMXRvWdHsqqF/tvddifR51y7kbmbc FqjYKWp5bEE9P7AQniqsvNtD9XCRFKdE05aC1rIRJMSUNcJcmgsPDhpDkHrrGZvYoeNZ mJhHiMlyEVVi8j1k86ExuwnVcDX7Y3sKnu3PU= 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=DWPc9OP4YILOJaC/aFXluQxItm3LNrgmYWqZRjNNVY8=; b=gHRsQD5HIkrwj5dZzQ5ASOe2NNxLjSuzgcfff/T1SxQu3h7ypQqRQKWGXbWYzC/nu6 DR7tcN41UBWqJad8YgmIDFuydnFZlaFLee7GWXGe3t6PTfVvPD3+iIa1savFgM5V5I3G YEf+INnWX2G9yd+cp9hWgcJFWKX5yk79Rul/Kzz+wlmlfasV0v9xHYHnQoeC2CdfPUEV HflLVmYFoo45HTGlcE+uDSE5/5N6nlcfzljKPbDvKOMJS71rtzasD4CI+aevMSrN/WEO o/oP37/9qqCjF1IRFJIWLXo7K7RQB/TNidTQuKrPnUhY/xju8PaIThVA5af+Dj2j4oDH olxw== X-Gm-Message-State: AN3rC/7ZzFaAhsJGdqMcWqhtScyZe5d8myvLrNqw17jV3317bC3vCa7q ivoPi3XmQoqBMOFw X-Received: by 10.84.236.10 with SMTP id q10mr13788024plk.1.1492409011562; Sun, 16 Apr 2017 23:03:31 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id r7sm15297099pfj.20.2017.04.16.23.03.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Apr 2017 23:03:30 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , 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 Subject: [PATCH V2 14/17] thermal: cpu_cooling: get_level() can't fail Date: Mon, 17 Apr 2017 11:31:59 +0530 Message-Id: <97570bba76733addd028e3292d02d70035a029c4.1492408342.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 frequency passed to get_level() is returned by cpu_power_to_freq() and it is guaranteed that get_level() can't fail. Get rid of error code. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index fa29f830fdc0..4ec9234488c6 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -119,22 +119,19 @@ static LIST_HEAD(cpufreq_cdev_list); * @cpufreq_cdev: cpufreq_cdev for which the property is required * @freq: Frequency * - * Return: level on success, THERMAL_CSTATE_INVALID on error. + * Return: level corresponding to the frequency. */ static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, unsigned int freq) { + struct freq_table *freq_table = cpufreq_cdev->freq_table; unsigned long level; - for (level = 0; level <= cpufreq_cdev->max_level; level++) { - if (freq == cpufreq_cdev->freq_table[level].frequency) - return level; - - if (freq > cpufreq_cdev->freq_table[level].frequency) + for (level = 1; level < cpufreq_cdev->max_level; level++) + if (freq > freq_table[level].frequency) break; - } - return THERMAL_CSTATE_INVALID; + return level - 1; } /** @@ -623,13 +620,6 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev, target_freq = cpu_power_to_freq(cpufreq_cdev, normalised_power); *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", - target_freq, policy->cpu); - return -EINVAL; - } - trace_thermal_power_cpu_limit(policy->related_cpus, target_freq, *state, power); return 0; From patchwork Mon Apr 17 06:02:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97505 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1212773qgf; Sun, 16 Apr 2017 23:03:57 -0700 (PDT) X-Received: by 10.84.231.204 with SMTP id g12mr12034980pln.145.1492409037552; Sun, 16 Apr 2017 23:03:57 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g26si10020227pge.96.2017.04.16.23.03.57; Sun, 16 Apr 2017 23:03:57 -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 S933014AbdDQGDu (ORCPT + 12 others); Mon, 17 Apr 2017 02:03:50 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:36533 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932993AbdDQGDr (ORCPT ); Mon, 17 Apr 2017 02:03:47 -0400 Received: by mail-pf0-f172.google.com with SMTP id 194so22275531pfv.3 for ; Sun, 16 Apr 2017 23:03:41 -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=4CQ86N6Dd1pYfyB7qMIpunWt3Pvwfh8awvk19JdwHIc=; b=imLckBT7+cIYH9HBcSqwrQhv8YOaOiBX9Oh+Dzd5eO8EERLzRJXN5NMLWD3PjpLlNs /Qq6F8z8FoeCKei0mgMoietADBw8pj68Xlo004PhNIXtUvwT3GbrU/fjoqyOQXXTbvy3 KBDVex7ttOFFF8lfEJ1uCBvOvUJP3DVW/cGZ0= 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=4CQ86N6Dd1pYfyB7qMIpunWt3Pvwfh8awvk19JdwHIc=; b=K07c7yWDycXHgLfLQwOaestmJgT9NqPY9mQLk/+fqwn5sQz8Nt6u2TG02vCTnfigme NUbixyf193f9Lu9hJcdo3bmn9Ln2OTjjfXPyEYNd+3YVERhaEXDof/Heuzav3V+LxGwC O96bMC1edK3l4ncgH1H5H/5hZlcqrLuIwJ7UPT1eqwAnTc0xr9cQP5WKA6on2c018R8h n9ykKWa2aOlTvhXJiBEtyGcZwGyh5cLoHKnUdbxuB+QimkyGEYFClNGaRCgDw0gD1uJx 4zaifssVq/EuVDGnZySdqqWyi71+TkrLtx1HHGFu1frp1fXfm129cPFyWPMl3aXCD48c hv2Q== X-Gm-Message-State: AN3rC/44g0aCMz00NqyAyPWtFAtocXp9fuI9j5dP6X/B4Bp+yKn3yKCX al8ILcnmL7T6zqHN X-Received: by 10.98.7.1 with SMTP id b1mr10289717pfd.20.1492409021300; Sun, 16 Apr 2017 23:03:41 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id b185sm15305163pfa.61.2017.04.16.23.03.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Apr 2017 23:03:40 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , 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 Subject: [PATCH V2 17/17] thermal: cpu_cooling: Rearrange struct cpufreq_cooling_device Date: Mon, 17 Apr 2017 11:32:02 +0530 Message-Id: <908063832c268f8add94afd2695b2567bc0912ea.1492408342.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 dfc3638ea939..99ffd9f6cbb9 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; };