ubuntu 12.10 perf stat <不支持>周期 [英] ubuntu 12.10 perf stat <not supported> cycles

查看:39
本文介绍了ubuntu 12.10 perf stat <不支持>周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的系统是ubuntu-12.10-desktop-amd64

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

我通过安装 perf

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

当我使用 perf list 时,它会按预期列出所有事件.但是当我使用perf stat时,结果似乎异常

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

结果是:

 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?

推荐答案

您已虚拟化 Ubuntu,但硬件计数器(PMU/PMC MSR 寄存器)未虚拟化.Xen(或其他虚拟化软件)应该知道如何使用 PMC 寄存器,为来宾模拟它们并将请求转发到真实硬件.我不知道它是否在 Xen 中完成.但是对于 Amazon AWS EC2 来说,只实施基本的硬件事件(并且仅在专用实例上)需要数年时间,它们仅在 2017 年 5 月完成:http://www.brendangregg.com/blog/2017-05-04/the-pmcs-of-ec2.html Brendan Gregg 的EC2 的 PMC:测量 IPC":

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:

性能监控计数器 (PMC) 现在可从 AWS EC2 云中的专用主机类型公开获得.全世界的 PMC 书呆子们欢欣鼓舞!(我们六个人.)...在这篇文章中,我将总结 EC2 中可用的 PMC,它们仅适用于专用主机(例如,m4.16xl、i3.16xl),并且我将演示测量 IPC.请注意,PMC 也称为 HPC(硬件性能计数器)和其他名称.

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.

他还解释了 Xen 及其在极少数情况下启用的原因:

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

这在云端怎么可能?

您可能想知道云来宾是如何读取 PMC 的.有用像这样:PMC 通过特权指令 RDMSR 和用于配置的 WRMSR(我在 EC2 的 MSR 中写过),以及用于阅读的 RDPMC.特权指令导致访客退出,这由管理程序处理.然后管理程序可以运行自己的如果实际硬件允许,代码,并配置 PMC,并保存和每当来宾之间进行上下文切换时恢复其状态.

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.

多年前支持主流 Xen,其虚拟性能监控单元 (vPMU).它是在 Xen 引导中使用 vpmu=on 配置的线.但是,它很少被打开.为什么?

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?

PMC有上百个,而且都是用vpmu=on暴露出来的.有些会带来安全风险吗?多篇论文被发布显示 PMC 侧信道攻击,从而测量某些PMC 在向已知目标程序发送输入时最终可能会泄漏目标状态的位.虽然这些在实践中不太可能,并且此类攻击不仅限于 PMC(例如,还有定时攻击),您可以理解不想启用的偏执安全策略默认为所有 PMC.

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.

所以,解决方案:

  • 在非虚拟化(本机、主机)Linux(Ubuntu 或任何其他)上运行 perf.
  • 在启用 vpmu=on 启动选项的情况下使用 Xen(仅当您不将此 PC 的虚拟访客提供给不受信任的用户时)
  • 将其他虚拟化解决方案与虚拟化 PMU 结合使用.Vmware 中可能会根据 VirtualBox 页面启用一些基本事件:https://gist.github.com/dannas/1fa2cfb0d3d108282955 关于 Virtualbox 性能计数器的说明" pmu_notes.txt 由 danna 撰写(好评).有些是 KVM 为来宾模拟的:https://stackoverflow.com/a/43460663
  • 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:旧的 perf list 没有检查任何东西,它只是打印所有已知事件,甚至不支持/未实现的硬件事件.它没有打印真正的 CPU 事件集.libpfm4 有表格,并且有英特尔特定的 perf 包装器 ocperf.py of github.com/andikleen/pmu-tools 使用英特尔特定的名称.

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.

这篇关于ubuntu 12.10 perf stat &lt;不支持&gt;周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