Commit 73e6aafd authored by Zhao Lei's avatar Zhao Lei Committed by Ingo Molnar

sched/cpuacct: Simplify the cpuacct code

 - Use for() instead of while() loop in some functions
   to make the code simpler.

 - Use this_cpu_ptr() instead of per_cpu_ptr() to make the code
   cleaner and a bit faster.
Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarZhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Tejun Heo <htejun@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/d8a7ef9592f55224630cb26dea239f05b6398a4e.1458187654.git.zhaolei@cn.fujitsu.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 1a736b77
...@@ -238,23 +238,10 @@ static struct cftype files[] = { ...@@ -238,23 +238,10 @@ static struct cftype files[] = {
void cpuacct_charge(struct task_struct *tsk, u64 cputime) void cpuacct_charge(struct task_struct *tsk, u64 cputime)
{ {
struct cpuacct *ca; struct cpuacct *ca;
int cpu;
cpu = task_cpu(tsk);
rcu_read_lock(); rcu_read_lock();
for (ca = task_ca(tsk); ca; ca = parent_ca(ca))
ca = task_ca(tsk); *this_cpu_ptr(ca->cpuusage) += cputime;
while (true) {
u64 *cpuusage = per_cpu_ptr(ca->cpuusage, cpu);
*cpuusage += cputime;
ca = parent_ca(ca);
if (!ca)
break;
}
rcu_read_unlock(); rcu_read_unlock();
} }
...@@ -263,18 +250,13 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime) ...@@ -263,18 +250,13 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime)
* *
* Note: it's the caller that updates the account of the root cgroup. * Note: it's the caller that updates the account of the root cgroup.
*/ */
void cpuacct_account_field(struct task_struct *p, int index, u64 val) void cpuacct_account_field(struct task_struct *tsk, int index, u64 val)
{ {
struct kernel_cpustat *kcpustat;
struct cpuacct *ca; struct cpuacct *ca;
rcu_read_lock(); rcu_read_lock();
ca = task_ca(p); for (ca = task_ca(tsk); ca != &root_cpuacct; ca = parent_ca(ca))
while (ca != &root_cpuacct) { this_cpu_ptr(ca->cpustat)->cpustat[index] += val;
kcpustat = this_cpu_ptr(ca->cpustat);
kcpustat->cpustat[index] += val;
ca = parent_ca(ca);
}
rcu_read_unlock(); rcu_read_unlock();
} }
......
#ifdef CONFIG_CGROUP_CPUACCT #ifdef CONFIG_CGROUP_CPUACCT
extern void cpuacct_charge(struct task_struct *tsk, u64 cputime); extern void cpuacct_charge(struct task_struct *tsk, u64 cputime);
extern void cpuacct_account_field(struct task_struct *p, int index, u64 val); extern void cpuacct_account_field(struct task_struct *tsk, int index, u64 val);
#else #else
...@@ -10,7 +10,7 @@ static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime) ...@@ -10,7 +10,7 @@ static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime)
} }
static inline void static inline void
cpuacct_account_field(struct task_struct *p, int index, u64 val) cpuacct_account_field(struct task_struct *tsk, int index, u64 val)
{ {
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment