aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Chen <kenchen@google.com>2008-12-16 01:02:01 -0500
committerIngo Molnar <mingo@elte.hu>2008-12-16 06:15:00 -0500
commit720f54988e17b33f3f477010b3a68ee872d20d5a (patch)
treeebb475d1a7af97926c1f469a57bef47c46e9ae98
parent34f28ecd0f4bdc733c681294d02d9fab5880591b (diff)
sched, cpuacct: refactoring cpuusage_read / cpuusage_write
Impact: micro-optimize the code on 64-bit architectures In the thread regarding to 'export percpu cpuacct cgroup stats' http://lkml.org/lkml/2008/12/7/13 akpm pointed out that current cpuacct code is inefficient. This patch refactoring the following: * make cpu_rq locking only on 32-bit * change iterator to each_present_cpu instead of each_possible_cpu to make it hotplug friendly. It's a bit of code churn, but I was rewarded with 160 byte code size saving on x86-64 arch and zero code size change on i386. Signed-off-by: Ken Chen <kenchen@google.com> Cc: Paul Menage <menage@google.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--kernel/sched.c56
1 files changed, 39 insertions, 17 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 88215066efae..41b7e2d524d6 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -9275,6 +9275,41 @@ cpuacct_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp)
9275 kfree(ca); 9275 kfree(ca);
9276} 9276}
9277 9277
9278static u64 cpuacct_cpuusage_read(struct cpuacct *ca, int cpu)
9279{
9280 u64 *cpuusage = percpu_ptr(ca->cpuusage, cpu);
9281 u64 data;
9282
9283#ifndef CONFIG_64BIT
9284 /*
9285 * Take rq->lock to make 64-bit read safe on 32-bit platforms.
9286 */
9287 spin_lock_irq(&cpu_rq(cpu)->lock);
9288 data = *cpuusage;
9289 spin_unlock_irq(&cpu_rq(cpu)->lock);
9290#else
9291 data = *cpuusage;
9292#endif
9293
9294 return data;
9295}
9296
9297static void cpuacct_cpuusage_write(struct cpuacct *ca, int cpu, u64 val)
9298{
9299 u64 *cpuusage = percpu_ptr(ca->cpuusage, cpu);
9300
9301#ifndef CONFIG_64BIT
9302 /*
9303 * Take rq->lock to make 64-bit write safe on 32-bit platforms.
9304 */
9305 spin_lock_irq(&cpu_rq(cpu)->lock);
9306 *cpuusage = val;
9307 spin_unlock_irq(&cpu_rq(cpu)->lock);
9308#else
9309 *cpuusage = val;
9310#endif
9311}
9312
9278/* return total cpu usage (in nanoseconds) of a group */ 9313/* return total cpu usage (in nanoseconds) of a group */
9279static u64 cpuusage_read(struct cgroup *cgrp, struct cftype *cft) 9314static u64 cpuusage_read(struct cgroup *cgrp, struct cftype *cft)
9280{ 9315{
@@ -9282,17 +9317,8 @@ static u64 cpuusage_read(struct cgroup *cgrp, struct cftype *cft)
9282 u64 totalcpuusage = 0; 9317 u64 totalcpuusage = 0;
9283 int i; 9318 int i;
9284 9319
9285 for_each_possible_cpu(i) { 9320 for_each_present_cpu(i)
9286 u64 *cpuusage = percpu_ptr(ca->cpuusage, i); 9321 totalcpuusage += cpuacct_cpuusage_read(ca, i);
9287
9288 /*
9289 * Take rq->lock to make 64-bit addition safe on 32-bit
9290 * platforms.
9291 */
9292 spin_lock_irq(&cpu_rq(i)->lock);
9293 totalcpuusage += *cpuusage;
9294 spin_unlock_irq(&cpu_rq(i)->lock);
9295 }
9296 9322
9297 return totalcpuusage; 9323 return totalcpuusage;
9298} 9324}
@@ -9309,13 +9335,9 @@ static int cpuusage_write(struct cgroup *cgrp, struct cftype *cftype,
9309 goto out; 9335 goto out;
9310 } 9336 }
9311 9337
9312 for_each_possible_cpu(i) { 9338 for_each_present_cpu(i)
9313 u64 *cpuusage = percpu_ptr(ca->cpuusage, i); 9339 cpuacct_cpuusage_write(ca, i, 0);
9314 9340
9315 spin_lock_irq(&cpu_rq(i)->lock);
9316 *cpuusage = 0;
9317 spin_unlock_irq(&cpu_rq(i)->lock);
9318 }
9319out: 9341out:
9320 return err; 9342 return err;
9321} 9343}