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

fix(ICache): block waylookup if there is a pending gpf #3719

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/main/scala/xiangshan/frontend/icache/WayLookup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class WayLookup(implicit p: Parameters) extends ICacheModule {

private val gpf_entry = RegInit(0.U.asTypeOf(Valid(new WayLookupGPFEntry)))
private val gpfPtr = RegInit(WayLookupPtr(false.B, 0.U))
private val gpf_hit = gpfPtr === readPtr && gpf_entry.valid

when(io.flush) {
// we don't need to reset gpfPtr, since the valid is actually gpf_entries.excp_tlb_gpf
Expand Down Expand Up @@ -143,25 +144,38 @@ class WayLookup(implicit p: Parameters) extends ICacheModule {
* read
******************************************************************************
*/
// if the entry is empty, but there is a valid write, we can bypass it to read port (maybe timing critical)
private val can_bypass = empty && io.write.valid
io.read.valid := !empty || io.write.valid
when (empty && io.write.valid) { // bypass
when (can_bypass) {
io.read.bits := io.write.bits
}.otherwise {
}.otherwise { // can't bypass
io.read.bits.entry := entries(readPtr.value)
io.read.bits.gpf := Mux(readPtr === gpfPtr && gpf_entry.valid, gpf_entry.bits, 0.U.asTypeOf(new WayLookupGPFEntry))
when(gpf_hit) { // ptr match && entry valid
io.read.bits.gpf := gpf_entry.bits
// also clear gpf_entry.valid when it's read, note this will be override by write (L175)
when (io.read.fire) {
gpf_entry.valid := false.B
}
}.otherwise { // gpf not hit
io.read.bits.gpf := 0.U.asTypeOf(new WayLookupGPFEntry)
}
}

/**
******************************************************************************
* write
******************************************************************************
*/
io.write.ready := !full
// if there is a valid gpf to be read, we should stall the write
private val gpf_stall = gpf_entry.valid && !(io.read.fire && gpf_hit)
io.write.ready := !full && !gpf_stall
when(io.write.fire) {
entries(writePtr.value) := io.write.bits.entry
// save gpf iff no gpf is already saved
when(!gpf_entry.valid && io.write.bits.itlb_exception.map(_ === ExceptionType.gpf).reduce(_||_)) {
gpf_entry.valid := true.B
when(io.write.bits.itlb_exception.map(_ === ExceptionType.gpf).reduce(_||_)) {
// if gpf_entry is bypassed, we don't need to save it
// note this will override the read (L156)
gpf_entry.valid := !(can_bypass && io.read.fire)
gpf_entry.bits := io.write.bits.gpf
gpfPtr := writePtr
}
Expand Down
Loading