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

PseudoLRU non-power-of-2 #2493

Merged
merged 17 commits into from
May 29, 2020
Merged

PseudoLRU non-power-of-2 #2493

merged 17 commits into from
May 29, 2020

Conversation

ingallsj
Copy link
Contributor

@ingallsj ingallsj commented May 28, 2020

Related issue:
Type of change: performance enhancement
Impact: API addition (no impact on existing code)
Development Phase: implementation

Release Notes

  • Formerly, the PseudoLRU algorithm would not replace all entries in a non-power-of-2 ways cache (or TLB). For example, PLRU with 6 ways results in way 5 (the sixth way) never being replaced unless it is otherwise invalidated. However, the way index is always "in bounds", so this is purely a performance bug, not a functional bug.
  • The new PseudoLRU algorithm is more verbose Chisel code, with extra if-statements to recursively descend an un-balanced binary tree.
  • I wrote tests to exercise the old and the new PLRU behavior. @hcook do I need to do anything else to include these in CI regressions?
  • While I was at it, I upgraded Replacement.scala to Chisel3.
  • I also added TrueLRU as an option for a replacement policy, based on code we had outside Rocket-chip.
  • Lastly, I exposed some more internals of the ReplacementPolicy classes as public function defs to use outside Rocket-chip.

@ingallsj ingallsj changed the title Plru pow2 PseudoLRU non-power-of-2 May 28, 2020
Copy link
Member

@hcook hcook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you actually want them to run on every PR CI you have to add them to UnittestSuite list in regression/Makefile

PLRU. get_next_state made my eyes cross so i applaud you for adding a unit test

@@ -61,7 +61,7 @@ endif

ifeq ($(SUITE),UnittestSuite)
PROJECT=freechips.rocketchip.unittest
CONFIGS=$(PROJECT).AMBAUnitTestConfig $(PROJECT).TLSimpleUnitTestConfig $(PROJECT).TLWidthUnitTestConfig
CONFIGS=$(PROJECT).AMBAUnitTestConfig $(PROJECT).TLSimpleUnitTestConfig $(PROJECT).TLWidthUnitTestConfig $(PROJECT).ScatterGatherTestConfig $(PROJECT).PLRUUnitTestConfig $(PROJECT).PowerQueueTestConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably too long of a line for lint et al, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about lint in makefiles, but the line keeps getting shorter as I remove tests that I tried to add but fail in CI regressions! 🙃

state(this_ways-3,half_ways-1)),
Mux(way(log2Ceil(this_ways)-1),
state(half_ways-2,0),
get_next_state(state(half_ways-2,0), way(log2Ceil(half_ways)-1,0), half_ways)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johningalls-sifive can you add some comments here or in another file that explains in detail what is going on? The software-engineer in me sees all these magic -3, -2, -1 values, and the lack of comments, and although I trust you that it does the right thing, I don't know if anyone besides you can maintain this function as it currently is! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree completely and went through the PseudoLRU code again. Let me know if it's improved now!

}
}

def get_next_state(state: UInt, way: UInt, this_ways: Int): UInt = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a fan of descriptive parameter and variable names. Would either n_ways or this_nways be better than just "this_ways", which (to me at least) does not clearly convey that it is the total number of ways?

Similarly, I'd change "way" to "touched_way", and if typing that is too annoying, say val w = touched_way, and use w in the code below for conciseness. That way, people fully understand the parameters to get_next_state() even without any comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to tree_nways and touch_way

@ingallsj
Copy link
Contributor Author

I think if you actually want them to run on every PR CI you have to add them to UnittestSuite list in regression/Makefile

this (and other) unit test that I tried to add to the PR CI regression Makefile fails with

/home/runner/work/rocket-chip/rocket-chip/src/main/resources/csrc/verilator.h:29:1: fatal error: /home/runner/work/rocket-chip/rocket-chip/emulator/generated-src/freechips.rocketchip.unittest.<name>Config.plusArgs: No such file or directory
 #endif
 ^
compilation terminated.

@ingallsj
Copy link
Contributor Author

the PLRU unit test is passing running this command locally:

make -C vsim run PROJECT=freechips.rocketchip.unittest CONFIG=freechips.rocketchip.unittest.PLRUUnitTestConfig

@ingallsj ingallsj merged commit 5b8b0f7 into master May 29, 2020
@ingallsj ingallsj deleted the plruPow2 branch May 29, 2020 17:09
mwachs5 pushed a commit that referenced this pull request Jun 24, 2020
* PLRUTest passing 2,4 ways

* PLRUTest passing 3 ways

* PLRUTest unexpected discrepancies with 6 ways: never replaces way 5

* PLRUTest failing 6 ways: never replaces way 5

* PLRU for non-power-of-two entries

* TrueLRU

* expose some class ReplacementPolicy public def

* PLRU gracefully handle 1 way

* add all remaining UnitTestConfig to regression

* TLXbarUnitTest fails to elaborate

* ECCUnitTest passes locally but fails in CI

* ScatterGatherTest passes locally but fails in CI

* PLRUUnitTest passes locally but fails in CI

* PowerQueueTestConfig passes locally but fails in CI

* more explanation in variable names and comments

* PseudoLRU get_next_state touch_way_sized padTo/extract

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

Successfully merging this pull request may close these issues.

3 participants