From: Jeff Dike <jdike@addtoit.com>
To: Andrew Morton <akpm@osdl.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
uml-devel <user-mode-linux-devel@lists.sourceforge.net>
Subject: [uml-devel] [PATCH 2/2] UML - Add stack usage monitoring
Date: Tue, 19 Jun 2007 14:42:45 -0400 [thread overview]
Message-ID: <20070619184245.GA10567@c2.user-mode-linux.org> (raw)
Add a machanism to see how much of a kernel stack is used. This
allocates zeroed stacks and sees where the lowest non-zero byte is on
process exit. It keeps track of the lowest value and logs values as
they get lower.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
--
arch/um/Kconfig.debug | 9 +++++++++
arch/um/defconfig | 1 +
arch/um/kernel/process.c | 29 +++++++++++++++++++++++++++++
include/asm-um/thread_info.h | 16 ++++++++++++++++
4 files changed, 55 insertions(+)
Index: linux-2.6.21-mm/arch/um/Kconfig.debug
===================================================================
--- linux-2.6.21-mm.orig/arch/um/Kconfig.debug 2007-06-19 13:37:16.000000000 -0400
+++ linux-2.6.21-mm/arch/um/Kconfig.debug 2007-06-19 14:05:59.000000000 -0400
@@ -47,4 +47,13 @@ config GCOV
If you're involved in UML kernel development and want to use gcov,
say Y. If you're unsure, say N.
+config DEBUG_STACK_USAGE
+ bool "Stack utilization instrumentation"
+ default N
+ help
+ Track the maximum kernel stack usage - this will look at each
+ kernel stack at process exit and log it if it's the deepest
+ stack seen so far.
+
+ This option will slow down process creation and destruction somewhat.
endmenu
Index: linux-2.6.21-mm/arch/um/kernel/process.c
===================================================================
--- linux-2.6.21-mm.orig/arch/um/kernel/process.c 2007-06-19 13:37:16.000000000 -0400
+++ linux-2.6.21-mm/arch/um/kernel/process.c 2007-06-19 14:01:55.000000000 -0400
@@ -411,3 +411,32 @@ unsigned long arch_align_stack(unsigned
return sp & ~0xf;
}
#endif
+
+#ifdef CONFIG_DEBUG_STACK_USAGE
+
+static DEFINE_SPINLOCK(low_water_lock);
+static int lowest_to_date = THREAD_SIZE;
+
+void check_stack_usage(struct thread_info *s)
+{
+ unsigned int *stack, *p, *end;
+ int left;
+
+ stack = (unsigned int *) (s + 1);
+ end = (unsigned int *) ((unsigned long) s + THREAD_SIZE);
+ for(p = stack; p < end; p++){
+ if(*p != 0)
+ break;
+ }
+
+ left = (p - stack) * sizeof(*p);
+
+ spin_lock(&low_water_lock);
+ if(left < lowest_to_date){
+ printk("Greatest stack depth - %d bytes left\n", left);
+ lowest_to_date = left;
+ }
+ spin_unlock(&low_water_lock);
+}
+
+#endif
Index: linux-2.6.21-mm/include/asm-um/thread_info.h
===================================================================
--- linux-2.6.21-mm.orig/include/asm-um/thread_info.h 2007-06-19 13:37:16.000000000 -0400
+++ linux-2.6.21-mm/include/asm-um/thread_info.h 2007-06-19 13:57:07.000000000 -0400
@@ -52,6 +52,20 @@ static inline struct thread_info *curren
return ti;
}
+#ifdef CONFIG_DEBUG_STACK_USAGE
+
+extern void check_stack_usage(struct thread_info *stack);
+
+#define alloc_thread_info(tsk) \
+ ((struct thread_info *) __get_free_pages(GFP_KERNEL | __GFP_ZERO, \
+ CONFIG_KERNEL_STACK_ORDER))
+
+#define free_thread_info(ti) ({ check_stack_usage(ti) ; \
+ free_pages((unsigned long)(ti), \
+ CONFIG_KERNEL_STACK_ORDER); })
+
+#else
+
/* thread information allocation */
#define alloc_thread_info(tsk) \
((struct thread_info *) __get_free_pages(GFP_KERNEL, \
@@ -61,6 +75,8 @@ static inline struct thread_info *curren
#endif
+#endif
+
#define PREEMPT_ACTIVE 0x10000000
#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
Index: linux-2.6.21-mm/arch/um/defconfig
===================================================================
--- linux-2.6.21-mm.orig/arch/um/defconfig 2007-06-19 13:37:16.000000000 -0400
+++ linux-2.6.21-mm/arch/um/defconfig 2007-06-19 13:51:44.000000000 -0400
@@ -527,3 +527,4 @@ CONFIG_FORCED_INLINING=y
# CONFIG_RCU_TORTURE_TEST is not set
# CONFIG_GPROF is not set
# CONFIG_GCOV is not set
+# CONFIG_DEBUG_STACK_USAGE is not set
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
WARNING: multiple messages have this Message-ID (diff)
From: Jeff Dike <jdike@addtoit.com>
To: Andrew Morton <akpm@osdl.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
uml-devel <user-mode-linux-devel@lists.sourceforge.net>
Subject: [PATCH 2/2] UML - Add stack usage monitoring
Date: Tue, 19 Jun 2007 14:42:45 -0400 [thread overview]
Message-ID: <20070619184245.GA10567@c2.user-mode-linux.org> (raw)
Add a machanism to see how much of a kernel stack is used. This
allocates zeroed stacks and sees where the lowest non-zero byte is on
process exit. It keeps track of the lowest value and logs values as
they get lower.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
--
arch/um/Kconfig.debug | 9 +++++++++
arch/um/defconfig | 1 +
arch/um/kernel/process.c | 29 +++++++++++++++++++++++++++++
include/asm-um/thread_info.h | 16 ++++++++++++++++
4 files changed, 55 insertions(+)
Index: linux-2.6.21-mm/arch/um/Kconfig.debug
===================================================================
--- linux-2.6.21-mm.orig/arch/um/Kconfig.debug 2007-06-19 13:37:16.000000000 -0400
+++ linux-2.6.21-mm/arch/um/Kconfig.debug 2007-06-19 14:05:59.000000000 -0400
@@ -47,4 +47,13 @@ config GCOV
If you're involved in UML kernel development and want to use gcov,
say Y. If you're unsure, say N.
+config DEBUG_STACK_USAGE
+ bool "Stack utilization instrumentation"
+ default N
+ help
+ Track the maximum kernel stack usage - this will look at each
+ kernel stack at process exit and log it if it's the deepest
+ stack seen so far.
+
+ This option will slow down process creation and destruction somewhat.
endmenu
Index: linux-2.6.21-mm/arch/um/kernel/process.c
===================================================================
--- linux-2.6.21-mm.orig/arch/um/kernel/process.c 2007-06-19 13:37:16.000000000 -0400
+++ linux-2.6.21-mm/arch/um/kernel/process.c 2007-06-19 14:01:55.000000000 -0400
@@ -411,3 +411,32 @@ unsigned long arch_align_stack(unsigned
return sp & ~0xf;
}
#endif
+
+#ifdef CONFIG_DEBUG_STACK_USAGE
+
+static DEFINE_SPINLOCK(low_water_lock);
+static int lowest_to_date = THREAD_SIZE;
+
+void check_stack_usage(struct thread_info *s)
+{
+ unsigned int *stack, *p, *end;
+ int left;
+
+ stack = (unsigned int *) (s + 1);
+ end = (unsigned int *) ((unsigned long) s + THREAD_SIZE);
+ for(p = stack; p < end; p++){
+ if(*p != 0)
+ break;
+ }
+
+ left = (p - stack) * sizeof(*p);
+
+ spin_lock(&low_water_lock);
+ if(left < lowest_to_date){
+ printk("Greatest stack depth - %d bytes left\n", left);
+ lowest_to_date = left;
+ }
+ spin_unlock(&low_water_lock);
+}
+
+#endif
Index: linux-2.6.21-mm/include/asm-um/thread_info.h
===================================================================
--- linux-2.6.21-mm.orig/include/asm-um/thread_info.h 2007-06-19 13:37:16.000000000 -0400
+++ linux-2.6.21-mm/include/asm-um/thread_info.h 2007-06-19 13:57:07.000000000 -0400
@@ -52,6 +52,20 @@ static inline struct thread_info *curren
return ti;
}
+#ifdef CONFIG_DEBUG_STACK_USAGE
+
+extern void check_stack_usage(struct thread_info *stack);
+
+#define alloc_thread_info(tsk) \
+ ((struct thread_info *) __get_free_pages(GFP_KERNEL | __GFP_ZERO, \
+ CONFIG_KERNEL_STACK_ORDER))
+
+#define free_thread_info(ti) ({ check_stack_usage(ti) ; \
+ free_pages((unsigned long)(ti), \
+ CONFIG_KERNEL_STACK_ORDER); })
+
+#else
+
/* thread information allocation */
#define alloc_thread_info(tsk) \
((struct thread_info *) __get_free_pages(GFP_KERNEL, \
@@ -61,6 +75,8 @@ static inline struct thread_info *curren
#endif
+#endif
+
#define PREEMPT_ACTIVE 0x10000000
#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
Index: linux-2.6.21-mm/arch/um/defconfig
===================================================================
--- linux-2.6.21-mm.orig/arch/um/defconfig 2007-06-19 13:37:16.000000000 -0400
+++ linux-2.6.21-mm/arch/um/defconfig 2007-06-19 13:51:44.000000000 -0400
@@ -527,3 +527,4 @@ CONFIG_FORCED_INLINING=y
# CONFIG_RCU_TORTURE_TEST is not set
# CONFIG_GPROF is not set
# CONFIG_GCOV is not set
+# CONFIG_DEBUG_STACK_USAGE is not set
next reply other threads:[~2007-06-19 18:42 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-19 18:42 Jeff Dike [this message]
2007-06-19 18:42 ` [PATCH 2/2] UML - Add stack usage monitoring Jeff Dike
2007-06-19 18:54 ` [uml-devel] " Andrew Morton
2007-06-19 18:54 ` Andrew Morton
2007-06-19 19:50 ` [uml-devel] " Jeff Dike
2007-06-19 19:50 ` Jeff Dike
2007-06-19 19:57 ` [uml-devel] " Randy Dunlap
2007-06-19 19:57 ` Randy Dunlap
2007-06-20 15:37 ` [uml-devel] " Jeff Dike
2007-06-20 15:37 ` Jeff Dike
2007-06-19 20:14 ` [uml-devel] " Andrew Morton
2007-06-19 20:14 ` Andrew Morton
2007-06-20 14:06 ` [uml-devel] " Blaisorblade
2007-06-20 14:06 ` Blaisorblade
2007-06-20 15:17 ` Jeff Dike
2007-06-20 15:17 ` Jeff Dike
2007-06-20 20:20 ` Blaisorblade
2007-06-20 20:20 ` Blaisorblade
2007-06-20 18:23 ` Jeff Dike
2007-06-20 18:23 ` Jeff Dike
2007-06-20 14:18 ` [uml-devel] " Blaisorblade
2007-06-20 14:18 ` Blaisorblade
2007-06-20 15:20 ` Jeff Dike
2007-06-20 15:20 ` Jeff Dike
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070619184245.GA10567@c2.user-mode-linux.org \
--to=jdike@addtoit.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=user-mode-linux-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.