Skip to content

Commit

Permalink
Debug: use LogPerfControl from difftest (#165)
Browse files Browse the repository at this point in the history
Avoid the large number of timer counters and global enable wirings.
  • Loading branch information
poemonsense authored Jan 20, 2024
1 parent a912f32 commit ee6dc8b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
2 changes: 1 addition & 1 deletion difftest
25 changes: 3 additions & 22 deletions src/main/scala/sim/NutShellSim.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@

package sim

import system._
import nutcore.NutCoreConfig

import chisel3._
import chisel3.util._
import chisel3.util.experimental.BoringUtils

import bus.axi4._
import chisel3._
import device.AXI4RAM
import nutcore._
import utils.GTimer
import difftest._
import nutcore.NutCoreConfig
import system._

class SimTop extends Module {
lazy val config = NutCoreConfig(FPGAPlatform = false)
Expand All @@ -48,18 +42,5 @@ class SimTop extends Module {
soc.io.meip := mmio.io.meip

val difftest = DifftestModule.finish("nutshell")

val log_begin, log_end, log_level = WireInit(0.U(64.W))
log_begin := difftest.logCtrl.begin
log_end := difftest.logCtrl.end
log_level := difftest.logCtrl.level

assert(log_begin <= log_end)
BoringUtils.addSource(WireInit((GTimer() >= log_begin) && (GTimer() < log_end)), "DISPLAY_ENABLE")

// make BoringUtils not report boring exception when EnableDebug is set to false
val dummyWire = WireInit(false.B)
BoringUtils.addSink(dummyWire, "DISPLAY_ENABLE")

difftest.uart <> mmio.io.uart
}
26 changes: 9 additions & 17 deletions src/main/scala/utils/Debug.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
package utils

import chisel3._
import chisel3.util._
import chisel3.util.experimental.BoringUtils
import utils.LogLevel.LogLevel

import difftest.common.LogPerfControl
import nutcore.NutCoreConfig
import utils.LogLevel.LogLevel

object LogLevel extends Enumeration {
type LogLevel = Value
Expand All @@ -36,23 +34,17 @@ object LogLevel extends Enumeration {

object LogUtil {

def displayLog: Bool = {
val enableDisplay = WireInit(false.B)
BoringUtils.addSink(enableDisplay, "DISPLAY_ENABLE")
enableDisplay
def control(): (Bool, UInt) = {
val control = LogPerfControl()
(control.logEnable, control.timer)
}

// def LogLevel: UInt = {
// val log_level = WireInit(0.U(64.W))
// BoringUtils.addSink(log_level, "DISPLAY_LOG_LEVEL")
// log_level
// }

def apply(debugLevel: LogLevel)
(prefix: Boolean, cond: Bool, pable: Printable)
(implicit name: String): Any = {
val commonInfo = p"[${GTimer()}] $name: "
when (cond && displayLog) {
val c = control()
val commonInfo = p"[${c._2}] $name: "
when (cond && c._1) {
if(prefix) printf(commonInfo)
printf(pable)
}
Expand All @@ -77,7 +69,7 @@ sealed abstract class LogHelper(val logLevel: LogLevel) {
// NOOP/NutShell style debug
def apply(flag: Boolean = NutCoreConfig().EnableDebug, cond: Bool = true.B)(body: => Unit): Any = {
if(NutCoreConfig().EnhancedLog){
if(flag) { when (cond && LogUtil.displayLog) { body } }
if(flag) { when (cond && LogUtil.control()._1) { body } }
} else {
if(flag) { when (cond) { body } }
}
Expand Down

0 comments on commit ee6dc8b

Please sign in to comment.