[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zaj_Vw8B5E28TqZ2@pc636>
Date: Thu, 18 Jan 2024 11:37:11 +0100
From: Uladzislau Rezki <urezki@...il.com>
To: Frederic Weisbecker <frederic@...nel.org>
Cc: "Uladzislau Rezki (Sony)" <urezki@...il.com>,
"Paul E . McKenney" <paulmck@...nel.org>, RCU <rcu@...r.kernel.org>,
Neeraj upadhyay <Neeraj.Upadhyay@....com>,
Boqun Feng <boqun.feng@...il.com>, Hillf Danton <hdanton@...a.com>,
Joel Fernandes <joel@...lfernandes.org>,
LKML <linux-kernel@...r.kernel.org>,
Oleksiy Avramchenko <oleksiy.avramchenko@...y.com>
Subject: Re: [PATCH v4 1/4] rcu: Reduce synchronize_rcu() latency
On Sat, Jan 13, 2024 at 12:09:51AM +0100, Frederic Weisbecker wrote:
> Le Thu, Jan 04, 2024 at 05:25:07PM +0100, Uladzislau Rezki (Sony) a écrit :
> > diff --git a/kernel/rcu/Kconfig.debug b/kernel/rcu/Kconfig.debug
> > index 9b0b52e1836f..4812c6249185 100644
> > --- a/kernel/rcu/Kconfig.debug
> > +++ b/kernel/rcu/Kconfig.debug
> > @@ -168,4 +168,16 @@ config RCU_STRICT_GRACE_PERIOD
> > when looking for certain types of RCU usage bugs, for example,
> > too-short RCU read-side critical sections.
> >
> > +config RCU_SR_NORMAL_DEBUG_GP
> > + bool "Debug synchronize_rcu() callers for a grace period completion"
> > + depends on DEBUG_KERNEL && RCU_EXPERT
> > + default n
> > + help
> > + This option enables additional debugging for detecting a grace
> > + period incompletion for synchronize_rcu() users. If a GP is not
> > + fully passed for any user, the warning message is emitted.
> > +
> > + Say Y here if you want to enable such debugging
> > + Say N if you are unsure.
>
> How about just reuse CONFIG_PROVE_RCU instead?
>
Less extra CONFIG_* configuration we have the better approach is. I do
not mind, so we can reuse it. Thanks for this point :)
I see in some places indeed it is used as a debugging peace.
> > +
> > endmenu # "RCU Debugging"
> > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > index 499803234176..b756c40e4960 100644
> > --- a/kernel/rcu/tree.c
> > +++ b/kernel/rcu/tree.c
> > @@ -1422,6 +1422,106 @@ static void rcu_poll_gp_seq_end_unlocked(unsigned long *snap)
> > raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
> > }
> >
> > +/*
> > + * There are three lists for handling synchronize_rcu() users.
> > + * A first list corresponds to new coming users, second for users
> > + * which wait for a grace period and third is for which a grace
> > + * period is passed.
> > + */
> > +static struct sr_normal_state {
> > + struct llist_head srs_next; /* request a GP users. */
> > + struct llist_head srs_wait; /* wait for GP users. */
> > + struct llist_head srs_done; /* ready for GP users. */
> > +
> > + /*
> > + * In order to add a batch of nodes to already
> > + * existing srs-done-list, a tail of srs-wait-list
> > + * is maintained.
> > + */
> > + struct llist_node *srs_wait_tail;
> > +} sr;
>
> "sr" is good enough for a function scope variable but not for a file scope one.
>
> At least "sr_state" would be better. Or maybe you don't even need to name that
> struct and make instead:
>
> struct {
> ...
> ...
> } sr_normal_state;
>
It is moved by the following patch in the series under the "rcu_state" struct variable.
>
> > +
> > +/* Disabled by default. */
> > +static int rcu_normal_wake_from_gp;
> > +module_param(rcu_normal_wake_from_gp, int, 0644);
> > +
> > +static void rcu_sr_normal_complete(struct llist_node *node)
> > +{
> > + struct rcu_synchronize *rs = container_of(
> > + (struct rcu_head *) node, struct rcu_synchronize, head);
>
> Should there be some union in struct rcu_synchronize between struct rcu_head
> and struct llist_node?
>
> Anyway it's stack allocated, they could even be separate fields.
>
> > + unsigned long oldstate = (unsigned long) rs->head.func;
>
> Luckily struct callback_head layout allows such magic but if rcu_head
> and llist_node were separate, reviewers would be less hurt.
>
> If stack space really matters, something like the below?
>
> struct rcu_synchronize {
> union {
> struct rcu_head head;
> struct {
> struct llist_node node;
> unsigned long seq;
> }
> }
> struct completion completion;
> };
>
>
We can do that. I am not sure if should be a separate patch or as a big
change. I tend to separate it.
> > +
> > + WARN_ONCE(IS_ENABLED(CONFIG_RCU_SR_NORMAL_DEBUG_GP) &&
> > + !poll_state_synchronize_rcu(oldstate),
> > + "A full grace period is not passed yet: %lu",
> > + rcu_seq_diff(get_state_synchronize_rcu(), oldstate));
> > +
> > + /* Finally. */
> > + complete(&rs->completion);
> > +}
> > +
> [...]
> > +
> > +/*
> > + * Helper function for rcu_gp_cleanup().
> > + */
> > +static void rcu_sr_normal_gp_cleanup(void)
> > +{
> > + struct llist_node *head, *tail;
> > +
> > + if (llist_empty(&sr.srs_wait))
> > + return;
> > +
> > + tail = READ_ONCE(sr.srs_wait_tail);
>
> Is the READ_ONCE() needed?
>
> A part from those boring details:
>
> Reviewed-by: Frederic Weisbecker <frederic@...nel.org>
>
Appreciate for the review. I will fix all the comments.
Thanks!
--
Uladzislau Rezki
Powered by blists - more mailing lists