Subject: Re: [PATCH v11 4/8] rust: time: Introduce Instant type

From: Andreas Hindborg <[email-masked]>
Date: Thu, 03 Apr 2025 12:41:52 +0200

"FUJITA Tomonori" <[email-masked]> writes:

> On Sat, 22 Mar 2025 14:58:16 +0100
> Andreas Hindborg <[email-masked]> wrote:
>
>> FUJITA Tomonori <[email-masked]> 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 <[email-masked]>
>>> Reviewed-by: Boqun Feng <[email-masked]>
>>> Reviewed-by: Gary Guo <[email-masked]>
>>> Reviewed-by: Fiona Behrens <[email-masked]>
>>> Signed-off-by: FUJITA Tomonori <[email-masked]>
>>
>>
>> Reviewed-by: Andreas Hindborg <[email-masked]>
>>
>>
>> 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/[email-masked]