Skip to contentSkip to conversation

rcu/nocb: Avoid polling when myrdp->nocb_head_rdp list is empty

PATCH Superseded Zqiang 2 participants 3 messages Jun 6, 2022 – Jun 7, 2022 RCU

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH 1/1 rcu/nocb: Avoid polling when myrdp->nocb_head_rdp list is empty

Currently, If the 'rcu_nocb_poll' bootargs is enable, all rcuog kthreads enter polling mode. however, due to only insert CPU's rdp which belong to rcu_nocb_mask to 'nocb_head_rdp' list or all CPU's rdp served by rcuog kthread have been de-offloaded, these cause the 'nocb_head_rdp' list served by rcuog kthread is empty, when the 'nocb_head_rdp' is empty, the rcuog kthread in polling mode not actually do anything. fix it by exiting polling mode when the 'nocb_head_rdp'list is empty, otherwise entering polling mode.

---
 kernel/rcu/tree_nocb.h | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
kernel/rcu/tree_nocb.h +9 -5
index fa8e4f82e60c..c25c3e3dd22d 100644
@@ -698,10 +698,14 @@ static void nocb_gp_wait(struct rcu_data *my_rdp)
 				   TPS("WakeBypassIsDeferred"));
 	}
 	if (rcu_nocb_poll) {
-		/* Polling, so trace if first poll in the series. */
-		if (gotcbs)
-			trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("Poll"));
-		schedule_timeout_idle(1);
+		if (list_empty(&my_rdp->nocb_head_rdp)) {
+			rcu_wait(READ_ONCE(my_rdp->nocb_toggling_rdp));
+		} else {
+			/* Polling, so trace if first poll in the series. */
+			if (gotcbs)
+				trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("Poll"));
+			schedule_timeout_idle(1);
+		}
 	} else if (!needwait_gp) {
 		/* Wait for callbacks to appear. */
 		trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("Sleep"));
@@ -980,7 +984,7 @@ static int rdp_offload_toggle(struct rcu_data *rdp,
 	raw_spin_lock_irqsave(&rdp_gp->nocb_gp_lock, flags);
 	// Queue this rdp for add/del to/from the list to iterate on rcuog
 	WRITE_ONCE(rdp_gp->nocb_toggling_rdp, rdp);
-	if (rdp_gp->nocb_gp_sleep) {
+	if (rcu_nocb_poll || rdp_gp->nocb_gp_sleep) {
 		rdp_gp->nocb_gp_sleep = false;
 		wake_gp = true;
 	}
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 10 lines · Zqiang

Currently, If the 'rcu_nocb_poll' bootargs is enable, all rcuog kthreads enter polling mode. however, due to only insert CPU's rdp which belong to rcu_nocb_mask to 'nocb_head_rdp' list or all CPU's rdp served by rcuog kthread have been de-offloaded, these cause the 'nocb_head_rdp' list served by rcuog kthread is empty, when the 'nocb_head_rdp' is empty, the rcuog kthread in polling mode not actually do anything. fix it by exiting polling mode when the 'nocb_head_rdp'list is empty, otherwise entering polling mode.

Looks promising! A couple of questions below.

Quoted 9 lines
---
 kernel/rcu/tree_nocb.h | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
kernel/rcu/tree_nocb.h +0 -0
index fa8e4f82e60c..c25c3e3dd22d 100644

kernel/rcu/tree_nocb.h static void nocb_gp_wait(struct rcu_data *my_rdp) · line 701

Quoted 8 lines
kernel/rcu/tree_nocb.h +1 -4
@@ -698,10 +698,14 @@ static void nocb_gp_wait(struct rcu_data *my_rdp)
 				   TPS("WakeBypassIsDeferred"));
 	}
 	if (rcu_nocb_poll) {
-		/* Polling, so trace if first poll in the series. */
-		if (gotcbs)
-			trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("Poll"));
-		schedule_timeout_idle(1);
+		if (list_empty(&my_rdp->nocb_head_rdp)) {

Do we need to set rdp_gp->nocb_gp_sleep to true in here somewhere?

Quoted 11 lines
kernel/rcu/tree_nocb.h +7 -0
+			rcu_wait(READ_ONCE(my_rdp->nocb_toggling_rdp));
+		} else {
+			/* Polling, so trace if first poll in the series. */
+			if (gotcbs)
+				trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("Poll"));
+			schedule_timeout_idle(1);
+		}
 	} else if (!needwait_gp) {
 		/* Wait for callbacks to appear. */
 		trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("Sleep"));

