Skip to contentSkip to conversation

workqueue: add RCU quiescent state between items

PATCH Applied Joe Lawrence 4 participants 14 messages Oct 5, 2014 – Oct 8, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover workqueue: add RCU quiescent state between items

v2 - split into two patches: the first inlines the cond_resched_rcu_qs macro suitable for stable backport, the second converts to using cond_resched_rcu_qs.

Joe Lawrence (2):
workqueue: add quiescent state between work items
workqueue: use cond_resched_rcu_qs macro

 kernel/workqueue.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v2 1/2 workqueue: add quiescent state between work items

Similar to the stop_machine deadlock scenario on !PREEMPT kernels addressed in b22ce2785d97 "workqueue: cond_resched() after processing each work item", kworker threads requeueing back-to-back with zero jiffy delay can stall RCU. The cond_resched call introduced in that fix will yield only iff there are other higher priority tasks to run, so force a quiescent RCU state between work items.

Fixes b22ce2785d97 ("workqueue: cond_resched() after processing each work item")
---
 kernel/workqueue.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/workqueue.c +3 -1
index 5dbe22a..345bec9 100644
@@ -2043,8 +2043,10 @@ __acquires(&pool->lock)
 	 * kernels, where a requeueing work item waiting for something to
 	 * happen could deadlock with stop_machine as such work item could
 	 * indefinitely requeue itself while all other CPUs are trapped in
-	 * stop_machine.
+	 * stop_machine. At the same time, report a quiescent RCU state so
+	 * the same condition doesn't freeze RCU.
 	 */
+	rcu_note_voluntary_context_switch(current);
 	cond_resched();
 
 	spin_lock_irq(&pool->lock);
Signature · 1 line
1.7.10.4
maintainer Applied
#2 lore raw

Re: [PATCH v2 1/2] workqueue: add quiescent state between work items

Quoted 7 lines · Joe Lawrence

Similar to the stop_machine deadlock scenario on !PREEMPT kernels addressed in b22ce2785d97 "workqueue: cond_resched() after processing each work item", kworker threads requeueing back-to-back with zero jiffy delay can stall RCU. The cond_resched call introduced in that fix will yield only iff there are other higher priority tasks to run, so force a quiescent RCU state between work items.

Quoted 5 lines
Fixes b22ce2785d97 ("workqueue: cond_resched() after processing each work item")

Applied to wq/for-3.17-fixes. If 3.17 comes out before this gets merged, I'll send it as for-3.18.

Thanks.

Signature · 1 line
tejun
maintainer Acked-by
#3 lore raw

Re: [PATCH v2 1/2] workqueue: add quiescent state between work items

Quoted 8 lines · Tejun Heo
Quoted 7 lines · Joe Lawrence

Similar to the stop_machine deadlock scenario on !PREEMPT kernels addressed in b22ce2785d97 "workqueue: cond_resched() after processing each work item", kworker threads requeueing back-to-back with zero jiffy delay can stall RCU. The cond_resched call introduced in that fix will yield only iff there are other higher priority tasks to run, so force a quiescent RCU state between work items.

Quoted 8 lines
Quoted 5 lines
Fixes b22ce2785d97 ("workqueue: cond_resched() after processing each work item")

Applied to wq/for-3.17-fixes. If 3.17 comes out before this gets merged, I'll send it as for-3.18.

Oops, the rcu calls aren't in mainline yet. I think it'd be best to route these through the RCU tree. Paul, can you please route these two patches?

Thanks.

Signature · 1 line
tejun
#4 lore raw

Re: [PATCH v2 1/2] workqueue: add quiescent state between work items

Quoted 15 lines · Tejun Heo
Quoted 14 lines · Tejun Heo
Quoted 12 lines · Joe Lawrence

Similar to the stop_machine deadlock scenario on !PREEMPT kernels addressed in b22ce2785d97 "workqueue: cond_resched() after processing each work item", kworker threads requeueing back-to-back with zero jiffy delay can stall RCU. The cond_resched call introduced in that fix will yield only iff there are other higher priority tasks to run, so force a quiescent RCU state between work items.

