Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3358559pxb; Mon, 24 Jan 2022 08:01:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUvwV0igL6zw9LcXqoLrjI84dEI+mOhw0nCmt433Cdl+fRUlveu0KA+XdFCizhCYPadzKC X-Received: by 2002:a17:902:a38f:b0:14a:ec8d:51ac with SMTP id x15-20020a170902a38f00b0014aec8d51acmr14876586pla.132.1643040089236; Mon, 24 Jan 2022 08:01:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643040089; cv=none; d=google.com; s=arc-20160816; b=Q/RRv7v4T1AW6Uk5bBAfC1PB2+8NVm847oeopggpWCkfxZW7Pba4d+DEyVrkTnBANO +NJkLF5OBk4WgLVpSpH5pJ006gW4cQlu90ybAjgT1oLfl2Mzjm9oPQeONZTByu3C5/2h s5eo08OZWhsKsbX4NvyMD7sNKPPZqW87bJR0dnzDb+u+TvH44DLDSL9DxUmNdCB6aOgk UdJaZScTwG2k9oE8/aIxuO2odu7w36hgRO7jUOeSWy/xDiCxpG1LshTlV2dJsjYzjbqe 9O7gmNirZC/iWdj4u4rAnRg86xRqqpt4M7sunLNzmOciMGroKTA48jjwl9HzLg+mfbu/ EYCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=vLvbooC3sPtmNwZfZ5YLO/rFKwN4OtL/dn4YL198CUI=; b=M2fQTk2r8Ehjqur0VMDj1ph1F7g7N4AxNAu8TJP2blYMv5MV/Gwqyrobxumxmyy0gU dV6wopbV/359TUSBQ1mcukg4k6X3EMVYcO4YKwHCWVQo5i34QMs8naMJhYxWa5tpuuSA k7g9MLINcL+7PS8WcQ97Qf1tmw0TnLSGvAU+KdxT7QiHAtd1OdyODtWfaAHfE91SHTN+ taa4LYf3lW2U0ESv70jx6DT3j9RZX6b1yM81H0ywAgPmPT8hmxN7eApWdHPulbGmsSJr 465uyeqLgpfVYzY46FYpSU4/ov0ufM7p2t1Tb03iqp2O28bpMwNHAY90hjNnkHqZ5EzE ij1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=llVH3448; 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nv2si14997454pjb.47.2022.01.24.08.01.15; Mon, 24 Jan 2022 08:01:29 -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=@intel.com header.s=Intel header.b=llVH3448; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236072AbiAXCgp (ORCPT + 99 others); Sun, 23 Jan 2022 21:36:45 -0500 Received: from mga11.intel.com ([192.55.52.93]:17323 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232730AbiAXCgn (ORCPT ); Sun, 23 Jan 2022 21:36:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642991803; x=1674527803; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=4W/6d6ox9WDAH5pYObFQvG8KomKWbqV8TpEAHOtdqSw=; b=llVH3448d1WZcoI5jl3tbnLDRByBPBwRnZ2DamfbAMXUkzUf3QQ09X2d hfuAgQmfbvwV9JYi0js4ivgN+g/BhUaHRf0c8CUSOOWYdPGe79HZOmTjG LiVb7PNBNsC3RpUNrokrBEFnsWnO861sM/vlY/SedUcouDtNgKnXSQPF2 dkbZququiJ3YJ9hCZ6ot897VhCQGWioYQKio0w2RJ/a0VU5olbSfK69y5 vYC9AaWrkIMgFmDrUl4VWW5NOF4B3zNIIS/8uBy63jtr3C/Cia7kyYNyc Iy7OSMKW6epPY/cda5RoE6m1SsMUyuFIaBKoIvbBZPG1Ptd5TJMfTngr1 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10236"; a="243542702" X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="243542702" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2022 18:36:43 -0800 X-IronPort-AV: E=Sophos;i="5.88,311,1635231600"; d="scan'208";a="627328890" Received: from zq-optiplex-7090.bj.intel.com ([10.238.156.125]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2022 18:36:41 -0800 From: Zqiang To: paulmck@kernel.org Cc: linux-kernel@vger.kernel.org, qiang1.zhang@intel.com Subject: [PATCH v2] rcu: Add per-CPU rcuc task info to RCU CPU stall warnings Date: Mon, 24 Jan 2022 18:36:37 +0800 Message-Id: <20220124103637.4001386-1-qiang1.zhang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the 'use_softirq' be set zero, all RCU_SOFTIRQ processing be moved to per-CPU rcuc kthreads, if the rcuc kthreads is being starved, quiescent state can not report in time. the RCU stall may be triggered. this commit adds a stack trace of this CPU and dump rcuc kthreads stack to help analyze what prevents rcuc kthreads from running. Signed-off-by: Zqiang --- v1->v2: Avoid print anything when CPU is offline or idle. kernel/rcu/tree.c | 3 +++ kernel/rcu/tree.h | 1 + kernel/rcu/tree_plugin.h | 3 +++ kernel/rcu/tree_stall.h | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index a4c25a6283b0..e3fc31a0f546 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -2850,10 +2850,12 @@ static void rcu_cpu_kthread(unsigned int cpu) { unsigned int *statusp = this_cpu_ptr(&rcu_data.rcu_cpu_kthread_status); char work, *workp = this_cpu_ptr(&rcu_data.rcu_cpu_has_work); + unsigned long *j = this_cpu_ptr(&rcu_data.rcuc_activity); int spincnt; trace_rcu_utilization(TPS("Start CPU kthread@rcu_run")); for (spincnt = 0; spincnt < 10; spincnt++) { + WRITE_ONCE(*j, jiffies); local_bh_disable(); *statusp = RCU_KTHREAD_RUNNING; local_irq_disable(); @@ -2874,6 +2876,7 @@ static void rcu_cpu_kthread(unsigned int cpu) schedule_timeout_idle(2); trace_rcu_utilization(TPS("End CPU kthread@rcu_yield")); *statusp = RCU_KTHREAD_WAITING; + WRITE_ONCE(*j, jiffies); } static struct smp_hotplug_thread rcu_cpu_thread_spec = { diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h index 486fc901bd08..4e0fdebb62e8 100644 --- a/kernel/rcu/tree.h +++ b/kernel/rcu/tree.h @@ -237,6 +237,7 @@ struct rcu_data { /* rcuc per-CPU kthread or NULL. */ unsigned int rcu_cpu_kthread_status; char rcu_cpu_has_work; + unsigned long rcuc_activity; /* 7) Diagnostic data, including RCU CPU stall warnings. */ unsigned int softirq_snap; /* Snapshot of softirq activity. */ diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index c5b45c2f68a1..327bbfd79cc6 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h @@ -996,12 +996,15 @@ dump_blkd_tasks(struct rcu_node *rnp, int ncheck) */ static void rcu_cpu_kthread_setup(unsigned int cpu) { + struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu); #ifdef CONFIG_RCU_BOOST struct sched_param sp; sp.sched_priority = kthread_prio; sched_setscheduler_nocheck(current, SCHED_FIFO, &sp); #endif /* #ifdef CONFIG_RCU_BOOST */ + + WRITE_ONCE(rdp->rcuc_activity, jiffies); } #ifdef CONFIG_RCU_BOOST diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h index 21bebf7c9030..739a2d87ea5e 100644 --- a/kernel/rcu/tree_stall.h +++ b/kernel/rcu/tree_stall.h @@ -379,6 +379,15 @@ static bool rcu_is_gp_kthread_starving(unsigned long *jp) return j > 2 * HZ; } +static bool rcu_is_rcuc_kthread_starving(struct rcu_data *rdp, unsigned long *jp) +{ + unsigned long j = jiffies - READ_ONCE(rdp->rcuc_activity); + + if (jp) + *jp = j; + return j > 2 * HZ; +} + /* * Print out diagnostic information for the specified stalled CPU. * @@ -430,6 +439,30 @@ static void print_cpu_stall_info(int cpu) falsepositive ? " (false positive?)" : ""); } +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); + } + } + } + } +} + /* Complain about starvation of grace-period kthread. */ static void rcu_check_gp_kthread_starvation(void) { @@ -601,6 +634,9 @@ static void print_cpu_stall(unsigned long gps) rcu_check_gp_kthread_expired_fqs_timer(); rcu_check_gp_kthread_starvation(); + if (!use_softirq) + rcuc_kthread_dump(rdp); + rcu_dump_cpu_stacks(); raw_spin_lock_irqsave_rcu_node(rnp, flags); -- 2.25.1