From: Joel Fernandes <joelagnelf@nvidia.com>
To: paulmck@kernel.org
Cc: linux-kernel@vger.kernel.org,
Frederic Weisbecker <frederic@kernel.org>,
Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
Josh Triplett <josh@joshtriplett.org>,
Boqun Feng <boqun.feng@gmail.com>,
Uladzislau Rezki <urezki@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Zqiang <qiang.zhang@linux.dev>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
rcu@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH RFC 2/3] rcu: Refactor expedited handling check in rcu_read_unlock_special()
Date: Sun, 6 Jul 2025 15:16:54 -0400 [thread overview]
Message-ID: <52679e35-c6a4-4e0c-876a-a80a1a9b2bd8@nvidia.com> (raw)
In-Reply-To: <941d82f3-1c09-4db2-ae22-a80d04227673@paulmck-laptop>
Hi Paul,
On 7/6/2025 1:18 PM, Paul E. McKenney wrote:
> On Sat, Jul 05, 2025 at 04:39:16PM -0400, Joel Fernandes wrote:
>> Extract the complex expedited handling condition in rcu_read_unlock_special()
>> into a separate function rcu_unlock_needs_exp_handling() with detailed
>> comments explaining each condition.
>>
>> This improves code readability. No functional change intended.
>
> Very nice!!!
Thanks!
>
> Some questions and comments interspersed below.
I replied inline below:
>
> Thanx, Paul
>
>> Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
>> ---
>> kernel/rcu/tree_plugin.h | 80 +++++++++++++++++++++++++++++++++++-----
>> 1 file changed, 71 insertions(+), 9 deletions(-)
>>
>> diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
>> index baf57745b42f..8504d95bb35b 100644
>> --- a/kernel/rcu/tree_plugin.h
>> +++ b/kernel/rcu/tree_plugin.h
>> @@ -647,6 +647,72 @@ static void rcu_preempt_deferred_qs_handler(struct irq_work *iwp)
>> local_irq_restore(flags);
>> }
>>
>> +/*
>> + * Check if expedited grace period processing during unlock is needed.
>> + *
>> + * This function determines whether expedited handling is required based on:
>> + * 1. Task blocking an expedited grace period
>
> This is a heuristic. What we are actually checking is whether the task
> is blocking *some* grace period and whether at least one task (maybe
> this one, maybe not) is blocking an expedited grace period.
Makes sense, I changed this to:
* 1. Task blocking an expedited grace period (based on a heuristic, could be
* false-positive, see below.)
And the below comment to:
/*
* Check if this task is blocking an expedited grace period. If the
* task was preempted within an RCU read-side critical section and is
* on the expedited grace period blockers list (exp_tasks), we need
* expedited handling to unblock the expedited GP. This is not an exact
* check because 't' might not be on the exp_tasks list at all - its
* just a fast heuristic that can be false-positive sometimes.
*/
if (t->rcu_blocked_node && READ_ONCE(t->rcu_blocked_node->exp_tasks))
return true;
Hope that looks Ok.
>
> Why not an exact check? Because that would mean traversing the list
> starting at ->exp_tasks, and that list could potentially contain every
> task in the system. And I have received bug reports encountered on
> systems with hundreds of thousands of tasks.
Got it.
>
> I could imagine a more complex data structure that semi-efficiently
> tracked exact information, but I could also imagine this not being worth
> the effort.
>
>> + * 2. CPU participating in an expedited grace period
>> + * 3. Strict grace period mode requiring expedited handling
>> + * 4. RCU priority boosting needs when interrupts were disabled
>
> s/boosting/deboosting/
>
Fixed, thanks.
>
>> + */
>> + if (t->rcu_blocked_node && READ_ONCE(t->rcu_blocked_node->exp_tasks))
>> + return true;
>> +
>> + /*
>> + * Check if this CPU is participating in an expedited grace period.
>> + * The expmask bitmap tracks which CPUs need to check in for the
>> + * current expedited GP. If our CPU's bit is set, we need expedited
>> + * handling to help complete the expedited GP.
>> + */
>> + if (rdp->grpmask & READ_ONCE(rnp->expmask))
>> + return true;
>> +
>> + /*
>> + * In CONFIG_RCU_STRICT_GRACE_PERIOD=y kernels, all grace periods
>> + * are treated as short for testing purposes even if that means
>> + * disturbing the system more. Check if either:
>> + * - This CPU has not yet reported a quiescent state, or
>> + * - This task was preempted within an RCU critical section
>> + * In either case, requird expedited handling for strict GP mode.
>
> s/requird/required/ ;-)
I meant "require" :-D. Will fix.
>
>> + */
>> + if (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD) &&
>> + ((rdp->grpmask & READ_ONCE(rnp->qsmask)) || t->rcu_blocked_node))
>> + return true;
>> +
>> + /*
>> + * RCU priority boosting case: If a task is subject to RCU priority
>> + * boosting and exits an RCU read-side critical section with interrupts
>> + * disabled, we need expedited handling to ensure timely deboosting.
>> + * Without this, a low-priority task could incorrectly run at high
>> + * real-time priority for an extended period effecting real-time
>
> s/effecting/degrading/ to be more precise.
>
Fixed, thanks.
- Joel
next prev parent reply other threads:[~2025-07-06 19:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-05 20:39 [PATCH RFC 1/3] rcu: Fix rcu_read_unlock() deadloop due to IRQ work Joel Fernandes
2025-07-05 20:39 ` [PATCH RFC 2/3] rcu: Refactor expedited handling check in rcu_read_unlock_special() Joel Fernandes
2025-07-06 17:18 ` Paul E. McKenney
2025-07-06 19:16 ` Joel Fernandes [this message]
2025-07-07 4:20 ` Paul E. McKenney
2025-07-05 20:39 ` [PATCH RFC 3/3] rcu: Remove redundant check for irq state during unlock Joel Fernandes
2025-07-05 20:41 ` [PATCH RFC 1/3] rcu: Fix rcu_read_unlock() deadloop due to IRQ work Joel Fernandes
2025-07-06 17:08 ` Paul E. McKenney
2025-07-06 17:13 ` Joel Fernandes
2025-07-06 17:26 ` Paul E. McKenney
2025-07-06 18:37 ` Joel Fernandes
2025-07-07 13:26 ` qiang.zhang
2025-07-07 14:04 ` Paul E. McKenney
2025-07-07 14:51 ` Joel Fernandes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52679e35-c6a4-4e0c-876a-a80a1a9b2bd8@nvidia.com \
--to=joelagnelf@nvidia.com \
--cc=bigeasy@linutronix.de \
--cc=boqun.feng@gmail.com \
--cc=clrkwllms@kernel.org \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=neeraj.upadhyay@kernel.org \
--cc=paulmck@kernel.org \
--cc=qiang.zhang@linux.dev \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=urezki@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®