From patchwork Tue Nov 22 01:04:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 24078 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1929781wrr; Mon, 21 Nov 2022 17:04:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Wngtr2JP8jRWV7Ned4lNdWsI9knyggu3AEtk3VHph94gw76X2iPPevpV+CE95CttIWLhD X-Received: by 2002:a17:90a:7d0d:b0:1fa:b51d:8d83 with SMTP id g13-20020a17090a7d0d00b001fab51d8d83mr1539524pjl.169.1669079098161; Mon, 21 Nov 2022 17:04:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669079098; cv=none; d=google.com; s=arc-20160816; b=AxgWQxGQYJHI4ivgL5Wb30gzprogir5+1MxfxiWX6osiJrgXcRTAJbgtI65DqjwhZJ 62nLrAstOPPJO5wu9OvwbN4Y5G+XIVgTYaXZY2OJX1lMqjWIzckzrqv7PPYjxR32bHzy TtrJ/4g8bPFpHJJfZYEnVRt6otpsh8n75YKMKqpj/7WoNBW20RZSH1jiOB+SJ9LEKwYl Ke70mXDqGb8+gEUsSadRPFS9LfUOAC7IF5palK06hU3KA8yw/VUX4xJgrhSJ+NrNj/y0 BLhe6Dtdd5BvmhbVMhwwkCM+PZn/sDImElVy0QW+7bLgYLABnBa5DvORGOG8NUTVkZko 6pmQ== 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=uuQBoT0/9VgjI8k7NsHO7zPPIVhrYWCEsChCDjUY0bA=; b=vFeHUaw5E6sC0Gp3o98W+heqfagzzlaV+WmU3hLkV9JWbFjzgFSdct1SnBHsVQrzqi nGRT/3UAWY9tUV+UjqXiYYf27nT3P8NngR0jVClhlcewVYb3/93/eeU4t6nJwVEyRvqd QMSvTv6ejto0bMo9BB2JrUhlu1pxA0FJkSh8lIhhKyh86wJP9UBDgR4qNSpzMeIU5bfx zXQYlsRX4vo1b0MHXuQ3hCigO1sSM93GHFT+B7ipqTlGk8KoIs7TV0HjhNW+s2siifAy 4tseNG3aRMK/awv13AdFsoXoGDxIOLak0gwRzGXv4aFo8Cpk8aJeWrhba6F6xlOZjzhX yflg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JOQXCNm7; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y1-20020a62ce01000000b00542c772d478si12442849pfg.247.2022.11.21.17.04.44; Mon, 21 Nov 2022 17:04:58 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=JOQXCNm7; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232036AbiKVBEb (ORCPT + 99 others); Mon, 21 Nov 2022 20:04:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231928AbiKVBEY (ORCPT ); Mon, 21 Nov 2022 20:04:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4ECBDF40; Mon, 21 Nov 2022 17:04:23 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 65A6961519; Tue, 22 Nov 2022 01:04:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7E53C433B5; Tue, 22 Nov 2022 01:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669079062; bh=KTUh/BBOVf/jDi48jtrSyvr3uGxVW8ae61JQrk9NyJc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JOQXCNm70PQyyZeRLbwg93f07Dsei0nOfLuJ9J1re8t1PshudLXi0wOHO/zVlqGIJ fVVt/hwTYo9vGZqtrEO1CZRGiTXXVBXqaf+dkjkWlt60fJwBTjP/bp9KPDvz+MsFnM KDxvtvd9htvS0DItqONR8FyIvfCdbEc8wilPNw3hQOJfqZpXyDRbPaiNOBElGMjGAt vwn2Z/RP5gnqRTfvP6NmirIWhApQ/Z+zy6mgsJkEf4LTQXgUdo9Cb8FF3IN9mGnf6e +3vOtMoi/mz0ptRX5ZwaWDg8ZigkbAZDUqaO7IH64hw5l/IakTXYlKT/d1z3RzRbI1 5oNlhcSSFvNSg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 717D15C0641; Mon, 21 Nov 2022 17:04:22 -0800 (PST) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, Zhen Lei , Joel Fernandes , Frederic Weisbecker , "Paul E . McKenney" Subject: [PATCH v2 rcu 01/16] rcu: Simplify rcu_init_nohz() cpumask handling Date: Mon, 21 Nov 2022 17:04:06 -0800 Message-Id: <20221122010421.3799681-1-paulmck@kernel.org> X-Mailer: git-send-email 2.31.1.189.g2e36527f23 In-Reply-To: <20221122010408.GA3799268@paulmck-ThinkPad-P17-Gen-1> References: <20221122010408.GA3799268@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 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?1750156284236219131?= X-GMAIL-MSGID: =?utf-8?q?1750156284236219131?= From: Zhen Lei In kernels built with either CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y or CONFIG_NO_HZ_FULL=y, additional CPUs must be added to rcu_nocb_mask. Except that kernels booted without the rcu_nocbs= will not have allocated rcu_nocb_mask. And the current rcu_init_nohz() function uses its need_rcu_nocb_mask and offload_all local variables to track the rcu_nocb and nohz_full state. But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using cpumask_available() to check the rcu_nocb_mask state. This commit takes this approach, thereby simplifying and shortening the rcu_init_nohz() function. Signed-off-by: Zhen Lei Reviewed-by: Joel Fernandes (Google) Acked-by: Frederic Weisbecker Signed-off-by: Paul E. McKenney --- kernel/rcu/tree_nocb.h | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h index 0a5f0ef414845..ce526cc2791ca 100644 --- a/kernel/rcu/tree_nocb.h +++ b/kernel/rcu/tree_nocb.h @@ -1210,45 +1210,33 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload); void __init rcu_init_nohz(void) { int cpu; - bool need_rcu_nocb_mask = false; - bool offload_all = false; struct rcu_data *rdp; - -#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) - if (!rcu_state.nocb_is_setup) { - need_rcu_nocb_mask = true; - offload_all = true; - } -#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */ + const struct cpumask *cpumask = NULL; #if defined(CONFIG_NO_HZ_FULL) - if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) { - need_rcu_nocb_mask = true; - offload_all = false; /* NO_HZ_FULL has its own mask. */ - } -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ + if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) + cpumask = tick_nohz_full_mask; +#endif + + if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) && + !rcu_state.nocb_is_setup && !cpumask) + cpumask = cpu_possible_mask; - if (need_rcu_nocb_mask) { + if (cpumask) { if (!cpumask_available(rcu_nocb_mask)) { if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) { pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n"); return; } } + + cpumask_or(rcu_nocb_mask, rcu_nocb_mask, cpumask); rcu_state.nocb_is_setup = true; } if (!rcu_state.nocb_is_setup) return; -#if defined(CONFIG_NO_HZ_FULL) - if (tick_nohz_full_running) - cpumask_or(rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask); -#endif /* #if defined(CONFIG_NO_HZ_FULL) */ - - if (offload_all) - cpumask_setall(rcu_nocb_mask); - if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) { pr_info("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n"); cpumask_and(rcu_nocb_mask, cpu_possible_mask,