cpuacct.h 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/* Time spent by the tasks of the cpu accounting group executing in ... */
enum cpuacct_stat_index {
	CPUACCT_STAT_USER,	/* ... user mode */
	CPUACCT_STAT_SYSTEM,	/* ... kernel mode */

	CPUACCT_STAT_NSTATS,
};

#ifdef CONFIG_CGROUP_CPUACCT

#include <linux/cgroup.h>
/* track cpu usage of a group of tasks and its child groups */
struct cpuacct {
	struct cgroup_subsys_state css;
	/* cpuusage holds pointer to a u64-type object on every cpu */
	u64 __percpu *cpuusage;
	struct kernel_cpustat __percpu *cpustat;
};

extern struct cgroup_subsys cpuacct_subsys;
extern struct cpuacct root_cpuacct;

/* return cpu accounting group corresponding to this container */
static inline struct cpuacct *cgroup_ca(struct cgroup *cgrp)
{
	return container_of(cgroup_subsys_state(cgrp, cpuacct_subsys_id),
			    struct cpuacct, css);
}

/* return cpu accounting group to which this task belongs */
static inline struct cpuacct *task_ca(struct task_struct *tsk)
{
	return container_of(task_subsys_state(tsk, cpuacct_subsys_id),
			    struct cpuacct, css);
}

static inline struct cpuacct *parent_ca(struct cpuacct *ca)
{
39
	if (!ca->css.cgroup->parent)
40 41 42 43
		return NULL;
	return cgroup_ca(ca->css.cgroup->parent);
}

L
Li Zefan 已提交
44
extern void cpuacct_init(void);
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);
47 48 49

#else

L
Li Zefan 已提交
50 51 52 53
static inline void cpuacct_init(void)
{
}

54 55 56 57
static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime)
{
}

58 59 60 61 62
static inline void
cpuacct_account_field(struct task_struct *p, int index, u64 val)
{
}

63
#endif