diff options
author | Paul Menage <menage@google.com> | 2007-10-19 02:39:43 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-19 14:53:36 -0400 |
commit | 006cb99200a38a8e3b0cbc1be48035a08921e601 (patch) | |
tree | 9bbbc71000469f94dbd4fbc04b4fb2ff8777604b /kernel | |
parent | 62d0df64065e7c135d0002f069444fbdfc64768f (diff) |
Task Control Groups: simple task cgroup debug info subsystem
This example subsystem exports debugging information as an aid to diagnosing
refcount leaks, etc, in the cgroup framework.
Signed-off-by: Paul Menage <menage@google.com>
Cc: Serge E. Hallyn <serue@us.ibm.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Dave Hansen <haveblue@us.ibm.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Paul Jackson <pj@sgi.com>
Cc: Kirill Korotaev <dev@openvz.org>
Cc: Herbert Poetzl <herbert@13thfloor.at>
Cc: Srivatsa Vaddagiri <vatsa@in.ibm.com>
Cc: Cedric Le Goater <clg@fr.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/Makefile | 1 | ||||
-rw-r--r-- | kernel/cgroup_debug.c | 97 |
2 files changed, 98 insertions, 0 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 48a7fae00271..a50a6debe5fc 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
@@ -37,6 +37,7 @@ obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o | |||
37 | obj-$(CONFIG_KEXEC) += kexec.o | 37 | obj-$(CONFIG_KEXEC) += kexec.o |
38 | obj-$(CONFIG_COMPAT) += compat.o | 38 | obj-$(CONFIG_COMPAT) += compat.o |
39 | obj-$(CONFIG_CGROUPS) += cgroup.o | 39 | obj-$(CONFIG_CGROUPS) += cgroup.o |
40 | obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o | ||
40 | obj-$(CONFIG_CPUSETS) += cpuset.o | 41 | obj-$(CONFIG_CPUSETS) += cpuset.o |
41 | obj-$(CONFIG_CGROUP_CPUACCT) += cpu_acct.o | 42 | obj-$(CONFIG_CGROUP_CPUACCT) += cpu_acct.o |
42 | obj-$(CONFIG_IKCONFIG) += configs.o | 43 | obj-$(CONFIG_IKCONFIG) += configs.o |
diff --git a/kernel/cgroup_debug.c b/kernel/cgroup_debug.c new file mode 100644 index 000000000000..37301e877cb0 --- /dev/null +++ b/kernel/cgroup_debug.c | |||
@@ -0,0 +1,97 @@ | |||
1 | /* | ||
2 | * kernel/ccontainer_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 | |||
18 | static 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 | |||
29 | static void debug_destroy(struct cgroup_subsys *ss, struct cgroup *cont) | ||
30 | { | ||
31 | kfree(cont->subsys[debug_subsys_id]); | ||
32 | } | ||
33 | |||
34 | static u64 cgroup_refcount_read(struct cgroup *cont, struct cftype *cft) | ||
35 | { | ||
36 | return atomic_read(&cont->count); | ||
37 | } | ||
38 | |||
39 | static u64 taskcount_read(struct cgroup *cont, struct cftype *cft) | ||
40 | { | ||
41 | u64 count; | ||
42 | |||
43 | cgroup_lock(); | ||
44 | count = cgroup_task_count(cont); | ||
45 | cgroup_unlock(); | ||
46 | return count; | ||
47 | } | ||
48 | |||
49 | static u64 current_css_set_read(struct cgroup *cont, struct cftype *cft) | ||
50 | { | ||
51 | return (u64)(long)current->cgroups; | ||
52 | } | ||
53 | |||
54 | static u64 current_css_set_refcount_read(struct cgroup *cont, | ||
55 | struct cftype *cft) | ||
56 | { | ||
57 | u64 count; | ||
58 | |||
59 | rcu_read_lock(); | ||
60 | count = atomic_read(¤t->cgroups->ref.refcount); | ||
61 | rcu_read_unlock(); | ||
62 | return count; | ||
63 | } | ||
64 | |||
65 | static struct cftype files[] = { | ||
66 | { | ||
67 | .name = "cgroup_refcount", | ||
68 | .read_uint = cgroup_refcount_read, | ||
69 | }, | ||
70 | { | ||
71 | .name = "taskcount", | ||
72 | .read_uint = taskcount_read, | ||
73 | }, | ||
74 | |||
75 | { | ||
76 | .name = "current_css_set", | ||
77 | .read_uint = current_css_set_read, | ||
78 | }, | ||
79 | |||
80 | { | ||
81 | .name = "current_css_set_refcount", | ||
82 | .read_uint = current_css_set_refcount_read, | ||
83 | }, | ||
84 | }; | ||
85 | |||
86 | static int debug_populate(struct cgroup_subsys *ss, struct cgroup *cont) | ||
87 | { | ||
88 | return cgroup_add_files(cont, ss, files, ARRAY_SIZE(files)); | ||
89 | } | ||
90 | |||
91 | struct cgroup_subsys debug_subsys = { | ||
92 | .name = "debug", | ||
93 | .create = debug_create, | ||
94 | .destroy = debug_destroy, | ||
95 | .populate = debug_populate, | ||
96 | .subsys_id = debug_subsys_id, | ||
97 | }; | ||