cpuacct.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. CPUACCT_STAT_NSTATS,
  6. };
  7. #ifdef CONFIG_CGROUP_CPUACCT
  8. #include <linux/cgroup.h>
  9. /* track cpu usage of a group of tasks and its child groups */
  10. struct cpuacct {
  11. struct cgroup_subsys_state css;
  12. /* cpuusage holds pointer to a u64-type object on every cpu */
  13. u64 __percpu *cpuusage;
  14. struct kernel_cpustat __percpu *cpustat;
  15. };
  16. extern struct cgroup_subsys cpuacct_subsys;
  17. extern struct cpuacct root_cpuacct;
  18. /* return cpu accounting group corresponding to this container */
  19. static inline struct cpuacct *cgroup_ca(struct cgroup *cgrp)
  20. {
  21. return container_of(cgroup_subsys_state(cgrp, cpuacct_subsys_id),
  22. struct cpuacct, css);
  23. }
  24. /* return cpu accounting group to which this task belongs */
  25. static inline struct cpuacct *task_ca(struct task_struct *tsk)
  26. {
  27. return container_of(task_subsys_state(tsk, cpuacct_subsys_id),
  28. struct cpuacct, css);
  29. }
  30. static inline struct cpuacct *parent_ca(struct cpuacct *ca)
  31. {
  32. if (!ca || !ca->css.cgroup->parent)
  33. return NULL;
  34. return cgroup_ca(ca->css.cgroup->parent);
  35. }
  36. extern void cpuacct_init(void);
  37. extern void cpuacct_charge(struct task_struct *tsk, u64 cputime);
  38. extern void cpuacct_account_field(struct task_struct *p, int index, u64 val);
  39. #else
  40. static inline void cpuacct_init(void)
  41. {
  42. }
  43. static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime)
  44. {
  45. }
  46. static inline void
  47. cpuacct_account_field(struct task_struct *p, int index, u64 val)
  48. {
  49. }
  50. #endif