Re: [PATCH v9] rust: sync: condvar: use Delta<Jiffy> for timeout and result
From: FUJITA Tomonori
Date: Mon Nov 02 2026 - 19:10:09 EST
On Mon, 2 Nov 2026 07:51:29 -0800
Boqun Feng <boqun@xxxxxxxxxx> wrote:
> On Mon, Nov 02, 2026 at 12:59:34PM +0900, FUJITA Tomonori wrote:
>> From: FUJITA Tomonori <fujita.tomonori@xxxxxxxxx>
>>
>> wait_interruptible_timeout() takes the timeout as a raw Jiffies, and
>> CondVarTimeoutResult reports the remaining time as a raw Jiffies. The
>> type does not show the unit.
>>
>> Switch the parameter and the result fields to Delta<Jiffy>.
>>
>> Delta<Jiffy> is signed, but schedule_timeout() prints an error and a
>> stack dump for a negative timeout. Clamp a negative timeout to zero, so
>> it means an immediate timeout.
>>
>> Update the only user, binder. It now converts the freeze timeout with
>> Delta::to_jiffies_timeout() instead of msecs_to_jiffies(). Both round
>> up, so a short timeout does not become zero. They differ only for a
>> very long timeout. msecs_to_jiffies() returns MAX_JIFFY_OFFSET for
>> 2^31 ms (about 24.9 days) or more, which means an infinite
>> timeout. to_jiffies_timeout() has no such special case. It converts
>> such a value to the matching number of jiffies, so the wait is long
>> but finite.
>>
>> Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
>> Signed-off-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxx>
>
> Thanks. Alice, any concern regarding the change in binder?
>
> I have some naming suggestion, please see below:
[...]
>> @@ -248,11 +261,11 @@ pub enum CondVarTimeoutResult {
>> /// Somebody woke us up.
>> Woken {
>> /// Remaining sleep duration.
>> - jiffies: Jiffies,
>> + jiffies: Delta<Jiffy>,
>> },
>> /// A signal occurred.
>> Signal {
>> /// Remaining sleep duration.
>> - jiffies: Jiffies,
>> + jiffies: Delta<Jiffy>,
>
> Similar for these two: s/jiffies/remainder
>
> Thoughts?
Sounds good to me. Now that the type shows the unit, the names should
say what the value means. I'll rename all of them in v10.
I'll wait a few days for Alice's comment on the binder change before
sending v10.