Show task_cgroup's nr_running in cgroup's "cpu.stat" file.

This may be useful for containers to check a statistics
of a single container.

Signed-off-by: Kirill Tkhai <[email protected]>
---
 kernel/sched/core.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 1b54707f5344..96dd30e6d243 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6671,7 +6671,7 @@ static int __cfs_schedulable(struct task_group *tg, u64 
period, u64 quota)
 static int cpu_stats_show(struct seq_file *sf, void *v)
 {
        struct task_group *tg = css_tg(seq_css(sf));
-       int i, nr_iowait = 0;
+       int i, nr_running = 0, nr_iowait = 0;
 #ifdef CONFIG_CFS_BANDWIDTH
        struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
 
@@ -6680,8 +6680,15 @@ static int cpu_stats_show(struct seq_file *sf, void *v)
        seq_printf(sf, "throttled_time %llu\n", cfs_b->throttled_time);
 #endif
        for_each_possible_cpu(i) {
+#ifdef CONFIG_FAIR_GROUP_SCHED
+               nr_running += tg->cfs_rq[i]->nr_running;
+#endif
+#ifdef CONFIG_RT_GROUP_SCHED
+               nr_running += tg->rt_rq[i]->rt_nr_running;
+#endif
                nr_iowait += atomic_read(&tg->stat[i].nr_iowait);
        }
+       seq_printf(sf, "nr_running %d\n", nr_running);
        seq_printf(sf, "nr_iowait %d\n", nr_iowait);
 
        return 0;

Reply via email to