linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@linaro.org>
To: Javi Merino <javi.merino@kernel.org>,
	Zhang Rui <rui.zhang@intel.com>,
	Eduardo Valentin <edubezval@gmail.com>,
	Lukasz Luba <lukasz.luba@arm.com>,
	Amit Daniel Kachhap <amit.kachhap@gmail.com>,
	Viresh Kumar <viresh.kumar@linaro.org>
Cc: linaro-kernel@lists.linaro.org,
	Rafael Wysocki <rjw@rjwysocki.net>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Punit Agrawal <punit.agrawal@arm.com>
Subject: [PATCH V3 13/17] thermal: cpu_cooling: create structure for idle time stats
Date: Wed, 19 Apr 2017 10:59:08 +0530	[thread overview]
Message-ID: <0b2ff123ccb13c1ba0edb5716d28994884d87734.1492579345.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <cover.1492579345.git.viresh.kumar@linaro.org>
In-Reply-To: <cover.1492579345.git.viresh.kumar@linaro.org>

We keep two arrays for idle time stats and allocate memory for them
separately. It would be much easier to follow if we create an array of
idle stats structure instead and allocate it once.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/thermal/cpu_cooling.c | 53 ++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 28 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 17d6d4635936..71d15448a293 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -62,6 +62,16 @@ struct freq_table {
 };
 
 /**
+ * struct time_in_idle - Idle time stats
+ * @time: previous reading of the absolute time that this cpu was idle
+ * @timestamp: wall time of the last invocation of get_cpu_idle_time_us()
+ */
+struct time_in_idle {
+	u64 time;
+	u64 timestamp;
+};
+
+/**
  * struct cpufreq_cooling_device - data for cooling device with cpufreq
  * @id: unique integer value corresponding to each cpufreq_cooling_device
  *	registered.
@@ -76,9 +86,7 @@ struct freq_table {
  *	cpufreq frequencies.
  * @node: list_head to link all cpufreq_cooling_device together.
  * @last_load: load measured by the latest call to cpufreq_get_requested_power()
- * @time_in_idle: previous reading of the absolute time that this cpu was idle
- * @time_in_idle_timestamp: wall time of the last invocation of
- *	get_cpu_idle_time_us()
+ * @idle_time: idle time stats
  * @cpu_dev: the cpu_device of policy->cpu.
  * @plat_get_static_power: callback to calculate the static power
  *
@@ -95,8 +103,7 @@ struct cpufreq_cooling_device {
 	struct freq_table *freq_table;	/* In descending order */
 	struct list_head node;
 	u32 last_load;
-	u64 *time_in_idle;
-	u64 *time_in_idle_timestamp;
+	struct time_in_idle *idle_time;
 	struct device *cpu_dev;
 	get_static_t plat_get_static_power;
 };
