Skip to content

Commit 10d0da7

Browse files
committed
flush finish after all responses received
1 parent 755fbce commit 10d0da7

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

src/main/scala/radiance/memory/MuonDCache.scala

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ class CacheFlushUnit(implicit edge: TLEdgeOut, p: Parameters) extends L1HellaCac
6161

6262
val flushing = RegInit(false.B)
6363
val flushCounter = Counter(nSets * nWays)
64-
// val respPending = RegInit(false.B)
65-
// val respCounter = Counter(nSets * nWays)
64+
val srcWidth = io.wb_req.bits.source.getWidth - 1
65+
val inFlights = RegInit(0.U((srcWidth + 1).W))
6666

6767
when (io.flush) {
6868
assert(!flushing, "already flushing")
6969
flushing := true.B
7070
}
71-
io.busy := flushing
71+
io.busy := flushing || (inFlights > 0.U)
7272

7373
// when (io.wbReq.fire || io.meta_write.fire) {
7474
// val wrap = flushCounter.inc()
@@ -82,7 +82,7 @@ class CacheFlushUnit(implicit edge: TLEdgeOut, p: Parameters) extends L1HellaCac
8282
val wrap = flushCounter.inc()
8383
when (wrap) {
8484
flushing := false.B
85-
printf("CACHE FLUSH COMPLETE!\n")
85+
printf("all cache flush requests sent out\n")
8686
}
8787
}
8888

@@ -111,24 +111,24 @@ class CacheFlushUnit(implicit edge: TLEdgeOut, p: Parameters) extends L1HellaCac
111111
metaValid := false.B
112112
}
113113

114-
val wb_stall = WireInit(false.B)
115-
val wb_and_src_ready = io.wb_req.ready && !wb_stall
116-
val wb_and_src_fire = wb_and_src_ready && io.wb_req.valid
114+
val wbStall = WireInit(false.B)
115+
val wbAndSrcReady = io.wb_req.ready && !wbStall
116+
val wbAndSrcFire = wbAndSrcReady && io.wb_req.valid
117117

118118
val (isDirty, respType, nextCoh) = meta.coh.onCacheControl(M_FLUSH)
119119
// invalid line gets automatically skipped
120120

121121
// valid line: invalidate in tag array
122122
// need double fire for dirty lines
123-
io.meta_write.valid := metaValid && meta.coh.isValid() && (!isDirty || wb_and_src_ready)
123+
io.meta_write.valid := metaValid && meta.coh.isValid() && (!isDirty || wbAndSrcReady)
124124
io.meta_write.bits.way_en := metaReq.way_en
125125
io.meta_write.bits.idx := metaReq.idx
126126
io.meta_write.bits.tag := meta.tag
127127
io.meta_write.bits.data.tag := meta.tag
128128
io.meta_write.bits.data.coh := nextCoh
129129

130130
// dirty line: send a writeback request with voluntary release
131-
io.wb_req.valid := metaValid && meta.coh.isValid() && isDirty && io.meta_write.ready && !wb_stall
131+
io.wb_req.valid := metaValid && meta.coh.isValid() && isDirty && io.meta_write.ready && !wbStall
132132
io.wb_req.bits.idx := metaReq.idx
133133
io.wb_req.bits.tag := meta.tag
134134
io.wb_req.bits.param := respType
@@ -137,18 +137,16 @@ class CacheFlushUnit(implicit edge: TLEdgeOut, p: Parameters) extends L1HellaCac
137137

138138
// count and pray (voluntary releases do not require a response, reused src id probably ok)
139139
// the first half of the source space is mapped to releases, we have to avoid the second half
140-
val src_width = io.wb_req.bits.source.getWidth - 1
141-
io.wb_req.bits.source := Counter(wb_and_src_fire, 1 << src_width)._1
142-
val in_flights = RegInit(0.U((src_width + 1).W))
143-
when (wb_and_src_fire && !io.wb_resp_fire) {
144-
in_flights := in_flights + 1.U
145-
}.elsewhen (!wb_and_src_fire && io.wb_resp_fire) {
146-
in_flights := in_flights - 1.U
140+
io.wb_req.bits.source := Counter(wbAndSrcFire, 1 << srcWidth)._1
141+
when (wbAndSrcFire && !io.wb_resp_fire) {
142+
inFlights := inFlights + 1.U
143+
}.elsewhen (!wbAndSrcFire && io.wb_resp_fire) {
144+
inFlights := inFlights - 1.U
147145
}
148-
wb_stall := in_flights >= (1 << src_width).U
146+
wbStall := inFlights >= (1 << srcWidth).U
149147

150148
// assert(io.wb_req.fire === wb_and_src_fire)
151-
assert(!wb_and_src_fire || io.meta_write.fire)
149+
assert(!wbAndSrcFire || io.meta_write.fire)
152150
}
153151

154152
class MuonNonBlockingDCache(staticIdForMetadataUseOnly: Int,

0 commit comments

Comments
 (0)