Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp879051rwi; Wed, 19 Oct 2022 04:13:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5gD5NlKZGYHlwQ+WRxPIe7Mrw/miW6z615FZCCkQLArU0sg+dPf5bmEGBTcTbdnceOpI6+ X-Received: by 2002:a17:90b:4c52:b0:20d:489b:5607 with SMTP id np18-20020a17090b4c5200b0020d489b5607mr9119957pjb.40.1666178027171; Wed, 19 Oct 2022 04:13:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666178027; cv=none; d=google.com; s=arc-20160816; b=T9Guu7ZL1YFaqcLy7ShFDmgqkVF2LKmR4dn/Eo+MYBF3gd8ukYlgKqFFrCaew4AUG3 Q1J56iQdCOW1ZJqMKtcy2mgB7PA5k2vbquKrtQBOhivqxkl0mUhyDkpNphoE2OsTMjwt 9vlZvqhGN3ljCMJrcd6HmCGGWdWlolbgsOGxBDA4W+xAe0F0OZ9XhXcxbyUH3HZNV5Jz acWiAX7CMD5t1d6LlEO/agL9h+62i5620nTRxJRtoSJTlJs0bpc1BKvlSn2AthR30gi8 uaX9g4BB7zoFAHi71lBaC1TaopWh1EIzN9YrsQtys0/vIZudl18YVicdSnxKFMoSBdwC GxOw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj5-20020a170903048500b00179f69eae64si18941294plb.620.2022.10.19.04.13.33; Wed, 19 Oct 2022 04:13:47 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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. -- 2.35.1