@@ -296,18 +303,19 @@ static u32 get_load(struct cpufreq_cooling_device *cpufreq_cdev, int cpu,
 {
 	u32 load;
 	u64 now, now_idle, delta_time, delta_idle;
+	struct time_in_idle *idle_time = &cpufreq_cdev->idle_time[cpu_idx];
 
 	now_idle = get_cpu_idle_time(cpu, &now, 0);
-	delta_idle = now_idle - cpufreq_cdev->time_in_idle[cpu_idx];
-	delta_time = now - cpufreq_cdev->time_in_idle_timestamp[cpu_idx];
+	delta_idle = now_idle - idle_time->time;
+	delta_time = now - idle_time->timestamp;
 
 	if (delta_time <= delta_idle)
 		load = 0;
 	else
 		load = div64_u64(100 * (delta_time - delta_idle), delta_time);
 
-	cpufreq_cdev->time_in_idle[cpu_idx] = now_idle;
-	cpufreq_cdev->time_in_idle_timestamp[cpu_idx] = now;
+	idle_time->time = now_idle;
+	idle_time->timestamp = now;
 
 	return load;
 }
@@ -711,22 +719,14 @@ __cpufreq_cooling_register(struct device_node *np,
 
 	cpufreq_cdev->policy = policy;
 	num_cpus = cpumask_weight(policy->related_cpus);
-	cpufreq_cdev->time_in_idle = kcalloc(num_cpus,
-					    sizeof(*cpufreq_cdev->time_in_idle),
-					    GFP_KERNEL);
-	if (!cpufreq_cdev->time_in_idle) {
+	cpufreq_cdev->idle_time = kcalloc(num_cpus,
+					 sizeof(*cpufreq_cdev->idle_time),
+					 GFP_KERNEL);
+	if (!cpufreq_cdev->idle_time) {
 		cdev = ERR_PTR(-ENOMEM);
 		goto free_cdev;
 	}
 
-	cpufreq_cdev->time_in_idle_timestamp =
-		kcalloc(num_cpus, sizeof(*cpufreq_cdev->time_in_idle_timestamp),
-			GFP_KERNEL);
-	if (!cpufreq_cdev->time_in_idle_timestamp) {
-		cdev = ERR_PTR(-ENOMEM);
-		goto free_time_in_idle;
-	}
-
 	/* max_level is an index, not a counter */
 	cpufreq_cdev->max_level = i - 1;
 
@@ -734,7 +734,7 @@ __cpufreq_cooling_register(struct device_node *np,
 					  GFP_KERNEL);
 	if (!cpufreq_cdev->freq_table) {
 		cdev = ERR_PTR(-ENOMEM);
-		goto free_time_in_idle_timestamp;
+		goto free_idle_time;
 	}
 
 	ret = ida_simple_get(&cpufreq_ida, 0, 0, GFP_KERNEL);
@@ -797,10 +797,8 @@ __cpufreq_cooling_register(struct device_node *np,
 	ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id);
 free_table:
 	kfree(cpufreq_cdev->freq_table);
-free_time_in_idle_timestamp:
-	kfree(cpufreq_cdev->time_in_idle_timestamp);
-free_time_in_idle:
-	kfree(cpufreq_cdev->time_in_idle);
+free_idle_time:
+	kfree(cpufreq_cdev->idle_time);
 free_cdev:
 	kfree(cpufreq_cdev);
 	return cdev;
@@ -943,8 +941,7 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
 
 	thermal_cooling_device_unregister(cpufreq_cdev->cdev);
 	ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id);
-	kfree(cpufreq_cdev->time_in_idle_timestamp);
-	kfree(cpufreq_cdev->time_in_idle);
+	kfree(cpufreq_cdev->idle_time);
 	kfree(cpufreq_cdev->freq_table);
 	kfree(cpufreq_cdev);
 }
-- 
2.12.0.432.g71c3a4f4ba37

  parent reply	other threads:[~2017-04-19  5:31 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-19  5:28 [PATCH V3 00/17] thermal: cpu_cooling: improve interaction with cpufreq core Viresh Kumar
2017-04-19  5:28 ` [PATCH V3 01/17] thermal: cpu_cooling: Avoid accessing potentially freed structures Viresh Kumar
2017-04-19  5:28 ` [PATCH V3 02/17] thermal: cpu_cooling: rearrange globals Viresh Kumar
2017-04-19  5:28 ` [PATCH V3 03/17] thermal: cpu_cooling: Name cpufreq cooling devices as cpufreq_cdev Viresh Kumar
2017-04-19  5:28 ` [PATCH V3 04/17] thermal: cpu_cooling: replace cool_dev with cdev Viresh Kumar
2017-04-19  5:29 ` [PATCH V3 05/17] thermal: cpu_cooling: remove cpufreq_cooling_get_level() Viresh Kumar
2017-04-19  5:29 ` [PATCH V3 06/17] thermal: cpu_cooling: get rid of a variable in cpufreq_set_cur_state() Viresh Kumar
2017-04-19  5:29 ` [PATCH V3 07/17] thermal: cpu_cooling: use cpufreq_policy to register cooling device Viresh Kumar
2017-04-19  5:29 ` [PATCH V3 08/17] cpufreq: create cpufreq_table_count_valid_entries() Viresh Kumar
2017-04-19  5:29 ` [PATCH V3 09/17] thermal: cpu_cooling: store cpufreq policy Viresh Kumar
2017-04-19  5:29 ` [PATCH V3 10/17] thermal: cpu_cooling: OPPs are registered for all CPUs Viresh Kumar
2017-04-19  5:29 ` [PATCH V3 11/17] thermal: cpu_cooling: get rid of 'allowed_cpus' Viresh Kumar
2017-04-24 16:53   ` Lukasz Luba
2017-04-25  4:57     ` Viresh Kumar
2017-04-25 10:19       ` Lukasz Luba
2017-04-25 10:27         ` Viresh Kumar
2017-04-19  5:29 ` [PATCH V3 12/17] thermal: cpu_cooling: merge frequency and power tables Viresh Kumar
2017-04-19  5:29 ` Viresh Kumar [this message]
2017-04-19  5:29 ` [PATCH V3 14/17] thermal: cpu_cooling: get_level() can't fail Viresh Kumar
2017-04-19  5:29 ` [PATCH V3 15/17] thermal: cpu_cooling: don't store cpu_dev in cpufreq_cdev Viresh Kumar
2017-04-19  5:29 ` [PATCH V3 16/17] thermal: cpu_cooling: 'freq' can't be zero in cpufreq_state2power() Viresh Kumar
2017-04-19  5:29 ` [PATCH V3 17/17] thermal: cpu_cooling: Rearrange struct cpufreq_cooling_device Viresh Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0b2ff123ccb13c1ba0edb5716d28994884d87734.1492579345.git.viresh.kumar@linaro.org \
    --to=viresh.kumar@linaro.org \
    --cc=amit.kachhap@gmail.com \
    --cc=edubezval@gmail.com \
    --cc=javi.merino@kernel.org \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=punit.agrawal@arm.com \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).