All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, linux-kernel@vger.kernel.org,
	zyhtheonly@gmail.com, zyhtheonly@yeah.net, zwp10758@gmail.com
Subject: Re: [PATCH] sched: print parent comm in sched_show_task()
Date: Wed, 4 Jan 2023 14:24:11 +0100	[thread overview]
Message-ID: <Y7V9+1AhGhgP52xO@alley> (raw)
In-Reply-To: <20221227161400.GA7646@didi-ThinkCentre-M930t-N000>

On Wed 2022-12-28 00:14:00, Tio Zhang wrote:
> 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.

> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -8854,6 +8854,7 @@ void sched_show_task(struct task_struct *p)
>  {
>  	unsigned long free = 0;
>  	int ppid;
> +	char pcomm[TASK_COMM_LEN];
>  
>  	if (!try_get_task_stack(p))
>  		return;
> @@ -8867,11 +8868,13 @@ void sched_show_task(struct task_struct *p)
>  #endif
>  	ppid = 0;

We need to intialized pcomm here:

	pcomm[0] = '\0';

Otherwise, it would include a garbage when pid_alive(p) returns false below..

>  	rcu_read_lock();
> -	if (pid_alive(p))
> +	if (pid_alive(p)) {
>  		ppid = task_pid_nr(rcu_dereference(p->real_parent));
> +		get_task_comm(pcomm, rcu_dereference(p->real_parent));
> +	}
>  	rcu_read_unlock();
> -	pr_cont(" stack:%-5lu pid:%-5d ppid:%-6d flags:0x%08lx\n",
> -		free, task_pid_nr(p), ppid,
> +	pr_cont(" stack:%-5lu pid:%-5d ppid:%-6d parent:%-15.15s
> flags:0x%08lx\n",

It would print:  .... parent:xxx flags:0000

Some people might be confused whether the flags are from
the task or from the parent.

A solution would be to move the parent value to another line.
It would even better solve the situation when the task
is not alive and we could not get information about the parent:

	if (pid_alive(p)) {
		struct parent = rcu_dereference(p->real_parent);

		pr_info("parent:%-15.15s ppid:%-6d\n",
			parent->comm, task_pid_nr(parent));
	}

> +		free, task_pid_nr(p), ppid, pcomm,
>  		read_task_thread_flags(p));
>  
>  	print_worker_info(KERN_INFO, p);

Best Regards,
Petr

  parent reply	other threads:[~2023-01-04 13:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-27 16:14 [PATCH] sched: print parent comm in sched_show_task() Tio Zhang
2022-12-29  4:25 ` Chen Yu
     [not found]   ` <CAEQmJ=gcCx1hMf7HicE5OFeUstipdtr=3JkF1JxLuP-CrG++Pw@mail.gmail.com>
2023-01-04 13:40     ` Petr Mladek
2023-01-06  9:51     ` Chen Yu
     [not found]       ` <CAEQmJ=gZJL6K1yUPq0hHy5D7Rc6g=5Ri72V_kE=xfqR6gJedWg@mail.gmail.com>
2023-01-12  8:40         ` Chen Yu
2023-01-04 13:24 ` Petr Mladek [this message]
2023-01-13 10:54 Tio Zhang
2023-01-16  9:26 ` Chen Yu
2023-01-17  8:33   ` 张元瀚 Tio Zhang
2023-01-18 11:06     ` Petr Mladek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y7V9+1AhGhgP52xO@alley \
    --to=pmladek@suse.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=vincent.guittot@linaro.org \
    --cc=zwp10758@gmail.com \
    --cc=zyhtheonly@gmail.com \
    --cc=zyhtheonly@yeah.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.