动态监控rdtsc [英] Perf Monitoring for rdtsc dynamically

查看:126
本文介绍了动态监控rdtsc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以使用perf动态地实时"监视汇编指令? 我已经看到,如果我使用perf record/perf top,然后单击记录的函数,我会看到汇编指令,但是我可以直接监视特定的汇编指令,例如rdtsc或clflush,例如,它们在一个进程中被调用的频率如何.一定时期内使用perf?

Is there a way to monitor for assembly instructions in "real-time" dynamically using perf? I have seen that if I use perf record /perf top and then click on the recorded functions, I see the assembly instructions, but can I directly monitor specific assembly instructions e.g., rdtsc or clflush e.g., how often they are called by a process within certain period using perf?

我正在Skylake和Haswell上使用Debian 9.

I am using Debian 9 on Skylake and also on Haswell.

sudo uname -a 
Linux bla 4.9.0-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux

sudo /proc/config.gz

返回command not found.

感谢任何帮助/想法.

推荐答案

是的,您当然可以构建可以动态采样在主机上运行的指令的东西.

Yes, you could certainly build something that dynamically samples instructions running on the host.

基本思想是定期对您感兴趣的进程进行采样(可能是全部"),并检查采样的指令指针周围的区域,以确定必须为此类采样执行的指令.已经存在:例如,通过拆卸直到下一个条件分支,或者可能直到基本块的末尾为止.

The basic idea is to periodically sample the processes you are interested in (which could be "all of them"), and examine the area around the sampled instruction pointer to determine the instructions that must have been executed for such a sample to have existed: for example, by disassembling until the next conditional branch, or perhaps just until the end of the basic block.

重复执行此操作,您将获得已执行指令的直方图,然后可以估算rdtsc或其他任何感兴趣的指令的运行频率.

Doing this repeatedly you'll get a histogram of executed instructions, and you can then estimate how often rdtsc or any other instruction of interest is operating.

这实际上并没有那么困难:perf topperf recordperf report中已经存在大多数逻辑:只需将perf top中的采样代码与perf top中的注释代码结合起来, /或perf report如上所述.也许您甚至可以在事后这样做:使用perf record --all-cpus收集示例,然后运行perf script或以其他方式解析文件以监视指令.

This isn't even actually all that difficult: most of the logic already exists in perf top, perf record and perf report: just combine the sampling code from perf top with the annotation code from perf top and/or perf report as described above. Perhaps you can even do it after the fact: use perf record --all-cpus to gather the samples and then run perf script or otherwise parse the file to monitor the instructions.

每个样本只会为您提供一小段执行指令的窗口,因此,如果您需要准确地捕获偶然的rdtsc,则根本无法使用.

Each sample will only give you a small window of executed instructions, so if you need to catch the occasional rdtsc accurately, this won't work at all.

您可以通过利用最新分支记录"功能来扩展每个样本的窗口",从而从最新分支的角度出发追溯过去的时间,并分解所有这些基本块,从而将每个样本的覆盖范围扩大很多.

You could extend the "window" for each sample by exploiting the "last branch record" feature to essentially go back in time based on the most recent branches, and disassemble all those basic blocks, which would extend your coverage per sample by a lot.

这篇关于动态监控rdtsc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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