2007-10-19 10:39:43 +04:00
/*
2008-04-29 12:00:04 +04:00
* kernel / cgroup_debug . c - Example cgroup subsystem that
2007-10-19 10:39:43 +04:00
* exposes debug info
*
* Copyright ( C ) Google Inc , 2007
*
* Developed by Paul Menage ( menage @ google . com )
*
*/
# include <linux/cgroup.h>
# include <linux/fs.h>
# include <linux/slab.h>
# include <linux/rcupdate.h>
# include <asm/atomic.h>
static struct cgroup_subsys_state * debug_create ( struct cgroup_subsys * ss ,
struct cgroup * cont )
{
struct cgroup_subsys_state * css = kzalloc ( sizeof ( * css ) , GFP_KERNEL ) ;
if ( ! css )
return ERR_PTR ( - ENOMEM ) ;
return css ;
}
static void debug_destroy ( struct cgroup_subsys * ss , struct cgroup * cont )
{
kfree ( cont - > subsys [ debug_subsys_id ] ) ;
}
static u64 cgroup_refcount_read ( struct cgroup * cont , struct cftype * cft )
{
return atomic_read ( & cont - > count ) ;
}
static u64 taskcount_read ( struct cgroup * cont , struct cftype * cft )
{
u64 count ;
count = cgroup_task_count ( cont ) ;
return count ;
}
static u64 current_css_set_read ( struct cgroup * cont , struct cftype * cft )
{
return ( u64 ) ( long ) current - > cgroups ;
}
static u64 current_css_set_refcount_read ( struct cgroup * cont ,
struct cftype * cft )
{
u64 count ;
rcu_read_lock ( ) ;
2008-10-19 07:28:03 +04:00
count = atomic_read ( & current - > cgroups - > refcount ) ;
2007-10-19 10:39:43 +04:00
rcu_read_unlock ( ) ;
return count ;
}
2008-04-29 12:00:04 +04:00
static u64 releasable_read ( struct cgroup * cgrp , struct cftype * cft )
{
return test_bit ( CGRP_RELEASABLE , & cgrp - > flags ) ;
}
2007-10-19 10:39:43 +04:00
static struct cftype files [ ] = {
{
. name = " cgroup_refcount " ,
2008-04-29 11:59:56 +04:00
. read_u64 = cgroup_refcount_read ,
2007-10-19 10:39:43 +04:00
} ,
{
. name = " taskcount " ,
2008-04-29 11:59:56 +04:00
. read_u64 = taskcount_read ,
2007-10-19 10:39:43 +04:00
} ,
{
. name = " current_css_set " ,
2008-04-29 11:59:56 +04:00
. read_u64 = current_css_set_read ,
2007-10-19 10:39:43 +04:00
} ,
{
. name = " current_css_set_refcount " ,
2008-04-29 11:59:56 +04:00
. read_u64 = current_css_set_refcount_read ,
2007-10-19 10:39:43 +04:00
} ,
2008-04-29 12:00:04 +04:00
{
. name = " releasable " ,
. read_u64 = releasable_read ,
2008-10-19 07:28:03 +04:00
} ,
2007-10-19 10:39:43 +04:00
} ;
static int debug_populate ( struct cgroup_subsys * ss , struct cgroup * cont )
{
return cgroup_add_files ( cont , ss , files , ARRAY_SIZE ( files ) ) ;
}
struct cgroup_subsys debug_subsys = {
. name = " debug " ,
. create = debug_create ,
. destroy = debug_destroy ,
. populate = debug_populate ,
. subsys_id = debug_subsys_id ,
} ;