mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
clock: Add clock_ns_to_ticks() function
Add a clock_ns_to_ticks() function which does the opposite of clock_ticks_to_ns(): given a duration in nanoseconds, it returns the number of clock ticks that would happen in that time. This is useful for devices that have a free running counter register whose value can be calculated when it is read. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Luc Michel <luc@lmichel.fr> Reviewed-by: Hao Wu <wuhaotsh@google.com> Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-id: 20210219144617.4782-4-peter.maydell@linaro.org
This commit is contained in:
parent
e4341623a3
commit
cd3a53b727
2 changed files with 53 additions and 0 deletions
|
@ -360,6 +360,18 @@ rather than simply passing it to a QEMUTimer function like
|
|||
``timer_mod_ns()`` then you should be careful to avoid overflow
|
||||
in those calculations, of course.)
|
||||
|
||||
Obtaining tick counts
|
||||
---------------------
|
||||
|
||||
For calculations where you need to know the number of ticks in
|
||||
a given duration, use ``clock_ns_to_ticks()``. This function handles
|
||||
possible non-whole-number-of-nanoseconds periods and avoids
|
||||
potential rounding errors. It will return '0' if the clock is stopped
|
||||
(i.e. it has period zero). If the inputs imply a tick count that
|
||||
overflows a 64-bit value (a very long duration for a clock with a
|
||||
very short period) the output value is truncated, so effectively
|
||||
the 64-bit output wraps around.
|
||||
|
||||
Changing a clock period
|
||||
-----------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue