diff options
author | Li Zefan <lizefan@huawei.com> | 2013-03-29 02:37:06 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2013-04-10 07:54:17 -0400 |
commit | 1966aaf7d54608e8ddb7ac454b461840e763409a (patch) | |
tree | 01010d8ff23842f4200e69d2955fd805f50d6e28 /kernel | |
parent | dbe4b41f9800223949ce72e4289814697e0ea91a (diff) |
sched/cpuacct: Add cpuacct_acount_field()
So we can remove open-coded cpuacct code in cputime.c.
Signed-off-by: Li Zefan <lizefan@huawei.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/51553692.9060008@huawei.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/sched/cpuacct.c | 23 | ||||
-rw-r--r-- | kernel/sched/cpuacct.h | 6 | ||||
-rw-r--r-- | kernel/sched/cputime.c | 18 |
3 files changed, 30 insertions, 17 deletions
diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c index 48b5e9184dcc..72bd971ea377 100644 --- a/kernel/sched/cpuacct.c +++ b/kernel/sched/cpuacct.c | |||
@@ -218,6 +218,29 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime) | |||
218 | rcu_read_unlock(); | 218 | rcu_read_unlock(); |
219 | } | 219 | } |
220 | 220 | ||
221 | /* | ||
222 | * Add user/system time to cpuacct. | ||
223 | * | ||
224 | * Note: it's the caller that updates the account of the root cgroup. | ||
225 | */ | ||
226 | void cpuacct_account_field(struct task_struct *p, int index, u64 val) | ||
227 | { | ||
228 | struct kernel_cpustat *kcpustat; | ||
229 | struct cpuacct *ca; | ||
230 | |||
231 | if (unlikely(!cpuacct_subsys.active)) | ||
232 | return; | ||
233 | |||
234 | rcu_read_lock(); | ||
235 | ca = task_ca(p); | ||
236 | while (ca && (ca != &root_cpuacct)) { | ||
237 | kcpustat = this_cpu_ptr(ca->cpustat); | ||
238 | kcpustat->cpustat[index] += val; | ||
239 | ca = parent_ca(ca); | ||
240 | } | ||
241 | rcu_read_unlock(); | ||
242 | } | ||
243 | |||
221 | void __init cpuacct_init(void) | 244 | void __init cpuacct_init(void) |
222 | { | 245 | { |
223 | root_cpuacct.cpustat = &kernel_cpustat; | 246 | root_cpuacct.cpustat = &kernel_cpustat; |
diff --git a/kernel/sched/cpuacct.h b/kernel/sched/cpuacct.h index 551acd729562..bd0409b85525 100644 --- a/kernel/sched/cpuacct.h +++ b/kernel/sched/cpuacct.h | |||
@@ -43,6 +43,7 @@ static inline struct cpuacct *parent_ca(struct cpuacct *ca) | |||
43 | 43 | ||
44 | extern void cpuacct_init(void); | 44 | extern void cpuacct_init(void); |
45 | extern void cpuacct_charge(struct task_struct *tsk, u64 cputime); | 45 | extern void cpuacct_charge(struct task_struct *tsk, u64 cputime); |
46 | extern void cpuacct_account_field(struct task_struct *p, int index, u64 val); | ||
46 | 47 | ||
47 | #else | 48 | #else |
48 | 49 | ||
@@ -54,4 +55,9 @@ static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime) | |||
54 | { | 55 | { |
55 | } | 56 | } |
56 | 57 | ||
58 | static inline void | ||
59 | cpuacct_account_field(struct task_struct *p, int index, u64 val) | ||
60 | { | ||
61 | } | ||
62 | |||
57 | #endif | 63 | #endif |
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index 699d59756ece..33508dc78d0c 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c | |||
@@ -115,10 +115,6 @@ static int irqtime_account_si_update(void) | |||
115 | static inline void task_group_account_field(struct task_struct *p, int index, | 115 | static inline void task_group_account_field(struct task_struct *p, int index, |
116 | u64 tmp) | 116 | u64 tmp) |
117 | { | 117 | { |
118 | #ifdef CONFIG_CGROUP_CPUACCT | ||
119 | struct kernel_cpustat *kcpustat; | ||
120 | struct cpuacct *ca; | ||
121 | #endif | ||
122 | /* | 118 | /* |
123 | * Since all updates are sure to touch the root cgroup, we | 119 | * Since all updates are sure to touch the root cgroup, we |
124 | * get ourselves ahead and touch it first. If the root cgroup | 120 | * get ourselves ahead and touch it first. If the root cgroup |
@@ -127,19 +123,7 @@ static inline void task_group_account_field(struct task_struct *p, int index, | |||
127 | */ | 123 | */ |
128 | __get_cpu_var(kernel_cpustat).cpustat[index] += tmp; | 124 | __get_cpu_var(kernel_cpustat).cpustat[index] += tmp; |
129 | 125 | ||
130 | #ifdef CONFIG_CGROUP_CPUACCT | 126 | cpuacct_account_field(p, index, tmp); |
131 | if (unlikely(!cpuacct_subsys.active)) | ||
132 | return; | ||
133 | |||
134 | rcu_read_lock(); | ||
135 | ca = task_ca(p); | ||
136 | while (ca && (ca != &root_cpuacct)) { | ||
137 | kcpustat = this_cpu_ptr(ca->cpustat); | ||
138 | kcpustat->cpustat[index] += tmp; | ||
139 | ca = parent_ca(ca); | ||
140 | } | ||
141 | rcu_read_unlock(); | ||
142 | #endif | ||
143 | } | 127 | } |
144 | 128 | ||
145 | /* | 129 | /* |