Re: [PATCH v11 4/8] rust: time: Introduce Instant type
From: Andreas Hindborg
Date: Thu Apr 03 2025 - 06:42:17 EST
"FUJITA Tomonori" <fujita.tomonori@xxxxxxxxx> writes:
> On Sat, 22 Mar 2025 14:58:16 +0100
> Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>
>> FUJITA Tomonori <fujita.tomonori@xxxxxxxxx> writes:
>>
>>> Introduce a type representing a specific point in time. We could use
>>> the Ktime type but C's ktime_t is used for both timestamp and
>>> timedelta. To avoid confusion, introduce a new Instant type for
>>> timestamp.
>>>
>>> Rename Ktime to Instant and modify their methods for timestamp.
>>>
>>> Implement the subtraction operator for Instant:
>>>
>>> Delta = Instant A - Instant B
>>>
>>> Tested-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
>>> Reviewed-by: Boqun Feng <boqun.feng@xxxxxxxxx>
>>> Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
>>> Reviewed-by: Fiona Behrens <me@xxxxxxxxxx>
>>> Signed-off-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxx>
>>
>>
>> Reviewed-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
>>
>>
>> As Boqun mentioned, we should make this generic over `ClockId` when the
>> hrtimer patches land.
>
> Seems that I overlooked his mail. Can you give me a pointer?
>
> I assume that you want the Instance type to vary depending on the
> clock source.
Yea, basically it is only okay to subtract instants if they are derived
from the same clock source. Boqun suggested here [1] before hrtimer
patches landed I think.
At any rate, now we have `kernel::time::ClockId`. It is an enum though,
so I am not sure how to go about it in practice. But we would want
`Instant<RealTime> - Instant<BootTime>` to give a compiler error.
Best regards,
Andreas Hindborg
[1] https://lore.kernel.org/all/ZxwFyl0xIje5gv7J@Boquns-Mac-mini.local