Paul Menage | 006cb99 | 2007-10-18 23:39:43 -0700 | [diff] [blame] | 1 | /* |
Paul Menage | 3116f0e | 2008-04-29 01:00:04 -0700 | [diff] [blame] | 2 | * kernel/cgroup_debug.c - Example cgroup subsystem that |
Paul Menage | 006cb99 | 2007-10-18 23:39:43 -0700 | [diff] [blame] | 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 | |
Paul Menage | 006cb99 | 2007-10-18 23:39:43 -0700 | [diff] [blame] | 43 | count = cgroup_task_count(cont); |
Paul Menage | 006cb99 | 2007-10-18 23:39:43 -0700 | [diff] [blame] | 44 | return count; |
| 45 | } |
| 46 | |
| 47 | static u64 current_css_set_read(struct cgroup *cont, struct cftype *cft) |
| 48 | { |
| 49 | return (u64)(long)current->cgroups; |
| 50 | } |
| 51 | |
| 52 | static u64 current_css_set_refcount_read(struct cgroup *cont, |
| 53 | struct cftype *cft) |
| 54 | { |
| 55 | u64 count; |
| 56 | |
| 57 | rcu_read_lock(); |
Lai Jiangshan | 146aa1b | 2008-10-18 20:28:03 -0700 | [diff] [blame] | 58 | count = atomic_read(¤t->cgroups->refcount); |
Paul Menage | 006cb99 | 2007-10-18 23:39:43 -0700 | [diff] [blame] | 59 | rcu_read_unlock(); |
| 60 | return count; |
| 61 | } |
| 62 | |
Paul Menage | 3116f0e | 2008-04-29 01:00:04 -0700 | [diff] [blame] | 63 | static u64 releasable_read(struct cgroup *cgrp, struct cftype *cft) |
| 64 | { |
| 65 | return test_bit(CGRP_RELEASABLE, &cgrp->flags); |
| 66 | } |
| 67 | |
Paul Menage | 006cb99 | 2007-10-18 23:39:43 -0700 | [diff] [blame] | 68 | static struct cftype files[] = { |
| 69 | { |
| 70 | .name = "cgroup_refcount", |
Paul Menage | f4c753b | 2008-04-29 00:59:56 -0700 | [diff] [blame] | 71 | .read_u64 = cgroup_refcount_read, |
Paul Menage | 006cb99 | 2007-10-18 23:39:43 -0700 | [diff] [blame] | 72 | }, |
| 73 | { |
| 74 | .name = "taskcount", |
Paul Menage | f4c753b | 2008-04-29 00:59:56 -0700 | [diff] [blame] | 75 | .read_u64 = taskcount_read, |
Paul Menage | 006cb99 | 2007-10-18 23:39:43 -0700 | [diff] [blame] | 76 | }, |
| 77 | |
| 78 | { |
| 79 | .name = "current_css_set", |
Paul Menage | f4c753b | 2008-04-29 00:59:56 -0700 | [diff] [blame] | 80 | .read_u64 = current_css_set_read, |
Paul Menage | 006cb99 | 2007-10-18 23:39:43 -0700 | [diff] [blame] | 81 | }, |
| 82 | |
| 83 | { |
| 84 | .name = "current_css_set_refcount", |
Paul Menage | f4c753b | 2008-04-29 00:59:56 -0700 | [diff] [blame] | 85 | .read_u64 = current_css_set_refcount_read, |
Paul Menage | 006cb99 | 2007-10-18 23:39:43 -0700 | [diff] [blame] | 86 | }, |
Paul Menage | 3116f0e | 2008-04-29 01:00:04 -0700 | [diff] [blame] | 87 | |
| 88 | { |
| 89 | .name = "releasable", |
| 90 | .read_u64 = releasable_read, |
Lai Jiangshan | 146aa1b | 2008-10-18 20:28:03 -0700 | [diff] [blame] | 91 | }, |
Paul Menage | 006cb99 | 2007-10-18 23:39:43 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | static int debug_populate(struct cgroup_subsys *ss, struct cgroup *cont) |
| 95 | { |
| 96 | return cgroup_add_files(cont, ss, files, ARRAY_SIZE(files)); |
| 97 | } |
| 98 | |
| 99 | struct 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 | }; |