iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.54k stars 3.88k forks source link

Reading perf events (as listed by perf list) in BPF Programs #1677

Open drandynisbet opened 6 years ago

drandynisbet commented 6 years ago

Hi, I would like to access (some of the) hardware/PMC counter events as identified by perf list, in order to be able to perform microarchitectural characterization on a per thread basis using a python/c bcc based tool that has been hacked from llcstat to undertake tracing.

Have I missed an appropriate example on how to configure events that are not listed under help(bcc.PerfHWConfig) help(bcc.PerfSWConfig) in python. Any pointers on which example to look at to achieve this. I'm currently using the stable packages on ubuntu 16.04, kernel 4.13.0-38-generic.

Cheers, Andy

yonghong-song commented 6 years ago

The kernel bpf perf event map should already support hardware counters in 4.13.x.

The bcc C++ interface to configure an arbitrary perf_event is contributed by @palmtenor

commit 6c33a5230ef5e34303de992f7b87b99656127a48
Author: Teng Qin <qinteng@fb.com>
Date:   Fri Mar 9 17:03:31 2018 -0800

    C++ interface for attaching to perf event with raw perf_event_attr argument

commit 5b7c6783d70a632a418887e40a860c87846ddf7c
Author: Teng Qin <qinteng@fb.com>
Date:   Fri Mar 9 16:57:11 2018 -0800

    Add perf event attaching interface with raw perf_event_attr argument

There is no example yet, but if you can find the correct config for your need, you should be able to use the python interface directly.

cc @palmtenor who may help describe how to find a config value for a particular event in perf list.

drandynisbet commented 6 years ago

Thanks for the information. I'll have a look through the commit and try to work out how to exploit it from C/python. I am familiar with configuring specific events using intel pcm and perf. But any further pointers for information would be very helpful.

Cheers, Andy