Skip to content

Commit 48e4e63

Browse files
committed
feat(Xstatistics): powerful perf counter
1 parent fcb8223 commit 48e4e63

File tree

4 files changed

+429
-5
lines changed

4 files changed

+429
-5
lines changed

src/main/scala/utility/ChiselTaggedTrace.scala

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,19 @@ import freechips.rocketchip.amba.ahb.AHBImpMaster.bundle
2424

2525
trait HasDPICUtils extends BlackBox with HasBlackBoxInline {
2626
var moduleName: String = ""
27-
def init(args: Bundle, negedge: Boolean = false, comb_output: Boolean = false) = {
27+
28+
/**
29+
*
30+
* make module that call dpic function
31+
*
32+
* io must contains "clock, reset, en"
33+
*
34+
* @param args input the io
35+
* @param negedge trigger on negedge clock
36+
* @param comb_output if has output, use wire out not reg
37+
* @param overrideFuncname override the dpic name, default is class name
38+
*/
39+
def init(args: Bundle, negedge: Boolean = false, comb_output: Boolean = false, overrideFuncname: String = "") {
2840
val field = args.elements.map(t => {
2941
val name = t._1
3042
val tpes = t._2.getClass.getMethods.map(x => x.getName()).toList
@@ -48,9 +60,9 @@ trait HasDPICUtils extends BlackBox with HasBlackBoxInline {
4860
throw new Exception
4961
}
5062

51-
val className = this.getClass().getSimpleName()
52-
moduleName = className + "_DPIC_Helper"
53-
val dpicFunc = lang.Character.toLowerCase(className.charAt(0)) + className.substring(1)
63+
val dpic_name = if (overrideFuncname.isEmpty()) this.getClass().getSimpleName() else overrideFuncname
64+
moduleName = dpic_name + "_DPIC_Helper"
65+
val dpicFunc = lang.Character.toLowerCase(dpic_name.charAt(0)) + dpic_name.substring(1)
5466
val verilog =
5567
s"""
5668
|import "DPI-C" function ${if (has_out) "longint unsigned" else "void"} $dpicFunc

src/main/scala/utility/LogUtils.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ private[utility] trait XSLogTap {
7777
object XSLog extends XSLogTap {
7878
private val logInfos = ListBuffer.empty[LogPerfParam]
7979
private val callBacks = ListBuffer.empty[(LogPerfIO) => Unit]
80+
private val callBacksWithClock = ListBuffer.empty[(LogPerfIO, Reset, Clock) => Unit]
8081
private val logModules = ListBuffer.empty[BaseModule]
8182

8283
private def unpackPrintable(pable: Printable): (String, Seq[Data]) = {
@@ -158,7 +159,9 @@ object XSLog extends XSLogTap {
158159
// As XSPerf depends on LogPerfIO, their apply will be buffered until collection
159160
// Register collect() method from Callers when first apply, then call that during collection
160161
def registerCaller(caller: LogPerfIO => Unit): Unit = callBacks += caller
162+
def registerCallerWithClock(caller: (LogPerfIO, Reset, Clock) => Unit): Unit = callBacksWithClock += caller
161163
def invokeCaller(ctrl: LogPerfIO): Unit = callBacks.foreach(caller => caller(ctrl))
164+
def invokeCallerWithClock(ctrl: LogPerfIO, reset: Reset, clock: Clock) = callBacksWithClock.foreach(caller => caller(ctrl, reset, clock))
162165

163166
// Should only be called during firrtl phase(ChiselStage)
164167
// PathName can not be accessed until circuit elaboration
@@ -205,6 +208,7 @@ private class LogPerfEndpoint()(implicit p: Parameters) extends Module {
205208
}
206209

207210
// To collect deferred call from XSPerf/..., invoke all registered caller
211+
XSLog.invokeCallerWithClock(io, reset, clock)
208212
XSLog.invokeCaller(io)
209213
// Group printfs with same cond to reduce system tasks for better thread schedule
210214
XSLog.tapInfos.groupBy(_.cond).values.foreach { infos =>

src/main/scala/utility/PerfCounterUtils.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ object XSPerfAccumulate extends HasRegularPerfName with XSLogTap {
7575
val next_counter = WireInit(0.U(64.W)).suggestName(perfName + "Next")
7676
next_counter := counter + perfCnt
7777
counter := Mux(perfClean, 0.U, next_counter)
78-
7978
XSPerfPrint(curMod)(perfDump, p"$perfName, $next_counter\n")
8079
}
8180
}

0 commit comments

Comments
 (0)