Skip to contentSkip to conversation

UML - Add stack usage monitoring

PATCH In review Jeff Dike 5 participants 12 messages Jun 19, 2007 – Jun 20, 2007 User-mode Linux (UML)

lore
Share & tools
lore

Jeff Dike

author
#0 lore raw

PATCH 2/2 UML - Add stack usage monitoring

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.

--

 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(+)
arch/um/Kconfig.debug +9 -0
Index: linux-2.6.21-mm/arch/um/Kconfig.debug
===================================================================
@@ -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
arch/um/kernel/process.c +29 -0
Index: linux-2.6.21-mm/arch/um/kernel/process.c
===================================================================
@@ -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
include/asm-um/thread_info.h +16 -0
Index: linux-2.6.21-mm/include/asm-um/thread_info.h
===================================================================
@@ -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 */
arch/um/defconfig +1 -0
Index: linux-2.6.21-mm/arch/um/defconfig
===================================================================
@@ -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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#1 lore raw
Quoted 5 lines · On Tue, 19 Jun 2007 14:42:45 -0400 Jeff Dike <[email protected]> wrote:

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.

remind us again why the generic code is unsuitable?

arch/um/kernel/process.c unsigned long arch_align_stack(unsigned · line 435

Quoted 3 lines
arch/um/kernel/process.c +3 -0
+	for(p = stack; p < end; p++){
+		if(*p != 0)
+	if(left < lowest_to_date){

Are there any plans to fix UML coding style?

-------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

author
#2 lore raw
Quoted 10 lines · Andrew Morton
Quoted 5 lines · On Tue, 19 Jun 2007 14:42:45 -0400 Jeff Dike <[email protected]> wrote:

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.

remind us again why the generic code is unsuitable?

It does something different - it will tell you the greatest stack usage of any currently running process. What I want to be able to do is run a workload and come back a few days later and see how close anything came to running out of stack.

Quoted 6 lines

arch/um/kernel/process.c unsigned long arch_align_stack(unsigned · line 435

Quoted 4 lines
arch/um/kernel/process.c +3 -0
+	for(p = stack; p < end; p++){
+		if(*p != 0)
+	if(left < lowest_to_date){

Are there any plans to fix UML coding style?

You know I have been fixing it. I forgot to eyeball this patch for style - fixed patch below.

Jeff

Signature · 124 lines
Work email - jdike at linux dot intel dot com


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 <[email protected]>
--
 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 14:06:36.000000000 -0400
+++ linux-2.6.21-mm/arch/um/Kconfig.debug	2007-06-19 14:06:44.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 14:06:36.000000000 -0400
+++ linux-2.6.21-mm/arch/um/kernel/process.c	2007-06-19 15:48:20.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 14:06:36.000000000 -0400
+++ linux-2.6.21-mm/include/asm-um/thread_info.h	2007-06-19 14:06:44.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 14:06:36.000000000 -0400
+++ linux-2.6.21-mm/arch/um/defconfig	2007-06-19 14:06: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
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#3 lore raw
Quoted 18 lines · On Tue, 19 Jun 2007 15:50:03 -0400 Jeff Dike wrote:

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.

--

 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
===================================================================

arch/um/Kconfig.debug config GCOV · line 56

Quoted 10 lines
arch/um/Kconfig.debug +7 -0
@@ -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.

Kconfig help text is indented 2 more spaces (by convention or CodingStyle).

Quoted 16 lines
arch/um/Kconfig.debug +2 -0
+
+	This option will slow down process creation and destruction somewhat.
 endmenu

Index: linux-2.6.21-mm/arch/um/kernel/process.c
===================================================================

arch/um/kernel/process.c +5 -0
@@ -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;

arch/um/kernel/process.c unsigned long arch_align_stack(unsigned · line 428

Quoted 10 lines
arch/um/kernel/process.c +10 -0
+
+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)
		if (*p != NULL)
or
		if (*p)

arch/um/kernel/process.c unsigned long arch_align_stack(unsigned · line 436

Quoted 8 lines
arch/um/kernel/process.c +8 -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);

Does UML need/use KERN_* facility levels in printk() calls?

arch/um/kernel/process.c unsigned long arch_align_stack(unsigned · line 442

Quoted 6 lines
arch/um/kernel/process.c +6 -0
+		lowest_to_date = left;
+	}
+	spin_unlock(&low_water_lock);
+}
+
+#endif

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

-------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

author
#4 lore raw
Quoted 2 lines · Randy Dunlap

Kconfig help text is indented 2 more spaces (by convention or CodingStyle).

OK, will fix.

Quoted 3 lines

arch/um/kernel/process.c unsigned long arch_align_stack(unsigned · line 428

Quoted 1 line
arch/um/kernel/process.c +1 -0
+		if(*p != 0)
		if (*p != NULL)

p is int *, so that's a int version pointer comparision.

Quoted 2 lines

or

		if (*p)

Conceptually, p is an int, not a boolean, so I prefer to type the extra characters to do the int-to-boolean conversion in places that want booleans.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (left < lowest_to_date) {
+		printk("Greatest stack depth - %d bytes left\n", left);

Does UML need/use KERN_* facility levels in printk() calls?

Yes, will fix.

Jeff

Signature · 11 lines
Work email - jdike at linux dot intel dot com

-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#5 lore raw
In reply to Jeff Dike
Quoted 10 lines · On Tue, 19 Jun 2007 15:50:03 -0400 Jeff Dike <[email protected]> wrote:
Quoted 9 lines · Andrew Morton
Quoted 5 lines · On Tue, 19 Jun 2007 14:42:45 -0400 Jeff Dike <[email protected]> wrote:

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.

Quoted 6 lines
Quoted 1 line

remind us again why the generic code is unsuitable?

It does something different - it will tell you the greatest stack usage of any currently running process. What I want to be able to do is run a workload and come back a few days later and see how close anything came to running out of stack.

<looks>

wth? I'm _sure_ we used to have code in there which would, within do_exit(), work out the maximum amount of kernel stack which a task had used and if that was max-since-boot, drop a printk.

Maybe I dreamed it, but I don't think so.

I wonder where it went?

Oh well. Your new code should really be generic, utilising the stack-page-zeroing which CONFIG_DEBUG_STACK_USAGE enables. There's nothing UML-specific about it.

low_water_lock and lowest_to_date should be static to check_stack_usage(), btw..

-------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#6 lore raw
Quoted 21 lines · Andrew Morton

On Tue, 19 Jun 2007 15:50:03 -0400

Quoted 9 lines · Jeff Dike
Quoted 8 lines · Andrew Morton

On Tue, 19 Jun 2007 14:42:45 -0400

Quoted 4 lines · Jeff Dike

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.

Quoted 6 lines
Quoted 1 line

remind us again why the generic code is unsuitable?

It does something different - it will tell you the greatest stack usage of any currently running process. What I want to be able to do is run a workload and come back a few days later and see how close anything came to running out of stack.

<looks>

Quoted 7 lines

wth? I'm _sure_ we used to have code in there which would, within do_exit(), work out the maximum amount of kernel stack which a task had used and if that was max-since-boot, drop a printk.

Maybe I dreamed it, but I don't think so.

I wonder where it went?

Oh, it's exactly what CONFIG_DEBUG_STACK_USAGE does for i386... (not sure if you were still wondering...).

Quoted 6 lines

Oh well. Your new code should really be generic, utilising the stack-page-zeroing which CONFIG_DEBUG_STACK_USAGE enables. There's nothing UML-specific about it.

low_water_lock and lowest_to_date should be static to check_stack_usage(), btw..

Signature · 13 lines
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade

-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
author
#7 lore raw
Quoted 2 lines · Blaisorblade

Oh, it's exactly what CONFIG_DEBUG_STACK_USAGE does for i386... (not sure if you were still wondering...).

Where? The only usage in i386 that I see is thread_info.h zeroing stacks as they are allocated.

Jeff

Signature · 11 lines
Work email - jdike at linux dot intel dot com

-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#8 lore raw
Quoted 6 lines · Jeff Dike
Quoted 2 lines · Blaisorblade

Oh, it's exactly what CONFIG_DEBUG_STACK_USAGE does for i386... (not sure if you were still wondering...).

Where? The only usage in i386 that I see is thread_info.h zeroing stacks as they are allocated.

I only looked at docs. But Andrew Morton said:

"Your new code should really be generic, utilising the stack-page-zeroing which CONFIG_DEBUG_STACK_USAGE enables."

In fact, the other reference is in kernel/sched.c. You may (or may not) join the two stack walking (I would) and match a bit descriptions.

Personally, I'd put the Kconfig option in lib/Kconfig.debug and have a Kconfig flag named DEBUG_STACK_USAGE_SUPPORT, much like LOCKDEP_SUPPORT (defined only by architectures supporting the option), but have no time right now.

Bye

Signature · 13 lines
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade

-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
author
#9 lore raw
In reply to Andrew Morton
Quoted 6 lines · Andrew Morton

Oh well. Your new code should really be generic, utilising the stack-page-zeroing which CONFIG_DEBUG_STACK_USAGE enables. There's nothing UML-specific about it.

low_water_lock and lowest_to_date should be static to check_stack_usage(), btw..

OK, here's a fixed version. Dunno if the prink wants to be more elaborate.

If this is OK, then drop the UML version.

Jeff

Signature · 121 lines
Work email - jdike at linux dot intel dot com



Add generic exit-time stack-depth checking to CONFIG_DEBUG_STACK_USAGE.

This also adds UML support.

Tested on UML and i386.

Signed-off-by: Jeff Dike <[email protected]>
--
 arch/um/Kconfig.debug        |    9 +++++++++
 arch/um/defconfig            |    1 +
 include/asm-um/thread_info.h |    9 +++++++++
 kernel/exit.c                |   24 ++++++++++++++++++++++++
 4 files changed, 43 insertions(+)

Index: linux-2.6.21-mm/kernel/exit.c
===================================================================
--- linux-2.6.21-mm.orig/kernel/exit.c	2007-06-20 11:57:07.000000000 -0400
+++ linux-2.6.21-mm/kernel/exit.c	2007-06-20 13:53:20.000000000 -0400
@@ -867,6 +867,27 @@ static void exit_notify(struct task_stru
 		release_task(tsk);
 }
 
+#ifdef CONFIG_DEBUG_STACK_USAGE
+static void check_stack_usage(void)
+{
+	static DEFINE_SPINLOCK(low_water_lock);
+	static int lowest_to_date = THREAD_SIZE;
+	unsigned long *n = end_of_stack(current), free;
+
+	while (*n == 0)
+		n++;
+	free = (unsigned long)n - (unsigned long)end_of_stack(current);
+
+	spin_lock(&low_water_lock);
+	if (free < lowest_to_date) {
+		printk(KERN_WARNING "Greatest stack depth - %ld bytes left\n",
+		       free);
+		lowest_to_date = free;
+	}
+	spin_unlock(&low_water_lock);
+}
+#endif
+
 fastcall NORET_TYPE void do_exit(long code)
 {
 	struct task_struct *tsk = current;
@@ -942,6 +963,9 @@ fastcall NORET_TYPE void do_exit(long co
 	exit_sem(tsk);
 	__exit_files(tsk);
 	__exit_fs(tsk);
+#ifdef CONFIG_DEBUG_STACK_USAGE
+	check_stack_usage();
+#endif
 	exit_thread();
 	container_exit(tsk, 1);
 	exit_keys(tsk);
Index: linux-2.6.21-mm/arch/um/Kconfig.debug
===================================================================
--- linux-2.6.21-mm.orig/arch/um/Kconfig.debug	2007-06-20 11:57:13.000000000 -0400
+++ linux-2.6.21-mm/arch/um/Kconfig.debug	2007-06-20 11:59:43.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/defconfig
===================================================================
--- linux-2.6.21-mm.orig/arch/um/defconfig	2007-06-20 11:57:13.000000000 -0400
+++ linux-2.6.21-mm/arch/um/defconfig	2007-06-20 11:58:29.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
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-20 11:57:13.000000000 -0400
+++ linux-2.6.21-mm/include/asm-um/thread_info.h	2007-06-20 14:17:22.000000000 -0400
@@ -52,10 +52,19 @@ static inline struct thread_info *curren
 	return ti;
 }
 
+#ifdef CONFIG_DEBUG_STACK_USAGE
+
+#define alloc_thread_info(tsk) \
+	((struct thread_info *) __get_free_pages(GFP_KERNEL | __GFP_ZERO, \
+						 CONFIG_KERNEL_STACK_ORDER))
+#else
+
 /* thread information allocation */
 #define alloc_thread_info(tsk) \
 	((struct thread_info *) __get_free_pages(GFP_KERNEL, \
 						 CONFIG_KERNEL_STACK_ORDER))
+#endif
+
 #define free_thread_info(ti) \
 	free_pages((unsigned long)(ti),CONFIG_KERNEL_STACK_ORDER)
 

-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#10 lore raw
In reply to Andrew Morton
Quoted 8 lines · Andrew Morton

On Tue, 19 Jun 2007 14:42:45 -0400

Quoted 4 lines · Jeff Dike

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.

Quoted 7 lines

remind us again why the generic code is unsuitable?

arch/um/kernel/process.c unsigned long arch_align_stack(unsigned · line 435

Quoted 3 lines
arch/um/kernel/process.c +3 -0
+	for(p = stack; p < end; p++){
+		if(*p != 0)
+	if(left < lowest_to_date){

Are there any plans to fix UML coding style?

In Italy we say "habits are hard to die"...

In an (unanswered) thread, titled "[RFC] Auto-fixups for CodingStyle against major UML violations" from 31/3/2007, also CC'ed to you, Jeff and LKML, I published a script (reattached here) which integrates with quilt and kbuild to fix all sources for these violations. It is not indent based, consequently it does not do any damages that indent would do.

Plus, with just a couple of tiny changes (for substitutions implying the use of '^'), it can also be run on unified diffs.

The only problem is just coordinating to run it together on a source tree and on the patch set applying on it. Otherwise the patchset manager would get hard-to-fix rejects.

In the end: are you interested in this stuff? I'm busy right now but can work to apply these changes after this thursday (i.e. tomorrow). I'd need to get Jeff's patchset to fix it.

Please let me know.

Bye!

Signature · 3 lines
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade

-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

author
#11 lore raw
Quoted 1 line · Blaisorblade

In Italy we say "habits are hard to die"...

"Old habits are hard to kill"

I'm working on it.

Quoted 3 lines

In the end: are you interested in this stuff? I'm busy right now but can work to apply these changes after this thursday
(i.e. tomorrow). I'd need to get Jeff's patchset to fix it.

I actually prefer to do them by hand (although that does have disadvantages, as we've just seen). The reason is that it makes me look at the code line-by-line, and I often see other things which need fixing.

Jeff

Signature · 11 lines
Work email - jdike at linux dot intel dot com

-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel