Skip to content

Commit dee5eec

Browse files
klin02ngc7331
andcommitted
fix(difftest): add masked RefillEvent, disable for now
After #3051, we have supported low-power read (read only 5 out of 8 8B-banks) in ICacheDataArray, and in V3, it was further modified to dynamically compute the mask based on the taken branch location. Though, previous DiffRefillEvent does not support masked comparison, instead it checks entire 512bit, so it will fail if we enable checks on cacheid >=3 (OpenXiangShan/difftest#712). As we're refactoring ICache recently, we need this check to ensure the refactored code is working properly. This commit removes unused idtfr and introduces masked refill-check for Difftest, where each mask bit controls comparison of 8B data. However, as the newly added masked Refill fails CI, we disable it for now, and wait for later fixup. Co-authored-by: ngc7331 <[email protected]>
1 parent 9beb7e5 commit dee5eec

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

src/main/scala/xiangshan/cache/dcache/mainpipe/MissQueue.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ class MissQueue(edge: TLEdgeOut, reqNum: Int)(implicit p: Parameters) extends DC
12971297
difftest.valid := io.refill_to_ldq.valid && io.refill_to_ldq.bits.hasdata && io.refill_to_ldq.bits.refill_done
12981298
difftest.addr := io.refill_to_ldq.bits.addr
12991299
difftest.data := io.refill_to_ldq.bits.data_raw.asTypeOf(difftest.data)
1300-
difftest.idtfr := DontCare
1300+
difftest.mask := VecInit.fill(difftest.mask.getWidth)(true.B).asUInt
13011301
}
13021302

13031303
// Perf count

src/main/scala/xiangshan/cache/mmu/L2TLB.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ class L2TLBImp(outer: L2TLB)(implicit p: Parameters) extends PtwModule(outer) wi
553553
difftest.valid := cache.io.refill.valid
554554
difftest.addr := difftest_ptw_addr(RegEnable(mem.d.bits.source, mem.d.valid))
555555
difftest.data := refill_data.asTypeOf(difftest.data)
556-
difftest.idtfr := DontCare
556+
difftest.mask := VecInit.fill(difftest.mask.getWidth)(true.B).asUInt
557557
}
558558

559559
if (env.EnableDifftest) {

src/main/scala/xiangshan/frontend/icache/ICacheMainPipe.scala

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -643,29 +643,28 @@ class ICacheMainPipe(implicit p: Parameters) extends ICacheModule with HasICache
643643
******************************************************************************
644644
*/
645645
if (env.EnableDifftest) {
646-
val discards = (0 until PortNumber).map { i =>
647-
ExceptionType.hasException(toIFU.bits.exception(i)) ||
648-
toIFU.bits.pmp_mmio(i) ||
649-
Pbmt.isUncache(toIFU.bits.itlb_pbmt(i))
650-
}
651-
val blkPaddrAll = s2_req_paddr.map(addr => (addr(PAddrBits - 1, blockOffBits) << blockOffBits).asUInt)
652-
(0 until ICacheDataBanks).foreach { i =>
653-
val diffMainPipeOut = DifftestModule(new DiffRefillEvent, dontCare = true)
654-
diffMainPipeOut.coreid := io.hartId
655-
diffMainPipeOut.index := (3 + i).U
656-
657-
val bankSel = getBankSel(s2_req_offset, s2_valid).reduce(_ | _)
658-
val lineSel = getLineSel(s2_req_offset)
659-
660-
diffMainPipeOut.valid := s2_fire && bankSel(i).asBool && Mux(lineSel(i), !discards(1), !discards(0))
661-
diffMainPipeOut.addr := Mux(
662-
lineSel(i),
663-
blkPaddrAll(1) + (i.U << log2Ceil(blockBytes / ICacheDataBanks)).asUInt,
664-
blkPaddrAll(0) + (i.U << log2Ceil(blockBytes / ICacheDataBanks)).asUInt
665-
)
666-
667-
diffMainPipeOut.data := s2_datas(i).asTypeOf(diffMainPipeOut.data)
668-
diffMainPipeOut.idtfr := DontCare
646+
val bankSel = getBankSel(s2_req_offset, s2_valid)
647+
648+
// do difftest for each fetched cache line
649+
s2_req_paddr.zipWithIndex.foreach { case (pa, i) =>
650+
val difftest = DifftestModule(new DiffRefillEvent, dontCare = true)
651+
difftest.coreid := io.hartId
652+
difftest.index := (3 + i).U // magic number 3/4: ICache MainPipe refill test
653+
654+
difftest.valid := false.B
655+
// difftest.valid := s2_fire && !(
656+
// ExceptionType.hasException(toIFU.bits.exception(i)) ||
657+
// toIFU.bits.pmp_mmio(i) ||
658+
// Pbmt.isUncache(toIFU.bits.itlb_pbmt(i))
659+
// )
660+
difftest.addr := Cat(pa(PAddrBits - 1, blockOffBits), 0.U(blockOffBits.W))
661+
difftest.data := s2_datas.asTypeOf(difftest.data)
662+
// NOTE: each mask bit controls (512bit / difftest.mask.getWidth) (currently 64bit) comparison
663+
// this only works for DataBanks <= difftest.mask.getWidth (and isPow2)
664+
difftest.mask := VecInit((0 until difftest.mask.getWidth).map { j =>
665+
// the j-th mask locates in (j / (difftest.mask.getWidth / DataBanks)) bank
666+
bankSel(i)(j / (difftest.mask.getWidth / ICacheDataBanks))
667+
}).asUInt
669668
}
670669
}
671670
}

src/main/scala/xiangshan/frontend/icache/ICacheMissUnit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,6 @@ class ICacheMissUnit(edge: TLEdgeOut)(implicit p: Parameters) extends ICacheModu
476476
difftest.valid := write_sram_valid
477477
difftest.addr := Cat(mshr_resp.blkPaddr, 0.U(blockOffBits.W))
478478
difftest.data := respDataReg.asTypeOf(difftest.data)
479-
difftest.idtfr := DontCare
479+
difftest.mask := VecInit.fill(difftest.mask.getWidth)(true.B).asUInt
480480
}
481481
}

0 commit comments

Comments
 (0)