简体   繁体   English

最适合正确测量缓存访问时间的计时器

[英]Best suitable Timer for correct measurement of cache access time

There exist so many timers which can be used to find time taken to execute a task or a program takes to complete its execution for example. 例如,存在如此多的计时器,可用于查找执行任务或程序完成其执行所花费的时间。

I would like to find the access time of L2 cache set by set by accessing array elements loaded into cache . 我想通过访问加载到cache中的数组元素来设置L2缓存的访问时间。 To find the access time of all sets of L2 cache set by set time calculation , I have tried different options like - rdtsc(), gettimeofday () , but not getting exact result as expected . 为了通过设置时间计算来找到所有L2高速缓存集的访问时间,我尝试了-rdtsc(),gettimeofday()之类的不同选项,但未获得预期的准确结果。

I am using intel i7 machine in linux with gcc 4.8. 我在Linux上使用gcc 4.8的intel i7机器。 What is the best timer to calculate the cache access time with more accuracy. 什么是最好的计时器,以更准确地计算缓存访问时间。

my approach is as follow 我的方法如下

for ( j=0; j<100000;j++
{

for ( set_no = 0 ; set_no< 4096; set_no ++)
{ 

start= rdtsc()
{
access all blocks of a set = set_no;
}
end = rdtsc()


time_taken[set_no]+= end -start ;
}
}

for(set_no=0;set_no<4096;set_no++)
printf(" time needed for access set %d = %llu", set_no, time_taken[set_no]/100000);

I would like to know whether BEST/SUITABLE Timer available in C or C++ ? 我想知道BEST / SUITABLE Timer是否在C或C ++中可用?

I need to prevent out-of_order execution in i3/i7 to get correct time measurement, so * SERIALIZATION of timer is required. 我需要防止i3 / i7中的乱序执行才能获得正确的时间测量,因此 * 需要定时器的序列化。 * Which timer should I use to get correct result with SERIALIZED OUTPUT. *使用SERIALIZED OUTPUT可获得正确结果的计时器。 rdtsc() has OPTION to serialized the timer output, DOES other timer also have the same ? rdtsc()具有对计时器输出进行序列化的选项,其他计时器也具有相同的功能吗?

should I use other option to calculate time to get better result ? 我应该使用其他选项来计算时间以获得更好的结果吗? Thanks in advance. 提前致谢。

Since your compiler is capable of C++11, I'd go with std::chrono::high_resolution_clock. 由于您的编译器可以使用C ++ 11,因此我将使用std :: chrono :: high_resolution_clock。 For http://en.cppreference.com/w/cpp/chrono/high_resolution_clock tells: 对于http://en.cppreference.com/w/cpp/chrono/high_resolution_clock来说

Class std::chrono::high_resolution_clock represents the clock with the smallest tick period provided by the implementation. 类std :: chrono :: high_resolution_clock表示实现所提供的最小滴答周期的时钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM