Skip to content

Commit dbe4b41

Browse files
lizf-osingomolnar
authored andcommitted
sched/cpuacct: Add cpuacct_init()
So we don't open-coded initialization of cpuacct in core.c. Signed-off-by: Li Zefan <lizefan@huawei.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/51553687.1060906@huawei.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 60fed78 commit dbe4b41

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎kernel/sched/core.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6936,12 +6936,8 @@ void __init sched_init(void)
69366936

69376937
#endif /* CONFIG_CGROUP_SCHED */
69386938

6939-
#ifdef CONFIG_CGROUP_CPUACCT
6940-
root_cpuacct.cpustat = &kernel_cpustat;
6941-
root_cpuacct.cpuusage = alloc_percpu(u64);
6942-
/* Too early, not expected to fail */
6943-
BUG_ON(!root_cpuacct.cpuusage);
6944-
#endif
6939+
cpuacct_init();
6940+
69456941
for_each_possible_cpu(i) {
69466942
struct rq *rq;
69476943

‎kernel/sched/cpuacct.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime)
218218
rcu_read_unlock();
219219
}
220220

221+
void __init cpuacct_init(void)
222+
{
223+
root_cpuacct.cpustat = &kernel_cpustat;
224+
root_cpuacct.cpuusage = alloc_percpu(u64);
225+
BUG_ON(!root_cpuacct.cpuusage); /* Too early, not expected to fail */
226+
}
227+
221228
struct cgroup_subsys cpuacct_subsys = {
222229
.name = "cpuacct",
223230
.css_alloc = cpuacct_css_alloc,

‎kernel/sched/cpuacct.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@ static inline struct cpuacct *parent_ca(struct cpuacct *ca)
4141
return cgroup_ca(ca->css.cgroup->parent);
4242
}
4343

44+
extern void cpuacct_init(void);
4445
extern void cpuacct_charge(struct task_struct *tsk, u64 cputime);
4546

4647
#else
4748

49+
static inline void cpuacct_init(void)
50+
{
51+
}
52+
4853
static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime)
4954
{
5055
}

0 commit comments

Comments
 (0)