gpt4 book ai didi

c++ - 我如何在 ubuntu 中分析 TLB 命中和 TLB 未命中

转载 作者:搜寻专家 更新时间:2023-10-31 00:18:55 26 4
gpt4 key购买 nike

我编写了一个简单的 C++ 程序,使用 for 循环打印从 1 到 100 的数字。我想找出特定程序在运行时发生的 TLB 命中数和未命中数。有没有可能得到这些数据?

我正在使用 Ubuntu。我用过 perf 工具。但它在不同的时间产生不同的结果。我很困惑我的代码的哪一部分导致了如此大量的 TLB 命中、TLB 未命中和缓存未命中。

当然可能还有其他进程同时运行,比如 Ubuntu GUI。但是,这个结果是否也包括那些过程?我使用的命令:perf stat -e dTLB-loads -e dTPerformance counter stats for './hellocc':

结果:第一次——

       909,822 dTLB-loads                                                  
2,023 dTLB-misses # 0.22% of all dTLB cache hits
4,512 cache-misses

0.006821182 seconds time elapsed

LB-未命中 ./hellocc

结果:第二次——'./hellocc' 的性能计数器统计:

       907,810 dTLB-loads                                                  
2,045 dTLB-misses # 0.23% of all dTLB cache hits
4,533 cache-misses

0.006780635 seconds time elapsed

我的简单代码:

#include <iostream>    
using namespace std;
int main
{
cout << "hello" << "\n";
for(int i=1; i <= 100; i = i + 1)
cout<< i << "\t" ;
return 0;
}

最佳答案

您可以模拟的一种方法是使用 cachegrind , valgrind 的一部分。

Cachegrind simulates how your program interacts with a machine's cache hierarchy and (optionally) branch predictor. It simulates a machine with independent first-level instruction and data caches (I1 and D1), backed by a unified second-level cache (L2). This exactly matches the configuration of many modern machines.

虽然这不是您的硬件,我认为您无法获得,但它是一个很好的替代品。

关于c++ - 我如何在 ubuntu 中分析 TLB 命中和 TLB 未命中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9298910/

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