Skip to contentSkip to conversation

parisc,metag: Implement CONFIG_DEBUG_STACK_USAGE option

PATCH In review Helge Deller 2 participants 2 messages Mar 19, 2016 – Apr 29, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 parisc,metag: Implement CONFIG_DEBUG_STACK_USAGE option

On parisc and metag the stack grows upwards, so for those we need to scan the stack downwards in order to calculate how much stack a process has used.

Tested on a 64bit parisc kernel.

include/linux/sched.h +8 -0
index 084ed9f..71591f3 100644
@@ -2859,10 +2859,18 @@ static inline unsigned long stack_not_used(struct task_struct *p)
 	unsigned long *n = end_of_stack(p);
 
 	do { 	/* Skip over canary */
+# ifdef CONFIG_STACK_GROWSUP
+		n--;
+# else
 		n++;
+# endif
 	} while (!*n);
 
+# ifdef CONFIG_STACK_GROWSUP
+	return (unsigned long)end_of_stack(p) - (unsigned long)n;
+# else
 	return (unsigned long)n - (unsigned long)end_of_stack(p);
+# endif
 }
 #endif
 extern void set_task_stack_end_magic(struct task_struct *tsk);
lib/Kconfig.debug +1 -1
index f28f7fa..901f96c 100644
@@ -546,7 +546,7 @@ config DEBUG_KMEMLEAK_DEFAULT_OFF
 
 config DEBUG_STACK_USAGE
 	bool "Stack utilization instrumentation"
-	depends on DEBUG_KERNEL && !IA64 && !PARISC && !METAG
+	depends on DEBUG_KERNEL && !IA64
 	help
 	  Enables the display of the minimum amount of free stack which each
 	  task has ever had available in the sysrq-T and sysrq-P debug output.
Tested-by Acked-by on v1 1/1
#1 lore raw

Hi Helge,

Quoted 7 lines · Helge Deller

On parisc and metag the stack grows upwards, so for those we need to scan the stack downwards in order to calculate how much stack a process has used.

Tested on a 64bit parisc kernel.

Looks good, and works on metag too!

Cheers
James

Quoted 37 lines
include/linux/sched.h +8 -0
index 084ed9f..71591f3 100644
@@ -2859,10 +2859,18 @@ static inline unsigned long stack_not_used(struct task_struct *p)
 	unsigned long *n = end_of_stack(p);
 
 	do { 	/* Skip over canary */
+# ifdef CONFIG_STACK_GROWSUP
+		n--;
+# else
 		n++;
+# endif
 	} while (!*n);
 
+# ifdef CONFIG_STACK_GROWSUP
+	return (unsigned long)end_of_stack(p) - (unsigned long)n;
+# else
 	return (unsigned long)n - (unsigned long)end_of_stack(p);
+# endif
 }
 #endif
 extern void set_task_stack_end_magic(struct task_struct *tsk);
lib/Kconfig.debug +1 -1
index f28f7fa..901f96c 100644
@@ -546,7 +546,7 @@ config DEBUG_KMEMLEAK_DEFAULT_OFF
 
 config DEBUG_STACK_USAGE
 	bool "Stack utilization instrumentation"
-	depends on DEBUG_KERNEL && !IA64 && !PARISC && !METAG
+	depends on DEBUG_KERNEL && !IA64
 	help
 	  Enables the display of the minimum amount of free stack which each
 	  task has ever had available in the sysrq-T and sysrq-P debug output.