mem: refactor LRU cache tags and add random replacment tags
Review Request #2167 - Created Feb. 21, 2014 and submitted
| Information | |
|---|---|
| Tony Gutierrez | |
| gem5 | |
| default | |
| Reviewers | |
| Default | |
this patch implements a new tags class that uses a random replacement policy. these tags prefer to evict invalid blocks first, if none are available a replacement candidate is chosen at random. this patch factors out the common code in the LRU class and creates a new abstract class: the BaseSetAssoc class. any set associative tag class must implement the functionality related to the actual replacement policy in the following methods: accessBlock() findVictim() insertBlock() invalidate()
Regressions pass
Issue Summary
| Description | From | Last Updated | Status |
|---|---|---|---|
| why not unsigned? | Ali Saidi | July 22, 2014, 7:24 a.m. | Open |
| It seems sensible to make it an unsigned param and only check for 0. | Andreas Hansson | July 22, 2014, 9:26 a.m. | Open |
| Same here, instead of an Int param it should probably be Unsigned. | Andreas Hansson | July 22, 2014, 9:26 a.m. | Open |
| Is Cycles, so it can never be < 0 | Andreas Hansson | July 22, 2014, 9:26 a.m. | Open |
| A bit pedantic perhaps, but (slightly stupid) static code analysers get unhappy with the member variables not being initialised in ... | Andreas Hansson | July 22, 2014, 9:26 a.m. | Open |
Description: |
|
|---|
-
src/mem/cache/tags/random_repl.cc (Diff revision 1) -
should this be const?
-
src/mem/cache/tags/random_repl.cc (Diff revision 1) -
should this not be using the mersenne twister rather? random_mt.random<int>(...)
Summary: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Diff: |
Revision 2 (+781 -379) |
Description: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 3 (+782 -381) |
Description: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 4 (+782 -381) |
Overall, I think this patch looks good and the refactoring is a well-needed change to the way we implement replacement policies. At a high level, I'd really appreciate it if you could split this patch into two patches so the refactoring becomes its own commit. That makes things like bisection much cleaner in the future. I also found the naming of the different classes a bit confusing. I would suggest that you rename BaseLRU -> BaseSetAssoc or something similar. After all, the common stuff that goes into this base class isn't really LRU specific. I also get a bit confused by the PseudoLRU class. When I think of pseudo-LRU, I generally think of things like tree-based LRU or the algorithm used in Nehalem. I'd suggest that you rename it to something with random in the name instead.
Hi Tony, Sorry for taking so long to get around to this. I think your patch is definitely a step in the right direction. My main concern is that it doesn't go far enough, in the sense that there's still a lot of duplication between the LRU and PseudoLRU classes that could be factored out into the common base class. I'm just eyeballing the diff here, so I might be missing something, but the two versions of insertBlock() and invalidate() look the same to me, and accessBlock() looks the same except for the added moveToHead() line in LRU (and the associated DPRINTF). Also, is there a need for all these functions to be virtual? The way we have the Cache class templated on the tag class, I would think not. (The whole intent of that templating is to avoid those virtual function calls.) If you don't want to add an additional virtual function dispatch, you can continue to have the most derived classes implement the interface, but then have them call non-virtual, potentially inlined common methods in the base class that provide the common code; or you can use CRTP to include code from the derived classes in what are syntactically base class methods. If you don't like those solutions, I'd be willing to consider trading a virtual function dispatch for less code redundancy. (Others can chime in on where they stand on these tradeoffs.) Also, it seems like preferentially replacing invalid blocks is orthogonal to the LRU vs. PseudoLRU replacement policy, and it would be nice to make it so. I'd be OK with breaking backward compatibility by making it universal and putting it in the base class too.
Summary: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Diff: |
Revision 5 (+807 -461) |
Summary: |
|
|---|
Summary: |
|
|---|
Description: |
|
|---|
-
src/mem/cache/tags/lru.hh (Diff revision 5) -
2003-2005,2014?
-
src/mem/cache/tags/lru.cc (Diff revision 5) -
why not unsigned?
looks good to me.. two minor issues, I think the copyrights you've updated should be 2003-2005, 2014 and i'm not sure why you changed from unsigned to int for extract set? otherwise ship it
-
src/mem/cache/tags/base_set_assoc.cc (Diff revision 5) -
It seems sensible to make it an unsigned param and only check for 0.
-
src/mem/cache/tags/base_set_assoc.cc (Diff revision 5) -
Same here, instead of an Int param it should probably be Unsigned.
-
src/mem/cache/tags/base_set_assoc.cc (Diff revision 5) -
Is Cycles, so it can never be < 0
-
src/mem/cache/tags/base_set_assoc.cc (Diff revision 5) -
A bit pedantic perhaps, but (slightly stupid) static code analysers get unhappy with the member variables not being initialised in the initialisation list. Could we add a default value, or move the assignment up to the initialisation list?
Some style-related suggestions, for the rest it looks great. Feel free to punt this to a later patch.
Looks good! Thanks for the changes.
