From c974407d911debb213edd1087ff54bdaa6039c8a Mon Sep 17 00:00:00 2001 From: Luoshan Cai <60723329+cailuoshan@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:52:04 +0800 Subject: [PATCH] Directory: choose other free way when refill way has conflict mshr entry, instead of refillRetry (#103) Co-authored-by: Cai Luoshan --- src/main/scala/coupledL2/Directory.scala | 39 +++++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/scala/coupledL2/Directory.scala b/src/main/scala/coupledL2/Directory.scala index f89e67b3..a440f260 100644 --- a/src/main/scala/coupledL2/Directory.scala +++ b/src/main/scala/coupledL2/Directory.scala @@ -182,17 +182,39 @@ class Directory(implicit p: Parameters) extends L2Module { val metaValidVec = metaAll_s3.map(_.state =/= MetaData.INVALID) val hitVec = tagMatchVec.zip(metaValidVec).map(x => x._1 && x._2) + /* ====== refill retry ====== */ + // when refill, ways that have not finished writing its refillData back to DS (in MSHR Release), + // or using by Alias-Acquire (hit), can not be used for replace. + // choose free way to refill, if all ways are occupied, we cancel the Grant and LET IT RETRY + // compare is done at Stage2 for better timing + val occWayMask_s2 = VecInit(io.msInfo.map(s => + Mux( + s.valid && (s.bits.set === req_s2.set) && (s.bits.blockRefill || s.bits.dirHit), + UIntToOH(s.bits.way, ways), + 0.U(ways.W) + ) + )).reduceTree(_ | _) + + val freeWayMask_s3 = RegEnable(~occWayMask_s2, refillReqValid_s2) + val refillRetry = !(freeWayMask_s3.orR) + val hitWay = OHToUInt(hitVec) val replaceWay = WireInit(UInt(wayBits.W), 0.U) val (inv, invalidWay) = invalid_way_sel(metaAll_s3, replaceWay) val chosenWay = Mux(inv, invalidWay, replaceWay) // if chosenWay not in wayMask, then choose a way in wayMask - // TODO: consider remove this is not used for better timing // for retry bug fixing: if the chosenway cause retry last time, choose another way - val finalWay = Mux( + /*val finalWay = Mux( req_s3.wayMask(chosenWay), chosenWay, PriorityEncoder(req_s3.wayMask) + )*/ + // for retry bug fixing: if the chosenway not in freewaymask, choose another way + // TODO: req_s3.wayMask not take into consideration + val finalWay = Mux( + freeWayMask_s3(chosenWay), + chosenWay, + PriorityEncoder(freeWayMask_s3) ) val hit_s3 = Cat(hitVec).orR @@ -217,19 +239,6 @@ class Directory(implicit p: Parameters) extends L2Module { io.read.ready := !io.metaWReq.valid && !io.tagWReq.valid && !replacerWen - /* ====== refill retry ====== */ - // if refill chooses a way that has not finished writing its refillData back to DS (in MSHR Release), - // or the way is using by Alias-Acquire (hit), we cancel the Grant and LET IT RETRY - - // comparing set is done at Stage2 for better timing - val wayConflictPartI = RegEnable(VecInit(io.msInfo.map(s => - s.valid && s.bits.set === req_s2.set)).asUInt, refillReqValid_s2) - - val wayConflictPartII = VecInit(io.msInfo.map(s => - (s.bits.blockRefill || s.bits.dirHit) && s.bits.way === finalWay - )).asUInt - val refillRetry = (wayConflictPartI & wayConflictPartII).orR - /* ======!! Replacement logic !!====== */ /* ====== Read, choose replaceWay ====== */ val repl_state_s3 = if(random_repl) {