Re: [PATCH net-next v2 2/6] rust: time: Introduce Delta type
From: FUJITA Tomonori
Date: Tue Oct 15 2024 - 08:14:09 EST
On Sat, 5 Oct 2024 20:02:55 +0200
Andrew Lunn <andrew@xxxxxxx> 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?
After investigating ktime_us_delta() and ktime_ms_delta() users, I
found that ten or so places which use nagative Deltas like:
timedout_ktime = ktime_add_us(ktime_get(), some_usecs);
// Do something that takes time
remaining = ktime_us_delta(timedout_ktime, ktime_get());
if (remaining > 0)
fsleep(remaining)
Looks straightforward. On second thought, I feel it would be better to
support nagative Deltas. We could use i64 everywhere.
And i64 is more compatible with Ktime Delta APIs; ktime_us_delta and
ktime_ms_delta returns s64; we create Delta without type conversion.