Skip to contentSkip to conversation

sched: print parent comm in sched_show_task()

PATCH Superseded Tio Zhang 3 participants 9 messages Jan 19, 2023 – Jun 2, 2023 2 messages not in the archive Scheduler

lore
Share & tools
lore

Tio Zhang

author
#0 lore raw

PATCH v2 1/1 sched: print parent comm in sched_show_task()

Knowing who the parent is might be useful for debugging.
For example, we can sometimes resolve kernel hung tasks by stopping the person who begins those hung tasks.
With the parent's name printed in sched_show_task(),
it might be helpful to let people know which "service" should be operated. Also, we move the parent info to a following new line while keeping the original line the same.
And we would print "parent:unknown ppid:<NULL>"
when the task is not alive.

---
 kernel/sched/core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
kernel/sched/core.c +12 -2
index cb2aa2b54c7a..5690a5700f9e 100644
@@ -8854,6 +8854,7 @@ void sched_show_task(struct task_struct *p)
 {
 	unsigned long free = 0;
 	int ppid;
+	char *pcomm = NULL;
 
 	if (!try_get_task_stack(p))
 		return;
@@ -8867,13 +8868,22 @@ void sched_show_task(struct task_struct *p)
 #endif
 	ppid = 0;
 	rcu_read_lock();
-	if (pid_alive(p))
-		ppid = task_pid_nr(rcu_dereference(p->real_parent));
+	if (pid_alive(p)) {
+		struct task_struct *parent = rcu_dereference(p->real_parent);
+
+		ppid = task_pid_nr(parent);
+		pcomm = parent->comm;
+	}
 	rcu_read_unlock();
 	pr_cont(" stack:%-5lu pid:%-5d ppid:%-6d flags:0x%08lx\n",
 		free, task_pid_nr(p), ppid,
 		read_task_thread_flags(p));
 
+	if (!ppid)
+		pr_info("parent:unknown         ppid:<NULL>\n");
+	else
+		pr_info("parent:%-15.15s ppid:%-6d\n", pcomm, ppid);
+
 	print_worker_info(KERN_INFO, p);
 	print_stop_info(KERN_INFO, p);
 	show_stack(p, NULL, KERN_INFO);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 32 lines · Tio Zhang

Knowing who the parent is might be useful for debugging.
For example, we can sometimes resolve kernel hung tasks by stopping the person who begins those hung tasks.
With the parent's name printed in sched_show_task(),
it might be helpful to let people know which "service" should be operated. Also, we move the parent info to a following new line while keeping the original line the same.
And we would print "parent:unknown ppid:<NULL>"
when the task is not alive.

---
 kernel/sched/core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
kernel/sched/core.c +1 -1
index cb2aa2b54c7a..5690a5700f9e 100644
@@ -8854,6 +8854,7 @@ void sched_show_task(struct task_struct *p)
 {
 	unsigned long free = 0;
 	int ppid;
+	char *pcomm = NULL;
 
 	if (!try_get_task_stack(p))
 		return;
@@ -8867,13 +8868,22 @@ void sched_show_task(struct task_struct *p)
 #endif
 	ppid = 0;
 	rcu_read_lock();
-	if (pid_alive(p))

kernel/sched/core.c void sched_show_task(struct task_struct *p) · line 8879

Quoted 10 lines
kernel/sched/core.c +6 -1
-		ppid = task_pid_nr(rcu_dereference(p->real_parent));
+	if (pid_alive(p)) {
+		struct task_struct *parent = rcu_dereference(p->real_parent);
+
+		ppid = task_pid_nr(parent);
+		pcomm = parent->comm;
+	}
 	rcu_read_unlock();
 	pr_cont(" stack:%-5lu pid:%-5d ppid:%-6d flags:0x%08lx\n",
 		free, task_pid_nr(p), ppid,

This prints "ppid:0" when pid_alive() returns false.

kernel/sched/core.c void sched_show_task(struct task_struct *p) · line 8883

Quoted 4 lines
kernel/sched/core.c +2 -0
 		read_task_thread_flags(p));
 
+	if (!ppid)
+		pr_info("parent:unknown         ppid:<NULL>\n");

This prints "ppid:<NULL>". The inconsistency is weird.

Also there is no need to print ppid twice. I would remove it from the " stack:..." line as it was done in the previous version of the patch.

kernel/sched/core.c void sched_show_task(struct task_struct *p) · line 8885

Quoted 3 lines
kernel/sched/core.c +2 -0
+	else
 
+		pr_info("parent:%-15.15s ppid:%-6d\n", pcomm, ppid);

"pcomm" must not be accessed after rcu_read_unlock(). The parent might disappear in the meantime.

I suggest to got back to the previous version and just add printing
"parent:unknown ppid:<NULL>\n" when pid_alive(p) fails.

Best Regards,
Petr

author
#2 lore raw

PATCH v2 2/2 sched: print parent comm in sched_show_task()

Knowing who the parent is might be useful for debugging.
For example, we can sometimes resolve kernel hung tasks by stopping the person who begins those hung tasks.
With the parent's name printed in sched_show_task(),
it might be helpful to let people know which "service" should be operated. Also, we move the parent info to a following new line.
It would better solve the situation when the task
is not alive and we could not get information about the parent.

---
 kernel/sched/core.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
kernel/sched/core.c +11 -7
index cb2aa2b54c7a..d8fd35684d6c 100644
@@ -8853,7 +8853,6 @@ SYSCALL_DEFINE2(sched_rr_get_interval_time32, pid_t, pid,
 void sched_show_task(struct task_struct *p)
 {
 	unsigned long free = 0;
-	int ppid;
 
 	if (!try_get_task_stack(p))
 		return;
@@ -8865,14 +8864,19 @@ void sched_show_task(struct task_struct *p)
 #ifdef CONFIG_DEBUG_STACK_USAGE
 	free = stack_not_used(p);
 #endif
-	ppid = 0;
+
+	pr_cont(" stack:%-5lu pid:%-5d flags:0x%08lx\n",
+		free, task_pid_nr(p), read_task_thread_flags(p));
+
 	rcu_read_lock();
-	if (pid_alive(p))
-		ppid = task_pid_nr(rcu_dereference(p->real_parent));
+	if (pid_alive(p)) {
+		struct task_struct *parent = rcu_dereference(p->real_parent);
+
+		pr_info("parent:%-15.15s ppid:%-6d", parent->comm, task_pid_nr(parent));
+	} else {
+		pr_info("parent:unknown         ppid:<NULL>\n");
+	}
 	rcu_read_unlock();
-	pr_cont(" stack:%-5lu pid:%-5d ppid:%-6d flags:0x%08lx\n",
-		free, task_pid_nr(p), ppid,
-		read_task_thread_flags(p));
 
 	print_worker_info(KERN_INFO, p);
 	print_stop_info(KERN_INFO, p);
Signature · 1 line
2.17.1
#3 lore raw

Hi Chen and sched maintainers,

Hope you are doing well!
Please help review this version and let me know if there are any following suggestions.

Thanks,

在 2023/1/31 下午4:10,“张元瀚 Tio Zhang”<[email protected] <mailto:[email protected]>> 写入:

Knowing who the parent is might be useful for debugging.
For example, we can sometimes resolve kernel hung tasks by stopping the person who begins those hung tasks.
With the parent's name printed in sched_show_task(),
it might be helpful to let people know which "service" should be operated. Also, we move the parent info to a following new line.
It would better solve the situation when the task
is not alive and we could not get information about the parent.

Signed-off-by Tio Zhang <[email protected] <mailto:[email protected]>>

---
kernel/sched/core.c | 18 +++++++++++-------

1 file changed, 11 insertions(+), 7 deletions(-)
kernel/sched/core.c +0 -0
index cb2aa2b54c7a..d8fd35684d6c 100644
@@ -8853,7 +8853,6 @@ SYSCALL_DEFINE2(sched_rr_get_interval_time32, pid_t, pid,

void sched_show_task(struct task_struct *p)
{
unsigned long free = 0;
- int ppid;

if (!try_get_task_stack(p))
return;
@@ -8865,14 +8864,19 @@ void sched_show_task(struct task_struct *p) #ifdef CONFIG_DEBUG_STACK_USAGE
free = stack_not_used(p);
#endif
- ppid = 0;
+
+ pr_cont(" stack:%-5lu pid:%-5d flags:0x%08lx\n",
+ free, task_pid_nr(p), read_task_thread_flags(p));
+
rcu_read_lock();
- if (pid_alive(p))
- ppid = task_pid_nr(rcu_dereference(p->real_parent));
+ if (pid_alive(p)) {
+ struct task_struct *parent = rcu_dereference(p->real_parent); +
+ pr_info("parent:%-15.15s ppid:%-6d", parent->comm, task_pid_nr(parent));
+ } else {
+ pr_info("parent:unknown ppid:<NULL>\n");
+ }
rcu_read_unlock();
- pr_cont(" stack:%-5lu pid:%-5d ppid:%-6d flags:0x%08lx\n",
- free, task_pid_nr(p), ppid,
- read_task_thread_flags(p));

print_worker_info(KERN_INFO, p);
print_stop_info(KERN_INFO, p);

Signature · 1 line
2.17.1
Tested-by on v2 2/2
#4 lore raw
In reply to Tio Zhang
Quoted 7 lines · Tio Zhang

Knowing who the parent is might be useful for debugging.
For example, we can sometimes resolve kernel hung tasks by stopping the person who begins those hung tasks.
With the parent's name printed in sched_show_task(),
it might be helpful to let people know which "service" should be operated. Also, we move the parent info to a following new line.
It would better solve the situation when the task

s/would better/would be better/

Quoted 4 lines

is not alive and we could not get information about the parent.

Looks ok to me,

thanks,
Chenyu

A message that is not in the archive (sent off-list or not yet received): CAEQmJ=igQ8J9Y+_dWE6yaaFXHC965Sw+RxywWNLD=4G=tj0_hw@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAEQmJ=iEC1G4MVRG=0XLWrCxqX_3E-6X-XbPeg8ti7oFjTBLBQ@mail.gmail.com

#7 lore raw

Hi,

please, send the patch as a plain text generated by git format-patch. Ideally send it using git send-email.

Also please use: [PATCH v3] instead of [PATCH v2 2/2].

This [RESEND] was a multi-part mail with html. It is hard to proceed by the tools like "b4". And it was even ignored by
https://lore.kernel.org/ so that it is not acrived.

The whole thread is messy. I suggest to send sent it as a new mail (In-Reply-To).

Also, please, add Andrew Morton <[email protected]>. He might take this kind of patch.

Otherwise, the patch looks OK.

Best Regards,
Petr

Quoted 141 lines · Yuanhan Zhang

Knowing who the parent is might be useful for debugging.
For example, we can sometimes resolve kernel hung tasks by stopping the person who begins those hung tasks.
With the parent's name printed in sched_show_task(),
it might be helpful to let people know which "service" should be operated. Also, we move the parent info to a following new line.
It would be better to solve the situation when the task
is not alive and we could not get information about the parent.

---
 kernel/sched/core.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
kernel/sched/core.c +0 -1
index cb2aa2b54c7a..d8fd35684d6c 100644
@@ -8853,7 +8853,6 @@ SYSCALL_DEFINE2(sched_rr_get_interval_time32, pid_t,
 pid,
 void sched_show_task(struct task_struct *p)
 {
        unsigned long free = 0;
-       int ppid;
 
        if (!try_get_task_stack(p))
                return;
kernel/sched/core.c +11 -6
@@ -8865,14 +8864,19 @@ void sched_show_task(struct task_struct *p)
 #ifdef CONFIG_DEBUG_STACK_USAGE
        free = stack_not_used(p);
 #endif
-       ppid = 0;
+
+       pr_cont(" stack:%-5lu pid:%-5d flags:0x%08lx\n",
+               free, task_pid_nr(p), read_task_thread_flags(p));
+
        rcu_read_lock();
-       if (pid_alive(p))
-               ppid = task_pid_nr(rcu_dereference(p->real_parent));
+       if (pid_alive(p)) {
+               struct task_struct *parent =
 rcu_dereference(p->real_parent);
+
+               pr_info("parent:%-15.15s ppid:%-6d", parent->comm,
 task_pid_nr(parent));
+       } else {
+               pr_info("parent:unknown         ppid:<NULL>\n");
+       }
        rcu_read_unlock();
-       pr_cont(" stack:%-5lu pid:%-5d ppid:%-6d flags:0x%08lx\n",
-               free, task_pid_nr(p), ppid,
-               read_task_thread_flags(p));
 
        print_worker_info(KERN_INFO, p);
        print_stop_info(KERN_INFO, p);

--
2.17.1

Quoted 81 lines · Yuanhan Zhang <[email protected]> 于2023年2月16日周四 16:19写道:

Knowing who the parent is might be useful for debugging.
For example, we can sometimes resolve kernel hung tasks by stopping the person who begins those hung tasks.
With the parent's name printed in sched_show_task(),
it might be helpful to let people know which "service" should be operated. Also, we move the parent info to a following new line.
It would be better to solve the situation when the task
is not alive and we could not get information about the parent.

---
 kernel/sched/core.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
kernel/sched/core.c +0 -1
index cb2aa2b54c7a..d8fd35684d6c 100644
@@ -8853,7 +8853,6 @@ SYSCALL_DEFINE2(sched_rr_get_interval_time32, pid_t,
 pid,
 void sched_show_task(struct task_struct *p)
 {
        unsigned long free = 0;
-       int ppid;
 
        if (!try_get_task_stack(p))
                return;
kernel/sched/core.c +11 -6
@@ -8865,14 +8864,19 @@ void sched_show_task(struct task_struct *p)
 #ifdef CONFIG_DEBUG_STACK_USAGE
        free = stack_not_used(p);
 #endif
-       ppid = 0;
+
+       pr_cont(" stack:%-5lu pid:%-5d flags:0x%08lx\n",
+               free, task_pid_nr(p), read_task_thread_flags(p));
+
        rcu_read_lock();
-       if (pid_alive(p))
-               ppid = task_pid_nr(rcu_dereference(p->real_parent));
+       if (pid_alive(p)) {
+               struct task_struct *parent =
 rcu_dereference(p->real_parent);
+
+               pr_info("parent:%-15.15s ppid:%-6d", parent->comm,
 task_pid_nr(parent));
+       } else {
+               pr_info("parent:unknown         ppid:<NULL>\n");
+       }
        rcu_read_unlock();
-       pr_cont(" stack:%-5lu pid:%-5d ppid:%-6d flags:0x%08lx\n",
-               free, task_pid_nr(p), ppid,
-               read_task_thread_flags(p));
 
        print_worker_info(KERN_INFO, p);
        print_stop_info(KERN_INFO, p);

--
2.17.1

Quoted 20 lines · Chen Yu <[email protected]> 于2023年2月10日周五 00:22写道:
Quoted 5 lines · Tio Zhang

Knowing who the parent is might be useful for debugging. For example, we can sometimes resolve kernel hung tasks by stopping the person who begins those hung tasks.
With the parent's name printed in sched_show_task(),
it might be helpful to let people know which "service" should be

operated.

Quoted 2 lines

Also, we move the parent info to a following new line. It would better solve the situation when the task

s/would better/would be better/

Quoted 4 lines

is not alive and we could not get information about the parent.

Looks ok to me,

thanks,
Chenyu

author
#8 lore raw

PATCH v3 1/1 sched: print parent comm in sched_show_task()

Knowing who the parent is might be useful for debugging.
For example, we can sometimes resolve kernel hung tasks by stopping the person who begins those hung tasks.
With the parent's name printed in sched_show_task(),
it might be helpful to let people know which "service" should be operated. Also, we move the parent info to a following new line.
It would be better to solve the situation when the task
is not alive and we could not get information about the parent.

---
 kernel/sched/core.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
kernel/sched/core.c +11 -7
index cb2aa2b54c7a..d8fd35684d6c 100644
@@ -8853,7 +8853,6 @@ SYSCALL_DEFINE2(sched_rr_get_interval_time32, pid_t, pid,
 void sched_show_task(struct task_struct *p)
 {
 	unsigned long free = 0;
-	int ppid;
 
 	if (!try_get_task_stack(p))
 		return;
@@ -8865,14 +8864,19 @@ void sched_show_task(struct task_struct *p)
 #ifdef CONFIG_DEBUG_STACK_USAGE
 	free = stack_not_used(p);
 #endif
-	ppid = 0;
+
+	pr_cont(" stack:%-5lu pid:%-5d flags:0x%08lx\n",
+		free, task_pid_nr(p), read_task_thread_flags(p));
+
 	rcu_read_lock();
-	if (pid_alive(p))
-		ppid = task_pid_nr(rcu_dereference(p->real_parent));
+	if (pid_alive(p)) {
+		struct task_struct *parent = rcu_dereference(p->real_parent);
+
+		pr_info("parent:%-15.15s ppid:%-6d", parent->comm, task_pid_nr(parent));
+	} else {
+		pr_info("parent:unknown         ppid:<NULL>\n");
+	}
 	rcu_read_unlock();
-	pr_cont(" stack:%-5lu pid:%-5d ppid:%-6d flags:0x%08lx\n",
-		free, task_pid_nr(p), ppid,
-		read_task_thread_flags(p));
 
 	print_worker_info(KERN_INFO, p);
 	print_stop_info(KERN_INFO, p);
Signature · 1 line
2.17.1
Reviewed-by on v3 1/1
#9 lore raw
Quoted 17 lines · Tio Zhang

Knowing who the parent is might be useful for debugging.
For example, we can sometimes resolve kernel hung tasks by stopping the person who begins those hung tasks.
With the parent's name printed in sched_show_task(),
it might be helpful to let people know which "service" should be operated. Also, we move the parent info to a following new line.
It would be better to solve the situation when the task
is not alive and we could not get information about the parent.

kernel/sched/core.c +1 -1
@@ -8865,14 +8864,19 @@ void sched_show_task(struct task_struct *p)
 #ifdef CONFIG_DEBUG_STACK_USAGE
 	free = stack_not_used(p);
 #endif
-	ppid = 0;
+

kernel/sched/core.c void sched_show_task(struct task_struct *p) · line 8875

Quoted 10 lines
kernel/sched/core.c +7 -2
+	pr_cont(" stack:%-5lu pid:%-5d flags:0x%08lx\n",
+		free, task_pid_nr(p), read_task_thread_flags(p));
+
 	rcu_read_lock();
-	if (pid_alive(p))
-		ppid = task_pid_nr(rcu_dereference(p->real_parent));
+	if (pid_alive(p)) {
+		struct task_struct *parent = rcu_dereference(p->real_parent);
+
+		pr_info("parent:%-15.15s ppid:%-6d", parent->comm, task_pid_nr(parent));

There is a missing new line delimiter "\n".

kernel/sched/core.c void sched_show_task(struct task_struct *p) · line 8882

Quoted 10 lines
kernel/sched/core.c +3 -3
+	} else {
+		pr_info("parent:unknown         ppid:<NULL>\n");
+	}
 	rcu_read_unlock();
-	pr_cont(" stack:%-5lu pid:%-5d ppid:%-6d flags:0x%08lx\n",
-		free, task_pid_nr(p), ppid,
-		read_task_thread_flags(p));
 
 	print_worker_info(KERN_INFO, p);
 	print_stop_info(KERN_INFO, p);

Otherwise, it looks good. With the added new line delimiter:

Best Regards,
Petr

author
#10 lore raw

PATCH v3 2/2 sched: print parent comm in sched_show_task()

Knowing who the parent is might be useful for debugging.
For example, we can sometimes resolve kernel hung tasks by stopping the person who begins those hung tasks.
With the parent's name printed in sched_show_task(),
it might be helpful to let people know which "service" should be operated. Also, we move the parent info to a following new line.
It would be better to solve the situation when the task
is not alive and we could not get information about the parent.

---
 kernel/sched/core.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
kernel/sched/core.c +11 -7
index cb2aa2b54c7a..d8fd35684d6c 100644
@@ -8853,7 +8853,6 @@ SYSCALL_DEFINE2(sched_rr_get_interval_time32, pid_t, pid,
 void sched_show_task(struct task_struct *p)
 {
 	unsigned long free = 0;
-	int ppid;
 
 	if (!try_get_task_stack(p))
 		return;
@@ -8865,14 +8864,19 @@ void sched_show_task(struct task_struct *p)
 #ifdef CONFIG_DEBUG_STACK_USAGE
 	free = stack_not_used(p);
 #endif
-	ppid = 0;
+
+	pr_cont(" stack:%-5lu pid:%-5d flags:0x%08lx\n",
+		free, task_pid_nr(p), read_task_thread_flags(p));
+
 	rcu_read_lock();
-	if (pid_alive(p))
-		ppid = task_pid_nr(rcu_dereference(p->real_parent));
+	if (pid_alive(p)) {
+		struct task_struct *parent = rcu_dereference(p->real_parent);
+
+		pr_info("parent:%-15.15s ppid:%-6d\n", parent->comm, task_pid_nr(parent));
+	} else {
+		pr_info("parent:unknown         ppid:<NULL>\n");
+	}
 	rcu_read_unlock();
-	pr_cont(" stack:%-5lu pid:%-5d ppid:%-6d flags:0x%08lx\n",
-		free, task_pid_nr(p), ppid,
-		read_task_thread_flags(p));
 
 	print_worker_info(KERN_INFO, p);
 	print_stop_info(KERN_INFO, p);
Signature · 1 line
2.17.1