From patchwork Wed Oct 19 08:32:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp254033wrs; Wed, 19 Oct 2022 03:59:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6T2fKiqzFCTXiAg1F57LuWXT/Cn3Nb04F4hO+Z3A7dp4usVqJtkAybjAB1Px2/MiFsGEnn X-Received: by 2002:a63:64d:0:b0:46b:158f:102e with SMTP id 74-20020a63064d000000b0046b158f102emr6985426pgg.150.1666177143315; Wed, 19 Oct 2022 03:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666177143; cv=none; d=google.com; s=arc-20160816; b=Omh3qQvYnTPctZO7gdxtKhFRhOkl6/ekejCGN7mXXnBCO/kQv5lNBi6eNBa1VyXQkL DrqwBg1+i+APRryrl8/xZH9hP+6K1QfOVY13/ezGi9cGDbebXsE/daR/0OddXpzckvj7 CTopEKfAoVfIfGNuSiGp6mr2eFQZqJ9eJKWm/wsbvu2q7XWSWECt+OAxok730jcCPPPI mkx8RpkEjHhtPfnaE4JjeStPd9IHfLsORQjFZU+ZTw5AugSoFX/+SUsBFZYxNpBJcOCq N0FhmaMr6VDS9Jpl7Y9bsSRsckQ5cYh3WEahoK15BNGSFRQ2bedS2PNSDpQQzmP2Ado9 clCw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kWwOZrZQOK+oucO2EIYPto+uUZRa4HfJbdSUU2Wgpxc=; b=na2C4d3Ym/N7khT8bnnVhCye0ztmEdj86hWcXjFgH7YYbf7ltCNKDGz95+oaKsnoLX gQ/9msMlbDHYEN0+l49nT/PRidiK6UwZ8cS8VUwY49xwLqNvHjeqhBf50Yk6F9dl5mR/ gF/FcyvoP3FvYsXdqKKotN4jWrw4gy+ZTcRqgEYLOyGpISZYRDYE9WAfikLjENNJP3mY M+kkMCYWvGONbb6oNxakMYSDLp4K/UL2tmDgBJwnOLW1BRpjABnQWPLmgSs+cvRJSEeP xA02RqyZ965j8bTkdc1JaMAqn2qvTrmlKvQZYu6kTCphCgkFQo95Odsx6Z6uBj5zE9yw 3M4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ahEE6/0u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a170903018100b0017336c464ecsi19583222plg.407.2022.10.19.03.58.50; Wed, 19 Oct 2022 03:59:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ahEE6/0u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234850AbiJSK6P (ORCPT + 99 others); Wed, 19 Oct 2022 06:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234748AbiJSK4p (ORCPT ); Wed, 19 Oct 2022 06:56:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B79A7BB2; Wed, 19 Oct 2022 03:27:51 -0700 (PDT) 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 615E9B82400; Wed, 19 Oct 2022 09:07:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA2C5C433D6; Wed, 19 Oct 2022 09:07:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170457; bh=EpH8F25ftH4qXMt5E1/aEv6zxIBXRJCjac9DWYRJ0Jc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ahEE6/0ubT+ZsrDMqXgYRehTmoCwCckBwG+Drr5loJ2osrBiXwEm9tZTHut123VOH DhQUGUGMF+k0YGBOU6W+gzTdTfueRAXSSqupZrOQzevA7+dpLu5DL3QqOpnVkWhcNK ySiQbpUkBuIGCOR20GR5SVjNUxTIgx88fjWf/Jzo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zqiang , "Paul E. McKenney" , Sasha Levin Subject: [PATCH 6.0 662/862] rcu: Avoid triggering strict-GP irq-work when RCU is idle Date: Wed, 19 Oct 2022 10:32:29 +0200 Message-Id: <20221019083319.221155015@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747113364275440551?= X-GMAIL-MSGID: =?utf-8?q?1747113364275440551?= From: Zqiang [ Upstream commit 621189a1fe93cb2b34d62c5cdb9e258bca044813 ] Kernels built with PREEMPT_RCU=y and RCU_STRICT_GRACE_PERIOD=y trigger irq-work from rcu_read_unlock(), and the resulting irq-work handler invokes rcu_preempt_deferred_qs_handle(). The point of this triggering is to force grace periods to end quickly in order to give tools like KASAN a better chance of detecting RCU usage bugs such as leaking RCU-protected pointers out of an RCU read-side critical section. However, this irq-work triggering is unconditional. This works, but there is no point in doing this irq-work unless the current grace period is waiting on the running CPU or task, which is not the common case. After all, in the common case there are many rcu_read_unlock() calls per CPU per grace period. This commit therefore triggers the irq-work only when the current grace period is waiting on the running CPU or task. This change was tested as follows on a four-CPU system: echo rcu_preempt_deferred_qs_handler > /sys/kernel/debug/tracing/set_ftrace_filter echo 1 > /sys/kernel/debug/tracing/function_profile_enabled insmod rcutorture.ko sleep 20 rmmod rcutorture.ko echo 0 > /sys/kernel/debug/tracing/function_profile_enabled echo > /sys/kernel/debug/tracing/set_ftrace_filter This procedure produces results in this per-CPU set of files: /sys/kernel/debug/tracing/trace_stat/function* Sample output from one of these files is as follows: Function Hit Time Avg s^2 -------- --- ---- --- --- rcu_preempt_deferred_qs_handle 838746 182650.3 us 0.217 us 0.004 us The baseline sum of the "Hit" values (the number of calls to this function) was 3,319,015. With this commit, that sum was 1,140,359, for a 2.9x reduction. The worst-case variance across the CPUs was less than 25%, so this large effect size is statistically significant. The raw data is available in the Link: URL. Link: https://lore.kernel.org/all/20220808022626.12825-1-qiang1.zhang@intel.com/ Signed-off-by: Zqiang Signed-off-by: Paul E. McKenney Signed-off-by: Sasha Levin --- kernel/rcu/tree_plugin.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index 438ecae6bd7e..49468b4d1b43 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h @@ -641,7 +641,8 @@ static void rcu_read_unlock_special(struct task_struct *t) expboost = (t->rcu_blocked_node && READ_ONCE(t->rcu_blocked_node->exp_tasks)) || (rdp->grpmask & READ_ONCE(rnp->expmask)) || - IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD) || + (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD) && + ((rdp->grpmask & READ_ONCE(rnp->qsmask)) || t->rcu_blocked_node)) || (IS_ENABLED(CONFIG_RCU_BOOST) && irqs_were_disabled && t->rcu_blocked_node); // Need to defer quiescent state until everything is enabled.