Skip to content

Commit

Permalink
CSR mcountinhibit (#2693)
Browse files Browse the repository at this point in the history
* CSR mcountinhibit

* mcountinhibit bit [1] is tied zero

* CSR.firstHPM
  • Loading branch information
ingallsj authored Nov 3, 2020
1 parent 4074969 commit 2040099
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/main/scala/rocket/CSR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,14 @@ class CSRFile(
val reg_vxsat = usingVector.option(Reg(Bool()))
val reg_vxrm = usingVector.option(Reg(UInt(io.vector.get.vxrm.getWidth.W)))

val reg_instret = WideCounter(64, io.retire)
val reg_cycle = if (enableCommitLog) reg_instret else withClock(io.ungated_clock) { WideCounter(64, !io.csr_stall) }
val reg_mcountinhibit = RegInit(0.U((CSR.firstHPM + nPerfCounters).W))
val reg_instret = WideCounter(64, io.retire, inhibit = reg_mcountinhibit(2))
val reg_cycle = if (enableCommitLog) WideCounter(64, io.retire, inhibit = reg_mcountinhibit(0))
else withClock(io.ungated_clock) { WideCounter(64, !io.csr_stall, inhibit = reg_mcountinhibit(0)) }
val reg_hpmevent = io.counters.map(c => Reg(init = UInt(0, xLen)))
(io.counters zip reg_hpmevent) foreach { case (c, e) => c.eventSel := e }
val reg_hpmcounter = io.counters.map(c => WideCounter(CSR.hpmWidth, c.inc, reset = false))
(io.counters zip reg_hpmevent) foreach { case (c, e) => c.eventSel := e }
val reg_hpmcounter = io.counters.zipWithIndex.map { case (c, i) =>
WideCounter(CSR.hpmWidth, c.inc, reset = false, inhibit = reg_mcountinhibit(CSR.firstHPM+i)) }

val mip = Wire(init=reg_mip)
mip.lip := (io.interrupts.lip: Seq[Bool])
Expand Down Expand Up @@ -517,6 +520,7 @@ class CSRFile(
read_mapping ++= vector_csrs

if (coreParams.haveBasicCounters) {
read_mapping += CSRs.mcountinhibit -> reg_mcountinhibit
read_mapping += CSRs.mcycle -> reg_cycle
read_mapping += CSRs.minstret -> reg_instret

Expand Down Expand Up @@ -893,6 +897,7 @@ class CSRFile(
when (decoded_addr(i + CSR.firstHPE)) { e := perfEventSets.maskEventSelector(wdata) }
}
if (coreParams.haveBasicCounters) {
when (decoded_addr(CSRs.mcountinhibit)) { reg_mcountinhibit := wdata & ~2.U(xLen.W) } // mcountinhibit bit [1] is tied zero
writeCounter(CSRs.mcycle, reg_cycle, wdata)
writeCounter(CSRs.minstret, reg_instret, wdata)
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/rocket/Instructions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ object CSRs {
val mhpmcounter29 = 0xb1d
val mhpmcounter30 = 0xb1e
val mhpmcounter31 = 0xb1f
val mcountinhibit = 0x320
val mhpmevent3 = 0x323
val mhpmevent4 = 0x324
val mhpmevent5 = 0x325
Expand Down Expand Up @@ -1322,6 +1323,7 @@ object CSRs {
res += mhpmcounter29
res += mhpmcounter30
res += mhpmcounter31
res += mcountinhibit
res += mhpmevent3
res += mhpmevent4
res += mhpmevent5
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/util/Counters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ object TwoWayCounter {
}

// a counter that clock gates most of its MSBs using the LSB carry-out
case class WideCounter(width: Int, inc: UInt = UInt(1), reset: Boolean = true)
case class WideCounter(width: Int, inc: UInt = UInt(1), reset: Boolean = true, inhibit: Bool = false.B)
{
private val isWide = width > 2*inc.getWidth
private val smallWidth = if (isWide) inc.getWidth max log2Up(width) else width
private val small = if (reset) Reg(init=UInt(0, smallWidth)) else Reg(UInt(width = smallWidth))
private val nextSmall = small +& inc
small := nextSmall
when (!inhibit) { small := nextSmall }

private val large = if (isWide) {
val r = if (reset) Reg(init=UInt(0, width - smallWidth)) else Reg(UInt(width = width - smallWidth))
when (nextSmall(smallWidth)) { r := r + UInt(1) }
when (nextSmall(smallWidth) && !inhibit) { r := r + UInt(1) }
r
} else null

Expand Down

0 comments on commit 2040099

Please sign in to comment.