Skip to content

Conversation

seldridge
Copy link
Member

@seldridge seldridge commented Mar 8, 2025

Add a missing ChiselSim ControlAPI. This currently only includes APIs to
enable and disalbe waveforms. This API was previously inaccessible
because you would need to get at an svsim Controller to use it.

Note: the enable/disable waveform APIs will have no effect unless the
simulator is compiled with waveform support.

Release Notes

Add ControlAPI to ChiselSim. This adds enableWaves and disableWaves functions. These functions require compiling a simulator with waveform support.

@seldridge seldridge added the Feature New feature, will be included in release notes label Mar 8, 2025
@seldridge seldridge force-pushed the dev/seldridge/stimulus-enable-disable-waves branch from 13e0e43 to 6e1fa37 Compare March 8, 2025 02:10
@seldridge seldridge changed the title [chiselsim] Add Enable/DisableWaves stimulus [chiselsim] Add Enable/DisableWaves control Mar 8, 2025
Add a missing ChiselSim ControlAPI.  This currently only includes APIs to
enable and disalbe waveforms.  This API was previously inaccessible
because you would need to get at an svsim Controller to use it.

Note: the enable/disable waveform APIs will have no effect unless the
simulator is compiled with waveform support.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
@seldridge seldridge force-pushed the dev/seldridge/stimulus-enable-disable-waves branch from 6e1fa37 to 5e9d29c Compare March 8, 2025 03:10
@seldridge seldridge changed the title [chiselsim] Add Enable/DisableWaves control [chiselsim] Add ControlAPI, Waveform Enable/Disable Support Mar 8, 2025
@seldridge seldridge changed the title [chiselsim] Add ControlAPI, Waveform Enable/Disable Support [chiselsim] Add ControlAPI w/ Waveform Enable/Disable Support Mar 8, 2025
Comment on lines +18 to +20
def enableWaves(): Unit = {
AnySimulatedModule.current.controller.setTraceEnabled(true)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for this to error if the simulator was not compiled with waveform dumping?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frustratingly, I didn't see a clean way of doing this. I plan to come back and do this as part of svsim cleanup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a pure-Verilog solution to do this here: #4787

This produces output like:

# ./mill 'chisel[2.13.16].test.testOnly' 'chiselTests.simulator.scalatest.FooSpec' -- -z "terminate before 11 cycles" 
[358/365] chisel[2.13.16].test.compile
[358] [info] compiling 1 Scala source to /Users/schuylereldridge/repos/github.com/chipsalliance/chisel/out/chisel/2.13.16/test/compile.dest/classes ...
[358] [info] done compiling
[365/365] chisel[2.13.16].test.testOnly
[365] FooSpec:
[365] Foo
[365] Bar
[365] - should terminate before 11 cycles have elapsed *** FAILED ***
[365]   chisel3.simulator.Exceptions$AssertionFailed: One or more assertions failed during Chiselsim simulation
[365] ------------------------------------------------------------------------------
[365] The following assertion failures were extracted from the log file:
[365] 
[365]   lineNo  line
[365]   ----------------------------------------------------------------------------
[365]        0  [4] %Error: testbench.sv:97: Assertion failed in TOP.svsimTestbench.simulation_enableTrace: Cannot enable waves as this simulator was not compiled to support them
[365] 
[365] For more information, see the complete log file:
[365] 
[365]   build/chiselsim/FooSpec/Bar/should-terminate-before-11-cycles-have-elapsed/workdir-verilator/simulation-log.txt
[365] ------------------------------------------------------------------------------
[365]   ...
[365] Run completed in 1 second, 970 milliseconds.
[365] Total number of tests run: 1
[365] Suites: completed 1, aborted 0
[365] Tests: succeeded 0, failed 1, canceled 0, ignored 0, pending 0
[365] *** 1 TEST FAILED ***
[365/365] ======================= chisel[2.13.16].test.testOnly chiselTests.simulator.scalatest.FooSpec -- -z terminate before 11 cycles ====================== 4s
1 tasks failed
chisel[2.13.16].test.testOnly 1 tests failed: 
  chiselTests.simulator.scalatest.FooSpec Bar should terminate before 11 cycles have elapsed

Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See question. I don't love that this is global but that's not this PRs fault, good to expose.

@seldridge seldridge merged commit e38904d into main Mar 11, 2025
15 checks passed
@seldridge seldridge deleted the dev/seldridge/stimulus-enable-disable-waves branch March 11, 2025 19:27
@kammoh
Copy link
Contributor

kammoh commented Mar 12, 2025

Excited to see these improvements finally landing on svsim 🎉
Really appreciate the great work!
With the current API, is it possible to enable trace generation before reset procedure completes?
Specifically, I’d like to have the reset assertion and deassertion present in the generated waveform.

@seldridge
Copy link
Member Author

With the current API, it possible to enable trace generation before reset procedure completes?

I'm trying to figure out the right way to expose this via SimulatorAPI.simulate (or not to expose it). After a7effb7, the reset initialization procedure is factored out to reusable stimulus.

So, the way to do this today is to use simulateRaw like:

simulateRaw(new Foo) { case dut => 
  enableWaves()
  ResetProcedure.module()(dut) // Or ResetProcedure.any if you don't have a Module
  // user stimulus
}

I'm considering adding an argument like enableWavesAtTimeZero argument to simulate which would do this for you. However, I'm somewhat concerned about the simulate API getting overly complex. That said, going the other direction and moving everything to use simulateRaw and then having that replace simulate gets tedious as every test needs the ResetProcedure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature, will be included in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants