Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3509786pxb; Mon, 24 Jan 2022 11:03:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7M6zgi1Gsh6oM5YhQzolVWz+CRl66hxc6G6JBiCKBLS+mHf5JVxg84EADomaYa+nx4Rx1 X-Received: by 2002:a05:6a00:1d93:b0:4c7:f78c:3f41 with SMTP id z19-20020a056a001d9300b004c7f78c3f41mr9338238pfw.54.1643051032885; Mon, 24 Jan 2022 11:03:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643051032; cv=none; d=google.com; s=arc-20160816; b=DczDX5LHbu2insDnjNimHfLuJwFbj2AK1hTxIgbL+nRqSITrtSFjk/HUIxQkt3cgJ/ hJDEFVNCwBo8IwlUIgOl+zMrVNeQBvl/EuiqY2eULES4QoL59iY6uDz1pjJW0jh2N7dE Pbe4EctbsfhDWBB6itb+cQe2vdk1M7FjII6pTmPHtD+W8wv+weyoD1ObVJVPwTF7TWp9 NQRQfw3ZZa49saiOhlNa3PrHrkCs05pradMcY1/SWRbJMQ5e4EHg+kayXWZ8aVj6zrX6 JEw9X+PCsk+gMMGVFrNc9hPDUusAjF4umygJ7gUWsNlJ+rNKdA4llMsJZv6RSCLFxfmm wdAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=M50nA6/tEvKXdW2UMYdiWp0YjcFHGhSzvEzmGWnzhsQ=; b=gTOwAmGf+CZFFzlmihzeh0MNN8YWQkUo8fV+Jr0H7sa0AYPZ/T/JUGeB9UcDAHYRaR LVUUqN6zxyGe9qMPJBd//+XnmjpXpb9Z6qaMwif7AkK9BAvbnDGXapqaMUClLfxQ0QAU qwExe2wuY/KEhDrZcr4DXR+jtgHwJdGqdEolloNPamL7TvwT9sIXO+MZMWsfMXRdgdRa mtnDAVwTDVGjVNwBapYZ6CAcUtquQxjb2I35LNZHODFic7FdZ+GSy7/xHyQa7qoqBJPw ZDo4uugJ/V2r2s5O/iHMh2IvKM1OUoI1tkU+ft/Sp7jz5IwSw7UjfaMQ7pDqNhoIkBQK ai3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gnuweeb.org header.s=default header.b=NKLVL7Tw; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c3si13350314pls.81.2022.01.24.11.03.39; Mon, 24 Jan 2022 11:03:52 -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=fail header.i=@gnuweeb.org header.s=default header.b=NKLVL7Tw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233802AbiAXKie (ORCPT + 99 others); Mon, 24 Jan 2022 05:38:34 -0500 Received: from ip59.38.31.103.in-addr.arpa.unknwn.cloudhost.asia ([103.31.38.59]:48160 "EHLO gnuweeb.org" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S232626AbiAXKi1 (ORCPT ); Mon, 24 Jan 2022 05:38:27 -0500 Received: from [192.168.88.87] (unknown [36.81.38.25]) by gnuweeb.org (Postfix) with ESMTPSA id 50EC2C302E; Mon, 24 Jan 2022 10:38:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=gnuweeb.org; s=default; t=1643020704; bh=xw1wMZsw66j6y31Lmm247ZVt9e0jOQk+3R9d5cjT3+U=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=NKLVL7Twe0p0sa+qQUMkRc/VP34HHu3BWClXN79ajhy7DDpzNiLSu5NoH4Y/UM7lb xwUDAseqcq3P32HNUP2RfbJCPbtQTfTQFiS2AnQerHL4mjd3UePNjOtLa3Q9cTJznU SGQXyjh5g+cnOmqfMumC6ZIExSvszXl6jXu03K6LAMMaNKqmJLVs35/1rgLFjXByLC TvZtCua9YOLqf+qaD+M8txM4IeCWkBHMDJDBJHkRsYPF8Hxe6qqzOgn0qmfn0CdRXQ KUE4xCXE2cp8opzWcIetELuVdWGQc+yCs4zb5cg90dy74agk4NDL5ue1FRzo7Zwsp3 pHbefpxqoyg2w== Message-ID: Date: Mon, 24 Jan 2022 17:38:21 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1 Subject: Re: [PATCH v2] rcu: Add per-CPU rcuc task info to RCU CPU stall warnings Content-Language: en-US To: Zqiang , paulmck@kernel.org Cc: linux-kernel@vger.kernel.org References: <20220124103637.4001386-1-qiang1.zhang@intel.com> From: Ammar Faizi In-Reply-To: <20220124103637.4001386-1-qiang1.zhang@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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); 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