aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorPaul Menage <menage@google.com>2009-09-23 18:56:20 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-09-24 10:20:57 -0400
commitfe6934354f8e287275500cd6ec73826d4d6ad457 (patch)
treef5ccab89d27472f5116257d1f7248594d3510882 /kernel
parentc6d57f3312a6619d47c5557b5f6154a74d04ff80 (diff)
cgroups: move the cgroup debug subsys into cgroup.c to access internal state
While it's architecturally clean to have the cgroup debug subsystem be completely independent of the cgroups framework, it limits its usefulness for debugging the contents of internal data structures. Move the debug subsystem code into the scope of all the cgroups data structures to make more detailed debugging possible. Signed-off-by: Paul Menage <menage@google.com> Reviewed-by: Li Zefan <lizf@cn.fujitsu.com> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Balbir Singh <balbir@in.ibm.com> Cc: Dhaval Giani <dhaval@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/Makefile1
-rw-r--r--kernel/cgroup.c88
-rw-r--r--kernel/cgroup_debug.c105
3 files changed, 88 insertions, 106 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index 187c89b4783d..b8d4cd8ac0b9 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -58,7 +58,6 @@ obj-$(CONFIG_KEXEC) += kexec.o
58obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o 58obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o
59obj-$(CONFIG_COMPAT) += compat.o 59obj-$(CONFIG_COMPAT) += compat.o
60obj-$(CONFIG_CGROUPS) += cgroup.o 60obj-$(CONFIG_CGROUPS) += cgroup.o
61obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o
62obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o 61obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o
63obj-$(CONFIG_CPUSETS) += cpuset.o 62obj-$(CONFIG_CPUSETS) += cpuset.o
64obj-$(CONFIG_CGROUP_NS) += ns_cgroup.o 63obj-$(CONFIG_CGROUP_NS) += ns_cgroup.o
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 03204044622f..ccec722213a4 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3781,3 +3781,91 @@ css_get_next(struct cgroup_subsys *ss, int id,
3781 return ret; 3781 return ret;
3782} 3782}
3783 3783
3784#ifdef CONFIG_CGROUP_DEBUG
3785static struct cgroup_subsys_state *debug_create(struct cgroup_subsys *ss,
3786 struct cgroup *cont)
3787{
3788 struct cgroup_subsys_state *css = kzalloc(sizeof(*css), GFP_KERNEL);
3789
3790 if (!css)
3791 return ERR_PTR(-ENOMEM);
3792
3793 return css;
3794}
3795
3796static void debug_destroy(struct cgroup_subsys *ss, struct cgroup *cont)
3797{
3798 kfree(cont->subsys[debug_subsys_id]);
3799}
3800
3801static u64 cgroup_refcount_read(struct cgroup *cont, struct cftype *cft)
3802{
3803 return atomic_read(&cont->count);
3804}
3805
3806static u64 debug_taskcount_read(struct cgroup *cont, struct cftype *cft)
3807{
3808 return cgroup_task_count(cont);
3809}
3810
3811static u64 current_css_set_read(struct cgroup *cont, struct cftype *cft)
3812{
3813 return (u64)(unsigned long)current->cgroups;
3814}
3815
3816static u64 current_css_set_refcount_read(struct cgroup *cont,
3817 struct cftype *cft)
3818{
3819 u64 count;
3820
3821 rcu_read_lock();
3822 count = atomic_read(&current->cgroups->refcount);
3823 rcu_read_unlock();
3824 return count;
3825}
3826
3827static u64 releasable_read(struct cgroup *cgrp, struct cftype *cft)
3828{
3829 return test_bit(CGRP_RELEASABLE, &cgrp->flags);
3830}
3831
3832static struct cftype debug_files[] = {
3833 {
3834 .name = "cgroup_refcount",
3835 .read_u64 = cgroup_refcount_read,
3836 },
3837 {
3838 .name = "taskcount",
3839 .read_u64 = debug_taskcount_read,
3840 },
3841
3842 {
3843 .name = "current_css_set",
3844 .read_u64 = current_css_set_read,
3845 },
3846
3847 {
3848 .name = "current_css_set_refcount",
3849 .read_u64 = current_css_set_refcount_read,
3850 },
3851
3852 {
3853 .name = "releasable",
3854 .read_u64 = releasable_read,
3855 },
3856};
3857
3858static int debug_populate(struct cgroup_subsys *ss, struct cgroup *cont)
3859{
3860 return cgroup_add_files(cont, ss, debug_files,
3861 ARRAY_SIZE(debug_files));
3862}
3863
3864struct cgroup_subsys debug_subsys = {
3865 .name = "debug",
3866 .create = debug_create,
3867 .destroy = debug_destroy,
3868 .populate = debug_populate,
3869 .subsys_id = debug_subsys_id,
3870};
3871#endif /* CONFIG_CGROUP_DEBUG */
diff --git a/kernel/cgroup_debug.c b/kernel/cgroup_debug.c
deleted file mode 100644
index 0c92d797baa6..000000000000
--- a/kernel/cgroup_debug.c
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * kernel/cgroup_debug.c - Example cgroup subsystem that
3 * exposes debug info
4 *
5 * Copyright (C) Google Inc, 2007
6 *
7 * Developed by Paul Menage (menage@google.com)
8 *
9 */
10
11#include <linux/cgroup.h>
12#include <linux/fs.h>
13#include <linux/slab.h>
14#include <linux/rcupdate.h>
15
16#include <asm/atomic.h>
17
18static struct cgroup_subsys_state *debug_create(struct cgroup_subsys *ss,
19 struct cgroup *cont)
20{
21 struct cgroup_subsys_state *css = kzalloc(sizeof(*css), GFP_KERNEL);
22
23 if (!css)
24 return ERR_PTR(-ENOMEM);
25
26 return css;
27}
28
29static void debug_destroy(struct cgroup_subsys *ss, struct cgroup *cont)
30{
31 kfree(cont->subsys[debug_subsys_id]);
32}
33
34static u64 cgroup_refcount_read(struct cgroup *cont, struct cftype *cft)
35{
36 return atomic_read(&cont->count);
37}
38
39static u64 taskcount_read(struct cgroup *cont, struct cftype *cft)
40{
41 u64 count;
42
43 count = cgroup_task_count(cont);
44 return count;
45}
46
47static u64 current_css_set_read(struct cgroup *cont, struct cftype *cft)
48{
49 return (u64)(long)current->cgroups;
50}
51
52static u64 current_css_set_refcount_read(struct cgroup *cont,
53 struct cftype *cft)
54{
55 u64 count;
56
57 rcu_read_lock();
58 count = atomic_read(&current->cgroups->refcount);
59 rcu_read_unlock();
60 return count;
61}
62
63static u64 releasable_read(struct cgroup *cgrp, struct cftype *cft)
64{
65 return test_bit(CGRP_RELEASABLE, &cgrp->flags);
66}
67
68static struct cftype files[] = {
69 {
70 .name = "cgroup_refcount",
71 .read_u64 = cgroup_refcount_read,
72 },
73 {
74 .name = "taskcount",
75 .read_u64 = taskcount_read,
76 },
77
78 {
79 .name = "current_css_set",
80 .read_u64 = current_css_set_read,
81 },
82
83 {
84 .name = "current_css_set_refcount",
85 .read_u64 = current_css_set_refcount_read,
86 },
87
88 {
89 .name = "releasable",
90 .read_u64 = releasable_read,
91 },
92};
93
94static int debug_populate(struct cgroup_subsys *ss, struct cgroup *cont)
95{
96 return cgroup_add_files(cont, ss, files, ARRAY_SIZE(files));
97}
98
99struct cgroup_subsys debug_subsys = {
100 .name = "debug",
101 .create = debug_create,
102 .destroy = debug_destroy,
103 .populate = debug_populate,
104 .subsys_id = debug_subsys_id,
105};