[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250827.133222.2149987174177655942.fujita.tomonori@gmail.com>
Date: Wed, 27 Aug 2025 13:32:22 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: daniel.almeida@...labora.com
Cc: a.hindborg@...nel.org, alex.gaynor@...il.com, ojeda@...nel.org,
aliceryhl@...gle.com, anna-maria@...utronix.de, bjorn3_gh@...tonmail.com,
boqun.feng@...il.com, dakr@...nel.org, frederic@...nel.org,
gary@...yguo.net, jstultz@...gle.com, linux-kernel@...r.kernel.org,
lossin@...nel.org, lyude@...hat.com, rust-for-linux@...r.kernel.org,
sboyd@...nel.org, tglx@...utronix.de, tmgross@...ch.edu,
acourbot@...dia.com
Subject: Re: [PATCH v1 2/2] rust: Add read_poll_timeout_atomic function
On Wed, 27 Aug 2025 09:35:59 +0900 (JST)
FUJITA Tomonori <fujita.tomonori@...il.com> wrote:
>>> +pub fn read_poll_timeout_atomic<Op, Cond, T>(
>>> + mut op: Op,
>>> + mut cond: Cond,
>>> + delay_delta: Delta,
>>> + timeout_delta: Delta,
>>> +) -> Result<T>
>>> +where
>>> + Op: FnMut() -> Result<T>,
>>> + Cond: FnMut(&T) -> bool,
>>> +{
>>> + let mut left_ns = timeout_delta.as_nanos();
>>> + let delay_ns = delay_delta.as_nanos();
>>> +
>>> + loop {
>>> + let val = op()?;
>>> + if cond(&val) {
>>> + // Unlike the C version, we immediately return.
>>> + // We know the condition is met so we don't need to check again.
>>> + return Ok(val);
>>> + }
>>> +
>>> + if left_ns < 0 {
>>> + // Unlike the C version, we immediately return.
>>> + // We have just called `op()` so we don't need to call it again.
>>> + return Err(ETIMEDOUT);
>>> + }
>>> +
>>> + if !delay_delta.is_zero() {
>>> + udelay(delay_delta);
>>> + left_ns -= delay_ns;
>>> + }
>>> +
>>> + cpu_relax();
>>> + left_ns -= 1;
>>
>> A comment on the line above would be nice.
>
> As I wrote in another email, the C version was changed to avoid using
> ktime, and that’s when the code above was added. I assume the delay is
> considered as 1ns as a compromise because ktime can’t be used.
>
> Maybe this comment should be added to the C version instead?
I meant that if we add a comment here, maybe it should be added to the
C version.
Powered by blists - more mailing lists