From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paul Menage Subject: [PATCH 13/33] task containersv11 simple task container debug info subsystem Date: Mon, 17 Sep 2007 14:03:20 -0700 Message-ID: <20070917210428.222009000@menage.corp.google.com> References: <20070917210307.116234000@menage.corp.google.com> Return-path: Content-Disposition: inline; filename=task-containersv11-simple-task-container-debug-info-subsystem.patch Sender: linux-kernel-owner@vger.kernel.org To: akpm@linuxfoundation.org, balbir@linux.vnet.ibm.com, "Serge E. Hallyn" , Cedric Le Goater , "Eric W. Biederman" , Pavel Cc: Nick Piggin , Peter Zijlstra , pj@sgi.com, containers@lists.osdl.org, linux-kernel@vger.kernel.org List-Id: containers.vger.kernel.org This example subsystem exports debugging information as an aid to diagnosing refcount leaks, etc, in the cgroup framework. Signed-off-by: Paul Menage --- include/linux/cgroup_subsys.h | 4 + init/Kconfig | 10 ++ kernel/Makefile | 1 kernel/cgroup_debug.c | 97 +++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+) diff -puN include/linux/cgroup_subsys.h~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem include/linux/cgroup_subsys.h --- a/include/linux/cgroup_subsys.h~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem +++ a/include/linux/cgroup_subsys.h @@ -19,4 +19,8 @@ SUBSYS(cpuacct) /* */ +#ifdef CONFIG_CGROUP_DEBUG +SUBSYS(debug) +#endif + /* */ diff -puN init/Kconfig~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem init/Kconfig --- a/init/Kconfig~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem +++ a/init/Kconfig @@ -282,6 +282,16 @@ config CGROUPS Say N if unsure. +config CGROUP_DEBUG + bool "Example debug cgroup subsystem" + depends on CGROUPS + help + This option enables a simple cgroup subsystem that + exports useful debugging information about the cgroups + framework + + Say N if unsure + config CPUSETS bool "Cpuset support" depends on SMP && CGROUPS diff -puN kernel/Makefile~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem kernel/Makefile --- a/kernel/Makefile~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem +++ a/kernel/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_CGROUPS) += cgroup.o +obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_CGROUP_CPUACCT) += cpu_acct.o obj-$(CONFIG_IKCONFIG) += configs.o diff -puN /dev/null kernel/cgroup_debug.c --- /dev/null +++ a/kernel/cgroup_debug.c @@ -0,0 +1,97 @@ +/* + * kernel/ccontainer_debug.c - Example cgroup subsystem that + * exposes debug info + * + * Copyright (C) Google Inc, 2007 + * + * Developed by Paul Menage (menage@google.com) + * + */ + +#include +#include +#include +#include + +#include + +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; + + cgroup_lock(); + count = cgroup_task_count(cont); + cgroup_unlock(); + 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(); + count = atomic_read(¤t->cgroups->ref.refcount); + rcu_read_unlock(); + return count; +} + +static struct cftype files[] = { + { + .name = "cgroup_refcount", + .read_uint = cgroup_refcount_read, + }, + { + .name = "taskcount", + .read_uint = taskcount_read, + }, + + { + .name = "current_css_set", + .read_uint = current_css_set_read, + }, + + { + .name = "current_css_set_refcount", + .read_uint = current_css_set_refcount_read, + }, +}; + +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, +}; _ -- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756943AbXIQVFK (ORCPT ); Mon, 17 Sep 2007 17:05:10 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752355AbXIQVE6 (ORCPT ); Mon, 17 Sep 2007 17:04:58 -0400 Received: from smtp-out.google.com ([216.239.45.13]:51785 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752874AbXIQVE5 (ORCPT ); Mon, 17 Sep 2007 17:04:57 -0400 DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=received:message-id:references:user-agent:date:from:to:cc: subject:content-disposition; b=rsSQIE0Mx0gTmdIdy6yAJRZFxyx/GNJYyPAAploe/uIlNG4E1EvFPDzEtkdOQqd6m g/Cr8p5T46z25EJHBQzsQ== Message-Id: <20070917210428.222009000@menage.corp.google.com> References: <20070917210307.116234000@menage.corp.google.com> User-Agent: quilt/0.45-1 Date: Mon, 17 Sep 2007 14:03:20 -0700 From: Paul Menage To: akpm@linuxfoundation.org, balbir@linux.vnet.ibm.com, "Serge E. Hallyn" , Cedric Le Goater , "Eric W. Biederman" , Pavel Emelianov , David Rientjes , Vaidyanathan Srinivasan Cc: Nick Piggin , Peter Zijlstra , pj@sgi.com, containers@lists.osdl.org, linux-kernel@vger.kernel.org Subject: [PATCH 13/33] task containersv11 simple task container debug info subsystem Content-Disposition: inline; filename=task-containersv11-simple-task-container-debug-info-subsystem.patch Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org This example subsystem exports debugging information as an aid to diagnosing refcount leaks, etc, in the cgroup framework. Signed-off-by: Paul Menage --- include/linux/cgroup_subsys.h | 4 + init/Kconfig | 10 ++ kernel/Makefile | 1 kernel/cgroup_debug.c | 97 +++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+) diff -puN include/linux/cgroup_subsys.h~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem include/linux/cgroup_subsys.h --- a/include/linux/cgroup_subsys.h~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem +++ a/include/linux/cgroup_subsys.h @@ -19,4 +19,8 @@ SUBSYS(cpuacct) /* */ +#ifdef CONFIG_CGROUP_DEBUG +SUBSYS(debug) +#endif + /* */ diff -puN init/Kconfig~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem init/Kconfig --- a/init/Kconfig~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem +++ a/init/Kconfig @@ -282,6 +282,16 @@ config CGROUPS Say N if unsure. +config CGROUP_DEBUG + bool "Example debug cgroup subsystem" + depends on CGROUPS + help + This option enables a simple cgroup subsystem that + exports useful debugging information about the cgroups + framework + + Say N if unsure + config CPUSETS bool "Cpuset support" depends on SMP && CGROUPS diff -puN kernel/Makefile~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem kernel/Makefile --- a/kernel/Makefile~task-cgroupsv11-simple-task-cgroup-debug-info-subsystem +++ a/kernel/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_CGROUPS) += cgroup.o +obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_CGROUP_CPUACCT) += cpu_acct.o obj-$(CONFIG_IKCONFIG) += configs.o diff -puN /dev/null kernel/cgroup_debug.c --- /dev/null +++ a/kernel/cgroup_debug.c @@ -0,0 +1,97 @@ +/* + * kernel/ccontainer_debug.c - Example cgroup subsystem that + * exposes debug info + * + * Copyright (C) Google Inc, 2007 + * + * Developed by Paul Menage (menage@google.com) + * + */ + +#include +#include +#include +#include + +#include + +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; + + cgroup_lock(); + count = cgroup_task_count(cont); + cgroup_unlock(); + 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(); + count = atomic_read(¤t->cgroups->ref.refcount); + rcu_read_unlock(); + return count; +} + +static struct cftype files[] = { + { + .name = "cgroup_refcount", + .read_uint = cgroup_refcount_read, + }, + { + .name = "taskcount", + .read_uint = taskcount_read, + }, + + { + .name = "current_css_set", + .read_uint = current_css_set_read, + }, + + { + .name = "current_css_set_refcount", + .read_uint = current_css_set_refcount_read, + }, +}; + +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, +}; _ --