Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5270787iog; Wed, 22 Jun 2022 16:09:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s+i2zhghH3rQr1XPidM9ZbtDekfMwGbgXfI/lrGZpimkHIJ1mPrUnLJL0SCkbhdQLZJcL1 X-Received: by 2002:a17:902:7fce:b0:16a:16ab:6fed with SMTP id t14-20020a1709027fce00b0016a16ab6fedmr22483326plb.145.1655939379755; Wed, 22 Jun 2022 16:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655939379; cv=none; d=google.com; s=arc-20160816; b=ipCf2pPwwfoe4of2CLFpLmojqlRlwOwWnJ+uH5rCfc94Hoeuy2zw+2K7ElIZqeYFXo eFvGSZu3HWOFeh4RW25fUCWu4bkRaB31iV8fcpJoegupSpyVpgVEaBy7wOXtPgjxu/yb J4q/oSGFJR2YY3dI+WGZTOatMdu4XahdQri2yi095OY005QrMZzFkFQ1XjhFgRuM9yKn EXRzCHPvYpQ6UmA1w2IKhaotOEq/tMO7Zl+mIYAvjPhTh1t6aVkYRsEA3TGVme0X39YR cJuy14k7xrWLAL8fvxuaAxq6ydG3oL60YvFs0SlJ5LucmfB/Pszf6DOmIYpNJu9VwNhA 5gNA== 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=oulAy7NlmqgAX/AG2BIWch0UpN6lWOBq/Xx+LqGxyiU=; b=wLha3Q/DcKMJXtpZosb/F5eKBO0Fzv3UcCJ4BzhlylAYMM6g8E90aGtSDD+AXhfRoW hDr/BoIgca7WBLQCceTGb+8fd6HDmNmoOmc1S4Lc4K2r6dzV0V5/pUUsaVGIaihp1361 LPh9oIXaV+LRGM6IWNmnuH5ER1V+n+Ct2YWLU/g5NXM7NoFdf2wRpQmtnfKWtDpsmvwz 6oMow25WmAVoirbeWR/vZZEgvMV88mmaj4dE7v1nEl1ZpKhgKR7it8IFZiIUZMydFZJ5 GZBpE40sVL0cyko9n5rldtFhGEUFAedCzncXKbMiV8BNWZwdcnkYux9A8xc85GHGW9wx InXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Zd4Acj6v; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kk8-20020a17090b4a0800b001eccf97e562si924251pjb.4.2022.06.22.16.09.27; Wed, 22 Jun 2022 16:09:39 -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=@joelfernandes.org header.s=google header.b=Zd4Acj6v; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376358AbiFVWwL (ORCPT + 99 others); Wed, 22 Jun 2022 18:52:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359771AbiFVWvt (ORCPT ); Wed, 22 Jun 2022 18:51:49 -0400 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 450FE41303 for ; Wed, 22 Jun 2022 15:51:48 -0700 (PDT) Received: by mail-qv1-xf2a.google.com with SMTP id o43so27420978qvo.4 for ; Wed, 22 Jun 2022 15:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oulAy7NlmqgAX/AG2BIWch0UpN6lWOBq/Xx+LqGxyiU=; b=Zd4Acj6vFejlAuM4LGySk0mn5EpwW09kqb0tPrWdZuUSIL1zdVj6CpnngjAG5CU35U 9yra0A4qcuU3QelVy9Thq3pL7e37068nnzNVRkCJG9aRq+zBR8VCYjCfHgtlXa90Ue4H IGj41tdwPLrWondJBlm13KXtRnLZJprFieFjI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oulAy7NlmqgAX/AG2BIWch0UpN6lWOBq/Xx+LqGxyiU=; b=dV1EhxEze450Ji2XM1P0ciQ7PP+9pflsDkGpUnFAHXHer7PC2KLsV/5jMNgVw3j9vc uKzU3sWD0m9cUrfu4gA1b4EjjbKH4Bkdnxqna2MCFriEVHAYQNcPb+IQ3+7WhtfKeprq lrdjT+nKwyq5fiHvB49YE4U6cMZjc5cJIJcA9dwyI+Wauem8A1jolkRuBdKiRaHat0J1 +4duOkAM9FTA59SEyjby3pP1r+1iVZrEzej7GmqGmtCQaA8gN90FwYQdi2hqXCL+7fAy t79TCsjq5u766vNxlVurivMhPqI0zWxfkC26hMkWhCyq2QKwxBAqacG3y/JC06mWsPxL u/hw== X-Gm-Message-State: AJIora8n79w+44bc67w6DrhfxSXF3/vcQROVWsLXx8DoGo+49l0CO/Rm m0QxeyINGCWEBuSAWHf2yskSXA== X-Received: by 2002:a0c:9066:0:b0:470:2b7a:2078 with SMTP id o93-20020a0c9066000000b004702b7a2078mr22020533qvo.51.1655938307947; Wed, 22 Jun 2022 15:51:47 -0700 (PDT) Received: from joelboxx.c.googlers.com.com (228.221.150.34.bc.googleusercontent.com. [34.150.221.228]) by smtp.gmail.com with ESMTPSA id k66-20020a37a145000000b006ab91fd03fasm1794022qke.19.2022.06.22.15.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 15:51:47 -0700 (PDT) From: "Joel Fernandes (Google)" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rushikesh.s.kadam@intel.com, urezki@gmail.com, neeraj.iitr10@gmail.com, frederic@kernel.org, paulmck@kernel.org, rostedt@goodmis.org, vineeth@bitbyteword.org, "Joel Fernandes (Google)" Subject: [PATCH v2 7/8] rcu/nocb: Rewrite deferred wake up logic to be more clean Date: Wed, 22 Jun 2022 22:51:01 +0000 Message-Id: <20220622225102.2112026-9-joel@joelfernandes.org> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog In-Reply-To: <20220622225102.2112026-1-joel@joelfernandes.org> References: <20220622225102.2112026-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 There are 2 things this function does: 1. modify the gp wake timer. 2. save the value of the strongest requested wake up so far. The strongest is "wake force" and the weakest is "lazy". The existing logic already does the following: 1. if the existing deferred wake is stronger than the requested one (requested in waketype), modify the gp timer to be more in the future. For example, if the existing one is WAKE and the new waketype requested is BYPASS, then the timer is made to expire later than earlier. 2. even though the timer is modified in #1, a weaker waketype does not end up changing rdp->nocb_gp_defer to be weaker. In other words, ->nocb_gp_defer records the strongest waketype requested so far, even though the timer may or may not be the soonest expiry possible. For simplicity, we write this logic using switch statements and consolidate some of the timer modification operations. Signed-off-by: Joel Fernandes (Google) --- kernel/rcu/tree_nocb.h | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h index 255f2945b0fc..67b0bd5d233a 100644 --- a/kernel/rcu/tree_nocb.h +++ b/kernel/rcu/tree_nocb.h @@ -282,6 +282,7 @@ static void wake_nocb_gp_defer(struct rcu_data *rdp, int waketype, { unsigned long flags; struct rcu_data *rdp_gp = rdp->nocb_gp_rdp; + unsigned long mod_jif = 0; raw_spin_lock_irqsave(&rdp_gp->nocb_gp_lock, flags); @@ -289,19 +290,31 @@ static void wake_nocb_gp_defer(struct rcu_data *rdp, int waketype, * Bypass wakeup overrides previous deferments. In case * of callback storm, no need to wake up too early. */ - if (waketype == RCU_NOCB_WAKE_LAZY) { - mod_timer(&rdp_gp->nocb_timer, jiffies + jiffies_till_flush); - WRITE_ONCE(rdp_gp->nocb_defer_wakeup, waketype); - } else if (waketype == RCU_NOCB_WAKE_BYPASS) { - mod_timer(&rdp_gp->nocb_timer, jiffies + 2); - WRITE_ONCE(rdp_gp->nocb_defer_wakeup, waketype); - } else { - if (rdp_gp->nocb_defer_wakeup < RCU_NOCB_WAKE) - mod_timer(&rdp_gp->nocb_timer, jiffies + 1); - if (rdp_gp->nocb_defer_wakeup < waketype) - WRITE_ONCE(rdp_gp->nocb_defer_wakeup, waketype); + switch (waketype) { + case RCU_NOCB_WAKE_LAZY: + mod_jif = jiffies_till_flush; + break; + + case RCU_NOCB_WAKE_BYPASS: + mod_jif = 2; + break; + + case RCU_NOCB_WAKE: + case RCU_NOCB_WAKE_FORCE: + // If the type of deferred wake is "stronger" + // than it was before, make it wake up the soonest. + if (rdp_gp->nocb_defer_wakeup < RCU_NOCB_WAKE) + mod_jif = 1; + break; } + if (mod_jif) + mod_timer(&rdp_gp->nocb_timer, jiffies + mod_jif); + + // If new type of wake up is strong than before, promote. + if (rdp_gp->nocb_defer_wakeup < waketype) + WRITE_ONCE(rdp_gp->nocb_defer_wakeup, waketype); + raw_spin_unlock_irqrestore(&rdp_gp->nocb_gp_lock, flags); trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, reason); -- 2.37.0.rc0.104.g0611611a94-goog