From: Peter Zijlstra on
On Fri, 2010-05-21 at 11:40 +0200, Frederic Weisbecker wrote:
> On Fri, May 21, 2010 at 11:02:03AM +0200, Peter Zijlstra wrote:

> > Also, avoid conditionals on the fast path by ordering with probe unregister
> > so that we should never get on the callback path without the data being there.
> >
> \
> > + head = per_cpu_ptr(event_call->perf_events, smp_processor_id());\

> Should be rcu_dereference_sched ?

No, I removed all that rcu stuff and synchronized against the probe
unregister.

I assumed that after probe unregister a tracepoint callback doesn't
happen, which then guarantees we should never get !head.

> > + for_each_possible_cpu(cpu)
> > + INIT_HLIST_HEAD(per_cpu_ptr(list, cpu));
> > +
> > + tp_event->perf_events = list;
>
>
>
> I suspect this must be rcu_assign_pointer.

Same thing as above, I do this before probe register, so I see no need
for RCU.

> > + list = per_cpu_ptr(list, smp_processor_id());
> > + hlist_add_head_rcu(&p_event->hlist_entry, list);
>
>
>
> Ah and may be small comment, because using the hlist api here
> may puzzle more people than just me ;)

What exactly is the puzzlement about?

> > + if (--tp_event->perf_refcount > 0)
> > + return;
> > +
> > + tp_event->perf_event_disable(tp_event);
>
>
>
> Don't we need a rcu_synchronize_sched() here?

Doesn't probe unregister synchronize things against its own callback?

> > + free_percpu(tp_event->perf_events);
> > + tp_event->perf_events = NULL;
>
>
>
> And rcu_assign?

Which again, makes any use of RCU unneeded.


> > + raw_data = per_cpu_ptr(perf_trace_buf[*rctxp], smp_processor_id());
>
>
>
> Needs rcu_dereference_sched too. And this could be __this_cpu_var()

Ahh! so that is what its called.

> > + preempt_disable_notrace();
>
>
> Why is this needed. We have the recursion context protection already.

Because:

@@ -4094,7 +4087,7 @@ end:

int perf_swevent_get_recursion_context(void)
{
- struct perf_cpu_context *cpuctx = &get_cpu_var(perf_cpu_context);
+ struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context);
int rctx;

if (in_nmi())

--
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: Peter Zijlstra on
On Fri, 2010-05-21 at 12:13 +0200, Frederic Weisbecker wrote:
> > I assumed that after probe unregister a tracepoint callback doesn't
> > happen, which then guarantees we should never get !head.

> I'm not sure about this. The tracepoints are called under rcu_read_lock(),
> but there is not synchronize_rcu() after we unregister a tracepoint, which
> means you can have a pending preempted one somewhere.
>
> There is a call_rcu that removes the callbacks, but that only protect
> the callback themselves.

Ah, ok, so we should do probe_unregister + synchronize_sched().

That should ensure __DO_TRACE() doesn't call into it anymore.

/me goes make a patch

--
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: Peter Zijlstra on
On Fri, 2010-05-21 at 12:13 +0200, Frederic Weisbecker wrote:
> > What exactly is the puzzlement about?

> The fact we use the hlist API not for hlist purpose but for a list.

I might miss the confusion, but hlist _are_ lists. Its just that their
structure is slightly different that the regular struct list_head stuff.

--
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: Peter Zijlstra on
On Fri, 2010-05-21 at 12:21 +0200, Frederic Weisbecker wrote:
> On Fri, May 21, 2010 at 12:19:09PM +0200, Peter Zijlstra wrote:
> > On Fri, 2010-05-21 at 12:13 +0200, Frederic Weisbecker wrote:
> > > > I assumed that after probe unregister a tracepoint callback doesn't
> > > > happen, which then guarantees we should never get !head.
> >
> > > I'm not sure about this. The tracepoints are called under rcu_read_lock(),
> > > but there is not synchronize_rcu() after we unregister a tracepoint, which
> > > means you can have a pending preempted one somewhere.
> > >
> > > There is a call_rcu that removes the callbacks, but that only protect
> > > the callback themselves.
> >
> > Ah, ok, so we should do probe_unregister + synchronize_sched().
> > That should ensure __DO_TRACE() doesn't call into it anymore.
> >
> > /me goes make a patch
> >
>
>
> Yep. But that also means we need to rcu_dereference_sched() to access
> the per cpu list of events.

Why?

The per-cpu vars are allocated and freed in a fully serialized manner,
there should be no races what so ever.

--
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: Ingo Molnar on

* Peter Zijlstra <peterz(a)infradead.org> wrote:

> On Fri, 2010-05-21 at 12:13 +0200, Frederic Weisbecker wrote:
> > > What exactly is the puzzlement about?
>
> > The fact we use the hlist API not for hlist purpose
> > but for a list.
>
> I might miss the confusion, but hlist _are_ lists. Its
> just that their structure is slightly different that the
> regular struct list_head stuff.

Using an API in such a mixed way may cause puzzlement ;-)

Fortunately we've got the ultimate anti-puzzlement weapon:
code comments.

Ingo
--
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/