Using perf to monitor raw event counters

走远了吗. 提交于 2020-07-17 06:48:54

问题


I am trying to measure certain hardware events on a (Intel Xeon) machine with multiple (physical) processors. Specifically, I wish to know how many requests are issued for reading 'offcore' data.

I found the OFFCORE_REQUESTS hardware event in Intels documentation and it gives the event descriptor 0xB0 and for data demands, the additional mask 0x01.

Would it then be correct to tell perf to record the event 0xB1 (i.e. 0xB0 | 0x01) and to call it as:

perf record -e r0B1 ./mytestapp someargs

Or is this incorrect? Because perf report shows no output for events entered like this.

The perf documentation is rather sparse in this area, apart from a tutorial entry which does not say which event it was (though this one works for me), or how it was encoded...

Any help is greatly appreciated.


回答1:


Ok, so I guess I figured it out.

For the the Intel machine I use, the format is as follows: <umask><eventselector> where both are hexadecimal values. The leading zeros of the umask can be dropped, but not for the event selector.

So for the event 0xB0 with the mask 0x01 I can call:

perf record -e r1B0 ./mytestapp someargs

I could not manage to find the exact parsing of it in the perf kernel code (any kernel hacker here?), but I found these sources:

  • A description of the use of perf with raw events in the c't magazine 13/03 (subscription required), which describes some raw events with their description from the Intel Architecture Software Developers Manuel (Vol 3b)
  • A patch on the kernel mailing list, discussing the proper way to document it. It specified that the pattern above was "... was x86 specific and imcomplete at that"
  • (Updated) The man page of newer versions shows an example on Intel machines: man perf-list

Update: As pointed out in the comments (thank you!), the libpfm translator can be used to obtain the proper event descriptor. The website linked in the comments (Bojan Nikolic: How to monitor the full range of CPU performance events), discovered by user 'osgx' explains it in further detail.




回答2:


It seems you can use as well:

perf record -e cpu/event=0xB1,umask=0x1/u ./mytestapp someargs

I don't know where this syntax is documented.

You can probably use the other arguments (edge, inv, cmask) as well.




回答3:


There are several libraries which can be helpful to work with raw PMU events.

perf's own wiki https://perf.wiki.kernel.org/index.php/Tutorial#Events recommends perf list --help man page for info about raw events encoding. And modern perf versions will list raw events as part of perf list output ("... if linked against the libpfm4 library, provides some short description of the events."). perf list --details will also print raw ids and masks of events.

Bojan Nikolic has "How to monitor the full range of CPU performance events" blog article about libpfm4 (perfmon2) lib usage to encode raw events for perf with help of showevtinfo and check_events tools.

There is also perf python wrapper ocperf which accepts intel's event names. It is written by Andi Kleen (Intel Open Source Technology Center) as part of pmu-tools set of utilities (LWN post from 2013, event lists by intel at https://download.01.org/perfmon/). There is a demo of ocperf (2011) http://halobates.de/modern-pmus-yokohama.pdf:

ocperf
•Perf wrapper to support Intel specific events
•Allows symbolic events and some additional events

    ocperf record -a −e offcore_response.any_data.remote_dram_0 sleep 10

PAPI library also has tool to explore raw events with some descriptions - papi_native_avail.



来源:https://stackoverflow.com/questions/16062244/using-perf-to-monitor-raw-event-counters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!