Fixes b22ce2785d97 ("workqueue: cond_resched() after processing each work item")
Quoted 8 lines
Quoted 2 lines

Applied to wq/for-3.17-fixes. If 3.17 comes out before this gets merged, I'll send it as for-3.18.

Oops, the rcu calls aren't in mainline yet. I think it'd be best to route these through the RCU tree. Paul, can you please route these two patches?

Will do!

I will try 3.17, failing that, 3.18.

Thanx, Paul

#5 lore raw

Re: [PATCH v2 1/2] workqueue: add quiescent state between work items

Quoted 23 lines · Mon, Oct 06, 2014 at 06:21:58AM CEST, [email protected] wrote:
Quoted 22 lines · Tejun Heo
Quoted 8 lines · Tejun Heo
Quoted 7 lines · Joe Lawrence

Similar to the stop_machine deadlock scenario on !PREEMPT kernels addressed in b22ce2785d97 "workqueue: cond_resched() after processing each work item", kworker threads requeueing back-to-back with zero jiffy delay can stall RCU. The cond_resched call introduced in that fix will yield only iff there are other higher priority tasks to run, so force a quiescent RCU state between work items.

Quoted 8 lines
Quoted 5 lines
Fixes b22ce2785d97 ("workqueue: cond_resched() after processing each work item")

Applied to wq/for-3.17-fixes. If 3.17 comes out before this gets merged, I'll send it as for-3.18.

Oops, the rcu calls aren't in mainline yet. I think it'd be best to route these through the RCU tree. Paul, can you please route these two patches?

Quoted 5 lines
Quoted 1 line

Will do!

I will try 3.17, failing that, 3.18.

Paul, Tehun, how do you propose to fix this on older kernels which do not have rcu_note_voluntary_context_switch? I'm particullary interested in 3.10.

Thanks.

#6 lore raw

Re: [PATCH v2 1/2] workqueue: add quiescent state between work items

Quoted 26 lines · Jiri Pirko
Quoted 25 lines · Mon, Oct 06, 2014 at 06:21:58AM CEST, [email protected] wrote:
Quoted 23 lines · Tejun Heo
Quoted 8 lines · Tejun Heo
Quoted 7 lines · Joe Lawrence

Similar to the stop_machine deadlock scenario on !PREEMPT kernels addressed in b22ce2785d97 "workqueue: cond_resched() after processing each work item", kworker threads requeueing back-to-back with zero jiffy delay can stall RCU. The cond_resched call introduced in that fix will yield only iff there are other higher priority tasks to run, so force a quiescent RCU state between work items.

Quoted 8 lines
Quoted 5 lines
Fixes b22ce2785d97 ("workqueue: cond_resched() after processing each work item")

Applied to wq/for-3.17-fixes. If 3.17 comes out before this gets merged, I'll send it as for-3.18.

Oops, the rcu calls aren't in mainline yet. I think it'd be best to route these through the RCU tree. Paul, can you please route these two patches?

Quoted 8 lines
Quoted 3 lines

Will do!

I will try 3.17, failing that, 3.18.

Paul, Tehun, how do you propose to fix this on older kernels which do not have rcu_note_voluntary_context_switch? I'm particullary interested in 3.10.

Hello, Jiri,

Older kernels can instead use rcu_note_context_switch().

Thanx, Paul

#7 lore raw

Re: [PATCH v2 1/2] workqueue: add quiescent state between work items

Quoted 1 line · On Tue, 7 Oct 2014 06:43:29 -0700 "Paul E. McKenney"…

On Tue, Oct 07, 2014 at 09:29:42AM +0200, Jiri Pirko wrote:

[ ... snip ... ]

Quoted 8 lines
Quoted 4 lines

Paul, Tehun, how do you propose to fix this on older kernels which do not have rcu_note_voluntary_context_switch? I'm particullary interested in 3.10.

Hello, Jiri,

Older kernels can instead use rcu_note_context_switch().

Hi Paul,

Does 4a81e8328d37 ("rcu: Reduce overhead of cond_resched() checks for RCU") affect a backport to 3.10?

