Skip to contentSkip to conversation

Wakes of the rcuc/ thread on isolated CPUs.

DISCUSSION Sebastian Andrzej Siewior 2 participants 6 messages Jul 5, 2024 – Jul 8, 2024 RCU

lore
Share & tools
lore
#0 lore raw

Hi,

I noticed this on an older kernel and reproduced it on -rc6: I boot the (RT) kernel with

	isolcpus=4-15 nohz=on nohz_full=4-15 rcu_nocbs=4-15 rcu_nocb_poll

and compiled a NOHZ_FULL kernel. If I pin a shell onto the isolated CPU and do nothing then everything seems fine. If I issue commands, this happens:
tick_nohz_handler() -> update_process_times() -> rcu_sched_clock_irq()

rcu_sched_clock_irq() invokes rcu_pending() which returns true due to

|         /* Have RCU grace period completed or started?  */
|         if (rcu_seq_current(&rnp->gp_seq) != rdp->gp_seq ||
|             unlikely(READ_ONCE(rdp->gpwrap))) /* outside lock */
|                 return 1;

And it is the first check of the two. Later I see

|         /* Is the RCU core waiting for a quiescent state from this CPU? */
|         gp_in_progress = rcu_gp_in_progress();
|         if (rdp->core_needs_qs && !rdp->cpu_no_qs.b.norm && gp_in_progress)
|                 return 1;

which triggers it but then "later" it fallbacks to the first case again. In both cases it wakes the rcuc/ thread on the isolated CPU.

Is this something that needs to happen on the isolated CPU or can this be excluded for rcu_rdp_is_offloaded() CPUs?

Sebastian

maintainer
#1 lore raw
Quoted 23 lines · Sebastian Andrzej Siewior

Hi,

I noticed this on an older kernel and reproduced it on -rc6: I boot the (RT) kernel with

	isolcpus=4-15 nohz=on nohz_full=4-15 rcu_nocbs=4-15 rcu_nocb_poll

and compiled a NOHZ_FULL kernel. If I pin a shell onto the isolated CPU and do nothing then everything seems fine. If I issue commands, this happens:

   tick_nohz_handler() -> update_process_times() -> rcu_sched_clock_irq()

rcu_sched_clock_irq() invokes rcu_pending() which returns true due to

|         /* Have RCU grace period completed or started?  */
|         if (rcu_seq_current(&rnp->gp_seq) != rdp->gp_seq ||
|             unlikely(READ_ONCE(rdp->gpwrap))) /* outside lock */
|                 return 1;

And it is the first check of the two. Later I see

|         /* Is the RCU core waiting for a quiescent state from this CPU? */
|         gp_in_progress = rcu_gp_in_progress();
|         if (rdp->core_needs_qs && !rdp->cpu_no_qs.b.norm && gp_in_progress)
|                 return 1;
Quoted 5 lines

which triggers it but then "later" it fallbacks to the first case again. In both cases it wakes the rcuc/ thread on the isolated CPU.

Is this something that needs to happen on the isolated CPU or can this be excluded for rcu_rdp_is_offloaded() CPUs?

As a workaround, the following commit in -rcu that is slated for the upcoming merge window addresses a similar case involving KVM and nohz_full:

68d124b09999 ("rcu: Add rcutree.nohz_full_patience_delay to reduce nohz_full OS jitter")

The KVM guys found that setting rcutree.nohz_full_patience_delay to 1000 (AKA one second) made things work better for them. Does this help your use case?

This is again a workaround. Clearly, it would be better if we could eliminate that second rcuc wakeup. I tried something similar some time back, and there was a problem with it. I will see if I can reconstitute the corresponding brain cells.

But in the meantime, one advantage of the workaround is that in the common case, it would reduce the number of rcuc wakeups to zero, rather than to just one.

Thoughts?

Thanx, Paul

#2 lore raw
Quoted 10 lines · Paul E. McKenney

As a workaround, the following commit in -rcu that is slated for the upcoming merge window addresses a similar case involving KVM and nohz_full:

68d124b09999 ("rcu: Add rcutree.nohz_full_patience_delay to reduce nohz_full OS jitter")

The KVM guys found that setting rcutree.nohz_full_patience_delay to 1000 (AKA one second) made things work better for them. Does this help your use case?

My problem is that I have a task stuck in percpu_down_write()/ __wait_rcu_gp() and I think this is because the RCU machinery is stuck and there is no grace period.
I have see a rcuc/ thread with a wakeup but it won't be scheduled because it's priority is lower than the thread that is currently on the CPU and that thread uses at 100%.
I *think* this explains it because the rcuc moves the grace period forward.
Looking at the patch, there would be a delay up to 5 secs which would mean if the task consumes 100% of the CPU then it doesn't change a thing.

