Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3507903pxb; Mon, 24 Jan 2022 11:01:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbjNuOIFX+B7jsEW9uJfdVhjmsN0CrncTVrzAv3NbmxmpVMJQaxaD7WN+Y7Rkus+e1oh6s X-Received: by 2002:a63:69c4:: with SMTP id e187mr12991039pgc.442.1643050910928; Mon, 24 Jan 2022 11:01:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643050910; cv=none; d=google.com; s=arc-20160816; b=vL0+beHcj3iQqKnJaI+RHZe3AE6LekeWm0vPJ7bj1MSKbzC7iqnLEm+iVJg2KE7LsM LQ5RnAeWpsDRvrhnwC2kpHSJhEiDCPepmhQ64mVxrLbjQWxsrIRxFx0qL0vZMpDr+UTa eBAsnF7mfPWlpZzotM4TsR6Q9EJRTsH9mHhI9JvekmDgDrqFoZc4FwtJ4hh3F0M4bppp gQ1mPjMZodMdu/ky91cnIwvhI+jPSj0VrShgLCeDYsL2ERfurh+zTu5zOU4rrK27EYYG XP3IYL2fUH5a44I9yVH0+O4G/ngSSoaiS262AL8zy/JiMt8R8hz2PMiNBbPh5uXDSJHa OJRA== 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=Ce8kmuDMtmmo/MImI7tUCkq4J+fQ4yOav8yciJHfcvU=; b=zQ5tj+qzu+0Z3XwOYjOr8ATTzeBuhhdF/jD1IepH+rW3BlHTZuJp4q22eWQhGaTpCM Y6CbnO3GaE7SSO+z0C6nVr3YuYVS+/7Ig1SmpcOlvFd+iEi8++wt5z1RBgQgGNvLts57 yvzRiwKFZRWxWGKrIeALZTfloJD1IU7Df+tkx7eWyGQghAewUmLMEMv0ek4J7yqHwsHD LMh9nUpRx+TYcl376bTfYspEv4lLeudZv/QhoCNs08kT9E9k0n0WV8nOH4SjnF2qm0md 1SskL1q/PBd+3LizI0nsg6V8fk3lzqqR9mdA7LE8Xi1hSodWf/7VsZdPNF+FYmfriN9h 1www== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gnuweeb.org header.s=default header.b=D8I8lBKc; 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 m5si10725293pgl.645.2022.01.24.11.01.36; Mon, 24 Jan 2022 11:01:50 -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=D8I8lBKc; 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 S237000AbiAXKEQ (ORCPT + 99 others); Mon, 24 Jan 2022 05:04:16 -0500 Received: from ip59.38.31.103.in-addr.arpa.unknwn.cloudhost.asia ([103.31.38.59]:48152 "EHLO gnuweeb.org" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S236914AbiAXKEH (ORCPT ); Mon, 24 Jan 2022 05:04:07 -0500 Received: from [192.168.88.87] (unknown [36.81.38.25]) by gnuweeb.org (Postfix) with ESMTPSA id 7E855C3022; Mon, 24 Jan 2022 10:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=gnuweeb.org; s=default; t=1643018644; bh=rLCietX+8asL0GcSnssoo9Wq4OVIrWT57SoaybWDYhA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=D8I8lBKcdphw4TT1nh6JGbDlzMDvNd7w+LbTh9C2P3I+s7FQa6DwgTorSMSACxQfX HtBWz83MD68F/lEG+LQx+E8ebS1d6nc6Z+9BQqA2ZV6jOGI8YIOy3E4o/dnBwd/VcQ eTGqfesNIVysSV4tM4oLMjhDs7dUtcaPWbq8xKTi1CcOER3+43ZyCvSi1/VFW1JCTq 5mq3ZIbUzB9cK5NBMqixW5Si9Flkcj0hr/D9RVqZU8E0FfnzWKBuBr0SFZpooMAMv6 9ZbJVCGnfqB9jD1auR+fYCF+PZt4NVE1DuC8rU8V5k1u/G/UXDCH6A82PEJ9Kxa1b3 BGgEoDYKJQdUQ== Message-ID: Date: Mon, 24 Jan 2022 17:03:58 +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: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Zqiang, On Sat, 22 Jan 2022 02:30:00 +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