如何从C程序刷新Linux中的CPU缓存? [英] How to flush the CPU cache in Linux from a C program?
问题描述
我正在编写一个C程序,需要在其中刷新内存.我想知道是否有任何UNIX系统命令来刷新CPU缓存.
I am writing a C program in which I need to flush my memory. I would like know if there is any UNIX system command to flush the CPU cache.
这是我的项目的要求,其中涉及计算逻辑所需的时间.
This is a requirement for my project which involves calculating the time taken for my logic.
我已经阅读过有关cacheflush(char *s, int a, int b)
函数的信息,但是我不确定它是否合适以及在参数中传递什么.
I have read about the cacheflush(char *s, int a, int b)
function but I am not sure as to whether it will be suitable and what to pass in the parameters.
推荐答案
-
我认为您的意思是"CPU缓存",而不是内存缓存
I take it you mean "CPU cache", not memory cache
上面的链接很好:通过CPU写入大量数据"的建议不是 Windows特定的
The link above is good: the suggestion "write a lot of data via CPU" is not Windows specific
这是同一主题的另一种变化:
Here's another variation on the same theme:
这是有关Linux和CPU缓存的文章:
Here's an article about Linux and CPU cache:
注意:
在此级别(非常低),"Linux"!="Unix"
At this (very, very low) level, "Linux" != "Unix"
这篇关于如何从C程序刷新Linux中的CPU缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!