一个应用程序中的函数耗费的总时间可以分为两个组成部分:
- 实际计算所花费的时间(Tcomp)
- 内存访问所花费的时间(Tmem)
通常,性能分析器会提供函数耗费的总时间估计。是否可能根据上述两个部分(Tcomp和Tmem)获得耗费时间的估计值?
一个应用程序中的函数耗费的总时间可以分为两个组成部分:
通常,性能分析器会提供函数耗费的总时间估计。是否可能根据上述两个部分(Tcomp和Tmem)获得耗费时间的估计值?
提出了“屋顶线”模型中的“算术强度”概念:https://crd.lbl.gov/departments/computer-science/PAR/research/roofline/。简单地说,它定义了每次内存访问执行的算术指令数量。
计算算术强度通常通过使用性能计数器来实现。
$ perf stat stress --vm 4 -t 3
stress: info: [4520] dispatching hogs: 0 cpu, 0 io, 4 vm, 0 hdd
stress: info: [4520] successful run completed in 3s
Performance counter stats for 'stress --vm 4 -t 3':
10767,074968 task-clock:u (msec) # 3,560 CPUs utilized
0 context-switches:u # 0,000 K/sec
0 cpu-migrations:u # 0,000 K/sec
4 555 919 page-faults:u # 0,423 M/sec
4 290 929 426 cycles:u # 0,399 GHz
67 779 143 instructions:u # 0,02 insn per cycle
18 074 114 branches:u # 1,679 M/sec
5 398 branch-misses:u # 0,03% of all branches
3,024851934 seconds time elapsed
CPU绑定测试,IPC很高(1.44):
$ perf stat stress --cpu 4 -t 3
stress: info: [4465] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
stress: info: [4465] successful run completed in 3s
Performance counter stats for 'stress --cpu 4 -t 3':
11419,683671 task-clock:u (msec) # 3,805 CPUs utilized
0 context-switches:u # 0,000 K/sec
0 cpu-migrations:u # 0,000 K/sec
108 page-faults:u # 0,009 K/sec
30 562 187 954 cycles:u # 2,676 GHz
43 995 290 836 instructions:u # 1,44 insn per cycle
13 043 425 872 branches:u # 1142,188 M/sec
26 312 747 branch-misses:u # 0,20% of all branches
3,001218526 seconds time elapsed
perf stat
或者 vtune)?有没有某些命令的变体可以定期打印 IPC,和/或系统范围内的 IPC 平均值(在 perf 的 man 手册中找不到周期间隔以便每 1 或 5 秒打印它,像 vmstat
、iostat
和 sar -n DEV
做的那样 https://medium.com/netflix-techblog/linux-performance-analysis-in-60-000-milliseconds-accc10403c55);tiptop 是什么?有任何关于受内存绑定/延迟绑定程序及其 IPC 的实际示例吗? - osgx由于计算在当前处理器架构中与内存访问重叠,所以无法测量这个值(并且做这个也没有意义)。此外,访问内存通常会分解为更多的步骤(访问内存、预取到各种高速缓存级别、实际读取到处理器寄存器)。
您可以使用perf及其硬件计数器(如果您的硬件支持)测量不同高速缓存级别上的高速缓存命中和缺失,以估算您的算法在您的硬件上的效率。