Skip to content

Conversation

@Max042004
Copy link
Contributor

@Max042004 Max042004 commented Nov 7, 2025

Previous commit 78836cf prevents frequently update of rv->csr_cycle by manipulate it with register. However, currently rv->csr_cycle only update after a block end or JIT clearing block map. This results csr cycle instructions cannot fetch up-to-date cycle. If csr cycle instructions are located in a same block, leading to the result cycle count becomes zero.

This commit updates rv->csr_cycle everytime before csr instruction is executed.


Summary by cubic

Synchronizes cycle and instret CSR reads by updating rv->csr_cycle right before those CSRs execute, so they return the current value even within the same block. Fixes cases where these CSRs could read zero or stale counts until block end.

  • Bug Fixes
    • Sync rv->csr_cycle only when accessing CSR_CYCLE/CYCLEH or CSR_INSTRET/INSTRETH in csrrw/csrrs/csrrc and their immediate variants.

Written for commit f69568a. Summary will update automatically on new commits.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Benchmarks

Benchmark suite Current: f69568a Previous: 1e5e3f8 Ratio
Dhrystone 1318 Average DMIPS over 10 runs 1303 Average DMIPS over 10 runs 0.99
Coremark 914.12 Average iterations/sec over 10 runs 916.441 Average iterations/sec over 10 runs 1.00

This comment was automatically generated by workflow using github-action-benchmark.

cubic-dev-ai[bot]

This comment was marked as resolved.

@jserv

This comment was marked as resolved.

@jserv jserv requested a review from vacantron November 7, 2025 15:20
@Max042004 Max042004 changed the title Fix csr cycle unasyc Fix csr cycle unasync Nov 11, 2025
@sysprog21 sysprog21 deleted a comment from cubic-dev-ai bot Nov 11, 2025
@jserv jserv requested a review from visitorckw November 11, 2025 06:41
@sysprog21 sysprog21 deleted a comment from cubic-dev-ai bot Nov 11, 2025
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Enforce the rules specified in https://cbea.ms/git-commit/ carefully.

Previous commit 78836cf prevents frequently update of rv->csr_cycle
by manipulate it with register. However, currently rv->csr_cycle only
update after a block end or JIT clearing block map. This results csr
cycle instructions cannot fetch up-to-date cycle.
If started cycle and ended cycle are located in a same block, it cause
the cycle count becomes zero.

This commit updates rv->csr_cycle before csr cycle instruction is
executed.
cubic-dev-ai[bot]

This comment was marked as resolved.

@jserv jserv merged commit 68fa45a into sysprog21:master Nov 12, 2025
8 of 11 checks passed
@jserv
Copy link
Contributor

jserv commented Nov 12, 2025

Thank @Max042004 for contributing!

@jserv jserv added this to the release-2025.2 milestone Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants