Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware Logging #595

Merged
merged 7 commits into from
Mar 14, 2024
Merged

Hardware Logging #595

merged 7 commits into from
Mar 14, 2024

Conversation

xThaid
Copy link

@xThaid xThaid commented Feb 29, 2024

Inspired by recent PR with assertions, I made a draft of a small utility for logging various events. The usage would be simple - call
log.debug(m, trigger, "message with formats, e.g. {:08x}", pc) somewhere in the circuit and then during the simulation, a log message would be printed whenever trigger is high with the signals provided.

I think this could also supersede assertions - a specific level of logging (could be error) could basically raise an assertion whenever a trigger is high.

As an example, I added one log to the jumpbranch unit and this is an excerpt from the output of the test:

DEBUG 477 coreblocks/fu/jumpbranch.py:212] jumping from 0x00002150 to 0x00002154; misprediction: 1
DEBUG 478 coreblocks/fu/jumpbranch.py:212] jumping from 0x0000215c to 0x00002160; misprediction: 0
DEBUG 494 coreblocks/fu/jumpbranch.py:212] jumping from 0x00002152 to 0x00002156; misprediction: 1
DEBUG 495 coreblocks/fu/jumpbranch.py:212] jumping from 0x00002154 to 0x00002240; misprediction: 1
DEBUG 498 coreblocks/fu/jumpbranch.py:212] jumping from 0x0000215c to 0x00002160; misprediction: 0
DEBUG 501 coreblocks/fu/jumpbranch.py:212] jumping from 0x00002166 to 0x00002168; misprediction: 0
DEBUG 502 coreblocks/fu/jumpbranch.py:212] jumping from 0x00002168 to 0x0000216c; misprediction: 1
DEBUG 521 coreblocks/fu/jumpbranch.py:212] jumping from 0x0000215c to 0x00002160; misprediction: 0
DEBUG 522 coreblocks/fu/jumpbranch.py:212] jumping from 0x00002166 to 0x0000216a; misprediction: 1
DEBUG 523 coreblocks/fu/jumpbranch.py:212] jumping from 0x0000216a to 0x0000216e; misprediction: 1
DEBUG 524 coreblocks/fu/jumpbranch.py:212] jumping from 0x0000216c to 0x00002240; misprediction: 1

It integrates with cocotb nicely:
image

TODO:

  • support for cocotb
  • CLI flags for setting the level
  • unify with assertions?
  • doc strings

To test it you can run either:

$ pytest --log-level=debug -vs -k test_jb_unit.py
$ pytest --coreblocks-regression --log-level DEBUG --coreblocks-log-filter "wishbone" -vs -k "rv32uc-rvc"
$ pytest --coreblocks-regression --log-level DEBUG --coreblocks-log-filter "backend" --coreblocks-backend pysim -vs -k "rv32uc-rvc"

@xThaid xThaid added infrastructure CI, testing, etc. tests Tests and testbenches (not infrastructure) enhancement New feature or request nice to have Could be useful, but not a top priority and removed infrastructure CI, testing, etc. labels Feb 29, 2024
@tilk
Copy link
Member

tilk commented Feb 29, 2024

Looks pretty cool - this makes another software development comfort available in hardware..

@xThaid xThaid marked this pull request as ready for review March 5, 2024 11:46
@tilk
Copy link
Member

tilk commented Mar 5, 2024

An idea - maybe the log entries should also contain some sort of subsystem identifiers? This way, a given subsystem might make log entries at different log levels, and it would be possible to filter both on log levels and subsystems.

@xThaid xThaid changed the title Debug logs Hardware debug logging Mar 9, 2024
@xThaid xThaid changed the title Hardware debug logging Hardware Logging Mar 9, 2024
@xThaid xThaid requested review from tilk and lekcyjna123 March 12, 2024 16:11
the log messages. Adapted from https://stackoverflow.com/a/56944256/3638629
"""

magenta = "\033[0;35m"
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't there any python library to print text in color?

Copy link
Author

Choose a reason for hiding this comment

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

I don't want to add another dependency for such a simple functionality.

def run_benchmarks_with_pysim(
benchmarks: list[str],
traces: bool,
) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this is multiline now, when there is less arguments?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

@tilk
Copy link
Member

tilk commented Mar 14, 2024

Waiting on branch conflicts.

@tilk tilk merged commit 1c273ff into kuznia-rdzeni:master Mar 14, 2024
8 checks passed
github-actions bot pushed a commit that referenced this pull request Mar 14, 2024
tilk pushed a commit to kuznia-rdzeni/transactron that referenced this pull request Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request nice to have Could be useful, but not a top priority tests Tests and testbenches (not infrastructure)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants