Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3534496pxb; Mon, 24 Jan 2022 11:37:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJySWCZR56YGX7bB2t8cp1aTR+JkuwPuSo92jMEA/gGrDYLZrh52KCBCxpWJAsEByc0ADNt4 X-Received: by 2002:a17:90b:4a48:: with SMTP id lb8mr3375586pjb.54.1643053038380; Mon, 24 Jan 2022 11:37:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643053038; cv=none; d=google.com; s=arc-20160816; b=bsbH0i4oMltL7DbCLbHXUG7Ac5r8S/fJwqR7BUO/WsF+6VsDNqMr0bNx/Xo9doYdaK OG7KkZ3MVdSdPzyh1PJUvw1CFAUYPU9CLSvPin02fncdIYL1KwLnzpkzYAOeJ97MJzGU T2UuQCfozr6SGwYlA4vtMK9D6DYRTZiMqTTW7lr9wBE/mgg55g1iwCYSnXkZ4nRYB2yq HLyCVUmQt6zhcekFKCHn5sD4k0levvq7mm+7dEIYIhrNp8FF5AfSS+Ma2Uzn05VE0Okr NxJ0hUPQ/nVadzfzdJRAIhFjlBHeL8c3IQUOCSpnI/3efKCDi0ZIm0OwKEvFoHt8qzJu Q5mg== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=FFs3Bs+c7i3cyPZO5FUA34IzPqRFZPJNR/qzJs24x8E=; b=YfMSzE0LZIWOC2FaOrCFRkHER9Yt58GjRae3aaRevSdcZLNxN5m8hNosWwGJPhgtt6 Qzu/qVle2fuQwoELc6743FaUTZTYZoVeteTUzMxL8q6zN+Q+UMBLc5eeqGgzqDN+4DJw PU9Ipk15redSINW9KS/j0a9eGznaRWXDSsjF334mKfqYCM3Ga7ba6KpUAfdub8MRUAfi HcbA9LCg4mRC8186XjDnW1HwJcKhdam0a19YhI+oRSPouEl7C5hUwHUdw4VqQlAOAxag bI2oVeGeiRm1d1CqYn0/c/mDGoNR/nsmtTkag561ZdTUlGfw7VbaNUj7e8cOs8Fmpsyg cjeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SnRbCnqD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b4si13461322plz.351.2022.01.24.11.37.06; Mon, 24 Jan 2022 11:37:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SnRbCnqD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243827AbiAXQmy (ORCPT + 99 others); Mon, 24 Jan 2022 11:42:54 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:46940 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243685AbiAXQmx (ORCPT ); Mon, 24 Jan 2022 11:42:53 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D2B2EB810FD for ; Mon, 24 Jan 2022 16:42:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FA64C340EE; Mon, 24 Jan 2022 16:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643042571; bh=SqErisRUlGDkdeqDrji8hZuLh+ZPAh1XtvZmsBKGgnI=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=SnRbCnqDSRoMaz5rHCrNC3g9sjlvYcZye/foIYb+917Y9TkUyssdjSrHR+0JEeD1+ sGXU1UqcSjFu0Ug1my+h8afOiHD+6K+7Y0A+3j99NrKzfUprtOJDfEV66nfcvlu/4i 4o1JRMdRwSM1Tx+tyomD73aYPMGMkh1MypTWCKDse6ymQJDcbzkTQPL15kZ5QL65BJ g3v7brTijPWj7bKxQy/cRjDBumDEbm8HPvWq+kI0MfEuWJDbhYYaD8VH7NSkhCzle7 nxK4YfasnedaCN3P14pt3+yswA/zl5mIpm4DK58pQ5DhDIhPS6CoMyWhFepyYOHXBb OVP7EWgPlswSw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 4B7895C1286; Mon, 24 Jan 2022 08:42:51 -0800 (PST) Date: Mon, 24 Jan 2022 08:42:51 -0800 From: "Paul E. McKenney" To: Ammar Faizi Cc: Zqiang , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] rcu: Add per-CPU rcuc task info to RCU CPU stall warnings Message-ID: <20220124164251.GF4285@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220124103637.4001386-1-qiang1.zhang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 24, 2022 at 05:38:21PM +0700, Ammar Faizi wrote: > > [ I resend and fix my reply, my previous reply seems to have an > issue with the "Date" ] > > Hi Zqiang, > > On Mon, 24 Jan 2022 18:36:37 +0800, Zqiang wrote:> +static void rcuc_kthread_dump(struct rcu_data *rdp) > > +{ > > + int cpu; > > + unsigned long j; > > + struct task_struct *rcuc = rdp->rcu_cpu_kthread_task; > > + > > + if (rcu_is_rcuc_kthread_starving(rdp, &j)) { > > + cpu = rcuc ? task_cpu(rcuc) : -1; > > + > > + if (rcuc) { > > + pr_err("%s kthread starved for %ld jiffies, stack dump:\n", > > + rcuc->comm, j); > > + sched_show_task(rcuc); > > + if (cpu >= 0) { > > + if (cpu_online(cpu) && !idle_cpu(cpu)) { > > + pr_err("Dump current CPU stack:\n"); > > + if (!trigger_single_cpu_backtrace(cpu)) > > + dump_cpu_task(cpu); > > + } > > + } > > + } > > + } > > +} > > 1) We can reduce the nested if with an early return after > checking `rcu_is_rcuc_kthread_starving()`. > > 2) This ternary operator doesn't make sense: > > `cpu = rcuc ? task_cpu(rcuc) : -1;` > > If `rcuc` is NULL, then the "if (rcuc)" block will never > be executed, and `cpu` variable won't be used, why should > we perform a conditional with ternary to assign -1 here? > > 3) We can use an early return as well for the `if (rcuc)` to > avoid more nested if. > > FWIW, this one makes more sense: > ``` > static void rcuc_kthread_dump(struct rcu_data *rdp) > { > int cpu; > unsigned long j; > struct task_struct *rcuc; > > if (!rcu_is_rcuc_kthread_starving(rdp, &j)) > return; > > rcuc = rdp->rcu_cpu_kthread_task; > if (!rcuc) > return; > > pr_err("%s kthread starved for %ld jiffies, stack dump:\n", rcuc->comm, j); Thank you for looking this over and for the great feedback, Ammar! I am also wondering why the above message should be printed when the corresponding CPU is offline or idle. Why not move the above pr_err() line down to replace the pr_err() line below? Thanx, Paul > sched_show_task(rcuc); > cpu = task_cpu(rcuc); > if (cpu_online(cpu) && !idle_cpu(cpu)) { > pr_err("Dump current CPU stack:\n"); > if (!trigger_single_cpu_backtrace(cpu)) > dump_cpu_task(cpu); > } > } > ``` > > Thank you! > > -- > Ammar Faizi