Thank you Paul for the pointers.

Quoted 4 lines

This is again a workaround. Clearly, it would be better if we could eliminate that second rcuc wakeup. I tried something similar some time back, and there was a problem with it. I will see if I can reconstitute the corresponding brain cells.

Is my assumption correct, in order to push the grace period forward, otherwise the whole is stuck?

Quoted 5 lines

But in the meantime, one advantage of the workaround is that in the common case, it would reduce the number of rcuc wakeups to zero, rather than to just one.

Thoughts?

I *think* if what I just wrote is correct, I will either have to raise the priority of rcuc/ or make the thread, that consumes 100% of the CPU lose its RT priority. Then with the limited number of wakeups it should be doable.

PS: I do remember the RCU-task thread we had. I did have an idea but I need check if this is feasible first. So I did not forget, just slow…

Quoted 1 line

Thanx, Paul

Sebastian

maintainer
#3 lore raw
Quoted 12 lines · Sebastian Andrzej Siewior
Quoted 10 lines · Paul E. McKenney

As a workaround, the following commit in -rcu that is slated for the upcoming merge window addresses a similar case involving KVM and nohz_full:

68d124b09999 ("rcu: Add rcutree.nohz_full_patience_delay to reduce nohz_full OS jitter")

The KVM guys found that setting rcutree.nohz_full_patience_delay to 1000 (AKA one second) made things work better for them. Does this help your use case?

Quoted 9 lines

My problem is that I have a task stuck in percpu_down_write()/ __wait_rcu_gp() and I think this is because the RCU machinery is stuck and there is no grace period.
I have see a rcuc/ thread with a wakeup but it won't be scheduled because it's priority is lower than the thread that is currently on the CPU and that thread uses at 100%.
I *think* this explains it because the rcuc moves the grace period forward.
Looking at the patch, there would be a delay up to 5 secs which would

I would have said "up to 1 sec", so what am I missing?

Quoted 2 lines

mean if the task consumes 100% of the CPU then it doesn't change a thing.

As long as RCU's grace-period kthread gets some CPU and as long as the CPU-bound task executes often in userspace, that task's CPU's rcuc kthread need never run. The grace-period kthread would see that the CPU has been in an extended quiescent state, and would report that quiescent state on that CPU's behalf.

Quoted 9 lines

Thank you Paul for the pointers.

Quoted 4 lines

This is again a workaround. Clearly, it would be better if we could eliminate that second rcuc wakeup. I tried something similar some time back, and there was a problem with it. I will see if I can reconstitute the corresponding brain cells.

Is my assumption correct, in order to push the grace period forward, otherwise the whole is stuck?

Again, if the CPU running the CPU-bound task executes in nohz_full userspace context, that CPU's rcuc kthread need never run.

Of course, if you tried the patch and it didn't help, that is another story. Hardware facts beat human theories, now as always.

Quoted 10 lines
Quoted 5 lines

But in the meantime, one advantage of the workaround is that in the common case, it would reduce the number of rcuc wakeups to zero, rather than to just one.

Thoughts?

I *think* if what I just wrote is correct, I will either have to raise the priority of rcuc/ or make the thread, that consumes 100% of the CPU lose its RT priority. Then with the limited number of wakeups it should be doable.

You can: (1) Raise the rcuc kthread's priority, as you say, (2) Ensure that the CPU-bound task runs frequently (or even always) in nohz_full usermode context, or (3) #2 and also apply the patch, which would in addition prevent the wakeups.

I think. After all, I could easily be missing something here.

Quoted 2 lines

PS: I do remember the RCU-task thread we had. I did have an idea but I need check if this is feasible first. So I did not forget, just slow…

I must confess that I have been wondering about how much tracing goes on withing real-time systems running in production...

Thanx, Paul

#4 lore raw
Quoted 3 lines · Paul E. McKenney
Quoted 1 line

Looking at the patch, there would be a delay up to 5 secs which would

I would have said "up to 1 sec", so what am I missing?

The patch description said that there is 5 sec upper limit. Yes, default 1 sec.

Quoted 8 lines
Quoted 2 lines

mean if the task consumes 100% of the CPU then it doesn't change a thing.

As long as RCU's grace-period kthread gets some CPU and as long as the CPU-bound task executes often in userspace, that task's CPU's rcuc kthread need never run. The grace-period kthread would see that the CPU has been in an extended quiescent state, and would report that quiescent state on that CPU's behalf.

Okay. So the 100% usage is the problem indeed.

Quoted 7 lines
Quoted 7 lines

Thank you Paul for the pointers.

Quoted 4 lines

