How to flush the CPU cache in Linux from a C program?

c, caching, flush, linux, unix

Solution

I take it you mean "CPU cache", not memory cache

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:

- How to clear CPU L1 and L2 cache

Here's an article about Linux and CPU cache:

- http://lwn.net/Articles/252125/

NOTE:

At this (very, very low) level, "Linux" != "Unix"

Problem

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. 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.

Original source

Related problems