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

Feat trace tmp1107 #3843

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
10 changes: 10 additions & 0 deletions src/main/scala/system/SoC.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ trait HasSoCParameter {
val NumCores = tiles.size
val EnableILA = soc.EnableILA

// Parameters for trace extension
val TraceTraceGroupNum = tiles.head.traceParams.TraceGroupNum
val TraceCauseWidth = tiles.head.XLEN
val TraceTvalWidth = tiles.head.traceParams.IaddrWidth
val TracePrivWidth = tiles.head.traceParams.PrivWidth
val TraceIaddrWidth = tiles.head.traceParams.IaddrWidth
val TraceItypeWidth = tiles.head.traceParams.ItypeWidth
val TraceIretireWidthCompressed = log2Up(tiles.head.RenameWidth * tiles.head.CommitWidth * 2)
val TraceIlastsizeWidth = tiles.head.traceParams.IlastsizeWidth

// L3 configurations
val L3InnerBusWidth = soc.L3InnerBusWidth
val L3BlockSize = soc.L3BlockSize
Expand Down
17 changes: 17 additions & 0 deletions src/main/scala/top/Top.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ class XSTop()(implicit p: Parameters) extends BaseXSSoc() with HasSoCParameter
val riscv_halt = Output(Vec(NumCores, Bool()))
val riscv_critical_error = Output(Vec(NumCores, Bool()))
val riscv_rst_vec = Input(Vec(NumCores, UInt(soc.PAddrBits.W)))
val traceCoreInterface = Vec(NumCores, new Bundle {
val fromEncoder = Input(new Bundle {
val enable = Bool()
val stall = Bool()
})
val toEncoder = Output(new Bundle {
val cause = UInt(TraceCauseWidth.W)
val tval = UInt(TraceTvalWidth.W)
val priv = UInt(TracePrivWidth.W)
val iaddr = UInt((TraceTraceGroupNum * TraceIaddrWidth).W)
val itype = UInt((TraceTraceGroupNum * TraceItypeWidth).W)
val iretire = UInt((TraceTraceGroupNum * TraceIretireWidthCompressed).W)
val ilastsize = UInt((TraceTraceGroupNum * TraceIlastsizeWidth).W)
})
})
})

val reset_sync = withClockAndReset(io.clock.asClock, io.reset) { ResetGen() }
Expand Down Expand Up @@ -294,6 +309,8 @@ class XSTop()(implicit p: Parameters) extends BaseXSSoc() with HasSoCParameter
core.module.io.clintTime := misc.module.clintTime
io.riscv_halt(i) := core.module.io.cpu_halt
io.riscv_critical_error(i) := core.module.io.cpu_crtical_error
io.traceCoreInterface(i).toEncoder := core.module.io.traceCoreInterface.toEncoder
core.module.io.traceCoreInterface.fromEncoder := io.traceCoreInterface(i).fromEncoder
core.module.io.reset_vector := io.riscv_rst_vec(i)
}

Expand Down
17 changes: 17 additions & 0 deletions src/main/scala/top/XSNoCTop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ class XSNoCTop()(implicit p: Parameters) extends BaseXSSoc with HasSoCParameter
val chi = new PortIO
val nodeID = Input(UInt(soc.NodeIDWidthList(issue).W))
val clintTime = Input(ValidIO(UInt(64.W)))
val traceCoreInterface = new Bundle {
val fromEncoder = Input(new Bundle {
val enable = Bool()
val stall = Bool()
})
val toEncoder = Output(new Bundle {
val cause = UInt(TraceCauseWidth.W)
val tval = UInt(TraceTvalWidth.W)
val priv = UInt(TracePrivWidth.W)
val iaddr = UInt((TraceTraceGroupNum * TraceIaddrWidth).W)
val itype = UInt((TraceTraceGroupNum * TraceItypeWidth).W)
val iretire = UInt((TraceTraceGroupNum * TraceIretireWidthCompressed).W)
val ilastsize = UInt((TraceTraceGroupNum * TraceIlastsizeWidth).W)
})
}
})
// imsic axi4lite io
val imsic_axi4lite = wrapper.u_imsic_bus_top.module.axi4lite.map(x => IO(chiselTypeOf(x)))
Expand Down Expand Up @@ -150,6 +165,8 @@ class XSNoCTop()(implicit p: Parameters) extends BaseXSSoc with HasSoCParameter
io.riscv_critical_error := core_with_l2.module.io.cpu_crtical_error
io.hartIsInReset := core_with_l2.module.io.hartIsInReset
core_with_l2.module.io.reset_vector := io.riscv_rst_vec
io.traceCoreInterface.toEncoder := core_with_l2.module.io.traceCoreInterface.toEncoder
core_with_l2.module.io.traceCoreInterface.fromEncoder := io.traceCoreInterface.fromEncoder

EnableClintAsyncBridge match {
case Some(param) =>
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/xiangshan/Bundle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import xiangshan.frontend.AllFoldedHistories
import xiangshan.frontend.AllAheadFoldedHistoryOldestBits
import xiangshan.frontend.RASPtr
import xiangshan.backend.rob.RobBundles.RobCommitEntryBundle
import xiangshan.backend.trace._

class ValidUndirectioned[T <: Data](gen: T) extends Bundle {
val valid = Bool()
Expand Down
10 changes: 8 additions & 2 deletions src/main/scala/xiangshan/L2Top.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ import freechips.rocketchip.diplomacy._
import freechips.rocketchip.interrupts._
import freechips.rocketchip.tile.{BusErrorUnit, BusErrorUnitParams, BusErrors, MaxHartIdBits}
import freechips.rocketchip.tilelink._
import coupledL2.{L2ParamKey, EnableCHI}
import coupledL2.{EnableCHI, L2ParamKey}
import coupledL2.tl2tl.TL2TLCoupledL2
import coupledL2.tl2chi.{TL2CHICoupledL2, PortIO, CHIIssue}
import coupledL2.tl2chi.{CHIIssue, PortIO, TL2CHICoupledL2}
import huancun.BankBitsKey
import system.HasSoCParameter
import top.BusPerfMonitor
import utility._
import xiangshan.cache.mmu.TlbRequestIO
import xiangshan.backend.fu.PMPRespBundle
import xiangshan.backend.trace.TraceCoreInterface

class L1BusErrorUnitInfo(implicit val p: Parameters) extends Bundle with HasSoCParameter {
val ecc_error = Valid(UInt(soc.PAddrBits.W))
Expand Down Expand Up @@ -161,6 +162,10 @@ class L2TopInlined()(implicit p: Parameters) extends LazyModule
val resetInFrontend = Input(Bool())
val toTile = Output(Bool())
}
val traceCoreInterface = new Bundle{
val fromCore = Flipped(new TraceCoreInterface)
val toTile = new TraceCoreInterface
}
val debugTopDown = new Bundle() {
val robTrueCommit = Input(UInt(64.W))
val robHeadPaddr = Flipped(Valid(UInt(36.W)))
Expand All @@ -183,6 +188,7 @@ class L2TopInlined()(implicit p: Parameters) extends LazyModule
io.hartId.toCore := io.hartId.fromTile
io.cpu_halt.toTile := io.cpu_halt.fromCore
io.cpu_critical_error.toTile := io.cpu_critical_error.fromCore
io.traceCoreInterface.toTile <> io.traceCoreInterface.fromCore
dontTouch(io.hartId)
dontTouch(io.cpu_halt)
dontTouch(io.cpu_critical_error)
Expand Down
23 changes: 21 additions & 2 deletions src/main/scala/xiangshan/Parameters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import xiangshan.backend.fu.FuConfig._
import xiangshan.backend.issue.{IntScheduler, IssueBlockParams, MemScheduler, SchdBlockParams, SchedulerType, VfScheduler, FpScheduler}
import xiangshan.backend.regfile._
import xiangshan.backend.BackendParams
import xiangshan.backend.trace._
import xiangshan.cache.DCacheParameters
import xiangshan.cache.prefetch._
import xiangshan.frontend.{BasePredictor, BranchPredictionResp, FTB, FakePredictor, RAS, Tage, ITTage, Tage_SC, FauFTB}
Expand Down Expand Up @@ -539,7 +540,15 @@ case class XSCoreParameters

// Parameters for trace extension.
// Trace parameters is useful for XSTOP.
val TraceGroupNum = 3 // Width to Encoder
val traceParams: TraceParams = new TraceParams(
HasEncoder = true,
TraceEnable = true,
TraceGroupNum = 1,
IaddrWidth = GPAddrBitsSv48x4,
PrivWidth = 3,
ItypeWidth = 4,
IlastsizeWidth = 1,
)
}

case object DebugOptionsKey extends Field[DebugOptions]
Expand Down Expand Up @@ -879,5 +888,15 @@ trait HasXSParameter {
protected def TriggerChainMaxLength = 2

// Parameters for Trace extension
def TraceGroupNum = coreParams.TraceGroupNum
def TraceGroupNum = coreParams.traceParams.TraceGroupNum
def HasEncoder = coreParams.traceParams.HasEncoder
def TraceEnable = coreParams.traceParams.TraceEnable
def CauseWidth = XLEN
def TvalWidth = coreParams.traceParams.IaddrWidth
def PrivWidth = coreParams.traceParams.PrivWidth
def IaddrWidth = coreParams.traceParams.IaddrWidth
def ItypeWidth = coreParams.traceParams.ItypeWidth
def IretireWidthInPipe = log2Up(RenameWidth * 2)
def IretireWidthCompressed = log2Up(RenameWidth * CommitWidth * 2)
def IlastsizeWidth = coreParams.traceParams.IlastsizeWidth
}
6 changes: 6 additions & 0 deletions src/main/scala/xiangshan/XSCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import utils._
import utility._
import xiangshan.backend._
import xiangshan.backend.fu.PMPRespBundle
import xiangshan.backend.trace.TraceCoreInterface
import xiangshan.cache.mmu._
import xiangshan.frontend._
import xiangshan.mem.L1PrefetchFuzzer
Expand Down Expand Up @@ -84,6 +85,7 @@ class XSCoreImp(outer: XSCoreBase) extends LazyModuleImp(outer)
val cpu_halt = Output(Bool())
val cpu_critical_error = Output(Bool())
val resetInFrontend = Output(Bool())
val traceCoreInterface = new TraceCoreInterface
val l2_pf_enable = Output(Bool())
val perfEvents = Input(Vec(numPCntHc * coreParams.L2NBanks + 1, new PerfEvent))
val beu_errors = Output(new XSL1BusErrors())
Expand Down Expand Up @@ -238,13 +240,17 @@ class XSCoreImp(outer: XSCoreBase) extends LazyModuleImp(outer)

io.cpu_halt := memBlock.io.outer_cpu_halt
io.cpu_critical_error := memBlock.io.outer_cpu_critical_error
io.traceCoreInterface <> backend.io.traceCoreInterface
io.beu_errors.icache <> memBlock.io.outer_beu_errors_icache
io.beu_errors.dcache <> memBlock.io.error.bits.toL1BusErrorUnitInfo(memBlock.io.error.valid)
io.beu_errors.l2 <> DontCare
io.l2_pf_enable := memBlock.io.outer_l2_pf_enable

memBlock.io.resetInFrontendBypass.fromFrontend := frontend.io.resetInFrontend
io.resetInFrontend := memBlock.io.resetInFrontendBypass.toL2Top
memBlock.io.traceCoreInterfaceBypass.fromBackend <> backend.io.traceCoreInterface
io.traceCoreInterface <> memBlock.io.traceCoreInterfaceBypass.toL2Top


if (debugOpts.ResetGen) {
backend.reset := memBlock.io.reset_backend
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/xiangshan/XSTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import top.{BusPerfMonitor, ArgParser, Generator}
import utility.{DelayN, ResetGen, TLClientsMerger, TLEdgeBuffer, TLLogger, Constantin, ChiselDB, FileRegisters}
import coupledL2.EnableCHI
import coupledL2.tl2chi.PortIO
import xiangshan.backend.trace.TraceCoreInterface

class XSTile()(implicit p: Parameters) extends LazyModule
with HasXSParameter
Expand Down Expand Up @@ -113,6 +114,7 @@ class XSTile()(implicit p: Parameters) extends LazyModule
val cpu_halt = Output(Bool())
val cpu_crtical_error = Output(Bool())
val hartIsInReset = Output(Bool())
val traceCoreInterface = new TraceCoreInterface
val debugTopDown = new Bundle {
val robHeadPaddr = Valid(UInt(PAddrBits.W))
val l3MissMatch = Input(Bool())
Expand Down Expand Up @@ -141,6 +143,8 @@ class XSTile()(implicit p: Parameters) extends LazyModule

l2top.module.io.hartIsInReset.resetInFrontend := core.module.io.resetInFrontend
io.hartIsInReset := l2top.module.io.hartIsInReset.toTile
l2top.module.io.traceCoreInterface.fromCore <> core.module.io.traceCoreInterface
io.traceCoreInterface <> l2top.module.io.traceCoreInterface.toTile

l2top.module.io.beu_errors.icache <> core.module.io.beu_errors.icache
l2top.module.io.beu_errors.dcache <> core.module.io.beu_errors.dcache
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/xiangshan/XSTileWrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import system.HasSoCParameter
import device.{IMSICAsync, MsiInfoBundle}
import coupledL2.tl2chi.{PortIO, AsyncPortIO, CHIAsyncBridgeSource}
import utility.{IntBuffer, ResetGen}
import xiangshan.backend.trace.TraceCoreInterface

// This module is used for XSNoCTop for async time domain and divide different
// voltage domain. Everything in this module should be in the core clock domain
Expand Down Expand Up @@ -61,6 +62,7 @@ class XSTileWrap()(implicit p: Parameters) extends LazyModule
val cpu_halt = Output(Bool())
val cpu_crtical_error = Output(Bool())
val hartIsInReset = Output(Bool())
val traceCoreInterface = new TraceCoreInterface
val debugTopDown = new Bundle {
val robHeadPaddr = Valid(UInt(PAddrBits.W))
val l3MissMatch = Input(Bool())
Expand Down Expand Up @@ -93,6 +95,7 @@ class XSTileWrap()(implicit p: Parameters) extends LazyModule
io.cpu_halt := tile.module.io.cpu_halt
io.cpu_crtical_error := tile.module.io.cpu_crtical_error
io.hartIsInReset := tile.module.io.hartIsInReset
io.traceCoreInterface <> tile.module.io.traceCoreInterface
io.debugTopDown <> tile.module.io.debugTopDown
tile.module.io.nodeID.foreach(_ := io.nodeID.get)

Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/xiangshan/backend/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import xiangshan.backend.fu.{FenceIO, FenceToSbuffer, FuConfig, FuType, PFEvent,
import xiangshan.backend.issue.EntryBundles._
import xiangshan.backend.issue.{CancelNetwork, Scheduler, SchedulerArithImp, SchedulerImpBase, SchedulerMemImp}
import xiangshan.backend.rob.{RobCoreTopDownIO, RobDebugRollingIO, RobLsqIO, RobPtr}
import xiangshan.backend.trace.TraceCoreInterface
import xiangshan.frontend.{FtqPtr, FtqRead, PreDecodeInfo}
import xiangshan.mem.{LqPtr, LsqEnqIO, SqPtr}

Expand Down Expand Up @@ -246,6 +247,7 @@ class BackendInlinedImp(override val wrapper: BackendInlined)(implicit p: Parame
ctrlBlock.io.robio.csr.intrBitSet := intExuBlock.io.csrio.get.interrupt
ctrlBlock.io.robio.csr.trapTarget := intExuBlock.io.csrio.get.trapTarget
ctrlBlock.io.robio.csr.isXRet := intExuBlock.io.csrio.get.isXRet
ctrlBlock.io.robio.csr.traceTrapInfo := intExuBlock.io.csrio.get.trapTraceInfo
ctrlBlock.io.robio.csr.wfiEvent := intExuBlock.io.csrio.get.wfi_event
ctrlBlock.io.robio.lsq <> io.mem.robLsqIO
ctrlBlock.io.robio.lsTopdownInfo <> io.mem.lsTopdownInfo
Expand Down Expand Up @@ -740,6 +742,8 @@ class BackendInlinedImp(override val wrapper: BackendInlined)(implicit p: Parame

io.toTop.cpuHalted := ctrlBlock.io.toTop.cpuHalt

io.traceCoreInterface <> ctrlBlock.io.traceCoreInterface

io.debugTopDown.fromRob := ctrlBlock.io.debugTopDown.fromRob
ctrlBlock.io.debugTopDown.fromCore := io.debugTopDown.fromCore

Expand Down Expand Up @@ -931,6 +935,8 @@ class BackendIO(implicit p: Parameters, params: BackendParams) extends XSBundle

val toTop = new BackendToTopBundle

val traceCoreInterface = new TraceCoreInterface

val fenceio = new FenceIO
// Todo: merge these bundles into BackendFrontendIO
val frontend = Flipped(new FrontendToCtrlIO)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/xiangshan/backend/Bundles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ object Bundles {
val instrSize = UInt(log2Ceil(RenameWidth + 1).W)
val dirtyFs = Bool()
val dirtyVs = Bool()
val traceBlockInPipe = new TracePipe(log2Up(RenameWidth * 2))
val traceBlockInPipe = new TracePipe(IretireWidthInPipe)

val eliminatedMove = Bool()
// Take snapshot at this CFI inst
Expand Down
48 changes: 47 additions & 1 deletion src/main/scala/xiangshan/backend/CtrlBlock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import xiangshan.backend.rob.{Rob, RobCSRIO, RobCoreTopDownIO, RobDebugRollingIO
import xiangshan.frontend.{FtqPtr, FtqRead, Ftq_RF_Components}
import xiangshan.mem.{LqPtr, LsqEnqIO}
import xiangshan.backend.issue.{FpScheduler, IntScheduler, MemScheduler, VfScheduler}
import xiangshan.backend.trace._

class CtrlToFtqIO(implicit p: Parameters) extends XSBundle {
val rob_commits = Vec(CommitWidth, Valid(new RobCommitInfo))
Expand Down Expand Up @@ -72,7 +73,8 @@ class CtrlBlockImp(
"robFlush" -> 1,
"load" -> params.LduCnt,
"hybrid" -> params.HyuCnt,
"store" -> (if(EnableStorePrefetchSMS) params.StaCnt else 0)
"store" -> (if(EnableStorePrefetchSMS) params.StaCnt else 0),
"trace" -> TraceGroupNum
))

private val numPcMemReadForExu = params.numPcReadPort
Expand Down Expand Up @@ -239,6 +241,48 @@ class CtrlBlockImp(
io.memStPcRead.foreach(_.data := 0.U)
}

/**
* trace begin
*/
val trace = Module(new Trace)
if(HasEncoder){
trace.io.fromEncoder.stall := io.traceCoreInterface.fromEncoder.stall
trace.io.fromEncoder.enable := io.traceCoreInterface.fromEncoder.enable
} else if(!HasEncoder && TraceEnable) {
trace.io.fromEncoder.enable := true.B
trace.io.fromEncoder.stall := false.B
} else if(!HasEncoder && !TraceEnable) {
trace.io.fromEncoder.enable := false.B
trace.io.fromEncoder.stall := false.B
}

trace.io.fromRob := rob.io.trace.traceCommitInfo
rob.io.trace.blockCommit := trace.io.blockRobCommit

if(backendParams.debugEn){
dontTouch(trace.io.toEncoder)
}

for ((pcMemIdx, i) <- pcMemRdIndexes("trace").zipWithIndex) {
val traceValid = trace.toPcMem(i).valid
pcMem.io.ren.get(pcMemIdx) := traceValid
pcMem.io.raddr(pcMemIdx) := trace.toPcMem(i).bits.ftqIdx.get.value
trace.io.fromPcMem(i) := pcMem.io.rdata(pcMemIdx).getPc(RegEnable(trace.toPcMem(i).bits.ftqOffset.get, traceValid))
}

io.traceCoreInterface.toEncoder.cause := trace.io.toEncoder.trap.cause.asUInt
io.traceCoreInterface.toEncoder.tval := trace.io.toEncoder.trap.tval.asUInt
io.traceCoreInterface.toEncoder.priv := trace.io.toEncoder.trap.priv.asUInt
io.traceCoreInterface.toEncoder.iaddr := VecInit(trace.io.toEncoder.blocks.map(_.bits.iaddr.get)).asUInt
io.traceCoreInterface.toEncoder.itype := VecInit(trace.io.toEncoder.blocks.map(_.bits.tracePipe.itype)).asUInt
io.traceCoreInterface.toEncoder.iretire := VecInit(trace.io.toEncoder.blocks.map(_.bits.tracePipe.iretire)).asUInt
io.traceCoreInterface.toEncoder.ilastsize := VecInit(trace.io.toEncoder.blocks.map(_.bits.tracePipe.ilastsize)).asUInt

/**
* trace end
*/


redirectGen.io.hartId := io.fromTop.hartId
redirectGen.io.oldestExuRedirect.valid := GatedValidRegNext(oldestExuRedirect.valid)
redirectGen.io.oldestExuRedirect.bits := RegEnable(oldestExuRedirect.bits, oldestExuRedirect.valid)
Expand Down Expand Up @@ -747,6 +791,8 @@ class CtrlBlockIO()(implicit p: Parameters, params: BackendParams) extends XSBun
val ratOldPest = new RatToVecExcpMod
})

val traceCoreInterface = new TraceCoreInterface

val perfInfo = Output(new Bundle{
val ctrlInfo = new Bundle {
val robFull = Bool()
Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/xiangshan/backend/MemBlock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import xiangshan.backend.datapath.NewPipelineConnect
import system.SoCParamsKey
import xiangshan.backend.fu.NewCSR.TriggerUtil
import xiangshan.ExceptionNO._
import xiangshan.backend.trace.TraceCoreInterface

trait HasMemBlockParameters extends HasXSParameter {
// number of memory units
Expand Down Expand Up @@ -318,6 +319,10 @@ class MemBlockInlinedImp(outer: MemBlockInlined) extends LazyModuleImp(outer)
val fromFrontend = Input(Bool())
val toL2Top = Output(Bool())
}
val traceCoreInterfaceBypass = new Bundle{
val fromBackend = Flipped(new TraceCoreInterface)
val toL2Top = new TraceCoreInterface
}
})

dontTouch(io.inner_hartId)
Expand Down Expand Up @@ -1869,6 +1874,7 @@ class MemBlockInlinedImp(outer: MemBlockInlined) extends LazyModuleImp(outer)
io.reset_backend := DontCare
}
io.resetInFrontendBypass.toL2Top := io.resetInFrontendBypass.fromFrontend
io.traceCoreInterfaceBypass.toL2Top <> io.traceCoreInterfaceBypass.fromBackend

// top-down info
dcache.io.debugTopDown.robHeadVaddr := io.debugTopDown.robHeadVaddr
Expand Down
Loading
Loading