rcu/tree: Improve comments in rcu_report_qs_rdp()
PATCH 1/1 rcu/tree: Improve comments in rcu_report_qs_rdp()
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
--- kernel/rcu/tree.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
kernel/rcu/tree.c +12 -1
@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP. +* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core() +* or note_gp_changes() may happen only after the GP after the +* current one has already started. Further, rcu_core() +* only accelerates if RCU is idle (no GP in progress). * * NOCB kthreads have their own way to deal with that... */
@@ -1993,6 +1998,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp)/* * ...but NOCB kthreads may miss or delay callbacks acceleration * if in the middle of a (de-)offloading process. +* +* Such missed acceleration may cause the callbacks to +* be stranded until RCU is fully de-offloaded, as +* acceleration from rcu_core() and note_gp_changes() +* cannot happen for fully/partially offloaded mode due +* to ordering dependency between rnp lock and nocb_lock. */ needacc = true; }
Signature · 1 line
2.39.1.519.gcb327c4b5f-goog
Quoted 20 lines
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
Cc Qiang Zhang <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>---
kernel/rcu/tree.c| 13 ++++++++++++-1 file changed, 12 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-0
kernel/rcu/tree.c rcu_report_qs_rdp(struct rcu_data *rdp) · line 1988
Quoted 7 lines
kernel/rcu/tree.c +3
-1@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP. +* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core()
Does the extra grace period delays means that if not accelerate callback, the grace period will take more time to end ? or refers to a delay in the start time of a new grace period?
Thanks
Zqiang
Quoted 22 lines
kernel/rcu/tree.c +9
-0+* or note_gp_changes() may happen only after the GP after the +* current one has already started. Further, rcu_core() +* only accelerates if RCU is idle (no GP in progress). * * NOCB kthreads have their own way to deal with that... */ @@ -1993,6 +1998,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp)/* * ...but NOCB kthreads may miss or delay callbacks acceleration * if in the middle of a (de-)offloading process. +* +* Such missed acceleration may cause the callbacks to +* be stranded until RCU is fully de-offloaded, as +* acceleration from rcu_core() and note_gp_changes() +* cannot happen for fully/partially offloaded mode due +* to ordering dependency between rnp lock and nocb_lock. */ needacc = true; }Signature · 1 line
2.39.1.519.gcb327c4b5f-goog
Quoted 25 lines · On Sun, Feb 5, 2023 at 10:09 PM Zhang, Qiang1 <[email protected]> wrote:
Quoted 25 lines
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
Cc Qiang Zhang <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>---
kernel/rcu/tree.c| 13 ++++++++++++-1 file changed, 12 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-1@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP.
Quoted 8 lines
kernel/rcu/tree.c rcu_report_qs_rdp(struct rcu_data *rdp) · line 1988
Quoted 3 lines
kernel/rcu/tree.c +3
-0+* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core() Does the extra grace period delays means that if not accelerate callback, the grace period will take more time to end ? or refers to a delay in the start time of a new grace period?
Yes, so IMO it is like this if we don't accelerate:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 (not accelerating anything).
4. GP1 ends
5. CPU1's note_gp_changes() is called, accelerate happens, now the CB will execute after GP3 (or alternately, rcu_core() on CPU1 does accelerate).
6. GP2 ends.
7. GP3 starts.
8. GP3 ends.
9. CB is invoked
Instead, what we will get the following thanks to the acceleration here is:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 and acceleration happens as done by the code this patch adds comments for.
4. GP1 ends
5. CPU1's note_gp_changes() is called
6. GP2 ends.
7. CB is invoked
Does that make sense or is there a subtlety I missed?
Thanks,
- Joel
Quoted 26 lines
Thanks
ZqiangQuoted 22 lines
kernel/rcu/tree.c +9
-1+* or note_gp_changes() may happen only after the GP after the +* current one has already started. Further, rcu_core() +* only accelerates if RCU is idle (no GP in progress). * * NOCB kthreads have their own way to deal with that... */ @@ -1993,6 +1998,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp)/* * ...but NOCB kthreads may miss or delay callbacks acceleration * if in the middle of a (de-)offloading process. +* +* Such missed acceleration may cause the callbacks to +* be stranded until RCU is fully de-offloaded, as +* acceleration from rcu_core() and note_gp_changes() +* cannot happen for fully/partially offloaded mode due +* to ordering dependency between rnp lock and nocb_lock. */ needacc = true; } --2.39.1.519.gcb327c4b5f-goog
Quoted 49 lines · Joel Fernandes
Quoted 25 lines · On Sun, Feb 5, 2023 at 10:09 PM Zhang, Qiang1 <[email protected]> wrote:
Quoted 25 lines
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
Cc Qiang Zhang <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>---
kernel/rcu/tree.c| 13 ++++++++++++-1 file changed, 12 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-1@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP. Quoted 8 lines
kernel/rcu/tree.c rcu_report_qs_rdp(struct rcu_data *rdp) · line 1988
Quoted 3 lines
kernel/rcu/tree.c +3
-0+* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core() Does the extra grace period delays means that if not accelerate callback, the grace period will take more time to end ? or refers to a delay in the start time of a new grace period?
Yes, so IMO it is like this if we don't accelerate:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 (not accelerating anything).
4. GP1 ends
5. CPU1'snote_gp_changes()is called, accelerate happens, now the CB will execute after GP3 (or alternately,rcu_core()on CPU1 does accelerate).
6. GP2 ends.
7. GP3 starts.
8. GP3 ends.
9. CB is invoked
Quoted 9 lines
Instead, what we will get the following thanks to the acceleration here is:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 and acceleration happens as done by the code this patch adds comments for.
4. GP1 ends
5. CPU1'snote_gp_changes()is called
6. GP2 ends.
7. CB is invoked
Sorry I missed some steps, here is the update:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 (not accelerating anything).
4. GP1 ends
5. GP2 starts for some other reason from some other CPU.
6. CPU1's note_gp_changes() is called, acceleration happens, now the CB will execute after GP3.
7. GP2 ends.
8. GP3 starts.
9. GP3 ends.
10. CB is invoked
Instead, what we will get the following thanks to the acceleration here is:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 and acceleration happens as done by the code this patch adds comments for.
4. GP1 ends
5. GP2 starts
6. GP2 ends.
7. CB is invoked
Does that make sense or is there a subtlety I missed?
Thanks,
- Joel
Quoted 82 lines · Joel Fernandes
Quoted 25 lines · On Sun, Feb 5, 2023 at 10:09 PM Zhang, Qiang1 <[email protected]> wrote:
Quoted 25 lines
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
Cc Qiang Zhang <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>---
kernel/rcu/tree.c| 13 ++++++++++++-1 file changed, 12 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-1@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP. Quoted 8 lines
kernel/rcu/tree.c rcu_report_qs_rdp(struct rcu_data *rdp) · line 1988
Quoted 3 lines
kernel/rcu/tree.c +3
-0+* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core() Does the extra grace period delays means that if not accelerate callback, the grace period will take more time to end ? or refers to a delay in the start time of a new grace period?
Yes, so IMO it is like this if we don't accelerate:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 (not accelerating anything).
4. GP1 ends
5. CPU1'snote_gp_changes()is called, accelerate happens, now the CB will execute after GP3 (or alternately,rcu_core()on CPU1 does accelerate).
6. GP2 ends.
7. GP3 starts.
8. GP3 ends.
9. CB is invokedInstead, what we will get the following thanks to the acceleration here is:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 and acceleration happens as done by the code this patch adds comments for.
4. GP1 ends
5. CPU1'snote_gp_changes()is called
6. GP2 ends.
7. CB is invokedSorry I missed some steps, here is the update:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 (not accelerating anything).
4. GP1 ends
5. GP2 starts for some other reason from some other CPU.
6. CPU1'snote_gp_changes()is called, acceleration happens, now the CB will execute after GP3.
7. GP2 ends.
8. GP3 starts.
9. GP3 ends.
10. CB is invokedInstead, what we will get the following thanks to the acceleration here is:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 and acceleration happens as done by the code this patch adds comments for.
4. GP1 ends
5. GP2 starts
6. GP2 ends.
7. CB is invoked
Quoted 1 line
Does that make sense or is there a subtlety I missed?
Thanks for detailed description, that is to say, the grace period delays means that if there is no acceleration, the invocation of callback may be delayed by one or more grace periods.
Can you re-describe the meaning of "grace period delays "in the comments?
Thanks
Zqiang
Quoted 4 lines
Thanks,
- Joel
Quoted 88 lines · On Mon, Feb 6, 2023 at 8:15 PM Zhang, Qiang1 <[email protected]> wrote:
Quoted 82 lines · Joel Fernandes
Quoted 25 lines · On Sun, Feb 5, 2023 at 10:09 PM Zhang, Qiang1 <[email protected]> wrote:
Quoted 25 lines
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
Cc Qiang Zhang <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>---
kernel/rcu/tree.c| 13 ++++++++++++-1 file changed, 12 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-1@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP. Quoted 8 lines
kernel/rcu/tree.c rcu_report_qs_rdp(struct rcu_data *rdp) · line 1988
Quoted 3 lines
kernel/rcu/tree.c +3
-0+* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core() Does the extra grace period delays means that if not accelerate callback, the grace period will take more time to end ? or refers to a delay in the start time of a new grace period?
Yes, so IMO it is like this if we don't accelerate:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 (not accelerating anything).
4. GP1 ends
5. CPU1'snote_gp_changes()is called, accelerate happens, now the CB will execute after GP3 (or alternately,rcu_core()on CPU1 does accelerate).
6. GP2 ends.
7. GP3 starts.
8. GP3 ends.
9. CB is invokedInstead, what we will get the following thanks to the acceleration here is:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 and acceleration happens as done by the code this patch adds comments for.
4. GP1 ends
5. CPU1'snote_gp_changes()is called
6. GP2 ends.
7. CB is invokedSorry I missed some steps, here is the update:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 (not accelerating anything).
4. GP1 ends
5. GP2 starts for some other reason from some other CPU.
6. CPU1'snote_gp_changes()is called, acceleration happens, now the CB will execute after GP3.
7. GP2 ends.
8. GP3 starts.
9. GP3 ends.
10. CB is invokedInstead, what we will get the following thanks to the acceleration here is:
1. Start GP 1
2. CPU1 queues callback C1 (not accelerated yet)
3. CPU1 reports QS for GP1 and acceleration happens as done by the code this patch adds comments for.
4. GP1 ends
5. GP2 starts
6. GP2 ends.
7. CB is invokedQuoted 1 line
Does that make sense or is there a subtlety I missed?
Quoted 5 lines
Thanks for detailed description, that is to say, the grace period delays means that if there is no acceleration, the invocation of callback may be delayed by one or more grace periods.
Can you re-describe the meaning of "grace period delays "in the comments?
Yes, good point. I should change it to "one or more delays". Thank you for the suggestion!
Sorry for my late reply as I was OOO this week.
- Joel
Quoted 10 lines
Thanks
ZqiangQuoted 4 lines
Thanks,
- Joel
Frederic Weisbecker
maintainerQuoted 19 lines · Joel Fernandes (Google)
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
Cc Qiang Zhang <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>--- kernel/rcu/tree.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-0
kernel/rcu/tree.c rcu_report_qs_rdp(struct rcu_data *rdp) · line 1991
Quoted 10 lines
kernel/rcu/tree.c +6
-1@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP. +* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core() +* or note_gp_changes() may happen only after the GP after the +* current one has already started. Further, rcu_core() +* only accelerates if RCU is idle (no GP in progress).
Actually note_gp_changes() should take care of that. My gut feeling is that the acceleration in rcu_report_qs_rdp() only stands for:
* callbacks that may be enqueued from an IRQ firing during the small window between the RNP unlock in note_gp_changes() and the RNP lock in rcu_report_qs_rdp()
* __note_gp_changes() got called even before from the GP kthread, and callbacks got enqueued between that and rcu_core().
Thanks.
Quoted 25 lines · Frederic Weisbecker
Quoted 23 lines · Joel Fernandes (Google)
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
Cc Qiang Zhang <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>--- kernel/rcu/tree.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-1@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP.
Quoted 8 lines
kernel/rcu/tree.c rcu_report_qs_rdp(struct rcu_data *rdp) · line 1991
Quoted 6 lines
kernel/rcu/tree.c +6
-0+* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core() +* or note_gp_changes() may happen only after the GP after the +* current one has already started. Further, rcu_core() +* only accelerates if RCU is idle (no GP in progress). Actually
note_gp_changes()should take care of that.
You are referring to rcu_core() -> rcu_check_quiescent_state() -> note_gp_changes() doing the acceleration prior to the rcu_core() -> rcu_report_qs_rdp() call, correct?
Ah, but note_gp_changes() has an early return which triggers if either:
1. The rnp spinlock trylock failed.
2. The start of a new grace period was already detected before, so rdp->gp_seq == rnp->gp_seq.
So I think it is possible that we are in the middle of a GP, and rcu_core() is called because QS reporting is required for the CPU, and say the current GP started we are in the middle off occurs from the same CPU so rdp->gp_seq == rnp->gp_seq.
Now, rcu_core()'s call to note_gp_changes() should return early but its later call to report_qs_rdp() will not accelerate the callback without the code we are commenting here.
Quoted 6 lines
My gut feeling is that the
acceleration inrcu_report_qs_rdp()only stands for:* callbacks that may be enqueued from an IRQ firing during the small window between the RNP unlock in
note_gp_changes()and the RNP lock inrcu_report_qs_rdp()
Sure, this also seems like a valid reason.
Quoted 2 lines
*
__note_gp_changes()got called even before from the GP kthread, and callbacks got enqueued between that andrcu_core().
Agreed. In this case we will take the early return in note_gp_changes() when called from the rcu_core(). So yeah, that was kind of my point as well but slightly different reasoning.
Let me know if you disagree with anything I mentioned, though.
- Joel
Quoted 52 lines · Joel Fernandes (Google)
Quoted 19 lines
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
Cc Qiang Zhang <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>--- kernel/rcu/tree.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-0kernel/rcu/tree.c rcu_report_qs_rdp(struct rcu_data *rdp) · line 1991
Quoted 10 lines
kernel/rcu/tree.c +6
-1@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP. +* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core() +* or note_gp_changes() may happen only after the GP after the +* current one has already started. Further, rcu_core() +* only accelerates if RCU is idle (no GP in progress). Actually
note_gp_changes()should take care of that.You are referring to
rcu_core()->rcu_check_quiescent_state()->note_gp_changes()doing the acceleration prior to thercu_core()->rcu_report_qs_rdp()call, correct?Ah, but
note_gp_changes()has an early return which triggers if either:
1. The rnp spinlock trylock failed.
2. The start of a new grace period was already detected before, sordp->gp_seq==rnp->gp_seq.So I think it is possible that we are in the middle of a GP, and
rcu_core()is called because QS reporting is required for the CPU, and say the current GP started we are in the middle off occurs from the same CPU sordp->gp_seq==rnp->gp_seq.Now, rcu_core()'s call to
note_gp_changes()should return early but its later call toreport_qs_rdp()will not accelerate the callback without the code we are commenting here.
Quoted 6 lines
My gut feeling is that the
acceleration inrcu_report_qs_rdp()only stands for:* callbacks that may be enqueued from an IRQ firing during the small window between the RNP unlock in
note_gp_changes()and the RNP lock inrcu_report_qs_rdp()
For rdp which is in the middle of a de-offloading process, the bypass list have been
flushed, the nocb kthreads may miss callbacks acceleration. invoke call_rcu()
will also not use bypass list. if at this time a new gp starts, before call rcu_report_qs_rdp() to report qs, even if rcu_core() invoke note_gp_changes() notice gp start, this rdp's callback may still miss acceleration if rdp still in de-offloading process, because invoke rcu_rdp_is_offloaded() still return true.
I think this is also a reason.
Thanks
Zqiang
Quoted 13 lines
Sure, this also seems like a valid reason.
*
__note_gp_changes()got called even before from the GP kthread, and callbacks got enqueued between that andrcu_core().Agreed. In this case we will take the early return in
note_gp_changes()when called from thercu_core(). So yeah, that was kind of my point as well but slightly different reasoning.Let me know if you disagree with anything I mentioned, though.
- Joel
Quoted 65 lines · On Feb 11, 2023, at 6:18 AM, Zhang, Qiang1 <[email protected]> wrote:
Quoted 53 lines
Quoted 22 lines · Joel Fernandes (Google)
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
Cc Qiang Zhang <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>---
kernel/rcu/tree.c| 13 ++++++++++++-1 file changed, 12 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-0kernel/rcu/tree.c rcu_report_qs_rdp(struct rcu_data *rdp) · line 1991
Quoted 10 lines
kernel/rcu/tree.c +6
-1@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP. +* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core() +* or note_gp_changes() may happen only after the GP after the +* current one has already started. Further, rcu_core() +* only accelerates if RCU is idle (no GP in progress). Actually
note_gp_changes()should take care of that.You are referring to
rcu_core()->rcu_check_quiescent_state()->note_gp_changes()doing the acceleration prior to thercu_core()->rcu_report_qs_rdp()call, correct?Ah, but
note_gp_changes()has an early return which triggers if either:
1. The rnp spinlock trylock failed.
2. The start of a new grace period was already detected before, sordp->gp_seq==rnp->gp_seq.So I think it is possible that we are in the middle of a GP, and
rcu_core()is called because QS reporting is required for the CPU, and say the current GP started we are in the middle off occurs from the same CPU sordp->gp_seq==rnp->gp_seq.Now, rcu_core()'s call to
note_gp_changes()should return early but its later call toreport_qs_rdp()will not accelerate the callback without the code we are commenting here.Quoted 6 lines
My gut feeling is that the
acceleration inrcu_report_qs_rdp()only stands for:* callbacks that may be enqueued from an IRQ firing during the small window between the RNP unlock in
note_gp_changes()and the RNP lock inrcu_report_qs_rdp()
Quoted 8 lines
For rdp which is in the middle of a de-offloading process, the bypass list have been
flushed, the nocb kthreads may miss callbacks acceleration. invokecall_rcu()
will also not use bypass list. if at this time a new gp starts, before callrcu_report_qs_rdp()to report qs, even ifrcu_core()invokenote_gp_changes()notice gp start, this rdp's callback may still miss acceleration if rdp still in de-offloading process, because invokercu_rdp_is_offloaded()still return true.I think this is also a reason.
I tend to agree with you. I am wondering the best way to document all these reasons. Perhaps it suffices to mention a few reasons briefly here, without going into too much detail (because details may be subject to change).
I will look through this entire thread again and take a call on how to proceed, but do let me know what you and Frederic think about the next steps. The main benefit of commenting is we dont look at this in a few years and run into the same question…
Thanks!
Joel
Quoted 17 lines
Thanks
ZqiangQuoted 13 lines
Sure, this also seems like a valid reason.
*
__note_gp_changes()got called even before from the GP kthread, and callbacks got enqueued between that andrcu_core().Agreed. In this case we will take the early return in
note_gp_changes()when called from thercu_core(). So yeah, that was kind of my point as well but slightly different reasoning.Let me know if you disagree with anything I mentioned, though.
- Joel
Quoted 71 lines · On Feb 11, 2023, at 6:18 AM, Zhang, Qiang1 <[email protected]> wrote:
Quoted 53 lines
Quoted 22 lines · Joel Fernandes (Google)
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
Cc Qiang Zhang <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>---
kernel/rcu/tree.c| 13 ++++++++++++-1 file changed, 12 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-0kernel/rcu/tree.c rcu_report_qs_rdp(struct rcu_data *rdp) · line 1991
Quoted 10 lines
kernel/rcu/tree.c +6
-1@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP. +* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core() +* or note_gp_changes() may happen only after the GP after the +* current one has already started. Further, rcu_core() +* only accelerates if RCU is idle (no GP in progress). Actually
note_gp_changes()should take care of that.You are referring to
rcu_core()->rcu_check_quiescent_state()->note_gp_changes()doing the acceleration prior to thercu_core()->rcu_report_qs_rdp()call, correct?Ah, but
note_gp_changes()has an early return which triggers if either:
1. The rnp spinlock trylock failed.
2. The start of a new grace period was already detected before, sordp->gp_seq==rnp->gp_seq.So I think it is possible that we are in the middle of a GP, and
rcu_core()is called because QS reporting is required for the CPU, and say the current GP started we are in the middle off occurs from the same CPU sordp->gp_seq==rnp->gp_seq.Now, rcu_core()'s call to
note_gp_changes()should return early but its later call toreport_qs_rdp()will not accelerate the callback without the code we are commenting here.Quoted 6 lines
My gut feeling is that the
acceleration inrcu_report_qs_rdp()only stands for:* callbacks that may be enqueued from an IRQ firing during the small window between the RNP unlock in
note_gp_changes()and the RNP lock inrcu_report_qs_rdp()For rdp which is in the middle of a de-offloading process, the bypass list have been
flushed, the nocb kthreads may miss callbacks acceleration. invokecall_rcu()
will also not use bypass list. if at this time a new gp starts, before callrcu_report_qs_rdp()to report qs, even ifrcu_core()invokenote_gp_changes()notice gp start, this rdp's callback may still miss acceleration if rdp still in de-offloading process, because invokercu_rdp_is_offloaded()still return true.
Quoted 3 lines
I think this is also a reason.
I tend to agree with you. I am wondering the best way to document all these reasons. Perhaps it suffices to mention a few reasons briefly here, without going into too much detail (because details may be subject to change).
Agree, just mention a few main reasons, and the details may be put in the document.
Thanks
Zqiang
Quoted 24 lines
I will look through this entire thread again and take a call on how to proceed, but do let me know what you and Frederic think about the next steps. The main benefit of commenting is we dont look at this in a few years and run into the same question…
Thanks!
Joel
Thanks
ZqiangQuoted 13 lines
Sure, this also seems like a valid reason.
*
__note_gp_changes()got called even before from the GP kthread, and callbacks got enqueued between that andrcu_core().Agreed. In this case we will take the early return in
note_gp_changes()when called from thercu_core(). So yeah, that was kind of my point as well but slightly different reasoning.Let me know if you disagree with anything I mentioned, though.
- Joel
Quoted 21 lines · Joel Fernandes (Google)
Recent discussion triggered due to a patch linked below, from Qiang, shed light on the need to accelerate from QS reporting paths.
Update the comments to capture this piece of knowledge.
Cc Qiang Zhang <[email protected]>Cc Frederic Weisbecker <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>--- kernel/rcu/tree.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)kernel/rcu/tree.c +0
-0@@ -1983,7 +1983,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp) }else {
kernel/rcu/tree.c rcu_report_qs_rdp(struct rcu_data *rdp) · line 1992
Quoted 10 lines
kernel/rcu/tree.c +6
-1/* * This GP can't end until cpu checks in, so all of our -* callbacks can be processed during the next GP. +* callbacks can be processed during the next GP. Do +* the acceleration from here otherwise there may be extra +* grace period delays, as any accelerations from rcu_core() +* or note_gp_changes() may happen only after the GP after the +* current one has already started. Further, rcu_core() +* only accelerates if RCU is idle (no GP in progress). *
And I couldn't help but pass this through ChatGPT:
Before:
This GP can't end until cpu checks in, so all of our callbacks can be processed during the next GP. Do the acceleration from here otherwise there may be extra grace period delays, as any accelerations from rcu_core() or note_gp_changes() may happen only after the GP after the current one has already started. Further, rcu_core() only accelerates if RCU is idle (no GP in progress). NOCB kthreads have their own way to deal with that...
After:
In order to ensure all callbacks are processed efficiently, this grace period (GP) must not end until the CPU checks in. To avoid unnecessary grace period delays, it is important to initiate acceleration from the current location. Any acceleration from the functions "rcu_core()" or "note_gp_changes()" may only occur after the next GP has already started. It is important to note that "rcu_core()" will only initiate acceleration if the RCU system is idle (no GP in progress). NOCB kthreads, on the other hand, have their own unique method for handling this situation.
It sounds well written, but maybe a bit factually incorrect.. trying again:
To ensure all callbacks are processed in the next grace period, this GP must not end until the CPU has checked in. To avoid any additional grace period delays, it's important to perform the acceleration from here. If acceleration is performed from rcu_core() or note_gp_changes(), it may only occur after the next GP has already started. Additionally, it's important to note that rcu_core() will only accelerate if RCU is idle and no GP is in progress. The NOCB kthreads have a separate mechanism for dealing with this issue.
Not bad, but the first sentence is still factually incorrect. Yes, I'm bored..why do you ask? ;-)
I think except for the first sentence though, it made for a nice grammatical re-write (give or take Frederic and Qiang's comments ;-)).
- Joel
Quoted 18 lines
kernel/rcu/tree.c +6
-1* NOCB kthreads have their own way to deal with that... */ @@ -1993,6 +1998,12 @@ rcu_report_qs_rdp(struct rcu_data *rdp)/* * ...but NOCB kthreads may miss or delay callbacks acceleration * if in the middle of a (de-)offloading process. +* +* Such missed acceleration may cause the callbacks to +* be stranded until RCU is fully de-offloaded, as +* acceleration from rcu_core() and note_gp_changes() +* cannot happen for fully/partially offloaded mode due +* to ordering dependency between rnp lock and nocb_lock. */ needacc = true; } --2.39.1.519.gcb327c4b5f-goog