ubuntu 12.10 perf stat <not supported> cycles
Asked Answered
F

1

9

The system I use is ubuntu-12.10-desktop-amd64

I install perf through

apt-get install linux-tools linux-tools-common linux-tools-3.5.0-40

when I use perf list, it list all the events as expected. But when I use perf stat, the result seems abnormal

perf stat ls

the result is:

 Performance counter stats for 'ls':

      3.988508 task-clock                #    0.678 CPUs utilized          
           172 context-switches          #    0.043 M/sec                  
             0 CPU-migrations            #    0.000 K/sec                  
           276 page-faults               #    0.069 M/sec                  
      <not supported> cycles                  
      <not supported> stalled-cycles-frontend 
      <not supported> stalled-cycles-backend  
      <not supported> instructions            
      <not supported> branches                
      <not supported> branch-misses           

   0.005883014 seconds time elapsed

Why these events are not supported? Any operation needed to enable these events?

Farad answered 4/11, 2013 at 7:4 Comment(1)
I find out that in original ubuntu system, perf works well. But when using ubuntu with xen, it will have the above problem. I compile xen from source. Any parameter needed when compiling xen??Farad
A
5

You have virtualized Ubuntu and hardware counters (PMU/PMC MSR registers) were not virtualized. Xen (or other virtualization software) should know how to work with PMC registers, emulate them for guest and forward requests to real hardware. I don't know is it done in Xen. But for Amazon AWS EC2 it took years to implement only basic hardware events (and only on dedicated instances), they were done only in May 2017: http://www.brendangregg.com/blog/2017-05-04/the-pmcs-of-ec2.html "The PMCs of EC2: Measuring IPC" by Brendan Gregg:

Performance Monitoring Counters (PMCs) are now publicly available from dedicated host types in the AWS EC2 cloud. PMC nerds worldwide rejoice! (All six of us.) ... In this post I'll summarize the PMCs available in EC2, which are for dedicated hosts only (eg, m4.16xl, i3.16xl), and I'll demonstrate measuring IPC. Note that PMCs are also known as HPCs (hardware performance counters), and other names as well.

He also explains about Xen and why they are enabled in rare cases:

How is this even possible in the cloud?

You might be wondering how cloud guests can read PMCs at all. It works like this: PMCs are managed via the privileged instructions RDMSR and WRMSR for configuration (which I wrote about in The MSRs of EC2), and RDPMC for reading. A privileged instruction causes a guest exit, which is handled by the hypervisor. The hypervisor can then run its own code, and configure PMCs if the actual hardware allows, and save and restore their state whenever it context switches between guests.

Mainstream Xen supported this years ago, with its virtual Performance Monitoring Unit (vPMU). It is configured using vpmu=on in the Xen boot line. However, it is rarely turned on. Why?

There are hundreds of PMCs, and they are all exposed with vpmu=on. Could some pose a security risk? A number of papers have been published showing PMC side-channel attacks, whereby measuring certain PMCs while sending input to a known target program can eventually leak bits of the target's state. While these are unlikely in practice, and such attacks aren't limited to PMCs (eg, there's also timing attacks), you can understand a paranoid security policy not wanting to enable all PMCs by default.

So, the solutions:

  • Run perf on not-virtualized (native, host) Linux (Ubuntu or any other).
  • Use Xen with vpmu=on boot option enabled (only if you don't give virtual guests of this PC to untrusted users)
  • Use other virtualization solution with virtualizated PMU. Some basic events may be enabled in Vmware according to VirtualBox page: https://gist.github.com/dannas/1fa2cfb0d3d108282955 "Notes about performance counters for Virtualbox" pmu_notes.txt by dannas (good review). Some are emulated for guests by KVM: https://stackoverflow.com/a/43460663

PS: old perf list did not check anything, it just printed all known events, even not supported / not implemented hw events. And it did not print real set of CPU events. libpfm4 has tables and there is Intel-specific perf wrapper ocperf.py of github.com/andikleen/pmu-tools to use Intel-specific names.

Angelika answered 30/5, 2017 at 3:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.