Skip to content

Commit

Permalink
Support ctrl/meta-decoupled temporal prefetcher (#74)
Browse files Browse the repository at this point in the history
* bump huancun

* mainpipe: enhance prefetch-train bundle

* perf: add tp rollingperf

* prefetch: support ctrl/meta-decoupled temporal prefetcher
  • Loading branch information
wakafa1 authored Oct 21, 2023
1 parent df2f06c commit a6fa656
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 78 deletions.
22 changes: 22 additions & 0 deletions src/main/scala/coupledL2/CoupledL2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.chipsalliance.cde.config.Parameters
import scala.math.max
import coupledL2.prefetch._
import coupledL2.utils.XSPerfAccumulate
import huancun.{TPmetaReq, TPmetaResp}

trait HasCoupledL2Parameters {
val p: Parameters
Expand Down Expand Up @@ -212,6 +213,16 @@ class CoupledL2(implicit p: Parameters) extends LazyModule with HasCoupledL2Para
Some(BundleBridgeSink(Some(() => new PrefetchRecv)))
case _ => None
}
val tpmeta_source_node = prefetchOpt match {
case Some(param: PrefetchReceiverParams) =>
if (param.hasTPPrefetcher) Some(BundleBridgeSource(() => DecoupledIO(new TPmetaReq))) else None
case _ => None
}
val tpmeta_sink_node = prefetchOpt match {
case Some(param: PrefetchReceiverParams) =>
if (param.hasTPPrefetcher) Some(BundleBridgeSink(Some(() => ValidIO(new TPmetaResp)))) else None
case _ => None
}

class CoupledL2Imp(wrapper: LazyModule) extends LazyModuleImp(wrapper) {
val banks = node.in.size
Expand Down Expand Up @@ -284,6 +295,17 @@ class CoupledL2(implicit p: Parameters) extends LazyModule with HasCoupledL2Para
}
}

tpmeta_source_node match {
case Some(x) =>
x.out.head._1 <> prefetcher.get.tpio.tpmeta_port.get.req
case None =>
}
tpmeta_sink_node match {
case Some(x) =>
prefetcher.get.tpio.tpmeta_port.get.resp <> x.in.head._1
case None =>
}

def restoreAddress(x: UInt, idx: Int) = {
restoreAddressUInt(x, idx.U)
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/coupledL2/MainPipe.scala
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,9 @@ class MainPipe(implicit p: Parameters) extends L2Module {
train.bits.source := Mux(req_s3.mergeA, req_s3.aMergeTask.sourceId, req_s3.sourceId)
train.bits.vaddr.foreach(_ := Mux(req_s3.mergeA, req_s3.aMergeTask.vaddr.getOrElse(0.U), req_s3.vaddr.getOrElse(0.U)))
train.bits.hit := Mux(req_s3.mergeA, true.B, dirResult_s3.hit)
train.bits.prefetched := Mux(req_s3.mergeA, true.B, meta_s3.prefetch.get(false.B))
train.bits.prefetched := Mux(req_s3.mergeA, true.B, meta_s3.prefetch.getOrElse(false.B))
train.bits.pfsource := meta_s3.prefetchSrc.getOrElse(PfSource.NoWhere.id.U) // TODO
train.bits.reqsource := req_s3.reqSource
}

/* ======== Stage 4 ======== */
Expand Down
15 changes: 15 additions & 0 deletions src/main/scala/coupledL2/TopDownMonitor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class TopDownMonitor()(implicit p: Parameters) extends L2Module {
)
val l2prefetchLate = io.latePF

// PF Accuracy
XSPerfRolling(
cacheParams, "L2PrefetchAccuracy",
PopCount(l2prefetchUseful), PopCount(l2prefetchSent),
Expand All @@ -179,6 +180,11 @@ class TopDownMonitor()(implicit p: Parameters) extends L2Module {
PopCount(l2prefetchUsefulSMS), PopCount(l2prefetchSentSMS),
1000, clock, reset
)
XSPerfRolling(
cacheParams, "L2PrefetchAccuracyTP",
PopCount(l2prefetchUsefulTP), PopCount(l2prefetchSentTP),
1000, clock, reset
)
XSPerfRolling(
cacheParams, "L2PrefetchAccuracyStride",
PopCount(l2prefetchUsefulStride), PopCount(l2prefetchSentStride),
Expand All @@ -194,11 +200,15 @@ class TopDownMonitor()(implicit p: Parameters) extends L2Module {
PopCount(l2prefetchUsefulTP), PopCount(l2prefetchSentTP),
1000, clock, reset
)

// PF Late
XSPerfRolling(
cacheParams, "L2PrefetchLate",
PopCount(l2prefetchLate), PopCount(l2prefetchUseful),
1000, clock, reset
)

// PF Coverage
XSPerfRolling(
cacheParams, "L2PrefetchCoverage",
PopCount(l2prefetchUseful), PopCount(l2demandRequest),
Expand All @@ -214,6 +224,11 @@ class TopDownMonitor()(implicit p: Parameters) extends L2Module {
PopCount(l2prefetchUsefulSMS), PopCount(l2demandRequest),
1000, clock, reset
)
XSPerfRolling(
cacheParams, "L2PrefetchCoverageTP",
PopCount(l2prefetchUsefulTP), PopCount(l2demandRequest),
1000, clock, reset
)
XSPerfRolling(
cacheParams, "L2PrefetchCoverageStride",
PopCount(l2prefetchUsefulStride), PopCount(l2demandRequest),
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/coupledL2/prefetch/PrefetchReceiver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ case class PrefetchReceiverParams(n: Int = 32) extends PrefetchParameters {
override val hasPrefetchBit: Boolean = true
override val hasPrefetchSrc: Boolean = true
override val inflightEntries: Int = n
val hasTPPrefetcher: Boolean = true
}

class PrefetchReceiver()(implicit p: Parameters) extends PrefetchModule {
Expand Down
7 changes: 7 additions & 0 deletions src/main/scala/coupledL2/prefetch/Prefetcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PrefetchTrain(implicit p: Parameters) extends PrefetchBundle {
val hit = Bool()
val prefetched = Bool()
val pfsource = UInt(PfSource.pfSourceBits.W)
val reqsource = UInt(MemReqSource.reqSourceBits.W)

def addr: UInt = Cat(tag, set, 0.U(offsetBits.W))
}
Expand Down Expand Up @@ -123,6 +124,9 @@ class PrefetchQueue(implicit p: Parameters) extends PrefetchModule {

class Prefetcher(implicit p: Parameters) extends PrefetchModule {
val io = IO(new PrefetchIO)
val tpio = IO(new Bundle() {
val tpmeta_port = prefetchOpt.map(_ => new tpmetaPortIO)
})
/* io_l2_pf_en:
* chicken bits for whether L2 prefetchers are enabled
* it will control BOP and TP prefetchers
Expand Down Expand Up @@ -184,6 +188,9 @@ class Prefetcher(implicit p: Parameters) extends PrefetchModule {
pipe.io.in <> pftQueue.io.deq
io.req <> pipe.io.out

// tpmeta interface
tp.io.tpmeta_port <> tpio.tpmeta_port.get

XSPerfAccumulate(cacheParams, "prefetch_req_fromSMS", pfRcv.io.req.valid)
XSPerfAccumulate(cacheParams, "prefetch_req_fromBOP", l2_pf_en && bop.io.req.valid)
XSPerfAccumulate(cacheParams, "prefetch_req_fromTP", l2_pf_en && tp.io.req.valid)
Expand Down
Loading

0 comments on commit a6fa656

Please sign in to comment.