Re: [PATCH 1/4] clock: Introduce clock_ticks_to_ns()

2020-12-10 Thread Richard Henderson
On 12/10/20 2:47 PM, Peter Maydell wrote: >> With the shift, you're discarding the high 32 bits of the result. You'll >> lose >> those same bits if you shift one of the inputs left by 32, and use only the >> high part of the result, e.g. >> >> mulu(&discard, &ret, clk->period, ticks << 32); >

Re: [PATCH 1/4] clock: Introduce clock_ticks_to_ns()

2020-12-10 Thread Peter Maydell
On Tue, 8 Dec 2020 at 23:39, Richard Henderson wrote: > > On 12/8/20 12:15 PM, Peter Maydell wrote: > > +static inline uint64_t clock_ticks_to_ns(const Clock *clk, uint64_t ticks) > > +{ > > +uint64_t ns_low, ns_high; > > + > > +/* > > + * clk->period is the period in units of 2^-32 ns

Re: [PATCH 1/4] clock: Introduce clock_ticks_to_ns()

2020-12-09 Thread Richard Henderson
On 12/9/20 8:26 AM, Peter Maydell wrote: > (print "Welcome to the end of the universe" and exit?) Sounds appropriately Hitchhiker's Guide. ;-) r~

Re: [PATCH 1/4] clock: Introduce clock_ticks_to_ns()

2020-12-09 Thread Peter Maydell
On Wed, 9 Dec 2020 at 14:11, Richard Henderson wrote: > This function is truncating back to 64.0, dropping the 32 high bits and 32 low > bits. We lose bits at 2^64 ns ~= 584 years. Which is still unreasonably > long, > but could still be had from a timer setting ~= never. > > An alternate to an

Re: [PATCH 1/4] clock: Introduce clock_ticks_to_ns()

2020-12-09 Thread Richard Henderson
On 12/9/20 2:49 AM, Luc Michel wrote: > On 12/9/20 12:39 AM, Richard Henderson wrote: >> On 12/8/20 12:15 PM, Peter Maydell wrote: >>> The clock_get_ns() API claims to return the period of a clock in >>> nanoseconds. Unfortunately since it returns an integer and a >>> clock's period is represented

Re: [PATCH 1/4] clock: Introduce clock_ticks_to_ns()

2020-12-09 Thread Luc Michel
On 12/9/20 12:39 AM, Richard Henderson wrote: On 12/8/20 12:15 PM, Peter Maydell wrote: The clock_get_ns() API claims to return the period of a clock in nanoseconds. Unfortunately since it returns an integer and a clock's period is represented in units of 2^-32 nanoseconds, the result is often a

Re: [PATCH 1/4] clock: Introduce clock_ticks_to_ns()

2020-12-08 Thread Richard Henderson
On 12/8/20 12:15 PM, Peter Maydell wrote: > The clock_get_ns() API claims to return the period of a clock in > nanoseconds. Unfortunately since it returns an integer and a > clock's period is represented in units of 2^-32 nanoseconds, > the result is often an approximation, and calculating a clock

[PATCH 1/4] clock: Introduce clock_ticks_to_ns()

2020-12-08 Thread Peter Maydell
The clock_get_ns() API claims to return the period of a clock in nanoseconds. Unfortunately since it returns an integer and a clock's period is represented in units of 2^-32 nanoseconds, the result is often an approximation, and calculating a clock expiry deadline by multiplying clock_get_ns() by a