Merge branch 'for-4.15' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
[sfrench/cifs-2.6.git] / include / linux / cgroup.h
index dddbc29e20098e0a9f0377f64b0945c87691d315..473e0c0abb8621f732ae3a384acbac63eca8ff11 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/nsproxy.h>
 #include <linux/user_namespace.h>
 #include <linux/refcount.h>
 #include <linux/nsproxy.h>
 #include <linux/user_namespace.h>
 #include <linux/refcount.h>
+#include <linux/kernel_stat.h>
 
 #include <linux/cgroup-defs.h>
 
 
 #include <linux/cgroup-defs.h>
 
@@ -689,6 +690,63 @@ static inline void cgroup_path_from_kernfs_id(const union kernfs_node_id *id,
        char *buf, size_t buflen) {}
 #endif /* !CONFIG_CGROUPS */
 
        char *buf, size_t buflen) {}
 #endif /* !CONFIG_CGROUPS */
 
+/*
+ * Basic resource stats.
+ */
+#ifdef CONFIG_CGROUPS
+
+#ifdef CONFIG_CGROUP_CPUACCT
+void cpuacct_charge(struct task_struct *tsk, u64 cputime);
+void cpuacct_account_field(struct task_struct *tsk, int index, u64 val);
+#else
+static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime) {}
+static inline void cpuacct_account_field(struct task_struct *tsk, int index,
+                                        u64 val) {}
+#endif
+
+void __cgroup_account_cputime(struct cgroup *cgrp, u64 delta_exec);
+void __cgroup_account_cputime_field(struct cgroup *cgrp,
+                                   enum cpu_usage_stat index, u64 delta_exec);
+
+static inline void cgroup_account_cputime(struct task_struct *task,
+                                         u64 delta_exec)
+{
+       struct cgroup *cgrp;
+
+       cpuacct_charge(task, delta_exec);
+
+       rcu_read_lock();
+       cgrp = task_dfl_cgroup(task);
+       if (cgroup_parent(cgrp))
+               __cgroup_account_cputime(cgrp, delta_exec);
+       rcu_read_unlock();
+}
+
+static inline void cgroup_account_cputime_field(struct task_struct *task,
+                                               enum cpu_usage_stat index,
+                                               u64 delta_exec)
+{
+       struct cgroup *cgrp;
+
+       cpuacct_account_field(task, index, delta_exec);
+
+       rcu_read_lock();
+       cgrp = task_dfl_cgroup(task);
+       if (cgroup_parent(cgrp))
+               __cgroup_account_cputime_field(cgrp, index, delta_exec);
+       rcu_read_unlock();
+}
+
+#else  /* CONFIG_CGROUPS */
+
+static inline void cgroup_account_cputime(struct task_struct *task,
+                                         u64 delta_exec) {}
+static inline void cgroup_account_cputime_field(struct task_struct *task,
+                                               enum cpu_usage_stat index,
+                                               u64 delta_exec) {}
+
+#endif /* CONFIG_CGROUPS */
+
 /*
  * sock->sk_cgrp_data handling.  For more info, see sock_cgroup_data
  * definition in cgroup-defs.h.
 /*
  * sock->sk_cgrp_data handling.  For more info, see sock_cgroup_data
  * definition in cgroup-defs.h.