Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Fix issues in IPCSimulatorContext (VCS) simulations #570

Merged
merged 2 commits into from
Dec 5, 2022

Conversation

mwachs5
Copy link
Contributor

@mwachs5 mwachs5 commented Dec 5, 2022

  • IPCSimulatorContext: better synchronization on the logs
  • TestApplicationException: changes for more useful assertion failure messages

Fixes #569 and #568

jackkoenig and others added 2 commits December 5, 2022 03:45
* IPCSimulatorContext: better synchronization on the logs

* TestApplicationException: changes for more useful assertion failure messages
Copy link
Collaborator

@ekiwi ekiwi left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks.

try {
tester.finish() // needed to dump VCDs + terminate any external process
} catch {
case e: TestApplicationException => throw new ChiselAssertionError(s"Simulator exited sooner than expected. See logs for more information about what is assumed to be a Chisel Assertion which failed.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer if the IPC mechanism could actually communicate if an assertion failed instead of the simulator crashing for some other reason similar to how the Verilator backend does it:

However, this is an improvement over the status quo, so I am happy to get it in for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i wasn't sure how to determine. It would appear that VCS returns 0 even if assert fires. Talking to some folks here i was told its not common to look at VCS error code to determine if an assertion failed. SO this would involve parsing log messages??

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure what the best approach would be. Verilator allows you to hook into the assertion mechanism. Not sure if there is a similar API for VPI. This would be cool future work, but of course nothing that will hold up this PR.

@@ -57,7 +57,11 @@ private[chiseltest] class IPCSimulatorContext(
private def startProcess(cmd: Seq[String], logs: ArrayBuffer[String], cwd: os.Path): Process = {
val processBuilder = Process(cmd, cwd = cwd.toIO)
// This makes everything written to stderr get added as lines to logs
val processLogger = ProcessLogger(println, logs += _) // don't log stdout
val processLogger = ProcessLogger(println, { str =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the lambda here have to be re-entrant? I did not know that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's less about reentrancy and more about thread safety with the reads in dumpLogs below. We sometimes see "Mutation occurred during iteration" exceptions. This is the straightforward fix, an alternative would be to use a thread-safe Queue like java.util.concurrent.ConcurrentLinkedQueue

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just wondered which other function is accessing the logs.

inChannel.close()
outChannel.close()
cmdChannel.close()
dumpLogs()
Copy link
Collaborator

Choose a reason for hiding this comment

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

would moving the dumpLongs command until after the channels are closed resolve the problem without adding the mutex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this change is not sufficient on its own. Is that what you are asking?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok

@ekiwi ekiwi added this to the 0.5.x milestone Dec 5, 2022
@ekiwi
Copy link
Collaborator

ekiwi commented Dec 5, 2022

This does need a sbt scalafmtAll in order to pass CI.

@CLAassistant
Copy link

CLAassistant commented Dec 5, 2022

CLA assistant check
All committers have signed the CLA.

@mwachs5
Copy link
Contributor Author

mwachs5 commented Dec 5, 2022

the CI failure looks like a verilator download issue...? Not sure how to re-launch CI

@ekiwi
Copy link
Collaborator

ekiwi commented Dec 5, 2022

the CI failure looks like a verilator download issue...? Not sure how to re-launch CI

You might not have the privileges to. The Mac CI stuff is very brittle and needs a couple of attempts. I will re-launch things until it all passes. Thanks for the contribution!

@ekiwi ekiwi added the Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. label Dec 5, 2022
@mergify mergify bot merged commit 5956488 into ucb-bar:main Dec 5, 2022
mergify bot pushed a commit that referenced this pull request Dec 5, 2022
* Fix issues in VCS simulations

* IPCSimulatorContext: better synchronization on the logs

* TestApplicationException: changes for more useful assertion failure messages

* scalafmt

Co-authored-by: Jack Koenig <[email protected]>
(cherry picked from commit 5956488)
@mergify mergify bot added the Backported This PR has been backported to marked stable branch label Dec 5, 2022
mergify bot added a commit that referenced this pull request Dec 5, 2022
* Fix issues in VCS simulations

* IPCSimulatorContext: better synchronization on the logs

* TestApplicationException: changes for more useful assertion failure messages

* scalafmt

Co-authored-by: Jack Koenig <[email protected]>
(cherry picked from commit 5956488)

Co-authored-by: Megan Wachs <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Backported This PR has been backported to marked stable branch Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TestApplicationException can be exposed to user but is private
4 participants