I noticed that rcu_note_context_switch added a call to rcu_momentary_dyntick_idle in that change, which is only present in v3.16+.

Would rcu_note_context_switch be effective by itself on a 3.10 kernel?

Thanks,

-- Joe

#8 lore raw

Re: [PATCH v2 1/2] workqueue: add quiescent state between work items

Quoted 16 lines · Joe Lawrence
Quoted 1 line · On Tue, 7 Oct 2014 06:43:29 -0700 "Paul E. McKenney"…

On Tue, Oct 07, 2014 at 09:29:42AM +0200, Jiri Pirko wrote:

[ ... snip ... ]

Quoted 8 lines
Quoted 4 lines

Paul, Tehun, how do you propose to fix this on older kernels which do not have rcu_note_voluntary_context_switch? I'm particullary interested in 3.10.

Hello, Jiri,

Older kernels can instead use rcu_note_context_switch().

Hi Paul,

Quoted 8 lines

Does 4a81e8328d37 ("rcu: Reduce overhead of cond_resched() checks for RCU") affect a backport to 3.10?

I noticed that rcu_note_context_switch added a call to rcu_momentary_dyntick_idle in that change, which is only present in v3.16+.

Would rcu_note_context_switch be effective by itself on a 3.10 kernel?

Should be fine. There is more overhead than current mainline, but that should not be in the noise compared to executing a work-queue item.

Thanx, Paul

#9 lore raw

Re: [PATCH v2 1/2] workqueue: add quiescent state between work items

Quoted 24 lines · Wed, Oct 08, 2014 at 05:24:11AM CEST, [email protected] wrote:
Quoted 23 lines · Joe Lawrence
Quoted 1 line · On Tue, 7 Oct 2014 06:43:29 -0700 "Paul E. McKenney"…

On Tue, Oct 07, 2014 at 09:29:42AM +0200, Jiri Pirko wrote:

[ ... snip ... ]

Quoted 8 lines
Quoted 4 lines

Paul, Tehun, how do you propose to fix this on older kernels which do not have rcu_note_voluntary_context_switch? I'm particullary interested in 3.10.

Hello, Jiri,

Older kernels can instead use rcu_note_context_switch().

Hi Paul,

Does 4a81e8328d37 ("rcu: Reduce overhead of cond_resched() checks for RCU") affect a backport to 3.10?

I noticed that rcu_note_context_switch added a call to rcu_momentary_dyntick_idle in that change, which is only present in v3.16+.

Quoted 7 lines
Quoted 1 line

Would rcu_note_context_switch be effective by itself on a 3.10 kernel?

Should be fine. There is more overhead than current mainline, but that should not be in the noise compared to executing a work-queue item.

Thanx, Paul

I cooked up following patch. Please tell me if it is fine or not. I can also send it oficially so it can be included into stable trees:

Subject: workqueue: Add quiescent state between work items

Similar to the stop_machine deadlock scenario on !PREEMPT kernels addressed in b22ce2785d97 "workqueue: cond_resched() after processing each work item", kworker threads requeueing back-to-back with zero jiffy delay can stall RCU. The cond_resched call introduced in that fix will yield only iff there are other higher priority tasks to run, so force a quiescent RCU state between work items.

---
 kernel/workqueue.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/workqueue.c +3 -1
index e9719c7..14a7163 100644
@@ -2196,8 +2196,10 @@ __acquires(&pool->lock)
 	 * kernels, where a requeueing work item waiting for something to
 	 * happen could deadlock with stop_machine as such work item could
 	 * indefinitely requeue itself while all other CPUs are trapped in
-	 * stop_machine.
+	 * stop_machine. At the same time, report a quiescent RCU state so
+	 * the same condition doesn't freeze RCU.
 	 */
+	rcu_note_context_switch(raw_smp_processor_id());
 	cond_resched();
 
 	spin_lock_irq(&pool->lock);
Signature · 1 line
1.9.3
#10 lore raw

Re: [PATCH v2 1/2] workqueue: add quiescent state between work items