kernel/rcu/tree_nocb.h static int rdp_offload_toggle(struct rcu_data *rdp, · line 987

Quoted 5 lines
kernel/rcu/tree_nocb.h +1 -1
@@ -980,7 +984,7 @@ static int rdp_offload_toggle(struct rcu_data *rdp,
 	raw_spin_lock_irqsave(&rdp_gp->nocb_gp_lock, flags);
 	// Queue this rdp for add/del to/from the list to iterate on rcuog
 	WRITE_ONCE(rdp_gp->nocb_toggling_rdp, rdp);
-	if (rdp_gp->nocb_gp_sleep) {
+	if (rcu_nocb_poll || rdp_gp->nocb_gp_sleep) {

Is it the case that other than when (de-)offloading, the rcuog kthread is never awakened when rcu_nocb_poll is set? If this is not the case, we would have spurious wakeups. (I believe that rcu_nocb_poll suppresses those wakeups, but it would be good to check.)

Quoted 6 lines
kernel/rcu/tree_nocb.h +0 -0
 		rdp_gp->nocb_gp_sleep = false;
 		wake_gp = true;
 	}
Signature · 1 line
2.25.1
#2 lore raw
Quoted 31 lines · Zqiang

Currently, If the 'rcu_nocb_poll' bootargs is enable, all rcuog kthreads enter polling mode. however, due to only insert CPU's rdp which belong to rcu_nocb_mask to 'nocb_head_rdp' list or all CPU's rdp served by rcuog kthread have been de-offloaded, these cause the 'nocb_head_rdp' list served by rcuog kthread is empty, when the 'nocb_head_rdp' is empty, the rcuog kthread in polling mode not actually do anything. fix it by exiting polling mode when the 'nocb_head_rdp'list is empty, otherwise entering polling mode.

Looks promising! A couple of questions below.

---
 kernel/rcu/tree_nocb.h | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
kernel/rcu/tree_nocb.h +1 -4
index fa8e4f82e60c..c25c3e3dd22d 100644
@@ -698,10 +698,14 @@ static void nocb_gp_wait(struct rcu_data *my_rdp)
 				   TPS("WakeBypassIsDeferred"));
 	}
 	if (rcu_nocb_poll) {
-		/* Polling, so trace if first poll in the series. */
-		if (gotcbs)
-			trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("Poll"));
-		schedule_timeout_idle(1);
+		if (list_empty(&my_rdp->nocb_head_rdp)) {
 
Quoted 1 line

Do we need to set rdp_gp->nocb_gp_sleep to true in here somewhere?

When rcu_nocb_poll is set, the rdp_gp->nocb_gp_sleep flags is not used.

Quoted 17 lines
kernel/rcu/tree_nocb.h +8 -1
+			rcu_wait(READ_ONCE(my_rdp->nocb_toggling_rdp));
+		} else {
+			/* Polling, so trace if first poll in the series. */
+			if (gotcbs)
+				trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("Poll"));
+			schedule_timeout_idle(1);
+		}
 	} else if (!needwait_gp) {
 		/* Wait for callbacks to appear. */
 		trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("Sleep"));
@@ -980,7 +984,7 @@ static int rdp_offload_toggle(struct rcu_data *rdp,
 	raw_spin_lock_irqsave(&rdp_gp->nocb_gp_lock, flags);
 	// Queue this rdp for add/del to/from the list to iterate on rcuog
 	WRITE_ONCE(rdp_gp->nocb_toggling_rdp, rdp);
-	if (rdp_gp->nocb_gp_sleep) {
+	if (rcu_nocb_poll || rdp_gp->nocb_gp_sleep) {
 
Quoted 4 lines

Is it the case that other than when (de-)offloading, the rcuog kthread is never awakened when rcu_nocb_poll is set? If this is not the case, we would have spurious wakeups. (I believe that rcu_nocb_poll suppresses those wakeups, but it would be good to check.)

When rcu_nocb_poll is set, only when (de-)offloading, actively call wake_up_process(rdp_gp->nocb_gp_kthread). in other cases
the __call_rcu_nocb_wake() will wakeup nocb_gp_kthread, but it met rcu_nocb_poll flags directly return.
In do_nocb_deferred_wakeup(), although there is no rcu_nocb_poll check, but rdp->nocb_defer_wakeup is always RCU_NOCB_WAKE_NOT, also directly return.

Due to rcu_nocb_poll is set, the rdp_gp->nocb_gp_sleep flags is not used, and
Not should be set. move rcu_nocb_poll from rdp_offload_toggle() to rcu_nocb_rdp_offload/deoffload()

Thanks
Zqiang

Quoted 6 lines
kernel/rcu/tree_nocb.h +0 -0
 		rdp_gp->nocb_gp_sleep = false;
 		wake_gp = true;
 	}
Signature · 1 line
2.25.1