Fix-Point opened a new pull request, #17316: URL: https://github.com/apache/nuttx/pull/17316
## Summary Part II of the PR https://github.com/apache/nuttx/pull/17276. This part of commits introduce `clockcount`, the time conversion API. We provide a unified ClockCount(clockcount.h) layer for fast and safe time conversions, including: - `count` to `timespec` - `count` to `tick` - `timespec` to `count` - `tick` to `count` We notice that there always at least two divisions in timing conversion. So clockcount implements two methods to accelerate time conversion: 1. Invariant Divisor Division Optimization: Used for converting counts to seconds or ticks. It can be enabled via `CONFIG_ONESHOT_FAST_DIVISION`. This division optimization can transforms a division into: - one unsigned high multiplication (`UMULH`), - one subtraction, - one addition, and - one logical right shift (`LShR`). Please note that Invariant Divisor Division Optimization does not necessarily provide a performance advantage. It is related to the overhead of `UMULH` and `UDIV` instructions on different CPU platforms. E.g. On early ARMv8A platforms (Cortex A-53), `UMULH` took 6 CPU cycles, which meant that enabling optimization was actually less efficient than direct division using the `UDIV` instructions. 2. Multiply-Shift Approximate Division: Used to convert delta counts into nanoseconds or ticks. Note this was enabled by default. If extramely precise time conversion is required, it should be disable. This method trades off slight precision (a few nanoseconds) for better performance. However, due to potential multiplication overflow, it is only suitable for relative time conversions. The first method is exact, but takes about 6-9 CPU cycles. The approximate approach requires only one unsigned multiplication and one `LShR`, typically consuming around 4 CPU cycles, making it significantly faster. Combining 1 and 2, we can achieve a fast and precise time conversion. ## Impact Currently `clockcount` is unused, so it should has no effect on NuttX. ## Testing Tested on qemu-intel64/qemu-armv7a/qemu-armv8a/rv-virt/sim, ostest passed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
