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 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -543,7 +544,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 = 3,
IaddrWidth = GPAddrBitsSv48x4,
PrivWidth = 3,
ItypeWidth = 4,
IlastsizeWidth = 1,
)
}

case object DebugOptionsKey extends Field[DebugOptions]
Expand Down Expand Up @@ -885,5 +894,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 @@ -240,13 +242,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 @@ -46,6 +46,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.fromTop.hartId := io.fromTop.hartId
ctrlBlock.io.frontend <> io.frontend
ctrlBlock.io.fromCSR.toDecode := intExuBlock.io.csrToDecode.get
ctrlBlock.io.fromCSR.traceCSR := intExuBlock.io.csrio.get.traceCSR
ctrlBlock.io.fromWB.wbData <> wbDataPath.io.toCtrlBlock.writeback
ctrlBlock.io.fromMem.stIn <> io.mem.stIn
ctrlBlock.io.fromMem.violation <> io.mem.memoryViolation
Expand Down Expand Up @@ -752,6 +754,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 @@ -947,6 +951,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
54 changes: 53 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,53 @@ 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))
}

// Trap/Xret only occor in block(0).
val tracePriv = Mux(Itype.isTrapOrXret(trace.io.toEncoder.blocks(0).bits.tracePipe.itype),
io.fromCSR.traceCSR.lastPriv,
io.fromCSR.traceCSR.currentPriv
)
io.traceCoreInterface.toEncoder.cause := io.fromCSR.traceCSR.cause.asUInt
io.traceCoreInterface.toEncoder.tval := io.fromCSR.traceCSR.tval.asUInt
io.traceCoreInterface.toEncoder.priv := tracePriv
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 @@ -686,6 +735,7 @@ class CtrlBlockIO()(implicit p: Parameters, params: BackendParams) extends XSBun
val frontend = Flipped(new FrontendToCtrlIO())
val fromCSR = new Bundle{
val toDecode = Input(new CSRToDecode)
val traceCSR = Input(new TraceCSR)
}
val toIssueBlock = new Bundle {
val flush = ValidIO(new Redirect)
Expand Down Expand Up @@ -754,6 +804,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
Loading
Loading