Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache handler #39

Closed
jupvfranco opened this issue Oct 30, 2014 · 3 comments
Closed

cache handler #39

jupvfranco opened this issue Oct 30, 2014 · 3 comments

Comments

@jupvfranco
Copy link

Hi,

I would like to know if it is possible or if you are planning to add to the compiler some handler that allows to have some control on what pages are loaded to cache and what pages are removed from it?

Thanks,
Juliana

@EliasC
Copy link
Contributor

EliasC commented Nov 4, 2014

Hi

I think this is hard to control in a fine-grained way since the cache is controlled by hardware. The way a cache generally works is that when you read a memory address, the processor will first check to see if it is in the cache (and if so, read it from there). If it is not, it will bring in a cacheline-sized chunk from memory that contains the value that you originally wanted to read. So every value you read, even if it is just once, will be loaded into the cache together with some surrounding memory, and it will stay there until its cacheline is replaced by another cacheline from memory.

X86 (and possibly other architectures) has special instructions for prefetching memory, which as far as I understand it is the same as reading the memory without using it (i.e. only bringing it into the cache). This can be used to increase the probability that certain memory is already in the cache when you want to read it, for example in a performance critical loop. The hardware does some prefetching on its own when it detects certain access patterns, for example reading the contents of a long array.

There are also instructions for flushing the whole cache, i.e. writing all of its contents back to memory, but telling it to remove individual cachelines is not possible as far as I know (and there is little reason to do so since it otherwise will just lie there until it is replaced by some other memory).

For Encore, I could imagine that we might go as far as adding prefetch-instructions when we can identify a need for it, but our focus is more on trying to layout data in memory in a way which benefits the cache without having to add such instructions.

I hope this made sense!

Why do you ask?

/Elias

@kaeluka
Copy link
Contributor

kaeluka commented Nov 4, 2014

@jupvfranco: what is it you're trying to do? :) Software prefetching, as mentioned by Elias can be used in some cases, but they're rather rare and to get portable performance would be hard (latencies vary on each system, so the optimal time for when to prefetch is different...).

Anyway, if you need prefetching, this is the GCC builtin to do it: https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Other-Builtins.html#Other-Builtins

If you use those instructions, remember that they only work on GCC, so please guard them with appropriate precompiler ifdefs so that the code will compile on other compilers, too.

@TobiasWrigstad
Copy link
Contributor

I am closing this. We can move the discussion elsewhere, but right now I think it is polluting the issue tracking space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants