Joshua Chia
Joshua Chia

Reputation: 1968

Let perf use certain performance counters properly with newer processors

I'm trying to use perf to measure certain events, including L1-dcache-stores, on my machine, which has a relatively new processor i9-10900K compared to the relatively old CentOS 7 with kernel 3.10.0-1127

The problem is that perf reports that L1-dcache-stores, together with some other events, is not supported when I run perf stat -e L1-dcache-stores, so I can't use it, at least in a straightforward way that I know. However, under CentOS 8 with kernel 4.18.0-193, perf works fine for this event on the same machine. So, I suspect it is because the older kernel doesn't know how to deal with certain performance counters on processors that are too new, and perf is essentially part of the kernel.

What can I do to use perf on the CentOS 7 system and have things like L1-dcache-stores working properly for my processor? I can't just take the perf binary from CentOS 8 and use it on CentOS 7 because the glibc version is different.

$ sudo perf stat -e L1-dcache-stores echo


 Performance counter stats for 'echo':

   <not supported>      L1-dcache-stores                                            

       0.000486304 seconds time elapsed

       0.000389000 seconds user
       0.000000000 seconds sys

Upvotes: 1

Views: 323

Answers (1)

Hadi Brais
Hadi Brais

Reputation: 23639

Support for your processor (Comet Lake) was added starting with the CentOS kernel package version 4.18.0-151.el8 (see the commit titled "perf/x86/intel: Add Comet Lake CPU support" listed in the changelog of the kernel). So all model-specific hardware events, including L1-dcache-stores, are supported by name in perf in 4.18.0-193 but not in 3.10.0-1127. That's why you're getting <not supported>. perf stat will tell you that all events categorized as "hardware cache events" to not be supported in 3.10.0-1127. Intel architectural hardware events, such as cycles and instructions, are supported by name in all versions of the perf_event subsystem.

The only way to use model-specific hardware events on a kernel that doesn't support the processor on which it's running is by specifying raw event codes rather than event names in the perf command. This method is described in the "ARBITRARY PMUS" section of the perf-list manual. For example, the perf event L1-dcache-stores would be mapped to the native event MEM_INST_RETIRED.ALL_STORES on your processor. The event code can then be determined by looking up the event name in the Intel manual.

perf stat -e cpu/event=0xd0,umask=0x82,name=MEM_INST_RETIRED.ALL_STORES/ ...

Upvotes: 3

Related Questions