Quoted 27 lines · Jiri Pirko
Quoted 26 lines · Wed, Oct 08, 2014 at 05:24:11AM CEST, [email protected] wrote:
Quoted 24 lines · Joe Lawrence
Quoted 1 line · On Tue, 7 Oct 2014 06:43:29 -0700 "Paul E. McKenney"…

On Tue, Oct 07, 2014 at 09:29:42AM +0200, Jiri Pirko wrote:

[ ... snip ... ]

Quoted 8 lines
Quoted 4 lines

Paul, Tehun, how do you propose to fix this on older kernels which do not have rcu_note_voluntary_context_switch? I'm particullary interested in 3.10.

Hello, Jiri,

Older kernels can instead use rcu_note_context_switch().

Hi Paul,

Does 4a81e8328d37 ("rcu: Reduce overhead of cond_resched() checks for RCU") affect a backport to 3.10?

I noticed that rcu_note_context_switch added a call to rcu_momentary_dyntick_idle in that change, which is only present in v3.16+.

Would rcu_note_context_switch be effective by itself on a 3.10 kernel?

Quoted 8 lines
Quoted 5 lines

Should be fine. There is more overhead than current mainline, but that should not be in the noise compared to executing a work-queue item.

Thanx, Paul

I cooked up following patch. Please tell me if it is fine or not. I can also send it oficially so it can be included into stable trees:

Looks good!

Thanx, Paul

Quoted 34 lines

Subject: workqueue: Add quiescent state between work items

Similar to the stop_machine deadlock scenario on !PREEMPT kernels addressed in b22ce2785d97 "workqueue: cond_resched() after processing each work item", kworker threads requeueing back-to-back with zero jiffy delay can stall RCU. The cond_resched call introduced in that fix will yield only iff there are other higher priority tasks to run, so force a quiescent RCU state between work items.

---
 kernel/workqueue.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/workqueue.c +3 -1
index e9719c7..14a7163 100644
@@ -2196,8 +2196,10 @@ __acquires(&pool->lock)
 	 * kernels, where a requeueing work item waiting for something to
 	 * happen could deadlock with stop_machine as such work item could
 	 * indefinitely requeue itself while all other CPUs are trapped in
-	 * stop_machine.
+	 * stop_machine. At the same time, report a quiescent RCU state so
+	 * the same condition doesn't freeze RCU.
 	 */
+	rcu_note_context_switch(raw_smp_processor_id());
 	cond_resched();
 
 	spin_lock_irq(&pool->lock);
Signature · 1 line
1.9.3
#11 lore raw

PATCH v2 2/2 workqueue: use cond_resched_rcu_qs macro

In reply to Joe Lawrence

Tidy up and use cond_resched_rcu_qs when calling cond_resched and reporting potential quiescent state to RCU.

---
 kernel/workqueue.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/workqueue.c +1 -2
index 345bec9..09b685d 100644
@@ -2046,8 +2046,7 @@ __acquires(&pool->lock)
 	 * stop_machine. At the same time, report a quiescent RCU state so
 	 * the same condition doesn't freeze RCU.
 	 */
-	rcu_note_voluntary_context_switch(current);
-	cond_resched();
+	cond_resched_rcu_qs();
 
 	spin_lock_irq(&pool->lock);
 
Signature · 1 line
1.7.10.4
Reviewed-by on v2 2/2
#12 lore raw

Re: [PATCH v2 2/2] workqueue: use cond_resched_rcu_qs macro

Quoted 4 lines · Joe Lawrence

Tidy up and use cond_resched_rcu_qs when calling cond_resched and reporting potential quiescent state to RCU.

Quoted 21 lines
---
 kernel/workqueue.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/workqueue.c +1 -2
index 345bec9..09b685d 100644
@@ -2046,8 +2046,7 @@ __acquires(&pool->lock)
 	 * stop_machine. At the same time, report a quiescent RCU state so
 	 * the same condition doesn't freeze RCU.
 	 */
-	rcu_note_voluntary_context_switch(current);
-	cond_resched();
+	cond_resched_rcu_qs();
 
 	spin_lock_irq(&pool->lock);
 
Signature · 1 line
1.7.10.4