Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp322224rwl; Wed, 4 Jan 2023 20:14:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXvLDBYI84n/Q00YP6ZnhbdCZXTIOxBZOEEbqHNJ28Nsp7dC+ys6AhMPZzRZIDnr16dvShb5 X-Received: by 2002:aa7:d448:0:b0:46c:8a01:7494 with SMTP id q8-20020aa7d448000000b0046c8a017494mr42341697edr.37.1672892049099; Wed, 04 Jan 2023 20:14:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672892049; cv=none; d=google.com; s=arc-20160816; b=NzY0pk+74vJgcCkPVMD4jvO0XFC5mpg/xjx3p77p/jFWNWVNl9pXNlShkkpv4qoZat PaUdhw41o7rq8+qrfO0bbj2YfqcSkU87T9ePpvs7IamvuHX3IpiHHyNI4CqHPTzEfych qc14U4uCD1JwGENeFZKsjX7HDVq2jYbTXqkOyHdA6PRT3+NWqog/YYCEdovjL7ZXxUt1 YqOeD200EdrbOhnbPW3AJM1dLb3zlNxnxONrLtLXJcApkFvRsYTU0kjxDr7KTNcHvnSr bPo72JuwvACwmhcpnIb/Vvk7CcTwgpZKwxfx6rJ4NS/5ZeAh03v+kpPd+Rf6wTxxLJTF XAsg== 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=SKbwcBc8RIQec3VEsx2UOumhuCsY9BOOUOIE01Gy/eg=; b=BG5hAVpKZAaXujqQ6fqWdlofYVO29qtOnTb9OrUy18KnKXjkwnLx6JR+aoD5BesdOM TCpYzR2l0MG6l2ZxNU1rEEnzpNwwf76xGzmKXg9vtE7yUkxNzpucCXjL/uuUI71Hbe98 sDzd7Cu3rBRvemoYQGA4JAGuT6b3Ac9m6snJTY7PnJTFEGdezQd6ddYRBWtorDCQh0oI JtRBfZTUr3F1eo9NZtXvht7K0QjZDZPYXwsxg8CBe3CdQt6xMcSelAsGK0wDS3imBwZC JS4yvk84vr9EHLN2/uaY7fFrCKut5LIrFXb8xyvzI50t3cE3g668rWPxYJIqe8XNEaF9 X9Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LWLxoqFJ; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j17-20020a05640211d100b00451e0d930dfsi36798868edw.497.2023.01.04.20.13.55; Wed, 04 Jan 2023 20:14:09 -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=@intel.com header.s=Intel header.b=LWLxoqFJ; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230101AbjAEDel (ORCPT + 55 others); Wed, 4 Jan 2023 22:34:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbjAEDej (ORCPT ); Wed, 4 Jan 2023 22:34:39 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C90064882C; Wed, 4 Jan 2023 19:34:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672889678; x=1704425678; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=QUTlUNdOBhgTJmvcsTFaL20j9mIag+B96H14BJHxIUs=; b=LWLxoqFJQjpjnipVakjFtQl0YcsP9FOIXBMeA6eqz3G2a3kpUSjfYQTL aptaOtz71sO6QgjmzV+z9GIF1v/UUBWtuQUHjUSRuFk8TuilMgkf2zEq4 V+sl9Hmz16JTV20N4ndpR7NEwbnb3HoJj7qv/Ivt6ngJ55oXtdmPOsP/j vOlAVbAlHszvU52S8T7CdlSVqq9p7HLfuVm/ViDA/pbB52tXaM4YOkPzc ESI60UCtpJCr45d68+9GDax7Ejr/bX08uoYhrBD3mfyCJLa64ron2SxGP 5a8tth9lUhxzXAPHJLADh00mRMYij4HLg3tAt1PzDH+MF/eS2ghAnv7LM g==; X-IronPort-AV: E=McAfee;i="6500,9779,10580"; a="322177651" X-IronPort-AV: E=Sophos;i="5.96,301,1665471600"; d="scan'208";a="322177651" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2023 19:34:38 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10580"; a="779428061" X-IronPort-AV: E=Sophos;i="5.96,301,1665471600"; d="scan'208";a="779428061" Received: from zq-optiplex-7090.bj.intel.com ([10.238.156.129]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2023 19:34:35 -0800 From: Zqiang To: paulmck@kernel.org, frederic@kernel.org, quic_neeraju@quicinc.com, joel@joelfernandes.org Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] rcu: Rework tick dependency setting into rcu_exp_handler() Date: Thu, 5 Jan 2023 11:40:00 +0800 Message-Id: <20230105034000.971748-1-qiang1.zhang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 Currently, when first find out the expedited grace period is not end and timeout occurred, we set tick dependency for CPUs that have not yet reported the quiescent state in the rcu_node structure's->expmask but need to eliminate races between set and clear tick dependency, setting CPU tick dependency need to hold rcu_node structure's->lock. This commit move tick dependency setting into rcu_exp_handler(), set tick dependency when fail to report a quiescent state and clear tick dependency in rcu_report_exp_rdp(). [from Frederic Weisbecker suggestion] Signed-off-by: Zqiang --- kernel/rcu/tree_exp.h | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h index 7cc4856da081..f1e947675727 100644 --- a/kernel/rcu/tree_exp.h +++ b/kernel/rcu/tree_exp.h @@ -586,39 +586,16 @@ static bool synchronize_rcu_expedited_wait_once(long tlimit) static void synchronize_rcu_expedited_wait(void) { int cpu; - unsigned long j; unsigned long jiffies_stall; unsigned long jiffies_start; unsigned long mask; int ndetected; - struct rcu_data *rdp; struct rcu_node *rnp; struct rcu_node *rnp_root = rcu_get_root(); - unsigned long flags; trace_rcu_exp_grace_period(rcu_state.name, rcu_exp_gp_seq_endval(), TPS("startwait")); jiffies_stall = rcu_exp_jiffies_till_stall_check(); jiffies_start = jiffies; - if (tick_nohz_full_enabled() && rcu_inkernel_boot_has_ended()) { - if (synchronize_rcu_expedited_wait_once(1)) - return; - rcu_for_each_leaf_node(rnp) { - raw_spin_lock_irqsave_rcu_node(rnp, flags); - mask = READ_ONCE(rnp->expmask); - for_each_leaf_node_cpu_mask(rnp, cpu, mask) { - rdp = per_cpu_ptr(&rcu_data, cpu); - if (rdp->rcu_forced_tick_exp) - continue; - rdp->rcu_forced_tick_exp = true; - if (cpu_online(cpu)) - tick_dep_set_cpu(cpu, TICK_DEP_BIT_RCU_EXP); - } - raw_spin_unlock_irqrestore_rcu_node(rnp, flags); - } - j = READ_ONCE(jiffies_till_first_fqs); - if (synchronize_rcu_expedited_wait_once(j + HZ)) - return; - } for (;;) { if (synchronize_rcu_expedited_wait_once(jiffies_stall)) @@ -729,6 +706,24 @@ static void rcu_exp_sel_wait_wake(unsigned long s) #ifdef CONFIG_PREEMPT_RCU +static void rcu_exp_set_tickdep(struct rcu_data *rdp) +{ + int cpu = rdp->cpu; + + if (tick_nohz_full_cpu(cpu) && rcu_inkernel_boot_has_ended() && + cpu_online(cpu)) { + /* + * The rcu_exp_handler() can be invoked from stop machine, + * at this time CPU has disabled all interrupts and offline, + * in which case, we don't need requeue IPI or irq work. + * which is not a problem since rcu_report_dead() does the + * QS report. + */ + rdp->rcu_forced_tick_exp = true; + tick_dep_set_cpu(cpu, TICK_DEP_BIT_RCU_EXP); + } +} + /* * Remote handler for smp_call_function_single(). If there is an * RCU read-side critical section in effect, request that the @@ -757,6 +752,7 @@ static void rcu_exp_handler(void *unused) WRITE_ONCE(rdp->cpu_no_qs.b.exp, true); set_tsk_need_resched(t); set_preempt_need_resched(); + rcu_exp_set_tickdep(rdp); } return; } @@ -778,6 +774,7 @@ static void rcu_exp_handler(void *unused) if (rnp->expmask & rdp->grpmask) { WRITE_ONCE(rdp->cpu_no_qs.b.exp, true); t->rcu_read_unlock_special.b.exp_hint = true; + rcu_exp_set_tickdep(rdp); } raw_spin_unlock_irqrestore_rcu_node(rnp, flags); return; -- 2.25.1