Re: Using perf_event_open() to sample multiple events of a process

From: Nadav Amit
Date: Mon Nov 08 2021 - 14:51:08 EST



> On Nov 8, 2021, at 7:24 AM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Sat, Nov 06, 2021 at 01:57:23AM +0100, Peter Zijlstra wrote:
>
>> The problem seems to be that we call perf_event_set_output() before we
>> set event->ctx, which is a bit of a problem.
>>
>> Now, afaict it's been broken since c3f00c70276d ("perf: Separate
>> find_get_context() from event initialization"), which is ages ago :/
>>
>> It's waaay too late to try and fix it; I'll be likely to make an even
>> bigger mess if I tried. Perhaps tomorrow.
>>
>> Clearly FD_OUTPUT isn't much used :-(
>
> The below seems to fix, it's a bit of a hack, but I couldn't really come
> up with anything saner.

I originally considered doing a similar hack. I assume it should work,
but I moved to using the ioctl workaround that you suggested.

Clearly nobody is using this feature if it is broken for 11 years.
There is always the option to deprecate it if there is an alternative.