[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241007.150148.1812176549368696434.fujita.tomonori@gmail.com>
Date: Mon, 07 Oct 2024 15:01:48 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: andrew@...n.ch
Cc: fujita.tomonori@...il.com, netdev@...r.kernel.org,
rust-for-linux@...r.kernel.org, hkallweit1@...il.com, tmgross@...ch.edu,
ojeda@...nel.org, alex.gaynor@...il.com, gary@...yguo.net,
bjorn3_gh@...tonmail.com, benno.lossin@...ton.me, a.hindborg@...sung.com,
aliceryhl@...gle.com, anna-maria@...utronix.de, frederic@...nel.org,
tglx@...utronix.de, arnd@...db.de, linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next v2 2/6] rust: time: Introduce Delta type
On Sat, 5 Oct 2024 20:02:55 +0200
Andrew Lunn <andrew@...n.ch> wrote:
>> +/// A span of time.
>> +#[derive(Copy, Clone)]
>> +pub struct Delta {
>> + nanos: i64,
>
> Is there are use case for negative Deltas ? Should this be u64?
I thought that logically Delta could be negative but considering Ktime
APIs like the following, I think that u64 is more appropriate now.
static inline ktime_t ktime_add_us(const ktime_t kt, const u64 usec)
{
return ktime_add_ns(kt, usec * NSEC_PER_USEC);
}
static inline ktime_t ktime_sub_us(const ktime_t kt, const u64 usec)
{
return ktime_sub_ns(kt, usec * NSEC_PER_USEC);
}
>> +}
>> +
>> +impl Delta {
>> + /// Create a new `Delta` from a number of nanoseconds.
>> + #[inline]
>> + pub fn from_nanos(nanos: u16) -> Self {
>
> So here you don't allow negative values.
>
> But why limit it to u16, when the base value is a 63 bits? 65535 nS is
> not very long.
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.
Powered by blists - more mailing lists