Skip to contentSkip to conversation

stack usage: Add pid to warning printk in check_stack_usage

PATCH In review Tim Bird 2 participants 2 messages Apr 11, 2012 – Apr 12, 2012

lore
Share & tools
lore

Tim Bird

author
#0 lore raw

PATCH 1/1 stack usage: Add pid to warning printk in check_stack_usage

In embedded systems, sometimes the same program (busybox) is the cause of multiple warnings. Outputting the pid with the program name in the warning printk helps distinguish which instances of a program are using the stack most.

This is a small patch, but useful.

---
 exit.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/exit.c +3 -3
index b8a6a09..bad923d 100644
@@ -898,9 +898,9 @@ static void check_stack_usage(void)
 
 	spin_lock(&low_water_lock);
 	if (free < lowest_to_date) {
-		printk(KERN_WARNING "%s used greatest stack depth: %lu bytes "
-				"left\n",
-				current->comm, free);
+		printk(KERN_WARNING "%s (%d) used greatest stack depth: "
+				"%lu bytes left\n",
+				current->comm, task_pid_nr(current), free);
 		lowest_to_date = free;
 	}
 	spin_unlock(&low_water_lock);
#1 lore raw
Quoted 8 lines · Tim Bird

In embedded systems, sometimes the same program (busybox) is the cause of multiple warnings. Outputting the pid with the program name in the warning printk helps distinguish which instances of a program are using the stack most.

This is a small patch, but useful.

Agreed, pid_nr alone is useless if you read the logs when this app has already terminated.

Quoted 23 lines
---
 exit.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/exit.c +3 -3
index b8a6a09..bad923d 100644
@@ -898,9 +898,9 @@ static void check_stack_usage(void)
 
 	spin_lock(&low_water_lock);
 	if (free < lowest_to_date) {
-		printk(KERN_WARNING "%s used greatest stack depth: %lu bytes "
-				"left\n",
-				current->comm, free);
+		printk(KERN_WARNING "%s (%d) used greatest stack depth: "
+				"%lu bytes left\n",
+				current->comm, task_pid_nr(current), free);
 		lowest_to_date = free;
 	}
 	spin_unlock(&low_water_lock);