简体   繁体   English

对标C代码-刷新缓存

[英]Benchmarking C code - Flush Cache

I am wondering if it is possible to force a cache flush within c using linux x86. 我想知道是否有可能使用linux x86在c中强制执行缓存刷新。 I have read several answers answering how to do this within the shell or using asm/cache.h (requiring me to write a linux module...) 我已经阅读了几个答案,回答了如何在外壳中执行此操作或使用asm / cache.h(要求我编写一个Linux模块...)

I am using the PAPI library which allows me to get very close to the exact number of clock cycles that a given block of code takes to execute. 我正在使用PAPI库,它使我可以非常接近给定代码块执行所需的确切时钟周期数。 However, since I want to time some extremely short functions I need to run the functions many times for accurate statistics (the timing function call takes longer than the code within the blocks takes to execute). 但是,由于我想对一些非常短的函数进行计时,因此我需要多次运行这些函数以进行准确的统计(计时函数调用所花的时间比执行块内代码所花费的时间还要长)。 By running the code multiple times the cache is speeding up the execution of successive calls of the same block of code and I would like to prevent this! 通过多次运行代码,缓存可以加快对同一代码块的连续调用的执行速度,我想防止这种情况!

I don't Know any standard way to do this other than loading other thing to the cache. 除了将其他内容加载到缓存之外,我不知道任何标准的方法来执行此操作。 My usual workaround is simply process something large enough to "cool down" the cache, say a matrix multiplication. 我通常的解决方法是简单地处理足够大的东西以“冷却”缓存,例如矩阵乘法。

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

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