accellera-official / systemc

SystemC Reference Implementation
https://systemc.org/overview/systemc/
Apache License 2.0
451 stars 145 forks source link

Avoid trace files to be outdated from simulation time #1

Closed dhedde closed 2 years ago

dhedde commented 4 years ago

Hi !

We found out recently that trace files are not flushed at the end of a time cycle. The consequence is that some traces can be held back in stdlib buffers. It is not a problem when using trace files in post-mortem analysis. But if we want to use these files during the simulation it is problematic.

The included file shows the case. Using tail -f on the output trace.vcd file while simulation is ongoing shows that traces are coming big chunk by big chunk every few seconds even though traces are generated every 100ms. case.cc.gz

One simple (the attached one) solution is to just add an fflush every time we've generated some traces. This patch just do that on both vcd and wif trace file. This guarantees that trace files are always up-to-date with current simulation time.

Of course the drawback is that it may slow down the simulation speed (especially if there is only a few changing traced signals). Other solutions exist such as adding API to created un-buffered trace files allowing to keep the previous-behavior. Here's an example commit for adding an optional argument to the sc_create_{vcd,wif}_trace_file.

Damien

pah commented 4 years ago

Thanks for your contribution, Damien!

For your contribution to be applicable for consideration by the Accellera working groups, you need to sign-off the Accellera Developer's Certificate of Origin as described in the CONTRIBUTING file.

dhedde commented 4 years ago

Hi Philipp,

I rebased on top of master and added the signed-off line

Sorry for the delay. Damien

AndrewGoodrich commented 2 years ago

This looks fine.