2007-06-19 18:43:31

by Jeff Dike

[permalink] [raw]
Subject: [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.

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


2007-06-19 18:55:30

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 2/2] UML - Add stack usage monitoring

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?

> + for(p = stack; p < end; p++){
> + if(*p != 0)
> + if(left < lowest_to_date){

Are there any plans to fix UML coding style?

2007-06-19 19:50:54

by Jeff Dike

[permalink] [raw]
Subject: Re: [PATCH 2/2] UML - Add stack usage monitoring

On Tue, Jun 19, 2007 at 11:54:22AM -0700, Andrew Morton wrote:
> 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.
>
> > + 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

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

2007-06-19 19:56:55

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH 2/2] UML - Add stack usage monitoring

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

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

> +
> + 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)

if (*p != NULL)
or
if (*p)

> + 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?

> + lowest_to_date = left;
> + }
> + spin_unlock(&low_water_lock);
> +}
> +
> +#endif

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

2007-06-19 20:15:15

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 2/2] UML - Add stack usage monitoring

On Tue, 19 Jun 2007 15:50:03 -0400
Jeff Dike <[email protected]> wrote:

> On Tue, Jun 19, 2007 at 11:54:22AM -0700, Andrew Morton wrote:
> > 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.

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

2007-06-20 14:26:16

by Blaisorblade

[permalink] [raw]
Subject: Re: [uml-devel] [PATCH 2/2] UML - Add stack usage monitoring

On marted? 19 giugno 2007, Andrew Morton wrote:
> On Tue, 19 Jun 2007 15:50:03 -0400
>
> Jeff Dike <[email protected]> wrote:
> > On Tue, Jun 19, 2007 at 11:54:22AM -0700, Andrew Morton wrote:
> > > 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.
>
> <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, it's exactly what CONFIG_DEBUG_STACK_USAGE does for i386... (not sure if
you were still wondering...).

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

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

2007-06-20 14:26:29

by Blaisorblade

[permalink] [raw]
Subject: Re: [uml-devel] [PATCH 2/2] UML - Add stack usage monitoring

On marted? 19 giugno 2007, Andrew Morton wrote:
> 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?
>
> > + 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!
--
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade


Attachments:
(No filename) (1.57 kB)
do-src-style-fix (2.73 kB)
Download all attachments

2007-06-20 15:18:24

by Jeff Dike

[permalink] [raw]
Subject: Re: [uml-devel] [PATCH 2/2] UML - Add stack usage monitoring

On Wed, Jun 20, 2007 at 04:06:58PM +0200, Blaisorblade wrote:
> 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

--
Work email - jdike at linux dot intel dot com

2007-06-20 15:20:42

by Jeff Dike

[permalink] [raw]
Subject: Re: [uml-devel] [PATCH 2/2] UML - Add stack usage monitoring

On Wed, Jun 20, 2007 at 04:18:56PM +0200, Blaisorblade wrote:
> In Italy we say "habits are hard to die"...

"Old habits are hard to kill"

I'm working on it.

> 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

--
Work email - jdike at linux dot intel dot com

2007-06-20 15:37:59

by Jeff Dike

[permalink] [raw]
Subject: Re: [PATCH 2/2] UML - Add stack usage monitoring

On Tue, Jun 19, 2007 at 12:57:07PM -0700, Randy Dunlap wrote:
> Kconfig help text is indented 2 more spaces (by convention or
> CodingStyle).

OK, will fix.

> > + if(*p != 0)
>
> if (*p != NULL)

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

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

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

--
Work email - jdike at linux dot intel dot com

2007-06-20 18:23:42

by Jeff Dike

[permalink] [raw]
Subject: Re: [PATCH 2/2] UML - Add stack usage monitoring

On Tue, Jun 19, 2007 at 01:14:41PM -0700, Andrew Morton wrote:
> 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

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

2007-06-20 22:40:57

by Blaisorblade

[permalink] [raw]
Subject: Re: [uml-devel] [PATCH 2/2] UML - Add stack usage monitoring

On mercoled? 20 giugno 2007, Jeff Dike wrote:
> On Wed, Jun 20, 2007 at 04:06:58PM +0200, Blaisorblade wrote:
> > 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
--
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade