Skip to content

Commit

Permalink
Merge pull request #44 from riscv/issue-42-fix
Browse files Browse the repository at this point in the history
Issue 42 fix (cycle counter encoding spec bug)
  • Loading branch information
bcstrongx authored Jan 6, 2025
2 parents 3f3fc99 + 8058188 commit 9c87013
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion body.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ _If implementation of any transfer type filter bit results in reduced software p

The `ctrdata` register may optionally include a count of CPU cycles elapsed since the prior CTR record. The elapsed cycle count value is represented by the CC field, which has a 12-bit mantissa component (Cycle Count Mantissa, or CCM) and a 4-bit exponent component (Cycle Count Exponent, or CCE).

The elapsed cycle counter (CtrCycleCounter) increments at the same rate as the `mcycle` counter. Only cycles while CTR is active are counted, where active implies that the current privilege mode is enabled for recording and CTR is not frozen. The CC field is encoded such that CCE holds 0 if the CtrCycleCounter value is less than 4096, otherwise it holds the index of the most significant one bit in the CtrCycleCounter value, minus 12. CCM holds CtrCycleCounter bits CCE+11:CCE.
The elapsed cycle counter (CtrCycleCounter) increments at the same rate as the `mcycle` counter. Only cycles while CTR is active are counted, where active implies that the current privilege mode is enabled for recording and CTR is not frozen. The CC field is encoded such that CCE holds 0 if the CtrCycleCounter value is less than 4096, otherwise it holds the index of the most significant one bit in the CtrCycleCounter value, minus 11. CCM holds CtrCycleCounter bits CCE+10:CCE-1.

The elapsed cycle count can then be calculated by software using the following formula:

Expand Down

0 comments on commit 9c87013

Please sign in to comment.