Skip to contentSkip to conversation

cpuacct: reduce one NULL check in fast-path

PATCH In review Li Zefan 2 participants 4 messages Mar 11, 2009 – Mar 13, 2009

lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/1 cpuacct: reduce one NULL check in fast-path

In cpuacct_charge(), task_ca() will never return NULL, so change for(...) to do{}while(...) to save one NULL check.

---
 kernel/sched.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/sched.c +3 -2
index 9bb6d24..bc8a91e 100644
@@ -9768,10 +9768,11 @@ static void cpuacct_charge(struct task_struct *tsk, u64 cputime)
 	cpu = task_cpu(tsk);
 	ca = task_ca(tsk);
 
-	for (; ca; ca = ca->parent) {
+	do {
 		u64 *cpuusage = percpu_ptr(ca->cpuusage, cpu);
 		*cpuusage += cputime;
-	}
+		ca = ca->parent;
+	} while (ca);
 }
 
 struct cgroup_subsys cpuacct_subsys = {
Signature · 1 line
1.5.4.rc3
#1 lore raw
Quoted 13 lines · Li Zefan

In cpuacct_charge(), task_ca() will never return NULL, so change for(...) to do{}while(...) to save one NULL check.

---
 kernel/sched.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/sched.c +0 -0
index 9bb6d24..bc8a91e 100644

kernel/sched.c static void cpuacct_charge(struct task_struct *tsk, u64 cputime) · line 9775

Quoted 10 lines
kernel/sched.c +3 -2
@@ -9768,10 +9768,11 @@ static void cpuacct_charge(struct task_struct *tsk, u64 cputime)
 	cpu = task_cpu(tsk);
 	ca = task_ca(tsk);
 
-	for (; ca; ca = ca->parent) {
+	do {
 		u64 *cpuusage = percpu_ptr(ca->cpuusage, cpu);
 		*cpuusage += cputime;
-	}
+		ca = ca->parent;
+	} while (ca);

This patch does not apply cleanly to the latest scheduler tree:

http://people.redhat.com/mingo/tip.git/README

Ingo

author
#2 lore raw

PATCH 1/1 cpuacct: reduce one NULL check in fast-path

In cpuacct_charge(), task_ca() will never return NULL, so change for(...) to do{}while(...) to save one NULL check.

---

rebased on tip tree

---
 kernel/sched.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/sched.c +3 -2
index d40964b..c167f38 100644
@@ -9867,10 +9867,11 @@ static void cpuacct_charge(struct task_struct *tsk, u64 cputime)
 	cpu = task_cpu(tsk);
 	ca = task_ca(tsk);
 
-	for (; ca; ca = ca->parent) {
+	do {
 		u64 *cpuusage = per_cpu_ptr(ca->cpuusage, cpu);
 		*cpuusage += cputime;
-	}
+		ca = ca->parent;
+	} while (ca);
 }
 
 struct cgroup_subsys cpuacct_subsys = {
Signature · 1 line
1.5.4.rc3
author
#3 lore raw
Commit-ID:  7a46c594bf7f1f2eeb1e12d4b857d5f581957a92
Gitweb:     http://git.kernel.org/tip/7a46c594bf7f1f2eeb1e12d4b857d5f581957a92
Author:     Li Zefan <[email protected]>
AuthorDate: Thu, 12 Mar 2009 09:23:01 +0800
Commit:     Ingo Molnar <[email protected]>
CommitDate: Fri, 13 Mar 2009 04:54:58 +0100

cpuacct: reduce one NULL check in fast-path

Impact: micro-optimization

In cpuacct_charge(), task_ca() will never return NULL, so change for(...) to do { } while(...) to save one NULL check.

Cc Peter Zijlstra <[email protected]>
Cc Paul Menage <[email protected]>
Cc Balbir Singh <[email protected]>
Cc Bharata B Rao <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/sched.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/sched.c +3 -2
index 0a76d0b..61e6356 100644
@@ -9599,10 +9599,11 @@ static void cpuacct_charge(struct task_struct *tsk, u64 cputime)
 	cpu = task_cpu(tsk);
 	ca = task_ca(tsk);
 
-	for (; ca; ca = ca->parent) {
+	do {
 		u64 *cpuusage = per_cpu_ptr(ca->cpuusage, cpu);
 		*cpuusage += cputime;
-	}
+		ca = ca->parent;
+	} while (ca);
 }
 
 struct cgroup_subsys cpuacct_subsys = {