[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <3E41A50E-3D33-4B66-AEBB-91870298137D@collabora.com>
Date: Wed, 27 Aug 2025 09:22:50 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: FUJITA Tomonori <fujita.tomonori@...il.com>,
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,
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 27 Aug 2025, at 09:19, Danilo Krummrich <dakr@...nel.org> wrote:
>
> On Wed Aug 27, 2025 at 2:14 PM CEST, Daniel Almeida wrote:
>> Hi Danilo,
>>
>> […}
>>
>>>
>>> Actually, let me put it in other words:
>>>
>>> let val = read_poll_timeout_atomic(
>>> || {
>>> // Fetch the offset to read from from the HW.
>>> let offset = io.read32(0x1000);
>>>
>>> // HW needs a break for some odd reason.
>>> udelay(100);
Why would we have a delay here? Can’t this be broken into two calls to
read_poll_timeout_atomic()? That would be equivalent to what you wrote
IIUC.
>>>
>>> // Read the actual value.
>>> io.try_read32(offset)
>>> },
>>> |val: &u32| *val == HW_READY,
>>> Delta::from_micros(0), // No delay, keep spinning.
>>> Delta::from_millis(10), // Timeout after 10ms.
>>> )?;
>>>
>>> Seems like a fairly reasonable usage without knowing the implementation details
>>> of read_poll_timeout_atomic(), right?
>>>
>>> Except that if the hardware does not become ready, this will spin for 16.67
>>> *minutes* -- in atomic context. Instead of the 10ms the user would expect.
This is where you lost me. Where does the 16.67 come from?
>>>
>>> This would be way less error prone if we do not provide a timeout value, but a
>>> retry count.
>>>
>>>> Instead, I think it makes much more sense to provide a retry count as function
>>>> argument, such that the user can specify "I want a dealy of 100us, try it 100
>>>> times".
>>>>
>>>> This way it is transparent to the caller that the timeout may be significantly
>>>> more than 10ms depending on the user's implementation.
>>>>
>>>> As for doing this in C vs Rust: I don't think things have to align in every
>>>> implementation detail. If we can improve things on the Rust side from the
>>>> get-go, we should not stop ourselves from doing so, just because a similar C
>>>> implementation is hard to refactor, due to having a lot of users already.
>>
>> I must say I do not follow. Can you expand yet some more on this?
>
> Sure, but it would help if you could clarify which aspect you want me to expand
> on. :)
Powered by blists - more mailing lists