0

There is a specific circular buffer I wish to keep hot in cache, however it can go unused for extended periods of time. This is causing cache misses.

I have an idle loop that can take responsibility for keeping the location hot, but I cannot see a way to do this using only the public interface without actually inserting/removing items.

Is there any action, using the public interface, that when the circular buffer is empty, will keep the insertion point hot in cache?

Chuu
  • 4,301
  • 2
  • 28
  • 54
  • you may write an allocator, exposing char* pointers to the underlying memory (ie the two underlying arrays); assuming the data fits a single cache line, you could then perform a read of the char* pointee (this would not violate aliasing rules) – Massimiliano Janes Jan 08 '18 at 17:00

2 Answers2

1

You may like to warm up your full fast path periodically by executing it in full and stopping as short from committing the effects of it as possible.

If you can get hold of a pointer to the front of the container you can use __builtin_prefetch on it to bring it into the cache. Alternatively, push and pop an element.

Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271
0

You might want to look into using CAT (Cache Allocation Technology). I'm not sure where it's at, at the moment, but see https://lwn.net/Articles/694800/ for where Linux was with it July 2016.

CAT is an Intel thing to separate pieces of cache and dedicate them to different purposes. Threads assigned one piece of cache cannot evict data belonging to other pieces, although I believe they can still make use of reading it.

Zan Lynx
  • 53,022
  • 10
  • 79
  • 131