From: Steven Rostedt on
On Fri, 2010-03-05 at 15:03 -0800, Paul E. McKenney wrote:
> Replace the calls to read_barrier_depends() in ftrace_list_func() with
> rcu_dereference_raw() to improve readability. The reason that we use
> rcu_dereference_raw() here is that removed entries are never freed,
> instead they are simply leaked. This is one of a very few cases where
> use of rcu_dereference_raw() is the long-term right answer. And I don't
> yet know of any others. ;-)
>
> Cc: Steven Rostedt <rostedt(a)goodmis.org>

Acked-by: Steven Rostedt <rostedt(a)goodmis.org>

Thanks Paul!

> Cc: Frederic Weisbecker <fweisbec(a)gmail.com>
> Cc: Ingo Molnar <mingo(a)redhat.com>
> Signed-off-by: Paul E. McKenney <paulmck(a)linux.vnet.ibm.com>
> ---

>
> @@ -154,8 +159,7 @@ static int __register_ftrace_function(struct ftrace_ops *ops)
> * the ops->next pointer is valid before another CPU sees
> * the ops pointer included into the ftrace_list.
> */
> - smp_wmb();
> - ftrace_list = ops;
> + rcu_assign_pointer(ftrace_list, ops);

[ Off topic ]

I looked at rcu_assign_pointer() and it is:

#define rcu_assign_pointer(p, v) \
({ \
if (!__builtin_constant_p(v) || \
((v) != NULL)) \
smp_wmb(); \
(p) = (v); \
})

My question is, why that crazy if? The only time that will fail is if we
are assigning the constant NULL to p. What makes NULL so important here?
Can't there be a case when assigning NULL to p will require that wmb()?

-- Steve


>
> if (ftrace_enabled) {
> ftrace_func_t func;


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Josh Triplett on
On Fri, Mar 05, 2010 at 08:29:05PM -0500, Steven Rostedt wrote:
> On Fri, 2010-03-05 at 15:03 -0800, Paul E. McKenney wrote:
> > Replace the calls to read_barrier_depends() in ftrace_list_func() with
> > rcu_dereference_raw() to improve readability. The reason that we use
> > rcu_dereference_raw() here is that removed entries are never freed,
> > instead they are simply leaked. This is one of a very few cases where
> > use of rcu_dereference_raw() is the long-term right answer. And I don't
> > yet know of any others. ;-)
> >
> > Cc: Steven Rostedt <rostedt(a)goodmis.org>
>
> Acked-by: Steven Rostedt <rostedt(a)goodmis.org>
>
> Thanks Paul!
>
> > Cc: Frederic Weisbecker <fweisbec(a)gmail.com>
> > Cc: Ingo Molnar <mingo(a)redhat.com>
> > Signed-off-by: Paul E. McKenney <paulmck(a)linux.vnet.ibm.com>
> > ---
>
> >
> > @@ -154,8 +159,7 @@ static int __register_ftrace_function(struct ftrace_ops *ops)
> > * the ops->next pointer is valid before another CPU sees
> > * the ops pointer included into the ftrace_list.
> > */
> > - smp_wmb();
> > - ftrace_list = ops;
> > + rcu_assign_pointer(ftrace_list, ops);
>
> [ Off topic ]
>
> I looked at rcu_assign_pointer() and it is:
>
> #define rcu_assign_pointer(p, v) \
> ({ \
> if (!__builtin_constant_p(v) || \
> ((v) != NULL)) \
> smp_wmb(); \
> (p) = (v); \
> })
>
> My question is, why that crazy if? The only time that will fail is if we
> are assigning the constant NULL to p. What makes NULL so important here?
> Can't there be a case when assigning NULL to p will require that wmb()?

The barrier ensures that the reader can't see the new p and the old
*p. Since you can't look at *NULL, that concern doesn't apply.

- Josh Triplett
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Steven Rostedt on
On Fri, 2010-03-05 at 17:45 -0800, Josh Triplett wrote:

> > #define rcu_assign_pointer(p, v) \
> > ({ \
> > if (!__builtin_constant_p(v) || \
> > ((v) != NULL)) \
> > smp_wmb(); \
> > (p) = (v); \
> > })
> >
> > My question is, why that crazy if? The only time that will fail is if we
> > are assigning the constant NULL to p. What makes NULL so important here?
> > Can't there be a case when assigning NULL to p will require that wmb()?
>
> The barrier ensures that the reader can't see the new p and the old
> *p. Since you can't look at *NULL, that concern doesn't apply.

Thanks for the explanation.

Question 2)

Then why the !__builtin_constant_p(v)?

If v is NULL, then the same should apply even if it is not a constant?
What am I missing?

-- Steve


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Josh Triplett on
On Fri, Mar 05, 2010 at 08:57:49PM -0500, Steven Rostedt wrote:
> On Fri, 2010-03-05 at 17:45 -0800, Josh Triplett wrote:
>
> > > #define rcu_assign_pointer(p, v) \
> > > ({ \
> > > if (!__builtin_constant_p(v) || \
> > > ((v) != NULL)) \
> > > smp_wmb(); \
> > > (p) = (v); \
> > > })
> > >
> > > My question is, why that crazy if? The only time that will fail is if we
> > > are assigning the constant NULL to p. What makes NULL so important here?
> > > Can't there be a case when assigning NULL to p will require that wmb()?
> >
> > The barrier ensures that the reader can't see the new p and the old
> > *p. Since you can't look at *NULL, that concern doesn't apply.
>
> Thanks for the explanation.
>
> Question 2)
>
> Then why the !__builtin_constant_p(v)?
>
> If v is NULL, then the same should apply even if it is not a constant?
> What am I missing?

Checking for __builtin_constant_p(v) ensures that this test happens at
compile time, and thus no conditional occurs at runtime. Together with
the assumption of compiler constant folding and dead code elimination,
this test means "if you can tell at compile time that the call assigns
NULL, emit no barrier, otherwise emit a barrier". Under no
circumstances will this macro actually emit conditional code.

- Josh Triplett
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Steven Rostedt on
On Fri, 2010-03-05 at 18:15 -0800, Josh Triplett wrote:

> > Question 2)
> >
> > Then why the !__builtin_constant_p(v)?
> >
> > If v is NULL, then the same should apply even if it is not a constant?
> > What am I missing?
>
> Checking for __builtin_constant_p(v) ensures that this test happens at
> compile time, and thus no conditional occurs at runtime. Together with
> the assumption of compiler constant folding and dead code elimination,
> this test means "if you can tell at compile time that the call assigns
> NULL, emit no barrier, otherwise emit a barrier". Under no
> circumstances will this macro actually emit conditional code.


Ah OK!

So the benefit of not doing a smb_wmb() when a variable is NULL is
outweighed by the benefits of removing branches and extra code.

Yes it now makes sense. Only remove the wmb() when we can guarantee that
it is never needed, and avoid unnecessary branches when it may not be
needed.

Thanks for clarifying!

-- Steve


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/