Re: [PATCH net-next v2 2/6] rust: time: Introduce Delta type
From: Andrew Lunn
Date: Mon Oct 07 2024 - 09:36:08 EST
> I thought that from_secs(u16) gives long enough duration but
> how about the following APIs?
>
> pub fn from_nanos(nanos: u64)
> pub fn from_micros(micros: u32)
> pub fn from_millis(millis: u16)
>
> You can create the maximum via from_nanos. from_micros and from_millis
> don't cause wrapping.
When i talked about transitive types, i was meaning that to_nanos(),
to_micros(), to_millis() should have the same type as from_nanos(),
to_micros(), and to_millis().
It is clear these APIs cause discard. millis is a lot less accurate
than nanos. Which is fine, the names make that obvious. But what about
the range? Are there values i can create using from_nanos() which i
cannot then use to_millis() on because it overflows the u16? And i
guess the overflow point is different to to_micros()? This API feels
inconsistent to me. This is why i suggested u64 is used
everywhere. And we avoid the range issues, by artificially clamping to
something which can be represented in all forms, so we have a uniform
behaviour.
But i have little experience of dealing with time in the kernel. I
don't know what the real issues are here, what developers have been
getting wrong for the last 30 years etc.
Andrew