[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250129.140429.1135515133511021153.fujita.tomonori@gmail.com>
Date: Wed, 29 Jan 2025 14:04:29 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: me@...enk.dev
Cc: fujita.tomonori@...il.com, linux-kernel@...r.kernel.org,
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, gary@...yguo.net, 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
Subject: Re: [PATCH v9 5/8] rust: time: Add wrapper for fsleep() function
On Tue, 28 Jan 2025 11:37:41 +0100
Fiona Behrens <me@...enk.dev> wrote:
>> Add a wrapper for fsleep(), flexible sleep functions in
>> include/linux/delay.h which typically deals with hardware delays.
>>
>> The kernel supports several sleep functions to handle various lengths
>> of delay. This adds fsleep(), automatically chooses the best sleep
>> method based on a duration.
>>
>> sleep functions including fsleep() belongs to TIMERS, not
>> TIMEKEEPING. They are maintained separately. rust/kernel/time.rs is an
>> abstraction for TIMEKEEPING. To make Rust abstractions match the C
>> side, add rust/kernel/time/delay.rs for this wrapper.
>>
>> fsleep() can only be used in a nonatomic context. This requirement is
>> not checked by these abstractions, but it is intended that klint [1]
>> or a similar tool will be used to check it in the future.
>>
>> Link: https://rust-for-linux.com/klint [1]
>> Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
>
> One question below, but fine with this as well
>
> Reviewed-by: Fiona Behrens <me@...enk.dev>
Thanks!
>> +pub fn fsleep(delta: Delta) {
>> + // The maximum value is set to `i32::MAX` microseconds to prevent integer
>> + // overflow inside fsleep, which could lead to unintentional infinite sleep.
>> + const MAX_DELTA: Delta = Delta::from_micros(i32::MAX as i64);
>> +
>> + let delta = if (Delta::ZERO..=MAX_DELTA).contains(&delta) {
>> + delta
>> + } else {
>> + // TODO: Add WARN_ONCE() when it's supported.
>> + MAX_DELTA
>> + };
>
> Did you try that with std::cmp::Ord you derived on Delta? This `.contains` looks a bit weird, maybe it also works with `delta <= MAX_DELTA`?
Do you mean using either if or match?
The link to the discussion that led to the current implementation is:
https://lore.kernel.org/lkml/CANiq72nNsmuQz1mEx2ov8SXj_UAEURDZFtLotf4qP2pf+r97eQ@mail.gmail.com/#t
Powered by blists - more mailing lists