From patchwork Wed May 19 01:30:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Chan X-Patchwork-Id: 100677 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4J1VOcf012192 for ; Wed, 19 May 2010 01:31:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756600Ab0ESBaz (ORCPT ); Tue, 18 May 2010 21:30:55 -0400 Received: from smtp-out.google.com ([74.125.121.35]:10986 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756068Ab0ESBag (ORCPT ); Tue, 18 May 2010 21:30:36 -0400 Received: from wpaz21.hot.corp.google.com (wpaz21.hot.corp.google.com [172.24.198.85]) by smtp-out.google.com with ESMTP id o4J1UPoB015557; Tue, 18 May 2010 18:30:25 -0700 Received: from mikechan.mtv.corp.google.com (mikechan.mtv.corp.google.com [172.18.102.252]) by wpaz21.hot.corp.google.com with ESMTP id o4J1UN1v005106; Tue, 18 May 2010 18:30:23 -0700 Received: by mikechan.mtv.corp.google.com (Postfix, from userid 18922) id 42F8F22022; Tue, 18 May 2010 18:30:23 -0700 (PDT) From: Mike Chan 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 Subject: [PATCH 3/4] scheduler: cpuacct: Enable platform callbacks for cpuacct power tracking Date: Tue, 18 May 2010 18:30:19 -0700 Message-Id: <1274232620-23003-4-git-send-email-mike@android.com> X-Mailer: git-send-email 1.7.0.1 In-Reply-To: <1274232620-23003-1-git-send-email-mike@android.com> References: <1274232620-23003-1-git-send-email-mike@android.com> X-System-Of-Record: true To: unlisted-recipients:; (no To-header on input) Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 19 May 2010 01:31:25 +0000 (UTC) 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)