From patchwork Thu Oct 19 12:01:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 155470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp330965vqb; Thu, 19 Oct 2023 05:03:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2J70FA5gEUcMd4zwkYWcEZOzDDdSAZVJFL9FAPCB2Ms0FrD3AiIP8bt7pyv49TlYXge2W X-Received: by 2002:a17:90a:cb8a:b0:26d:43f0:7ce4 with SMTP id a10-20020a17090acb8a00b0026d43f07ce4mr1888363pju.8.1697717017439; Thu, 19 Oct 2023 05:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697717017; cv=none; d=google.com; s=arc-20160816; b=fRMcmAB+jn0cJyHUBQa97SdMdnlwHZ44rrH/ReGIXj1xfDWsNyRyVKeHE3AuJ5cOYf bmYGmaD5bLT1V4xxHUrp6cyZo+gn7Ne6aKTN8Oy/cbk/6lgBpPFifcl9lz4H/hOD8a3V ox7a8HLLpQF98xo4pn1+5RjGuZu675e/kCG2buuoxM2KyFhbYSYu8TuTocAqDBqjWzbn x87wNik3uV8PMRnJ6TpIBYl15ndXW8bWtwPHkNh6BWZwCBg1Cx8FBOSL+fDX/Dpei5d0 nK1mRowh6vKHsI2Saa6PQqlWfVfxf1OiMXKJ8uvsUUA7kaZzKggwASp1SmygZLhSpVO1 TJ3g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xdGMtN2022i7QDT7e09CtGLVF/Qx9SBTbFlZC3GsL9Q=; fh=5+YmRexi1ebesok90zB32639YOcyyiie3F5fnFFoKq8=; b=tbKUNc09aS5YHJGLiDKVGOhJ9PvYaQxhGwxRpes1PmhPwUWwbzI+ZqKihH0vH7vKpZ 6DVkg9psVWLQXxhOsR8iQGfM3OWO3iI4gcb2rMXQZTMdTVNDBqOyCFfonbkwa1FIrwl8 padVuGNgO/fLaout5Y1118FaVJ2JJcScR+89Ia90Iy/2LOvSCkwS218WOFVOfrGV8GHG EVeQqurC9xkjTas3rQUrQsVxSLOgk03005jyl68nStW+dTVfH4PI6Q3ctwGpnM0W7pwk mygpugvmaZmkCoDhkBxfrUerIn3DA6Ia3JdYezQ2Wo4S739UXcgU0Eq+3KishPVw57T4 ApUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oHiWEClJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id il5-20020a17090b164500b00277374d74afsi2126176pjb.12.2023.10.19.05.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:03:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oHiWEClJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 8AEE781A7D25; Thu, 19 Oct 2023 05:03:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345537AbjJSMCa (ORCPT + 25 others); Thu, 19 Oct 2023 08:02:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345522AbjJSMCU (ORCPT ); Thu, 19 Oct 2023 08:02:20 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B28B187; Thu, 19 Oct 2023 05:02:18 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1F72C433C8; Thu, 19 Oct 2023 12:02:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697716938; bh=Vnj5hN2dPt9MAc5s8TCef1rcSgQpQJDKJ311AZcgTbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oHiWEClJahpQOALP7cH2yadREFbTb1JxW4abwGr8xTP67tB9OFxQYrkXWIO/TEQkN /6naZ9UwnQatD4XgLhF6rWC6UmJ8xaALg0DSBMb26W8CLI8Ff1PP9yyswYP7g+GHfP PtF01MW4KsALhsRkSIz2rs9UmJ6jZIZrzmQUii1Tmf+WZ6JCd+iExLL1Xs8OY1qTcZ 520FMxdydmor7RotTaYeHx+IilBR6CWoq7U0H054JnJ2WAc9k5M/X48vXBJoCNZ5lA KV3NYPlHj0mwG0g/Z7CFWIL+lmy+Lu+2I0m2TNg+pM20pwLZcnmJSmbBHhNH+k8rRv O+wnLthrWvBxg== From: Frederic Weisbecker To: LKML Cc: Zhen Lei , Boqun Feng , Joel Fernandes , Josh Triplett , Mathieu Desnoyers , Neeraj Upadhyay , "Paul E . McKenney" , Steven Rostedt , Uladzislau Rezki , rcu , Frederic Weisbecker Subject: [PATCH 3/6] rcu: Eliminate check_cpu_stall() duplicate code Date: Thu, 19 Oct 2023 14:01:59 +0200 Message-Id: <20231019120202.1216228-4-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019120202.1216228-1-frederic@kernel.org> References: <20231019120202.1216228-1-frederic@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:03:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780185319176486093 X-GMAIL-MSGID: 1780185319176486093 From: Zhen Lei The code and comments of self-detected and other-detected RCU CPU stall warnings are identical except the output function. This commit therefore refactors so as to consolidate the duplicate code. Signed-off-by: Zhen Lei Signed-off-by: Paul E. McKenney Signed-off-by: Frederic Weisbecker --- kernel/rcu/tree_stall.h | 42 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h index fc04a8d7ce96..2443d1d4a6dc 100644 --- a/kernel/rcu/tree_stall.h +++ b/kernel/rcu/tree_stall.h @@ -711,7 +711,7 @@ static void print_cpu_stall(unsigned long gps) static void check_cpu_stall(struct rcu_data *rdp) { - bool didstall = false; + bool self_detected; unsigned long gs1; unsigned long gs2; unsigned long gps; @@ -758,10 +758,10 @@ static void check_cpu_stall(struct rcu_data *rdp) return; /* No stall or GP completed since entering function. */ rnp = rdp->mynode; jn = jiffies + ULONG_MAX / 2; + self_detected = READ_ONCE(rnp->qsmask) & rdp->grpmask; if (rcu_gp_in_progress() && - (READ_ONCE(rnp->qsmask) & rdp->grpmask) && + (self_detected || ULONG_CMP_GE(j, js + RCU_STALL_RAT_DELAY)) && cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) { - /* * If a virtual machine is stopped by the host it can look to * the watchdog like an RCU stall. Check to see if the host @@ -770,33 +770,21 @@ static void check_cpu_stall(struct rcu_data *rdp) if (kvm_check_and_clear_guest_paused()) return; - /* We haven't checked in, so go dump stack. */ - print_cpu_stall(gps); - if (READ_ONCE(rcu_cpu_stall_ftrace_dump)) - rcu_ftrace_dump(DUMP_ALL); - didstall = true; - - } else if (rcu_gp_in_progress() && - ULONG_CMP_GE(j, js + RCU_STALL_RAT_DELAY) && - cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) { + if (self_detected) { + /* We haven't checked in, so go dump stack. */ + print_cpu_stall(gps); + } else { + /* They had a few time units to dump stack, so complain. */ + print_other_cpu_stall(gs2, gps); + } - /* - * If a virtual machine is stopped by the host it can look to - * the watchdog like an RCU stall. Check to see if the host - * stopped the vm. - */ - if (kvm_check_and_clear_guest_paused()) - return; - - /* They had a few time units to dump stack, so complain. */ - print_other_cpu_stall(gs2, gps); if (READ_ONCE(rcu_cpu_stall_ftrace_dump)) rcu_ftrace_dump(DUMP_ALL); - didstall = true; - } - if (didstall && READ_ONCE(rcu_state.jiffies_stall) == jn) { - jn = jiffies + 3 * rcu_jiffies_till_stall_check() + 3; - WRITE_ONCE(rcu_state.jiffies_stall, jn); + + if (READ_ONCE(rcu_state.jiffies_stall) == jn) { + jn = jiffies + 3 * rcu_jiffies_till_stall_check() + 3; + WRITE_ONCE(rcu_state.jiffies_stall, jn); + } } }