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

Store-to-load forwarding when cache miss in Lsu2 Plugin #43

Closed
atkarim opened this issue Sep 5, 2023 · 3 comments
Closed

Store-to-load forwarding when cache miss in Lsu2 Plugin #43

atkarim opened this issue Sep 5, 2023 · 3 comments

Comments

@atkarim
Copy link

atkarim commented Sep 5, 2023

Hi @Dolu1990,

I'm currently studying the Lsu2 plugin, and I may have an optimisation to suggest.

When a load instruction is processed in sharedPip, we check whether an older store instruction points to the same address in the checkSqMask and checkSqArbi stages.
If we detect an older store instruction with the same address, we have OLDER_STORE_HIT = True, and if this store is not waiting for address translation, we have OLDER_STORE_BYPASS_SUCCESS = True.

So, if this is the case, we're performing store-to-load forwarding, the data from the store is transmitted to the load, and written to the register.

Finally, if I've understood correctly, at the ctrl stage, we should enter the SUCCESS state, to indicate that the load instruction has been executed successfully. This is the case when the cache response is a cache hit.

However when the cache response in cacheRsp stage is a cache miss, we enter LOAD_MISS state in ctrl stage as rsp.redo = True.

}.elsewhen(IS_LOAD && rsp.redo) {

We will have to wait for the cache refill before entering the SUCCESS state, even if we already have the data we need to load.

My suggestion is to modify the above line in the Lsu2 plugin to avoid the LOAD_MISS state and enter the SUCCESS state directly when there is a store-to-load forwarding.

}.elsewhen(IS_LOAD && rsp.redo && !OLDER_STORE_BYPASS_SUCCESS) {

By doing this :

  • the cache will still be refilled, which is a good thing if subsequent load instructions point to that cache line.
  • the store-to-load forwarding is optimised and saves clock cycles.

I hope I've understood your plugin correctly, and that I haven't forgotten something that would make my suggestion invalid.

Thank you in advance for your feedback

@Dolu1990
Copy link
Member

Dolu1990 commented Sep 7, 2023

Hi,

Congratulation for being able to read the LSU2 monolite :)

So, yes you are right i think, when store to load bypass happen, we don't need a cache hit, but there is one very corner case thing :

  • NaxRiscv doesn't check store access being denied by the memory interconnect
  • So, if you assume a load is OK because it had a store bypass on cache miss, but the address accessed is effectively not memory mapped (denied by memory interconnect), then you will not produce a trap on the memory load either.

Very corner case.

@atkarim
Copy link
Author

atkarim commented Sep 7, 2023

Hi,

Thanks for your response.

I don't know if I can understand all of LSU2, but I'm trying. It's such a complex thing in an out-of-order core, congratulations on developing it.

Yes, you're right, I hadn't thought about that scenario, which is very interesting, you really have to think about everything.
This should require you to carry out a considerable amount of verification work during the development of your core.

@atkarim atkarim closed this as completed Sep 7, 2023
@Dolu1990
Copy link
Member

Dolu1990 commented Sep 7, 2023

Hi,

This should require you to carry out a considerable amount of verification work during the development of your core.

Debugging things is kind of easy, as long as the CPU behaviour is cross checked against a reference RISC-V model to catch the issue as soon as it happens. The main issue i git is to get "interresting" stimulus. https://github.com/chipsalliance/riscv-dv is unfortunatly System verilog, so not realy open-source dev friendly.

Currently i'm mostly using "booting linux" as a "indepth" stimulus generator, which isn't realy great XD

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

2 participants