Re: [RFC][PATCH] perf: Rewrite core context handling
From: Song Liu
Date: Wed Oct 17 2018 - 14:58:03 EST
> On Oct 17, 2018, at 11:33 AM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Wed, Oct 17, 2018 at 07:19:55PM +0200, Peter Zijlstra wrote:
>> On Wed, Oct 17, 2018 at 04:43:27PM +0000, Song Liu wrote:
>>
>>>> That makes task and cpu contexts wildly different, which will complicate
>>>> matters I feel.
>>>>
>>>
>>> I think we only need different logic when adding events to the task/cpu
>>> contexts. The ctx_sched_in() and ctx_sched_out() will need some extra
>>> logic to filter out events that are not being scheduled (don't schedule
>>> events on PMU-a when rotating PMU-b). This logic will be the same for
>>> task and cpu context. The difference is, the CPU context will not have
>>> such events, because we never added such event to CPU context.
>>>
>>> Does this make sense? I could try draft a RFC to see how difficult it is.
>>
>> I'm not sure it saves much, if we have multiple per-cpu contexts we get
>> to re-introduce the active_ctx_list and loose the simplification for the
>> online status.
>>
>> Plus that fundamental assymetry -- which would bother my OCD forever
>> more :-)
>
> Worse, the whole syscall that installs the events will come apart. The
> locking for the two cases is different :/
I agree... I didn't get into details of locking. I just consider these all
as part of "adding event to context".
I believe this patch should give close to the optimal performance. However,
I do feel it makes the logic more complicate. Before this patch, perf_cpu_context
and perf_event_context don't need to know much about multiple PMUs. With
this patch, the two extra *_pmu_context are necessary for performance (and
maybe also for correctness).
If we take first a baby step, how about adding more perf_event_ctx to
task_struct->perf_event_ctxp? We need one sw perf_event_ctx and a few hw
perf_event_ctx (one for each hw PMU). (I haven't checked whether it is OK
to allocate these when attaching events). (And I guess you don't really
like this..)
On the other hand, this patch makes it possible to create groups of events
from different hw PMUs. I guess that will be useful.
Thanks,
Song