记录 Linux 中任何 executable/process 的所有内存访问
Logging all memory accesses of any executable/process in Linux
我一直在寻找一种方法来记录 Linux 中 process/execution 的所有内存访问。我知道以前有人在这里问过关于这个话题的问题
但我想知道是否有任何非检测工具可以执行此操作 activity。我 不为此目的寻找 QEMU/ VALGRIND 因为它会有点慢,我希望尽可能少的开销。
为此,我查看了 perf mem
和 cpu/mem-loads/pp
等 PEBS 事件,但我发现它们只会收集采样数据,而我实际上想要跟踪所有内存访问而不进行任何采样。
我想知道是否有可能通过使用像 QEMU 这样的工具来收集所有内存访问而不会浪费太多开销。是否有可能仅使用 PERF 但不使用样本以便我获得所有内存访问数据?
是否还有我缺少的其他工具?或者任何其他给我所有内存访问数据的策略?
不可能 尽可能快地 运行 规范和在此 运行 中跟踪的所有内存访问(或高速缓存未命中)(使用系统内示踪剂)。做一个 运行 用于计时,另一个 运行 (更长,更慢),甚至重新编译二进制文件用于内存访问跟踪。
你可以从简短的程序(不是最近规范CPU的ref输入,或者你的大程序中的十亿内存访问)和使用perf
linux 工具 (perf_events) 来找到记录的内存请求与所有内存请求的可接受比率。有 perf mem
工具,或者您可以尝试一些启用 PEBS 的内存子系统事件。通过向 perf 事件说明符 perf record -e event:pp
添加 :p
和 :pp
后缀来启用 PEBS,其中 event 是 PEBS 事件之一。还可以尝试 pmu-tools ocperf.py 以更轻松地对英特尔事件名称进行编码并查找启用 PEBS 的事件。
尝试在内存性能测试中找出不同记录比率 (1% / 10% / 50%) 的实际(最大)开销。检查 Arithmetic Intensity scale of [Roofline model](https://crd.lbl.gov/departments/computer-science/PAR/research/roofline/ 左侧部分内存记录开销的最坏情况。这部分的典型测试有:STREAM(BLAS1)、RandomAccess(GUPS)和memlat几乎都是SpMV;许多真正的任务通常不会留在天平上:
- STREAM test (linear access to memory),
- RandomAccess (GUPS) 测试
- 一些内存延迟测试(memlat of 7z, lat_mem_rd of lmbench)。
你想跟踪每个 load/store 命令还是只想记录错过所有(某些)缓存并发送到 PC 的主 RAM 内存(到 L3)的请求?
为什么您不希望有任何开销并记录所有内存访问?这是不可能的,因为每次内存访问都有几个字节(内存地址,有时:指令地址)的跟踪记录到同一内存中。因此,启用内存跟踪(超过 10% 或内存访问跟踪)显然会限制可用内存带宽,并且程序会 运行 变慢。甚至可以注意到 1% 的跟踪,但它的影响(开销)较小。
您的 CPU E5-2620 v4 是 Broadwell-EP 14nm,因此它可能还有一些更早的 Intel PT 变体:https://software.intel.com/en-us/blogs/2013/09/18/processor-tracing https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/intel-pt.txt https://github.com/01org/processor-trace and especially Andi Kleen's blog on pt: http://halobates.de/blog/p/410 "Cheat sheet for Intel Processor Trace with Linux perf and gdb"
PT support in hardware: Broadwell (5th generation Core, Xeon v4) More overhead. No fine grained timing.
PS: 研究 SpecCPU 内存访问的学者与内存访问一起工作 dumps/traces, 转储生成缓慢:
- http://www.bu.edu/barc2015/abstracts/Karsli_BARC_2015.pdf - LLC 未命中记录到离线分析,未记录跟踪的时间 运行s
- http://users.ece.utexas.edu/~ljohn/teaching/382m-15/reading/gove.pdf - 所有 load/stores 通过写入额外的巨大跟踪缓冲区以定期(罕见)在线聚合进行检测。这种检测速度慢 2 倍或更慢,特别是对于内存带宽/延迟受限的内核。
- http://www.jaleels.org/ajaleel/publications/SPECanalysis.pdf(来自 Intel Corporation,VSSAD 的 Aamer Jaleel) - 基于 Pin 的检测 - 修改和检测程序代码以将内存访问元数据写入缓冲区。这种检测速度慢 2 倍或更慢,特别是对于内存带宽/延迟受限的内核。该论文列出并解释了仪器开销和注意事项:
Instrumentation Overhead: Instrumentation involves
injecting extra code dynamically or statically into the
target application. The additional code causes an
application to spend extra time in executing the original
application ... Additionally, for multi-threaded
applications, instrumentation can modify the ordering of
instructions executed between different threads of the
application. As a result, IDS with multi-threaded
applications comes at the lack of some fidelity
Lack of Speculation: Instrumentation only observes
instructions executed on the correct path of execution. As
a result, IDS may not be able to support wrong-path ...
User-level Traffic Only: Current binary instrumentation
tools only support user-level instrumentation. Thus,
applications that are kernel intensive are unsuitable for
user-level IDS.
我一直在寻找一种方法来记录 Linux 中 process/execution 的所有内存访问。我知道以前有人在这里问过关于这个话题的问题
但我想知道是否有任何非检测工具可以执行此操作 activity。我 不为此目的寻找 QEMU/ VALGRIND 因为它会有点慢,我希望尽可能少的开销。
为此,我查看了 perf mem
和 cpu/mem-loads/pp
等 PEBS 事件,但我发现它们只会收集采样数据,而我实际上想要跟踪所有内存访问而不进行任何采样。
我想知道是否有可能通过使用像 QEMU 这样的工具来收集所有内存访问而不会浪费太多开销。是否有可能仅使用 PERF 但不使用样本以便我获得所有内存访问数据?
是否还有我缺少的其他工具?或者任何其他给我所有内存访问数据的策略?
不可能 尽可能快地 运行 规范和在此 运行 中跟踪的所有内存访问(或高速缓存未命中)(使用系统内示踪剂)。做一个 运行 用于计时,另一个 运行 (更长,更慢),甚至重新编译二进制文件用于内存访问跟踪。
你可以从简短的程序(不是最近规范CPU的ref输入,或者你的大程序中的十亿内存访问)和使用perf
linux 工具 (perf_events) 来找到记录的内存请求与所有内存请求的可接受比率。有 perf mem
工具,或者您可以尝试一些启用 PEBS 的内存子系统事件。通过向 perf 事件说明符 perf record -e event:pp
添加 :p
和 :pp
后缀来启用 PEBS,其中 event 是 PEBS 事件之一。还可以尝试 pmu-tools ocperf.py 以更轻松地对英特尔事件名称进行编码并查找启用 PEBS 的事件。
尝试在内存性能测试中找出不同记录比率 (1% / 10% / 50%) 的实际(最大)开销。检查 Arithmetic Intensity scale of [Roofline model](https://crd.lbl.gov/departments/computer-science/PAR/research/roofline/ 左侧部分内存记录开销的最坏情况。这部分的典型测试有:STREAM(BLAS1)、RandomAccess(GUPS)和memlat几乎都是SpMV;许多真正的任务通常不会留在天平上:
- STREAM test (linear access to memory),
- RandomAccess (GUPS) 测试
- 一些内存延迟测试(memlat of 7z, lat_mem_rd of lmbench)。
你想跟踪每个 load/store 命令还是只想记录错过所有(某些)缓存并发送到 PC 的主 RAM 内存(到 L3)的请求?
为什么您不希望有任何开销并记录所有内存访问?这是不可能的,因为每次内存访问都有几个字节(内存地址,有时:指令地址)的跟踪记录到同一内存中。因此,启用内存跟踪(超过 10% 或内存访问跟踪)显然会限制可用内存带宽,并且程序会 运行 变慢。甚至可以注意到 1% 的跟踪,但它的影响(开销)较小。
您的 CPU E5-2620 v4 是 Broadwell-EP 14nm,因此它可能还有一些更早的 Intel PT 变体:https://software.intel.com/en-us/blogs/2013/09/18/processor-tracing https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/intel-pt.txt https://github.com/01org/processor-trace and especially Andi Kleen's blog on pt: http://halobates.de/blog/p/410 "Cheat sheet for Intel Processor Trace with Linux perf and gdb"
PT support in hardware: Broadwell (5th generation Core, Xeon v4) More overhead. No fine grained timing.
PS: 研究 SpecCPU 内存访问的学者与内存访问一起工作 dumps/traces, 转储生成缓慢:
- http://www.bu.edu/barc2015/abstracts/Karsli_BARC_2015.pdf - LLC 未命中记录到离线分析,未记录跟踪的时间 运行s
- http://users.ece.utexas.edu/~ljohn/teaching/382m-15/reading/gove.pdf - 所有 load/stores 通过写入额外的巨大跟踪缓冲区以定期(罕见)在线聚合进行检测。这种检测速度慢 2 倍或更慢,特别是对于内存带宽/延迟受限的内核。
- http://www.jaleels.org/ajaleel/publications/SPECanalysis.pdf(来自 Intel Corporation,VSSAD 的 Aamer Jaleel) - 基于 Pin 的检测 - 修改和检测程序代码以将内存访问元数据写入缓冲区。这种检测速度慢 2 倍或更慢,特别是对于内存带宽/延迟受限的内核。该论文列出并解释了仪器开销和注意事项:
Instrumentation Overhead: Instrumentation involves injecting extra code dynamically or statically into the target application. The additional code causes an application to spend extra time in executing the original application ... Additionally, for multi-threaded applications, instrumentation can modify the ordering of instructions executed between different threads of the application. As a result, IDS with multi-threaded applications comes at the lack of some fidelity
Lack of Speculation: Instrumentation only observes instructions executed on the correct path of execution. As a result, IDS may not be able to support wrong-path ...
User-level Traffic Only: Current binary instrumentation tools only support user-level instrumentation. Thus, applications that are kernel intensive are unsuitable for user-level IDS.