This is again a workaround. Clearly, it would be better if we could eliminate that second rcuc wakeup. I tried something similar some time back, and there was a problem with it. I will see if I can reconstitute the corresponding brain cells.

Quoted 8 lines
Quoted 2 lines

Is my assumption correct, in order to push the grace period forward, otherwise the whole is stuck?

Again, if the CPU running the CPU-bound task executes in nohz_full userspace context, that CPU's rcuc kthread need never run.

Of course, if you tried the patch and it didn't help, that is another story. Hardware facts beat human theories, now as always.

of course.

Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

But in the meantime, one advantage of the workaround is that in the common case, it would reduce the number of rcuc wakeups to zero, rather than to just one.

Thoughts?

I *think* if what I just wrote is correct, I will either have to raise the priority of rcuc/ or make the thread, that consumes 100% of the CPU lose its RT priority. Then with the limited number of wakeups it should be doable.

Quoted 6 lines

You can: (1) Raise the rcuc kthread's priority, as you say, (2) Ensure that the CPU-bound task runs frequently (or even always) in nohz_full usermode context, or (3) #2 and also apply the patch, which would in addition prevent the wakeups.

I think. After all, I could easily be missing something here.

Let me backport and see what happens in the end.

Thank you.

Quoted 5 lines
Quoted 2 lines

PS: I do remember the RCU-task thread we had. I did have an idea but I need check if this is feasible first. So I did not forget, just slow…

I must confess that I have been wondering about how much tracing goes on withing real-time systems running in production...

This is little I know. However, it is used during testing of production systems to see what is going on due to its little overhead.

Quoted 1 line

Thanx, Paul

Sebastian

maintainer
#5 lore raw
Quoted 7 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Paul E. McKenney
Quoted 1 line

Looking at the patch, there would be a delay up to 5 secs which would

I would have said "up to 1 sec", so what am I missing?

The patch description said that there is 5 sec upper limit. Yes, default 1 sec.

Ah, yes, there is a five-second upper limit on the value of the rcutree.nohz_full_patience_delay kernel boot parameter and there is a default one-second value. The default value places a one-second upper limit on the RCU grace-period kthread's patience.

So I guess we were both right. ;-)

Quoted 10 lines
Quoted 8 lines
Quoted 2 lines

mean if the task consumes 100% of the CPU then it doesn't change a thing.

As long as RCU's grace-period kthread gets some CPU and as long as the CPU-bound task executes often in userspace, that task's CPU's rcuc kthread need never run. The grace-period kthread would see that the CPU has been in an extended quiescent state, and would report that quiescent state on that CPU's behalf.

Okay. So the 100% usage is the problem indeed.

And, if that usage is nohz_full userspace execution, also the potential solution.

Quoted 34 lines
Quoted 7 lines
Quoted 7 lines

Thank you Paul for the pointers.

Quoted 4 lines

This is again a workaround. Clearly, it would be better if we could eliminate that second rcuc wakeup. I tried something similar some time back, and there was a problem with it. I will see if I can reconstitute the corresponding brain cells.

Quoted 8 lines
Quoted 2 lines

Is my assumption correct, in order to push the grace period forward, otherwise the whole is stuck?

Again, if the CPU running the CPU-bound task executes in nohz_full userspace context, that CPU's rcuc kthread need never run.

Of course, if you tried the patch and it didn't help, that is another story. Hardware facts beat human theories, now as always.

of course.

Quoted 16 lines
Quoted 10 lines
Quoted 5 lines

But in the meantime, one advantage of the workaround is that in the common case, it would reduce the number of rcuc wakeups to zero, rather than to just one.

Thoughts?

I *think* if what I just wrote is correct, I will either have to raise the priority of rcuc/ or make the thread, that consumes 100% of the CPU lose its RT priority. Then with the limited number of wakeups it should be doable.

You can: (1) Raise the rcuc kthread's priority, as you say, (2) Ensure that the CPU-bound task runs frequently (or even always) in nohz_full usermode context, or (3) #2 and also apply the patch, which would in addition prevent the wakeups.

Quoted 5 lines
Quoted 1 line

I think. After all, I could easily be missing something here.

Let me backport and see what happens in the end.

Thank you.

Thank you in advance, and I look forward to hearing how it goes!

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

PS: I do remember the RCU-task thread we had. I did have an idea but I need check if this is feasible first. So I did not forget, just slow…

I must confess that I have been wondering about how much tracing goes on withing real-time systems running in production...

This is little I know. However, it is used during testing of production systems to see what is going on due to its little overhead.

That should introduce some fun constraints into tracing mechanisms and their synchronizations. Or some fun constraints into which mechanisms are used when in production real-time systems. But why not both? ;-)

Thanx, Paul