s5z / zsim

A fast and scalable x86-64 multicore simulator
GNU General Public License v2.0
331 stars 184 forks source link

How to implement clflush in zsim #146

Open cyjseagull opened 7 years ago

cyjseagull commented 7 years ago

hello:

I have tried to implement **clflush** in zsim, I have figured out two methods now: 
  1. add a "clflush" function in filter_cache.h, this function call "invalidate" function to invalidate specified cache lines. However, I have encountered "assertion failed error in coherence_ctrls.h" before the simulation has done;

    1. add a "clflush" function in filter_cache.h, this function makes a request, call "processEviction" to delivery this invalidate request. However, I have encountered "deadlock" problems.

    Can you give me some advice about how to implement "clflush" function in zsim? I'll appreciate !

Thank you very much!

gaomy3832 commented 7 years ago

I think the first approach is more reasonable. The reason for the assertion fail is that invalidate should only be called for the cachelines that actually exist in the cache. This is a sanity check for the coherence protocol, and because coherence is complex, don't break it.

I would suggest to add another function in filter cache to do the flush: first lookup the line. If it is in the cache, then do invalidate, otherwise just skip it. In this way you won't break the current coherence protocol, which is a cleaner style.

Another thing is that how many levels you want to flush, just L1 or all caches? I don't remember the semantics of clflush, but you may need to think it over and recursively apply flush to the parent caches if needed.

cyjseagull commented 7 years ago

Thanks for your great advise very much ! I have added "clflush" that calls invalidate function to do the flush in filter cache, and finally, it works well without dead locks and assertions.

Considering that clflush should be done by every level of caches, and I have found that the "invalidate" function of all parent caches has already called "invalidate" function of every child (implemented by "sendInvalidates" function ). So I get the root parent of specified cache line and call "invalidate" function of parent cache to do the clflush, and it seems this method works well so far.