linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhang Rui <rui.zhang@intel.com>
To: linux-pm@vger.kernel.org
Cc: amit.daniel@samsung.com, gu1@aeroxteam.fr,
	hongbo.zhang@linaro.org, Zhang Rui <rui.zhang@intel.com>
Subject: [PATCH 2/5] Thermal: Introduce cpu cooling table
Date: Wed,  6 Feb 2013 12:30:03 +0800	[thread overview]
Message-ID: <1360125006-25018-3-git-send-email-rui.zhang@intel.com> (raw)
In-Reply-To: <1360125006-25018-1-git-send-email-rui.zhang@intel.com>

CPU cooling table is a cleaned cpufreq_frequency_table that
1. each entry represents a cooling state,
   aka, each entry has a different frequency.
2. does not have invalid entry.
3. does not have duplicate entry.
4. the frequencies of all the entries are in descending order.

we should use this table inside thermal layer and thermal drivers.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/thermal/cpu_cooling.c |   63 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 455c77a..08f12c7 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -115,6 +115,69 @@ static int is_cpufreq_valid(int cpu)
 	return !cpufreq_get_policy(&policy, cpu);
 }
 
+/*
+ * get the cleaned cpufreq_frequency_table that
+ * 1) does not have invalid entries
+ * 2) does not have duplicate entries
+ * 3) the frequency of the entries are in descending order
+ */
+static struct cpufreq_frequency_table *
+get_cpu_cooling_table(unsigned int cpu)
+{
+	int i = 0;
+	int level;
+	struct cpufreq_frequency_table *old, *new;
+	unsigned int freq = CPUFREQ_ENTRY_INVALID;
+	int descend = -1;
+
+	old = cpufreq_frequency_get_table(cpu);
+	if (!old)
+		return ERR_PTR(-EINVAL);
+
+	while (old[i].frequency != CPUFREQ_TABLE_END)
+		i++;
+
+	i++; /* one more entry for CPUFREQ_TABLE_END */
+
+	new = kzalloc(i * sizeof(struct cpufreq_frequency_table), GFP_KERNEL);
+	if (!new)
+		return ERR_PTR(-ENOMEM);
+
+	for (i = 0, level = 0; old[i].frequency != CPUFREQ_TABLE_END; i++) {
+		/* ignore invalid entry */
+		if (old[i].frequency == CPUFREQ_ENTRY_INVALID)
+			continue;
+
+		/* ignore duplicate entry */
+		if (freq == old[i].frequency)
+			continue;
+
+		/* found an valid entry */
+		new[level].frequency = old[i].frequency;
+
+		if (freq != CPUFREQ_ENTRY_INVALID && descend == -1)
+			descend = !!(freq > old[i].frequency);
+
+		/* freq always equals the last valid frequency */
+		freq = new[level].frequency;
+
+		level++;
+	}
+	new[level].frequency = CPUFREQ_ENTRY_INVALID;
+
+	/* convert to decending if in ascending order */
+	if (!descend) {
+		for(i = 0; i < (level - i - 1); i++) {
+			int j = level - i - 1;
+			freq = new[i].frequency;
+			new[i].frequency = new[j].frequency;
+			new[j].frequency = freq;
+		}
+	}
+
+	return new;
+}
+
 /**
  * get_cpu_frequency - get the absolute value of frequency from level.
  * @cpu: cpu for which frequency is fetched.
-- 
1.7.9.5


  parent reply	other threads:[~2013-02-06  4:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-06  4:30 [PATCH 0/5] Thermal: cpu cooling fix Zhang Rui
2013-02-06  4:30 ` [PATCH 1/5] Thermal: fix a wrong comment Zhang Rui
2013-02-06  4:30 ` Zhang Rui [this message]
2013-02-07  9:36   ` [PATCH 2/5] Thermal: Introduce cpu cooling table Hongbo Zhang
2013-02-08  3:30     ` Zhang Rui
2013-02-08 13:09       ` Hongbo Zhang
2013-02-06  4:30 ` [PATCH 3/5] Thermal: Get cpu frequency via " Zhang Rui
2013-02-06  4:30 ` [PATCH 4/5] Thermal: Get max cpu cooling states " Zhang Rui
2013-02-06  4:30 ` [PATCH 5/5] Thermal: Get cooling state " Zhang Rui
     [not found] <CADGdYn6ehM36k1O3O6mXnHRJBy42N5iACnbOB+bwjPx+RAqQTw@mail.gmail.com>
2013-02-07  1:56 ` [PATCH 2/5] Thermal: Introduce " amit daniel kachhap
2013-02-07  2:53   ` Zhang Rui
2013-02-07 23:18     ` amit kachhap

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=1360125006-25018-3-git-send-email-rui.zhang@intel.com \
    --to=rui.zhang@intel.com \
    --cc=amit.daniel@samsung.com \
    --cc=gu1@aeroxteam.fr \
    --cc=hongbo.zhang@linaro.org \
    --cc=linux-pm@vger.kernel.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).