gpt4 book ai didi

ubuntu 12.10 perf stat <不支持> 周期

转载 作者:太空宇宙 更新时间:2023-11-03 16:47:45 25 4
gpt4 key购买 nike

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

我通过安装perf

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

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

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

为什么不支持这些事件?启用这些事件需要任何操作吗?

最佳答案

您已虚拟化 Ubuntu,但未虚拟化硬件计数器(PMU/PMC MSR 寄存器)。 Xen(或其他虚拟化软件)应该知道如何使用 PMC 寄存器,为 guest 模拟它们并将请求转发到真实硬件。我不知道它是在 Xen 中完成的。但对于 Amazon AWS EC2 而言,仅实现基本硬件事件(并且仅在专用实例上)需要数年时间,它们仅在 2017 年 5 月完成:http://www.brendangregg.com/blog/2017-05-04/the-pmcs-of-ec2.html “EC2 的 PMC:衡量 IPC”,作者: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.

他还解释了 Xen 以及为什么在极少数情况下启用它们:

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.

因此,解决方案:

  • 在非虚拟化( native 、主机)Linux(Ubuntu 或任何其他)上运行 perf。
  • 在启用 vpmu=on 启动选项的情况下使用 Xen(仅当您不将此 PC 的虚拟 guest 提供给不受信任的用户时)
  • 将其他虚拟化解决方案与虚拟化 PMU 结合使用。根据 VirtualBox 页面,可能会在 Vmware 中启用一些基本事件:https://gist.github.com/dannas/1fa2cfb0d3d108282955 “关于 Virtualbox 性能计数器的注释”pmu_notes.txt by dannas(好评)。 KVM 为 guest 模拟了一些:https://stackoverflow.com/a/43460663

PS:旧的 perf list 没有检查任何东西,它只是打印所有已知事件,甚至不支持/未实现的硬件事件。而且它没有打印出真正的 CPU 事件集。 libpfm4 有表格并且有英特尔特定的 perf wrapper ocperf.py github.com/andikleen/pmu-tools 使用英特尔特定名称。

关于ubuntu 12.10 perf stat <不支持> 周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19763070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com