lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250403.134038.2188356790179825602.fujita.tomonori@gmail.com>
Date: Thu, 03 Apr 2025 13:40:38 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: a.hindborg@...nel.org
Cc: fujita.tomonori@...il.com, linux-kernel@...r.kernel.org,
 daniel.almeida@...labora.com, boqun.feng@...il.com, gary@...yguo.net,
 me@...enk.dev, rust-for-linux@...r.kernel.org, netdev@...r.kernel.org,
 andrew@...n.ch, hkallweit1@...il.com, tmgross@...ch.edu, ojeda@...nel.org,
 alex.gaynor@...il.com, 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,
 jstultz@...gle.com, sboyd@...nel.org, mingo@...hat.com,
 peterz@...radead.org, juri.lelli@...hat.com, vincent.guittot@...aro.org,
 dietmar.eggemann@....com, rostedt@...dmis.org, bsegall@...gle.com,
 mgorman@...e.de, vschneid@...hat.com, tgunders@...hat.com,
 david.laight.linux@...il.com
Subject: Re: [PATCH v11 4/8] rust: time: Introduce Instant type

On Sat, 22 Mar 2025 14:58:16 +0100
Andreas Hindborg <a.hindborg@...nel.org> wrote:

> FUJITA Tomonori <fujita.tomonori@...il.com> 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@...labora.com>
>> Reviewed-by: Boqun Feng <boqun.feng@...il.com>
>> Reviewed-by: Gary Guo <gary@...yguo.net>
>> Reviewed-by: Fiona Behrens <me@...enk.dev>
>> Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
> 
> 
> Reviewed-by: Andreas Hindborg <a.hindborg@...nel.org>
> 
> 
> 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.


>> -/// Returns the number of milliseconds between two ktimes.
>> -#[inline]
>> -pub fn ktime_ms_delta(later: Ktime, earlier: Ktime) -> i64 {
>> -    (later - earlier).to_ms()
>> -}
>> -
>> -impl core::ops::Sub for Ktime {
>> -    type Output = Ktime;
>> +impl core::ops::Sub for Instant {
>> +    type Output = Delta;
>>  
>> +    // By the type invariant, it never overflows.
>>      #[inline]
>> -    fn sub(self, other: Ktime) -> Ktime {
>> -        Self {
>> -            inner: self.inner - other.inner,
>> +    fn sub(self, other: Instant) -> Delta {
>> +        Delta {
>> +            nanos: self.inner - other.inner,
> 
> If this never overflows by invariant, would it make sense to use
> `unchecked_sub` or `wraping_sub`? That would remove the overflow check.

Yeah, I think that it can. But I prefer to keep the code as is to
catch a bug.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