Re: [PATCH v2] tracing/perf: Move rcu_irq_enter/exit_irqson() to perf trace point hook

From: Mathieu Desnoyers
Date: Tue Feb 11 2020 - 11:02:11 EST


----- On Feb 11, 2020, at 10:46 AM, Peter Zijlstra peterz@xxxxxxxxxxxxx wrote:

> On Tue, Feb 11, 2020 at 10:34:38AM -0500, Mathieu Desnoyers wrote:
>>
>> I'm puzzled by this function. It does:
>>
>> perf_tp_event(...)
>> {
>> hlist_for_each_entry_rcu(event, head, hlist_entry) {
>> ...
>> }
>> if (task && task != current) {
>> rcu_read_lock();
>> ... = rcu_dereference();
>> list_for_each_entry_rcu(...) {
>> ....
>> }
>> rcu_read_unlock();
>> }
>> }
>>
>> What is the purpose of the rcu_read_lock/unlock within the if (),
>> considering that there is already an hlist rcu iteration just before ?
>> It seems to assume that a RCU read-side of some kind of already
>> ongoing.
>
> IIRC the hlist_for_each_entry_rcu() uses the RCU stuff from the
> tracepoint API, while the stuff inside the if() uses regular RCU.
>
> Them were note the same one -- tracepoints used rcu-sched, perf used
> rcu.

Indeed, there is a call to tracepoint_synchronize_unregister() within
perf_trace_event_unreg(), which provides the required grace period
before freeing the perf event.

That tracepoint_synchronize_unregister() was initially doing a synchronize_sched()
as you point out. It then moved to synchronize_rcu() with the RCU flavors
consolidation, and we've added the synchronize_srcu(&tracepoint_srcu) as well,
which handles the rcuidle cases.

Adding a comment in perf_tp_event() detailing how each RCU use is synchronized
might help readability, e.g.:

At top of function:

/*
* Synchronization of the perf event RCU hlist is performed by the tracepoint API.
* Synchronization of the perf event context and perf event context event list
* is performed through explicit use of RCU.
*/

Thanks,

Mathieu

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com