Is there a way in c++ to quickly invalidate the L2 cache of a processor other than iterating through a large fake array?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m going to assume this is for performance testing and you want to eliminate cache effects between runs.
In that case, what you’d need to know to do this efficiently is:
Then it’s basically a matter of touching memory
allocation_sizebytes away from each other until you’ve flushed the cache entirely.Context switching also often invalidates the cache – it might be faster to
waitfor a millisecond and if the OS swaps you in and out, it’ll likely end up clearing the cache.