aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/cgroup-v2.txt15
-rw-r--r--include/linux/cgroup-defs.h2
-rw-r--r--include/linux/cgroup.h2
-rw-r--r--kernel/cgroup/cgroup-internal.h1
-rw-r--r--kernel/cgroup/cgroup.c60
-rw-r--r--kernel/cgroup/stat.c10
-rw-r--r--kernel/sched/core.c13
7 files changed, 75 insertions, 28 deletions
diff --git a/Documentation/cgroup-v2.txt b/Documentation/cgroup-v2.txt
index 0bbdc720dd7c..779211fbb69f 100644
--- a/Documentation/cgroup-v2.txt
+++ b/Documentation/cgroup-v2.txt
@@ -886,15 +886,6 @@ All cgroup core files are prefixed with "cgroup."
886 A dying cgroup can consume system resources not exceeding 886 A dying cgroup can consume system resources not exceeding
887 limits, which were active at the moment of cgroup deletion. 887 limits, which were active at the moment of cgroup deletion.
888 888
889 cpu.usage_usec
890 CPU time consumed in the subtree.
891
892 cpu.user_usec
893 User CPU time consumed in the subtree.
894
895 cpu.system_usec
896 System CPU time consumed in the subtree.
897
898 889
899Controllers 890Controllers
900=========== 891===========
@@ -915,12 +906,16 @@ All time durations are in microseconds.
915 906
916 cpu.stat 907 cpu.stat
917 A read-only flat-keyed file which exists on non-root cgroups. 908 A read-only flat-keyed file which exists on non-root cgroups.
909 This file exists whether the controller is enabled or not.
918 910
919 It reports the following six stats: 911 It always reports the following three stats:
920 912
921 - usage_usec 913 - usage_usec
922 - user_usec 914 - user_usec
923 - system_usec 915 - system_usec
916
917 and the following three when the controller is enabled:
918
924 - nr_periods 919 - nr_periods
925 - nr_throttled 920 - nr_throttled
926 - throttled_usec 921 - throttled_usec
diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index 3e55bbd31ad1..ada6df7b1f55 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -569,6 +569,8 @@ struct cgroup_subsys {
569 void (*css_released)(struct cgroup_subsys_state *css); 569 void (*css_released)(struct cgroup_subsys_state *css);
570 void (*css_free)(struct cgroup_subsys_state *css); 570 void (*css_free)(struct cgroup_subsys_state *css);
571 void (*css_reset)(struct cgroup_subsys_state *css); 571 void (*css_reset)(struct cgroup_subsys_state *css);
572 int (*css_extra_stat_show)(struct seq_file *seq,
573 struct cgroup_subsys_state *css);
572 574
573 int (*can_attach)(struct cgroup_taskset *tset); 575 int (*can_attach)(struct cgroup_taskset *tset);
574 void (*cancel_attach)(struct cgroup_taskset *tset); 576 void (*cancel_attach)(struct cgroup_taskset *tset);
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 328a70ce0e23..03cad08b09d1 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -703,8 +703,6 @@ static inline void cpuacct_account_field(struct task_struct *tsk, int index,
703 u64 val) {} 703 u64 val) {}
704#endif 704#endif
705 705
706void cgroup_stat_show_cputime(struct seq_file *seq, const char *prefix);
707
708void __cgroup_account_cputime(struct cgroup *cgrp, u64 delta_exec); 706void __cgroup_account_cputime(struct cgroup *cgrp, u64 delta_exec);
709void __cgroup_account_cputime_field(struct cgroup *cgrp, 707void __cgroup_account_cputime_field(struct cgroup *cgrp,
710 enum cpu_usage_stat index, u64 delta_exec); 708 enum cpu_usage_stat index, u64 delta_exec);
diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h
index fa642c99586a..4dc317090920 100644
--- a/kernel/cgroup/cgroup-internal.h
+++ b/kernel/cgroup/cgroup-internal.h
@@ -205,6 +205,7 @@ int cgroup_task_count(const struct cgroup *cgrp);
205void cgroup_stat_flush(struct cgroup *cgrp); 205void cgroup_stat_flush(struct cgroup *cgrp);
206int cgroup_stat_init(struct cgroup *cgrp); 206int cgroup_stat_init(struct cgroup *cgrp);
207void cgroup_stat_exit(struct cgroup *cgrp); 207void cgroup_stat_exit(struct cgroup *cgrp);
208void cgroup_stat_show_cputime(struct seq_file *seq);
208void cgroup_stat_boot(void); 209void cgroup_stat_boot(void);
209 210
210/* 211/*
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 7975b20f1fd1..d9773e49a1b4 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -464,6 +464,28 @@ static struct cgroup_subsys_state *cgroup_css(struct cgroup *cgrp,
464} 464}
465 465
466/** 466/**
467 * cgroup_tryget_css - try to get a cgroup's css for the specified subsystem
468 * @cgrp: the cgroup of interest
469 * @ss: the subsystem of interest
470 *
471 * Find and get @cgrp's css assocaited with @ss. If the css doesn't exist
472 * or is offline, %NULL is returned.
473 */
474static struct cgroup_subsys_state *cgroup_tryget_css(struct cgroup *cgrp,
475 struct cgroup_subsys *ss)
476{
477 struct cgroup_subsys_state *css;
478
479 rcu_read_lock();
480 css = cgroup_css(cgrp, ss);
481 if (!css || !css_tryget_online(css))
482 css = NULL;
483 rcu_read_unlock();
484
485 return css;
486}
487
488/**
467 * cgroup_e_css - obtain a cgroup's effective css for the specified subsystem 489 * cgroup_e_css - obtain a cgroup's effective css for the specified subsystem
468 * @cgrp: the cgroup of interest 490 * @cgrp: the cgroup of interest
469 * @ss: the subsystem of interest (%NULL returns @cgrp->self) 491 * @ss: the subsystem of interest (%NULL returns @cgrp->self)
@@ -3311,11 +3333,40 @@ static int cgroup_stat_show(struct seq_file *seq, void *v)
3311 seq_printf(seq, "nr_dying_descendants %d\n", 3333 seq_printf(seq, "nr_dying_descendants %d\n",
3312 cgroup->nr_dying_descendants); 3334 cgroup->nr_dying_descendants);
3313 3335
3314 cgroup_stat_show_cputime(seq, "cpu.");
3315
3316 return 0; 3336 return 0;
3317} 3337}
3318 3338
3339static int __maybe_unused cgroup_extra_stat_show(struct seq_file *seq,
3340 struct cgroup *cgrp, int ssid)
3341{
3342 struct cgroup_subsys *ss = cgroup_subsys[ssid];
3343 struct cgroup_subsys_state *css;
3344 int ret;
3345
3346 if (!ss->css_extra_stat_show)
3347 return 0;
3348
3349 css = cgroup_tryget_css(cgrp, ss);
3350 if (!css)
3351 return 0;
3352
3353 ret = ss->css_extra_stat_show(seq, css);
3354 css_put(css);
3355 return ret;
3356}
3357
3358static int cpu_stat_show(struct seq_file *seq, void *v)
3359{
3360 struct cgroup *cgrp = seq_css(seq)->cgroup;
3361 int ret = 0;
3362
3363 cgroup_stat_show_cputime(seq);
3364#ifdef CONFIG_CGROUP_SCHED
3365 ret = cgroup_extra_stat_show(seq, cgrp, cpu_cgrp_id);
3366#endif
3367 return ret;
3368}
3369
3319static int cgroup_file_open(struct kernfs_open_file *of) 3370static int cgroup_file_open(struct kernfs_open_file *of)
3320{ 3371{
3321 struct cftype *cft = of->kn->priv; 3372 struct cftype *cft = of->kn->priv;
@@ -4423,6 +4474,11 @@ static struct cftype cgroup_base_files[] = {
4423 .name = "cgroup.stat", 4474 .name = "cgroup.stat",
4424 .seq_show = cgroup_stat_show, 4475 .seq_show = cgroup_stat_show,
4425 }, 4476 },
4477 {
4478 .name = "cpu.stat",
4479 .flags = CFTYPE_NOT_ON_ROOT,
4480 .seq_show = cpu_stat_show,
4481 },
4426 { } /* terminate */ 4482 { } /* terminate */
4427}; 4483};
4428 4484
diff --git a/kernel/cgroup/stat.c b/kernel/cgroup/stat.c
index 9cce79e89320..133b465691d6 100644
--- a/kernel/cgroup/stat.c
+++ b/kernel/cgroup/stat.c
@@ -256,7 +256,7 @@ void __cgroup_account_cputime_field(struct cgroup *cgrp,
256 cgroup_cpu_stat_account_end(cgrp, cstat); 256 cgroup_cpu_stat_account_end(cgrp, cstat);
257} 257}
258 258
259void cgroup_stat_show_cputime(struct seq_file *seq, const char *prefix) 259void cgroup_stat_show_cputime(struct seq_file *seq)
260{ 260{
261 struct cgroup *cgrp = seq_css(seq)->cgroup; 261 struct cgroup *cgrp = seq_css(seq)->cgroup;
262 u64 usage, utime, stime; 262 u64 usage, utime, stime;
@@ -278,10 +278,10 @@ void cgroup_stat_show_cputime(struct seq_file *seq, const char *prefix)
278 do_div(utime, NSEC_PER_USEC); 278 do_div(utime, NSEC_PER_USEC);
279 do_div(stime, NSEC_PER_USEC); 279 do_div(stime, NSEC_PER_USEC);
280 280
281 seq_printf(seq, "%susage_usec %llu\n" 281 seq_printf(seq, "usage_usec %llu\n"
282 "%suser_usec %llu\n" 282 "user_usec %llu\n"
283 "%ssystem_usec %llu\n", 283 "system_usec %llu\n",
284 prefix, usage, prefix, utime, prefix, stime); 284 usage, utime, stime);
285} 285}
286 286
287int cgroup_stat_init(struct cgroup *cgrp) 287int cgroup_stat_init(struct cgroup *cgrp)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ad255162a830..0b3eec389552 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6678,13 +6678,12 @@ static struct cftype cpu_legacy_files[] = {
6678 { } /* Terminate */ 6678 { } /* Terminate */
6679}; 6679};
6680 6680
6681static int cpu_stat_show(struct seq_file *sf, void *v) 6681static int cpu_extra_stat_show(struct seq_file *sf,
6682 struct cgroup_subsys_state *css)
6682{ 6683{
6683 cgroup_stat_show_cputime(sf, "");
6684
6685#ifdef CONFIG_CFS_BANDWIDTH 6684#ifdef CONFIG_CFS_BANDWIDTH
6686 { 6685 {
6687 struct task_group *tg = css_tg(seq_css(sf)); 6686 struct task_group *tg = css_tg(css);
6688 struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth; 6687 struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
6689 u64 throttled_usec; 6688 u64 throttled_usec;
6690 6689
@@ -6817,11 +6816,6 @@ static ssize_t cpu_max_write(struct kernfs_open_file *of,
6817#endif 6816#endif
6818 6817
6819static struct cftype cpu_files[] = { 6818static struct cftype cpu_files[] = {
6820 {
6821 .name = "stat",
6822 .flags = CFTYPE_NOT_ON_ROOT,
6823 .seq_show = cpu_stat_show,
6824 },
6825#ifdef CONFIG_FAIR_GROUP_SCHED 6819#ifdef CONFIG_FAIR_GROUP_SCHED
6826 { 6820 {
6827 .name = "weight", 6821 .name = "weight",
@@ -6852,6 +6846,7 @@ struct cgroup_subsys cpu_cgrp_subsys = {
6852 .css_online = cpu_cgroup_css_online, 6846 .css_online = cpu_cgroup_css_online,
6853 .css_released = cpu_cgroup_css_released, 6847 .css_released = cpu_cgroup_css_released,
6854 .css_free = cpu_cgroup_css_free, 6848 .css_free = cpu_cgroup_css_free,
6849 .css_extra_stat_show = cpu_extra_stat_show,
6855 .fork = cpu_cgroup_fork, 6850 .fork = cpu_cgroup_fork,
6856 .can_attach = cpu_cgroup_can_attach, 6851 .can_attach = cpu_cgroup_can_attach,
6857 .attach = cpu_cgroup_attach, 6852 .attach = cpu_cgroup_attach,