Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2613137rwb; Fri, 20 Jan 2023 05:20:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXundJ1Yw1cMZIusEBJc0oG/UZTUgTJCwLmmRbgf3F4cSoKt3nobHgUBlN/ctMV3/YY70imj X-Received: by 2002:a17:906:d8a8:b0:84b:b481:6188 with SMTP id qc8-20020a170906d8a800b0084bb4816188mr11451884ejb.64.1674220847759; Fri, 20 Jan 2023 05:20:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674220847; cv=none; d=google.com; s=arc-20160816; b=ju8WT31eKOFEymWUqvek7wszLxCh9RQOeHwul9Mxl7CYQEYplLRAddJdSwzGu4AT61 puyoLxEepbkjHGmEOua3GKbVVG8eMRJtTFsiAFGBuWuJECICvmNdk77VO6Pup3mIFsgb VcQS1IaQ0uvbKrS1dfVKxJiKZBSx5yRAtX2snbAD42Khq0NF3/5lipsi8vZbcoehUSge pfiuXxm/S50Jef+Z9SlJR6ngqeHg2vCrhcqJC1IiyWU7gsO8hdiBkeL9SDClC/z2lBWq sstGHkai1YBM6WOhg9UrYMoTTOO2jVBcnI9/oqwK78xSWlA2PSyCP8dCBwBWI5lps4RB lhFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date:dkim-signature; bh=XjqgFtVUkUjbCCMGAoadZ1mxvxex83rO/FB4iaCTZXY=; b=dQ2pGsVEzTESohKaMjQTbWYdrCXb/TerxwLedLopBWbCev/pbhrfppTeBQ8Bqzt/SX Eg1nJN6dSpuRAJX7F2C83BTzRDv4YJ6BkOoY2WCPoS0cF3ful8ocF7LYkI1AONxSV7kn 1bPm5xjOhE1AMgHnuFonzHovRzqFk4RAJgcSjI4FhsU5MtCXaJ41pyIkNvVtfj0OTln2 f8Oifw97KCNFTwAj+0H11sxJKAExxIoAh3ginRRRZlfJ+GN2D2/n+IheKZHMqgI0Cc6t bCL5eVf7MO/oCOWvZyRpV55HqtfQjR1e3M5IHSRTC/0mOBMahOOhPJDRoTdtKPVVKuoY zE5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=BSsv+L1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xe3-20020a170907318300b0084d1b43b503si39929232ejb.793.2023.01.20.05.20.35; Fri, 20 Jan 2023 05:20:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=BSsv+L1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229962AbjATNJk (ORCPT + 49 others); Fri, 20 Jan 2023 08:09:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbjATNJh (ORCPT ); Fri, 20 Jan 2023 08:09:37 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2443EC6D for ; Fri, 20 Jan 2023 05:09:35 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id ACFC45F9E7; Fri, 20 Jan 2023 13:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1674220174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XjqgFtVUkUjbCCMGAoadZ1mxvxex83rO/FB4iaCTZXY=; b=BSsv+L1mqvz4MbLUgk9m3et8S5Jg0NjIL+ZZ5z6rzfYMOTH2/W2jhdo8pVm6zsLwu7SsH7 AYaZoeU+6ITyoJ00RPjehurQGzOjll/pslTCaQ221NmB3jC0X+3vlJPz28c2TxRk5Hs/17 jvCsTjQj+KLHG2/QM3Fuq/iCpsG8ry8= Received: from suse.cz (unknown [10.100.208.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 4B2682C141; Fri, 20 Jan 2023 13:09:34 +0000 (UTC) Date: Fri, 20 Jan 2023 14:09:33 +0100 From: Petr Mladek To: yu.c.chen@intel.com, juri.lelli@redhat.com, mingo@redhat.com, peterz@infradead.org, vincent.guittot@linaro.org, linux-kernel@vger.kernel.org, zyhtheonly@gmail.com, zwp10758@gmail.com, zyhtheonly@yeah.net Subject: Re: [PATCH v2] sched: print parent comm in sched_show_task() Message-ID: References: <20230119110642.GA6463@didi-ThinkCentre-M930t-N000> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230119110642.GA6463@didi-ThinkCentre-M930t-N000> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2023-01-19 19:06:42, 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. > 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:" > when the task is not alive. > > Signed-off-by: Tio Zhang > --- > kernel/sched/core.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index cb2aa2b54c7a..5690a5700f9e 100644 > --- 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 = 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, This prints "ppid:0" when pid_alive() returns false. > read_task_thread_flags(p)); > > + if (!ppid) > + pr_info("parent:unknown ppid:\n"); This prints "ppid:". 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. > + 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:\n" when pid_alive(p) fails. Best Regards, Petr