summaryrefslogtreecommitdiffstats
path: root/kernel/cgroup
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2017-10-23 19:18:27 -0400
committerTejun Heo <tj@kernel.org>2017-10-26 13:56:33 -0400
commitd41bf8c9deaed1a90b18d3ffc5639d4c19f0259a (patch)
tree38573de8fb3d037a30430bd16af6806031c2036c /kernel/cgroup
parent0d5936344f30aba0f6ddb92b030cb6a05168efe6 (diff)
cgroup, sched: Move basic cpu stats from cgroup.stat to cpu.stat
The basic cpu stat is currently shown with "cpu." prefix in cgroup.stat, and the same information is duplicated in cpu.stat when cpu controller is enabled. This is ugly and not very scalable as we want to expand the coverage of stat information which is always available. This patch makes cgroup core always create "cpu.stat" file and show the basic cpu stat there and calls the cpu controller to show the extra stats when enabled. This ensures that the same information isn't presented in multiple places and makes future expansion of basic stats easier. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Diffstat (limited to 'kernel/cgroup')
-rw-r--r--kernel/cgroup/cgroup-internal.h1
-rw-r--r--kernel/cgroup/cgroup.c60
-rw-r--r--kernel/cgroup/stat.c10
3 files changed, 64 insertions, 7 deletions
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)