2 * kernel/cgroup_debug.c - Example cgroup subsystem that
5 * Copyright (C) Google Inc, 2007
7 * Developed by Paul Menage (menage@google.com)
11 #include <linux/cgroup.h>
13 #include <linux/slab.h>
14 #include <linux/rcupdate.h>
16 #include <asm/atomic.h>
18 static struct cgroup_subsys_state
*debug_create(struct cgroup_subsys
*ss
,
21 struct cgroup_subsys_state
*css
= kzalloc(sizeof(*css
), GFP_KERNEL
);
24 return ERR_PTR(-ENOMEM
);
29 static void debug_destroy(struct cgroup_subsys
*ss
, struct cgroup
*cont
)
31 kfree(cont
->subsys
[debug_subsys_id
]);
34 static u64
cgroup_refcount_read(struct cgroup
*cont
, struct cftype
*cft
)
36 return atomic_read(&cont
->count
);
39 static u64
taskcount_read(struct cgroup
*cont
, struct cftype
*cft
)
44 count
= cgroup_task_count(cont
);
49 static u64
current_css_set_read(struct cgroup
*cont
, struct cftype
*cft
)
51 return (u64
)(long)current
->cgroups
;
54 static u64
current_css_set_refcount_read(struct cgroup
*cont
,
60 count
= atomic_read(¤t
->cgroups
->refcount
);
65 static u64
releasable_read(struct cgroup
*cgrp
, struct cftype
*cft
)
67 return test_bit(CGRP_RELEASABLE
, &cgrp
->flags
);
70 static struct cftype files
[] = {
72 .name
= "cgroup_refcount",
73 .read_u64
= cgroup_refcount_read
,
77 .read_u64
= taskcount_read
,
81 .name
= "current_css_set",
82 .read_u64
= current_css_set_read
,
86 .name
= "current_css_set_refcount",
87 .read_u64
= current_css_set_refcount_read
,
92 .read_u64
= releasable_read
,
96 static int debug_populate(struct cgroup_subsys
*ss
, struct cgroup
*cont
)
98 return cgroup_add_files(cont
, ss
, files
, ARRAY_SIZE(files
));
101 struct cgroup_subsys debug_subsys
= {
103 .create
= debug_create
,
104 .destroy
= debug_destroy
,
105 .populate
= debug_populate
,
106 .subsys_id
= debug_subsys_id
,