Skip to content

Commit 60fed78

Browse files
lizf-osingomolnar
authored andcommitted
sched: Split cpuacct code out of sched.h
Add cpuacct.h and let sched.h include it. Signed-off-by: Li Zefan <lizefan@huawei.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/5155367B.2060506@huawei.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 2e76c24 commit 60fed78

2 files changed

Lines changed: 53 additions & 47 deletions

File tree

‎kernel/sched/cpuacct.h‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* Time spent by the tasks of the cpu accounting group executing in ... */
2+
enum cpuacct_stat_index {
3+
CPUACCT_STAT_USER, /* ... user mode */
4+
CPUACCT_STAT_SYSTEM, /* ... kernel mode */
5+
6+
CPUACCT_STAT_NSTATS,
7+
};
8+
9+
#ifdef CONFIG_CGROUP_CPUACCT
10+
11+
#include <linux/cgroup.h>
12+
/* track cpu usage of a group of tasks and its child groups */
13+
struct cpuacct {
14+
struct cgroup_subsys_state css;
15+
/* cpuusage holds pointer to a u64-type object on every cpu */
16+
u64 __percpu *cpuusage;
17+
struct kernel_cpustat __percpu *cpustat;
18+
};
19+
20+
extern struct cgroup_subsys cpuacct_subsys;
21+
extern struct cpuacct root_cpuacct;
22+
23+
/* return cpu accounting group corresponding to this container */
24+
static inline struct cpuacct *cgroup_ca(struct cgroup *cgrp)
25+
{
26+
return container_of(cgroup_subsys_state(cgrp, cpuacct_subsys_id),
27+
struct cpuacct, css);
28+
}
29+
30+
/* return cpu accounting group to which this task belongs */
31+
static inline struct cpuacct *task_ca(struct task_struct *tsk)
32+
{
33+
return container_of(task_subsys_state(tsk, cpuacct_subsys_id),
34+
struct cpuacct, css);
35+
}
36+
37+
static inline struct cpuacct *parent_ca(struct cpuacct *ca)
38+
{
39+
if (!ca || !ca->css.cgroup->parent)
40+
return NULL;
41+
return cgroup_ca(ca->css.cgroup->parent);
42+
}
43+
44+
extern void cpuacct_charge(struct task_struct *tsk, u64 cputime);
45+
46+
#else
47+
48+
static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime)
49+
{
50+
}
51+
52+
#endif

‎kernel/sched/sched.h‎

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/stop_machine.h>
88

99
#include "cpupri.h"
10+
#include "cpuacct.h"
1011

1112
extern __read_mostly int scheduler_running;
1213

@@ -950,14 +951,6 @@ static const u32 prio_to_wmult[40] = {
950951
/* 15 */ 119304647, 148102320, 186737708, 238609294, 286331153,
951952
};
952953

953-
/* Time spent by the tasks of the cpu accounting group executing in ... */
954-
enum cpuacct_stat_index {
955-
CPUACCT_STAT_USER, /* ... user mode */
956-
CPUACCT_STAT_SYSTEM, /* ... kernel mode */
957-
958-
CPUACCT_STAT_NSTATS,
959-
};
960-
961954
#define ENQUEUE_WAKEUP 1
962955
#define ENQUEUE_HEAD 2
963956
#ifdef CONFIG_SMP
@@ -1054,45 +1047,6 @@ extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime
10541047

10551048
extern void update_idle_cpu_load(struct rq *this_rq);
10561049

1057-
#ifdef CONFIG_CGROUP_CPUACCT
1058-
#include <linux/cgroup.h>
1059-
/* track cpu usage of a group of tasks and its child groups */
1060-
struct cpuacct {
1061-
struct cgroup_subsys_state css;
1062-
/* cpuusage holds pointer to a u64-type object on every cpu */
1063-
u64 __percpu *cpuusage;
1064-
struct kernel_cpustat __percpu *cpustat;
1065-
};
1066-
1067-
extern struct cgroup_subsys cpuacct_subsys;
1068-
extern struct cpuacct root_cpuacct;
1069-
1070-
/* return cpu accounting group corresponding to this container */
1071-
static inline struct cpuacct *cgroup_ca(struct cgroup *cgrp)
1072-
{
1073-
return container_of(cgroup_subsys_state(cgrp, cpuacct_subsys_id),
1074-
struct cpuacct, css);
1075-
}
1076-
1077-
/* return cpu accounting group to which this task belongs */
1078-
static inline struct cpuacct *task_ca(struct task_struct *tsk)
1079-
{
1080-
return container_of(task_subsys_state(tsk, cpuacct_subsys_id),
1081-
struct cpuacct, css);
1082-
}
1083-
1084-
static inline struct cpuacct *parent_ca(struct cpuacct *ca)
1085-
{
1086-
if (!ca || !ca->css.cgroup->parent)
1087-
return NULL;
1088-
return cgroup_ca(ca->css.cgroup->parent);
1089-
}
1090-
1091-
extern void cpuacct_charge(struct task_struct *tsk, u64 cputime);
1092-
#else
1093-
static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime) {}
1094-
#endif
1095-
10961050
#ifdef CONFIG_PARAVIRT
10971051
static inline u64 steal_ticks(u64 steal)
10981052
{

0 commit comments

Comments
 (0)