mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] clock: Change cyc2ns return type to uint64_t
@ 2021-03-25 13:38 Jules Maselbas
  2021-03-25 13:38 ` [PATCH 2/4] clock: Update cs->cycle_last when switching clock Jules Maselbas
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jules Maselbas @ 2021-03-25 13:38 UTC (permalink / raw)
  To: barebox; +Cc: Jules Maselbas

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.

Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
 include/clock.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-25 13:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-25 13:38 [PATCH 1/4] clock: Change cyc2ns return type to uint64_t Jules Maselbas
2021-03-25 13:38 ` [PATCH 2/4] clock: Update cs->cycle_last when switching clock Jules Maselbas
2021-03-25 13:38 ` [PATCH 3/4] clock: Remove time_beginning Jules Maselbas
2021-03-25 13:38 ` [PATCH 4/4] common: common_console: Rework log_print Jules Maselbas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox