Re: [RFC PATCH 0/6] bpf: Introduce the new ability of eBPF programs to access hardware PMU counter

Alexei Starovoitov
2015-07-18T01:22:27Z

On 7/17/15 6:02 PM, pi3orama wrote:
> An example: we want to count the number of cycles between entry and exit point of a particular library function (glibc write() for example). Context switch is possible, but we don't care cycles consumed by other tasks. Then we need to create a perf event in task context using:
>
> perf _event_open(&attr, pid, -1/* cpu */, ...);
> Since it is a library function, we have to choose pids we interest.

sure. just store that fd under whatever index in perf_event_array
and use it from the program. index is not cpuid. it's just an index.

> We should also probe sys_clone and create new perf event when thread creating, we haven't think how to do that now.

opening a perf_event from the program? That will be very very hard.
Much easier to kprobe sys_clone and signal to user space via
bpf_output_trace_data() and user space will be
perf_event_open-ing new event for new task.

ps
please tweak your email client to wrap lines.