Re: [PATCH 1/4] clock: Change cyc2ns return type to uint64_t

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jules,

On Thu, Mar 25, 2021 at 02:38:34PM +0100, Jules Maselbas wrote:
> Using an uint32_t to count nanosec will overflow every ~4sec, this means
> that if get_time_ns is not called often enough the time keeping will be
> wrong. By changing the return type to uint64_t doesn't fix the underlying
> overflow issue but it will take more than 500 years to happen and I think
> it's safe to assume this won't be an issue.

That's a nice one. I was aware that we'll have overflow issues when the
underlying timer runs over more than once (which can happen quite fast
with 32bit timers), but I wasn't aware that we have a problem after 4
seconds no matter how often the timer overflows.

Applied, thanks

Sascha

> 
> diff --git a/include/clock.h b/include/clock.h
> index d681bf630..e6197e7eb 100644
> --- a/include/clock.h
> +++ b/include/clock.h
> @@ -17,7 +17,7 @@ struct clocksource {
>  	int		(*init)(struct clocksource*);
>  };
>  
> -static inline uint32_t cyc2ns(struct clocksource *cs, uint64_t cycles)
> +static inline uint64_t cyc2ns(struct clocksource *cs, uint64_t cycles)
>  {
>          uint64_t ret = cycles;
>          ret = (ret * cs->mult) >> cs->shift;
> -- 
> 2.17.1
> 
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@xxxxxxxxxxxxxxxxxxx
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux