linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Chan <mike@android.com>
To: unlisted-recipients:; (no To-header on input)
Cc: khilman@deeprootsystems.com, menage@google.com,
	balbir@in.ibm.com, cpufreq@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org,
	Mike Chan <mike@android.com>
Subject: [PATCH 3/4] scheduler: cpuacct: Enable platform callbacks for cpuacct power tracking
Date: Tue, 18 May 2010 18:30:19 -0700	[thread overview]
Message-ID: <1274232620-23003-4-git-send-email-mike@android.com> (raw)
In-Reply-To: <1274232620-23003-1-git-send-email-mike@android.com>

Platform must register cpu power function that return power in
milliWatt seconds.

Signed-off-by: Mike Chan <mike@android.com>
---
 Documentation/cgroups/cpuacct.txt |    3 +++
 include/linux/cpuacct.h           |    4 +++-
 kernel/sched.c                    |   24 ++++++++++++++++++++++--
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/Documentation/cgroups/cpuacct.txt b/Documentation/cgroups/cpuacct.txt
index 600d2d0..84e471b 100644
--- a/Documentation/cgroups/cpuacct.txt
+++ b/Documentation/cgroups/cpuacct.txt
@@ -44,6 +44,9 @@ cpuacct.cpufreq file gives CPU time (in nanoseconds) spent at each CPU
 frequency. Platform hooks must be implemented inorder to properly track
 time at each CPU frequency.
 
+cpuacct.power file gives CPU power consumed (in milliWatt seconds). Platform
+must provide and implement power callback functions.
+
 cpuacct controller uses percpu_counter interface to collect user and
 system times. This has two side effects:
 
diff --git a/include/linux/cpuacct.h b/include/linux/cpuacct.h
index 9ff479e..effe842 100644
--- a/include/linux/cpuacct.h
+++ b/include/linux/cpuacct.h
@@ -31,7 +31,9 @@ struct cpuacct_cpufreq_calls {
 	 */
 	void (*init) (void **cpuacct_data);
 	void (*charge) (void *cpuacct_data,  u64 cputime, unsigned int cpu);
-	void (*show) (void *cpuacct_data, struct cgroup_map_cb *cb);
+	void (*cpufreq_show) (void *cpuacct_data, struct cgroup_map_cb *cb);
+	/* Returns power consumed in milliWatt seconds */
+	u64 (*power_usage) (void *cpuacct_data);
 };
 
 int cpuacct_register_cpufreq(struct cpuacct_cpufreq_calls *fn);
diff --git a/kernel/sched.c b/kernel/sched.c
index 6b6c45a..d55d8af 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -8838,12 +8838,28 @@ static int cpuacct_cpufreq_show(struct cgroup *cgrp, struct cftype *cft,
 		struct cgroup_map_cb *cb)
 {
 	struct cpuacct *ca = cgroup_ca(cgrp);
-	if (ca->cpufreq_fn && ca->cpufreq_fn->show)
-		ca->cpufreq_fn->show(ca->cpuacct_data, cb);
+	if (ca->cpufreq_fn && ca->cpufreq_fn->cpufreq_show)
+		ca->cpufreq_fn->cpufreq_show(ca->cpuacct_data, cb);
 
 	return 0;
 }
 
+/* return total cpu power usage (milliWatt second) of a group */
+static u64 cpuacct_powerusage_read(struct cgroup *cgrp, struct cftype *cft)
+{
+	int i;
+	struct cpuacct *ca = cgroup_ca(cgrp);
+	u64 totalpower = 0;
+
+	if (ca->cpufreq_fn && ca->cpufreq_fn->power_usage)
+		for_each_present_cpu(i) {
+			totalpower += ca->cpufreq_fn->power_usage(
+					ca->cpuacct_data);
+		}
+
+	return totalpower;
+}
+
 static struct cftype files[] = {
 	{
 		.name = "usage",
@@ -8862,6 +8878,10 @@ static struct cftype files[] = {
 		.name =  "cpufreq",
 		.read_map = cpuacct_cpufreq_show,
 	},
+	{
+		.name = "power",
+		.read_u64 = cpuacct_powerusage_read
+	},
 };
 
 static int cpuacct_populate(struct cgroup_subsys *ss, struct cgroup *cgrp)
-- 
1.7.0.1


  parent reply	other threads:[~2010-05-19  1:30 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-19  1:30 [PATCH 0/4] Enable cpu frequency and power tracking for cpuacct cgroup Mike Chan
2010-05-19  1:30 ` [PATCH 1/4] scheduler: cpuacct: Enable platform hooks to track cpuusage for CPU frequencies Mike Chan
2010-05-19  1:30 ` [PATCH 2/4] omap: cpu: Implement callbacks for cpu frequency tracking in cpuacct Mike Chan
2010-05-19  1:30 ` Mike Chan [this message]
2010-05-19  9:30   ` [PATCH] scheduler: Extract cgroups_cpuaccount code from sched.c into own file Thomas Renninger
2010-05-19  9:37     ` Peter Zijlstra
2010-05-19 10:27       ` Peter Zijlstra
2010-05-19 18:58         ` scheduler: cleanup sched.c and extract cgroup_cpuaccount stuff into separate file Thomas Renninger
2010-05-19 18:58         ` [PATCH 1/2] scheduler: Extract cgroups_cpuaccount code from sched.c into own file V2 Thomas Renninger
2010-05-19 18:58         ` [PATCH 2/2] scheduler: cgroups cpuaccouting: Make cpuusage atomic Thomas Renninger
2010-05-19 19:02           ` Peter Zijlstra
2010-05-19 19:13             ` Thomas Renninger
2010-05-19 19:31               ` Mike Chan
2010-05-20 10:53             ` Thomas Renninger
2010-05-20  0:43           ` KAMEZAWA Hiroyuki
2010-05-19 19:06     ` [PATCH] scheduler: Extract cgroups_cpuaccount code from sched.c into own file Mike Chan
2010-05-19  1:30 ` [PATCH 4/4] omap: cpu: Power tracking support for cgroup cpuacct Mike Chan
2010-05-19 13:11   ` Nishanth Menon
2010-05-19 15:34     ` Thomas Renninger
2010-05-19 18:56       ` Mike Chan
2010-05-19 19:00         ` Nishanth Menon

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=1274232620-23003-4-git-send-email-mike@android.com \
    --to=mike@android.com \
    --cc=balbir@in.ibm.com \
    --cc=cpufreq@vger.kernel.org \
    --cc=khilman@deeprootsystems.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=menage@google.com \
    /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).