Skip to main content

Crate clf

Crate clf 

Source
Expand description

Flush the data cache line.

This crate can be used when you do benchmarks that are not dependent on the cpu cache.

§Supports

  • x86_64, aarch64 (native implementation)
  • mips64el, powerpc64le … etc (fallback to __builtin_clear_cache)
  • minimum support rustc 1.70.0 (due to core::arch and asm!)

§Examples

Easy to use:

let a = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
clf::cache_line_flush_with_slice(&a);

or

let a = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
let begin_ptr = a.as_ptr();
let end_ptr = unsafe { begin_ptr.add(a.len()) };
unsafe { clf::cache_line_flush_with_ptr(begin_ptr, end_ptr) };

§References

CPU cache

§Benchmarking

To measure the effectiveness of the cache flushing, you can run the included benchmarks:

make bench

This will compare the access time of “warm” data versus “flushed” data.

Functions§

cache_line_flush_with_ptr
flush the data cache line, this parameters are pointers.
cache_line_flush_with_slice
flush the data cache line, this parameter is a slice.