]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rcu/nocb: Extract nocb_defer_wakeup_cancel() helper
authorJoel Fernandes <joelagnelf@nvidia.com>
Fri, 23 Jan 2026 14:30:31 +0000 (09:30 -0500)
committerBoqun Feng <boqun.feng@gmail.com>
Fri, 23 Jan 2026 19:12:25 +0000 (11:12 -0800)
The pattern of checking nocb_defer_wakeup and deleting the timer is
duplicated in __wake_nocb_gp() and nocb_gp_wait(). Extract this into a
common helper function nocb_defer_wakeup_cancel().

This removes code duplication and makes it easier to maintain.

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
kernel/rcu/tree_nocb.h

index 64a8ff350f92f91aec82c9f791d0ad5d100ab03f..b3337c7231ccb887e8acad455ee6f0f397661eac 100644 (file)
@@ -190,6 +190,15 @@ static void rcu_init_one_nocb(struct rcu_node *rnp)
        init_swait_queue_head(&rnp->nocb_gp_wq[1]);
 }
 
+/* Clear any pending deferred wakeup timer (nocb_gp_lock must be held). */
+static void nocb_defer_wakeup_cancel(struct rcu_data *rdp_gp)
+{
+       if (rdp_gp->nocb_defer_wakeup > RCU_NOCB_WAKE_NOT) {
+               WRITE_ONCE(rdp_gp->nocb_defer_wakeup, RCU_NOCB_WAKE_NOT);
+               timer_delete(&rdp_gp->nocb_timer);
+       }
+}
+
 static bool __wake_nocb_gp(struct rcu_data *rdp_gp,
                           struct rcu_data *rdp,
                           unsigned long flags)
@@ -204,10 +213,7 @@ static bool __wake_nocb_gp(struct rcu_data *rdp_gp,
                return false;
        }
 
-       if (rdp_gp->nocb_defer_wakeup > RCU_NOCB_WAKE_NOT) {
-               WRITE_ONCE(rdp_gp->nocb_defer_wakeup, RCU_NOCB_WAKE_NOT);
-               timer_delete(&rdp_gp->nocb_timer);
-       }
+       nocb_defer_wakeup_cancel(rdp_gp);
 
        if (READ_ONCE(rdp_gp->nocb_gp_sleep)) {
                WRITE_ONCE(rdp_gp->nocb_gp_sleep, false);
@@ -788,10 +794,7 @@ static void nocb_gp_wait(struct rcu_data *my_rdp)
                if (rdp_toggling)
                        my_rdp->nocb_toggling_rdp = NULL;
 
-               if (my_rdp->nocb_defer_wakeup > RCU_NOCB_WAKE_NOT) {
-                       WRITE_ONCE(my_rdp->nocb_defer_wakeup, RCU_NOCB_WAKE_NOT);
-                       timer_delete(&my_rdp->nocb_timer);
-               }
+               nocb_defer_wakeup_cancel(my_rdp);
                WRITE_ONCE(my_rdp->nocb_gp_sleep, true);
                raw_spin_unlock_irqrestore(&my_rdp->nocb_gp_lock, flags);
        } else {