Re: [PATCH v2 1/4] rust: time: add jiffies conversion helpers to Delta

FUJITA Tomonori <[email protected]>
Newsgroups org.kernel.vger.rust-for-linux
Message-ID <[email protected]>
On Wed, 15 Jul 2026 15:38:17 +0100
"Gary Guo" <[email protected]> wrote:

> On Wed Jul 15, 2026 at 3:22 PM BST, Miguel Ojeda wrote:
>> On Wed, Jul 15, 2026 at 3:34 PM Andreas Hindborg <[email protected]> wrote:
>>>
>>> I think widening to 128 bits is fine. My question is why `NSEC_PER_SEC
>>> as u128` instead of `u128::from(NSEC_PER_SEC)`?
>>
>> Yes, please avoid casts if possible.
>>
>> Regarding `u128` -- please make sure it works in 32-bit architectures.
>> It seems like you are doing a 128-bit multiplication there?
> 
> This will also need a division when HZ is not a factor of NSEC_PER_SEC -- which
> will be the case for HZ_300.
> 
> This should just limit the precision by doing a multiplication with
> (USEC_PER_SEC / HZ) like jiffies_to_usecs.

Agreed.

Device drivers use jiffies_to_usecs() rather than
jiffies64_to_nsecs(), so the microsecond precision from a plain
(USEC_PER_SEC / HZ) multiplication should be sufficient here.

I'll implement it with that logic in v3.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.